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:
const material = new PhongMaterial();
// Set the `diffuseColor` property
material.setDiffuseColor([1.0, 0.0, 0.0, 1.0]);
console.log(material.getDiffuseColor());
Getters for non-scalar types have an optional argument to skip an array allocation:
const material = new PhongMaterial();
const diffuse = [0, 0, 0, 0];
material.getDiffuseColor(diffuse);
console.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:
// Note the `.js` instead of `.d.ts`
import {PhongOpaque} from './materials.js';
const mesh = object.getComponent('mesh');
const material = mesh.material as PhongOpaque;
material.setDiffuseColor([1, 0, 0, 1]); // Set a red diffuse
Static Members
.constructor(engine, params) ⇒ MaterialMaterial.wrap(engine, index) ⇒ null | Material
Properties
Methods
Constructor
.constructor(engine: WonderlandEngine, params: number | MaterialParameters) ⇒ Material
Deprecated: Use getTemplate via materials to create a new material with a given pipeline:
const PhongMaterial = engine.materials.getTemplate('Phong Opaque');
const material = new PhongMaterial();
material.setDiffuseColor([1, 0, 0]);
| Param | Type | Description |
|---|---|---|
engine | WonderlandEngine | |
params | number | MaterialParameters |
Static Members
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.
| Param | Type | Description |
|---|---|---|
engine | WonderlandEngine | Engine instance. |
index | number | The index. |
Properties
.pipeline: string
Name of the pipeline used by this material.
.shader: string
Deprecated: Use pipeline instead.
Methods
.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.
| Param | Type | Description |
|---|---|---|
name | string | The name to check. |