Select Page

Yes, you can apply color to a GLB (GLTF) model in Three.js.

Here’s an example of how to apply a solid color to a GLB model in Three.js:

const loader = new THREE.GLTFLoader();
loader.load("model.glb", function(gltf) {
  const model = gltf.scene;
  const material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
  model.traverse(function(node) {
    if (node.isMesh) {
      node.material = material;
    }
  });
  scene.add(model);
});

In this example, we use the GLTFLoader class to load the GLB model, and then traverse its hierarchy to find all mesh nodes. For each mesh node, we set its material to a MeshBasicMaterial with a red color (0xff0000).

You can also apply textures or multiple materials to different parts of the GLB model in a similar manner.