"Slow update" of children positions

Hello,
I’m working on my first threejs project and I feel that I’m missing something fundamental. Let’s say I have loaded a model of a tangram. It has a group named “peces”, that contains the pieces as their children.

I change the, scale and rotation of the tangram and add it to the scene, but then, localToWorld() relative to the pieces (in setupPieces() ) is calculated according to the original scale and rotation of the tangram.
If I execute setupPieces() later (frames later), it is set up correctly.

Thanks in advance

setupPuzzle(){

    this.tangram.scale.set(.1,.1,.1);
    this.tangram.position.set(0,0,0);
    this.tangram.name = "tangram";

    this.tangram.rotation.x = -0.065;
    this.tangram.rotation.y = -0.205;
    this.tangram.rotation.z = -0.065;
    this.scene.add( this.tangram );

    this.pieces_tangram = this.tangram.getObjectByName("peces").children
    this.setupPieces();
}

setupPieces(){
    for(var i=0;i<this.pieces_tangram.length;i++){
        this.pieces_tangram[i].geometry.computeBoundingSphere()
        this.pieces_tangram[i].geometry.computeBoundingBox()

        var sphpos = this.pieces_tangram[i].localToWorld(this.pieces_tangram[i].geometry.boundingSphere.center);

        // adding box at the bounding sphere center to debug position
        var box_object = new THREE.Mesh( new THREE.BoxBufferGeometry( 0.1, 0.1, 0.1 ), new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) );
        box_object.position.set(sphpos.x,sphpos.y,sphpos.z);
        this.scene.add( box_object );
    }
}

Notice that this usage will introduce problems since you modify the center vector of the bounding sphere. It should be:

var piece = this.pieces_tangram[i];

var sphpos = piece.geometry.boundingSphere.center.clone();
piece.localToWorld( sphpos );

Thanks for that @Mugen87 - that helped me understand some basic concepts and put me in the right path

1 Like