MaterialManager
Manage materials.
Creation
To create a material, first retrieve the class associated to the pipeline using getTemplate:
1const PhongMaterial = engine.materials.getTemplate('Phong Opaque');
Creating a material is then done using the constructor:
- MaterialManager
- ._wrapInstance(instance) ⇒ Material
- .getTemplate<T>(pipeline) ⇒ MaterialConstructor
- .wrap(index) ⇒ null | Material
._wrapInstance(instance: Material) ⇒ Material
Wrap a material instance.
@todo: Remove at 2.0.0.
Note: Wrapping should only be called once per instance.
Returns: The new material, wrapped in a proxy.
Param | Type | Description |
---|---|---|
instance | Material | The material instance. |
.getTemplate<T>(pipeline: string) ⇒ MaterialConstructor
Get the material class with the given pipeline name.
Usage
TypeScript
This method provide a simple way to cast the constructor returned by getTemplate
:
However, this means manually writing types for each pipeline.
Fortunately, 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
.
Material constructors will then be typed automatically when using a string literal pipeline name:
Returns: The material class.
Throws: Error
if the material class doesn’t exist.
Param | Type | Description |
---|---|---|
pipeline | string | The pipeline name to search for. |
Template Param | Type Definition |
---|---|
T | extends Material |
.wrap(index: number) ⇒ null | Material
Param | Type | Description |
---|---|---|
index | number |