I've searched extensively through the documentation and numerous examples, but I couldn't find the correct syntax for assigning a material to either a Collada .dae or OBJLoader .obj file.
Json files seem to work well when creating a Mesh
, with the loader set as geometry and the material properly assigned.
For example, the following code works:
var loader = new THREE.JSONLoader();
loader.load( "modelPath.js", function(geometry){
var material = new THREE.MeshLambertMaterial({color: 0x666666});
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
});
However, the following code does not work:
var loader = new THREE.ColladaLoader();
loader.load( "modelPath.dae", function(geometry){
var material = new THREE.MeshLambertMaterial({color: 0x666666});
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
});
Similarly, the code below does not work either:
var loader = new THREE.OBJLoader();
loader.load( "modelPath.obj", function(geometry){
var material = new THREE.MeshLambertMaterial({color: 0x666666});
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
});
I have also attempted to set the material within the function(geometry)
, like
geometry.material = new THREE.MeshLambertMaterial({ color: 0xff0000});
, but without success.
The .Dae format seems to retain the material color directly from 3D programs like Cinema 4D. Is there a proper way to assign a material to these loaders? If so, how can it be done?