How to setup materials in THREE.js when loading Collada (dae) models?
Asked Answered
A

1

5

How do I setup materials in THREE.js when loading Collada (dae) models?

I have the following code:

new THREE.ColladaLoader().load('models/cylinder.dae',
  function(collada) {
    var model = collada.scene;
    model.scale.set(10.0, 10.0, 10.0);
        
    // attempt to set a material - doesn't work...
    collada.dae.materials[0] = new THREE.MeshBasicMaterial({
      color: 0xff0000, 
      wireframe: true 
    });
        
    scene.add(model);
});

Thanks for any help.

Anthozoan answered 26/11, 2011 at 21:18 Comment(0)
W
5
var loader = new THREE.ColladaLoader();
loader.options.convertUpAxis = true;
loader.load( './models/cylinder.dae',function colladaReady( collada ) {

model = collada.scene;
model_geometry = collada.scene.children[ 0 ].geometry;
model_material = collada.scene.children[ 0 ].material;

model.scale.set(10.0, 10.0, 10.0);
model.updateMatrix();
});

if you are getting model_material as 'undefined', then take a look at the Collada object

console.log(collada);

sometimes there are children inside children, so you might have to do this:

model_material = collada.scene.children[ 0 ].children[ 0 ].material;

Take a look at the Collada model and then modify it accordingly.

Workman answered 7/6, 2012 at 7:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.