Je ne peux pas charger plusieurs objets avec collada et quelques réponses ici en débordement de pile ne fonctionnent pas pour moi. Je l'ai fait avec l'exportation three.js mais avec collada ne fonctionne pas. Voici mon code. Si quelqu'un sait comment serait un épargnant de vie. Merci!Three.js Collada - Charger plusieurs objets Collada dans Three js
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: Ce que je veux faire est de manipuler l'échelle des objets sur les valeurs d'entrée des utilisateurs dans un formulaire. J'ai trouvé cette technick où je charge un fichier colada avec deux objets blender avec des noms différents et avec le code ci-dessous je peux changer l'échelle de Cube, mais l'échelle de Cube.001 ne changera pas. Aussi, si je donne un nom comme 'dsds' le fichier colada ne chargera même pas. Voici le code
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);
});
peut-être 'renderer.render (appareil photo, scène)' dans votre 'render()' fonction? – gaitat
Nop .. Je reçois cette erreur: Uncaught TypeError: Impossible de lire la propriété 'x' de –
où (sur quelle ligne)? – gaitat