I am struggling to load multiple objects with collada and the solutions provided on stack overflow are not working for me. While I was successful in loading with three.js export, collada is giving me trouble. I have shared my code below. Any help would be greatly appreciated. Thank you!
function o(){
var loader = new THREE.ColladaLoader();
scene = new THREE.Scene();
loader.options.convertUpAxis = true;
loader.load('nn.dae', function (collada){
dae = collada.scene;
dae.scale.x = dae.scale.y = dae.scale.z = 3;
//dae.updateMatrix();
scene.add(dae);
//console.log(scene);
});
loader.load('erer.dae', function (collada){
dae1 = collada.scene;
dae1.scale.x = dae1.scale.y = dae1.scale.z = 3;
//dae1.updateMatrix();
//scene.add(dae1);
//console.log(scene);
});
init();
animate();
}
o();
function init(){
/*creates empty scene object and renderer*/
camera = new THREE.PerspectiveCamera(45, 600/400, .1, 500);
renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setClearColor(0x000000);
renderer.setSize(600, 400);
renderer.shadowMapEnabled= true;
renderer.shadowMapSoft = true;
/*add controls*/
camera.position.x = 5;
camera.position.y = 9;
camera.position.z = 42;
camera.lookAt(scene.position);
/*datGUI controls object*/
guiControls = new function(){
this.rotationX = 0.0;
this.rotationY = 0.0;
this.rotationZ = 0.0;
this.lightX = 19;
this.lightY = 47;
this.lightZ = 19;
this.intensity = 2.5;
this.distance = 373;
this.angle = 1.6;
this.exponent = 38;
this.shadowCameraNear = 34;
this.shadowCameraFar = 2635;
this.shadowCameraFov = 68;
this.shadowCameraVisible=false;
this.shadowMapWidth=512;
this.shadowMapHeight=512;
this.shadowBias=0.00;
this.shadowDarkness=0.11;
}
/*adds spot light with starting parameters*/
spotLight = new THREE.SpotLight(0xffffff);
spotLight.castShadow = true;
spotLight.position.set (20, 35, 40);
spotLight.intensity = guiControls.intensity;
spotLight.distance = guiControls.distance;
spotLight.angle = guiControls.angle;
spotLight.exponent = guiControls.exponent;
spotLight.shadowCameraNear = guiControls.shadowCameraNear;
spotLight.shadowCameraFar = guiControls.shadowCameraFar;
spotLight.shadowCameraFov = guiControls.shadowCameraFov;
spotLight.shadowCameraVisible = guiControls.shadowCameraVisible;
spotLight.shadowBias = guiControls.shadowBias;
spotLight.shadowDarkness = guiControls.shadowDarkness;
scene.add(spotLight);
/*adds controls to scene*/
$("#webGL-container").append(renderer.domElement);
/*stats*/
}
function render() {
spotLight.position.x = guiControls.lightX;
spotLight.position.y = guiControls.lightY;
spotLight.position.z = guiControls.lightZ;
}
EDIT: I am trying to manipulate the scale of objects based on user input values from a form. I came across a technique where I load a collada file with two blender objects having different names. However, I am facing issues in changing the scale of both objects separately. The provided code only works for changing the scale of Cube, not Cube.001. Also, when I give a different name like 'dsds', the collada file fails to load. Here is the updated code snippet:
loader.options.convertUpAxis = true;
loader.load('vaddsi.dae', function (collada){
dae = collada.scene;
dae.scale.x = dae.scale.y = dae.scale.z = 3;
dae.traverse(function (child){
if (child.colladaId == "Cube.001"){
child.traverse(function(e){
e.castShadow = true;
e.receiveShadow = true;
e.scale.x=0.4;
if (e.material instanceof THREE.Mesh){
//e.material.needsUpdate = true;
}
});
}
if (child.colladaId == "Cube"){
child.traverse(function(e){
e.scale.x=2;
if (e.material instanceof THREE.Mesh){
e.material.needsUpdate = true;
}
});
}
});
dae.updateMatrix();
init();
animate();
console.log(scene);
});