Skip to content

Instantly share code, notes, and snippets.

@ste-vg
Created March 9, 2021 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ste-vg/5db4061898d073bdcc93bc737e4c2d07 to your computer and use it in GitHub Desktop.
Save ste-vg/5db4061898d073bdcc93bc737e4c2d07 to your computer and use it in GitHub Desktop.
const textureLight = textureLoader.load('/textures/matcap-light-512.png')
const textureDark = textureLoader.load('/textures/matcap-dark-512.png')
const materials = {
light: new THREE.MeshMatcapMaterial({ matcap: textureLight }),
dark: new THREE.MeshMatcapMaterial({ matcap: textureDark }),
}
const updateAllMaterials = (scene) =>
{
scene.traverse((child) =>
{
if(child instanceof THREE.Mesh)
{
const type = child.name.split('_')[0]
if(materials[type]) child.material = materials[type];
else console.error(`This mesh name was missing the material type`, child.name)
}
})
}
const models = [
{file: 'model1.glb'},
{file: 'model2.glb'}
]
models.forEach(model =>
{
gltfLoader.load(
`/models/${model.file}`,
(gltf) =>
{
scene.add(gltf.scene)
updateAllMaterials(gltf.scene)
}
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment