Changing Material Properties at Runtime
You can change any material properties you find in the editor at runtime as well. This might be switching the texture for a flipbook, highlighting an object to indicate interactivity or to simply animate the specularity based on weather.
In Wonderland Engine, you can retrieve a material used by a mesh component by retrieving
the component with WL.Object.getComponent or
specify a parameter to your custom component with type WL.Type.Material
.
Change material properties
Changing material properties is as simple as setting the corresponding properties on a WL.Material.
Any property that can be set from the material properties panel, can be set here.
Example: Fade component
The example below animates the alpha value of the material based on time. This could be used as a fade in effect for an object.
Note that every object that uses the material set on the mesh component will be affected by the animation. To make the animation unique to the object, the component uses WL.Material.clone to retrieve a unique instance and set that to the mesh.
|
|
Note that the material properties, like diffuseColor
here, depend on the pipeline and shader
used. You may want to modify flatColor
for “Flat Opaque” instead, for example,
or something completely different for custom shaders.
Any property shown in the material properties panel for the material can be edited in this way.