Share a material with a .mat.json
site/media/lessons/learn-scenefeats.lesson.ts (4 steps) Instead of copying material settings onto every entity, define a material once in a
.mat.json file and point entities at it with materialRef. Change the file and every
referencing entity updates. This scene has three shapes β box, sphere, cylinder β all wearing one
polished-gold material.
-
Open the scene. The scene is already open β if you followed the link above, the shared-material scene is loaded and rendering (in the local dev editor:
VGAI_PROJECT=examples/learn-matfiles npm run dev): three shapes, identical gold finish.
Box, sphere, cylinder β one shared material. -
Select the GoldBox. A cube using the shared gold material (not an inline copy).
The cube references the shared material. -
Select the GoldSphere. Same gold material β reused, not duplicated.
The sphere reuses the same material file. -
Select the GoldCylinder. All three entities
materialRefthe one.mat.json.
One material asset, three entities.
// polished-gold.mat.json (the shared asset){ "version": 1, "name": "Polished Gold", "material": { "type": "standard", "color": "#ffcc33", "metalness": 1.0, "roughness": 0.3 } }
// each entity references it (no inline `material`):"materialRef": "materials/polished-gold.mat.json"Recap
New functionality
- Authored a shared material as a .mat.json
- Referenced it from three entities with materialRef
New concepts & skills
- A .mat.json is { version, name, material } β a reusable material asset
- materialRef points an entity at it; one source, many objects
- materialRef and inline material are mutually exclusive (load-time error)
Next lesson β Materials (manual)
On Your Own!
Extend what you built:
- Edit polished-gold.mat.json (e.g. roughness) and reload β all three update
- Add a fourth shape that materialRefs the same file
- Make a second .mat.json and point one shape at it