Three.js How to get position of a mesh?

后端 未结 5 498
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 06:44

With the below code, position of a mesh is returned as (0, 0, 0) but it is not. So is the positioın vector calculated after render process?

me.         


        
5条回答
  •  旧巷少年郎
    2020-12-10 07:16

    object.position is always local to the object. If you want to get the position in world space you need to get it from object.matrixWorld.

    Try with this:

    scene.add(objMesh);
    scene.updateMatrixWorld(true);
    var position = new THREE.Vector3();
    position.getPositionFromMatrix( objMesh.matrixWorld );
    alert(position.x + ',' + position.y + ',' + position.z);
    

    r58


    Update:

    The function getPositionFromMatrix() has been renamed to setFromMatrixPosition().

提交回复
热议问题