Three.js如何获得网格的位置?
使用下面的代码,网格的位置将返回为(0,0,0)但不是。那么渲染过程后计算的positioın向量是什么?
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.scene.add(objMesh); //me is a project class
objMesh.updateMatrixWorld(true);
alert(objMesh.position.x + ',' + objMesh.position.y + ',' + objMesh.position.z);
objMesh是从objfile创建的,它被正确地添加到场景中并且质心大约是(-8, 3,0)
但是objMesh的位置向量是(0,0,0)我们必须首先自动计算某些东西,还是应该从网格的几何顶点手动计算它?
objMesh is created from objfile, it is added to the scene correctly and centroid is approx (-8, 3, 0) but position vector of objMesh is (0, 0, 0) do we have to auto calculate something first or should i calculate it manually from geometry vertices of the mesh ?
http://81.214.75.32:8181/admin 是网址
网站是土耳其语所以我将翻译UI项目
the site is in Turkish so i will translate the UI items
在网站上有Dosya菜单项
选择菜单项并选择ProjeAç
a对话框出现
在该对话框中选择MUTFAK_1
场景将在该场景中出现
,每个网格位置为(0,0,0)
是可能的:)
in the site there is "Dosya" menu item oppen the menu item and select "Proje Aç" a dialog appears in that dialog select MUTFAK_1 scene will appear in that scene, every meshes position is (0, 0, 0) is that possible :)
是的。经过与mrdoob的一些谈话,我意识到。对象的位置是他们自己的本地。我的情况是考虑顶点找到网格的中心点。下面是获得质心的代码,该代码来自答案#447( https:// github .com / mrdoob / three.js / issues / 447 )
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...
根据 https://github.com/mrdoob/three更新
.js / wiki / Migration , .addSelf 在r55之后被重命名为 .add
Update
according to https://github.com/mrdoob/three.js/wiki/Migration, the .addSelf had been renamed to .add after r55