createMesh#setMaterial¶
Summary¶
createMesh#setMaterial replaces a mesh's shading material while keeping its geometry and transform. The mesh takes the caller's existing reference to the replacement and releases its reference to the old material.
Syntax¶
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
material |
Material |
Yes | Live material. When switching to a different material that another owner also uses, call retain() first to acquire the reference the mesh will take. |
Returns¶
this - The same mesh, for chaining. Passing its current material leaves ownership unchanged. Calling on a destroyed mesh throws.
Example¶
const mesh = wgpu.createMesh(wgpu.geometry.box(), wgpu.material.unlit());
mesh.setMaterial(wgpu.material.standard());
mesh.destroy();