Samsy
Samsy

Reputation: 375

Three.js, Imported Camera from Collada can not look at an object scene

Im struggling with Three.js to understand how Collada Animation workout ! I got an animation with a moving camera in 3Dsmax, and i exported the scene into Collada.

loader.load( ColladaName, function ( collada ) {

    model = collada.scene;
    model.updateMatrix();
    animations = collada.animations;
    kfAnimationsLength = animations.length;
    model.scale.x = model.scale.y = model.scale.z = 0.001; // 1/8 scale, modeled in cm
    document.getElementById('preload').style.opacity = '0';

    callback()

} );

I capture the camera object from the collada :

 model.traverse(function(child) {

    if (child instanceof THREE.PerspectiveCamera) {

        camera = child;
        camera.near = 1;
        camera.fov = 30;
        camera.castShadow = true;
    }

    if (child instanceof THREE.SpotLight) {

        child.castShadow = true;

        child.shadowBias = 0.02;

        child.shadowCameraNear = 1;
        child.shadowCameraFov = 60;
        child.intensity = 1.2;

        child.shadowMapWidth = 1024; // default is 1024
        child.shadowMapHeight = 1024; // default is 1024
        child.shadowDarkness = 0.06; // default is 512

    }

});

 camera.aspect = window.innerWidth / window.innerHeight;

 camera.updateProjectionMatrix();

Then i render it in my scene : camera.lookAt(scene.position) renderer.render(scene, camera);

Everything show up, i can see my model, with my imported camera, but my camera doesnt look at the scene and doesnt reproduce the x-rotation like in my 3Dsm zoom in, and zoom out ! If i log the camera position it always show : 0,0,0. Better, if i log the model.children[0] position, wich correspond to the perspective camera imported into the collada, it always show 0,0,0

What am i doing wrong ?

EDIT 1 :

I tried to set my camera matrix with the imported camera from the collada :

camera.matrixNeedsUpdate = true;
model.children[0].matrixNeedsUpdate = true;
model.children[0].lookAt(model.position)

camera.matrix.elements = model.children[0].matrix.elements

but no results unfortunately..

Upvotes: 1

Views: 1243

Answers (1)

mrdoob
mrdoob

Reputation: 19602

I suspect the problem is that you're doing a camera.lookAt() to a position that is in "local space".

Try doing this:

var vector = new THREE.Vector3();
vector.setFromMatrixPosition( object.matrixWorld );

camera.lookAt( vector );

Upvotes: 2

Related Questions