Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
608 views
in Technique[技术] by (71.8m points)

javascript - Three.js How to get position of a mesh?

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 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 is the url

the site is in Turkish so i will translate the UI items

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 :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...