There are generally three ways to create materials:
Refer to the Model Import and Usage tutorial. First, import the model into the editor. In most cases, the model will automatically bind its material, requiring no user action.
To modify the model's material, click the duplicate and remap
button to generate a copy of the material. Note that Remap will modify the model's preset, affecting all model instances (as shown below):
To modify only a specific model's material, use the incremental modification feature:
Directly drag the material into the scene to bind it.
You can also create or modify materials via scripts. Below is a demo that replaces a material by attaching a script to a cube entity:
export default class extends Script {
onStart() {
// Get all renderers
const renderers = [];
this.entity.getComponentsIncludeChildren(MeshRenderer, renderers);
const renderer = renderers[0];
// Modify material directly
const material = renderer.getMaterial();
material.baseColor.set(1, 0, 0, 1);
// Or replace the material
const pbrMaterial = new PBRMaterial(engine);
const material = renderer.setMaterial(material);
}
}