Three.js How to get position of a mesh?

后端 未结 5 486
被撕碎了的回忆
被撕碎了的回忆 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 06:57

    Yeah. after some talk with mrdoob, i realized that .position of objects are local to theirselves. My situation was to find the center point of my mesh considering the vertices. Below is the code to get the centroid which came from an answer #447 ( https://github.com/mrdoob/three.js/issues/447 )

    geom.centroid = new THREE.Vector3();
    for (var i = 0, l = geom.vertices.length; i < l; i++) {
        geom.centroid.addSelf(geom.vertices[i]);
    }
    geom.centroid.divideScalar(geom.vertices.length);
    

    Now we have centroid of geometry...

    Update according to https://github.com/mrdoob/three.js/wiki/Migration, the .addSelf had been renamed to .add after r55

提交回复
热议问题