Material

1.2.0+

Wrapper around a native material.

For more information about how to create materials, have a look at the MaterialManager class.

Properties 

The material properties are automatically converted into getters/setters:

1const material = new PhongMaterial();
2
3// Set the `diffuseColor` property
4material.setDiffuseColor([1.0, 0.0, 0.0, 1.0]);
5console.log(material.getDiffuseColor());

Getters for non-scalar types have an optional argument to skip an array allocation:

1const material = new PhongMaterial();
2const diffuse = [0, 0, 0, 0];
3material.getDiffuseColor(diffuse);
4console.log(diffuse) // Prints '[1.0, 1.0, 1.0, 1.0]'

Note: Materials are per-engine, they can thus be shared by multiple scenes.

TypeScript 

The Wonderland Editor can automatically generate material definitions (.d.ts) from the project pipelines.

To enable the generation, go to the Project Settings > JavaScript panel and set materialDefinitions to a path, e.g., materials.d.ts.

It’s then possible to cast the material type using:

1// Note the `.js` instead of `.d.ts`
2import {PhongOpaque} from './materials.js';
3
4const mesh = object.getComponent('mesh');
5const material = mesh.material as PhongOpaque;
6material.setDiffuseColor([1, 0, 0, 1]); // Set a red diffuse

.constructor(engine: WonderlandEngine, params: number | MaterialParameters) ⇒ Material 

Deprecated: Use getTemplate via materials to create a new material with a given pipeline:

1const PhongMaterial = engine.materials.getTemplate('Phong Opaque');
2const material = new PhongMaterial();
3material.setDiffuseColor([1, 0, 0]);
ParamTypeDescription
engineWonderlandEngine
paramsnumber | MaterialParameters

.pipeline: string 

Name of the pipeline used by this material.

.shader: string 

Deprecated: Use pipeline instead.

.clone() ⇒ null | Material 

Create a copy of the underlying native material.

Returns: Material clone.

.hasParameter(name: string) ⇒ boolean 

Check whether a parameter exists on this material.

Returns: true if the parameter with name name exists on this material, false otherwise.

ParamTypeDescription
namestringThe name to check.

.toString() ⇒ string 

Material.wrap(engine: WonderlandEngine, index: number) ⇒ null | Material 

Wrap a native material index.

Returns: Material instance or null if index <= 0.

Deprecated: Use the materials instead.

ParamTypeDescription
engineWonderlandEngineEngine instance.
indexnumberThe index.