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
263 views
in Technique[技术] by (71.8m points)

javascript - Three.js add an object to a group but keep global position/rotation/scale as it was

I want to move an object from one group (or world/scene) to another group, but keep it's global transformation intact. Basically, I don't want to see the object change.

basically, something like this:

//store current world transformation
var origWorldMatrix = myObject.matrixWorld.clone();

//move object to a group (that is positioned and rotated arbitrarily)
someGroup.add( myObject );

//restore previous world transformation
myObject.matrixWorld.copy( origWorldMatrix );

However, this doesn't seem to work. I guess because the world matrix is always updated the next frame, based on the local position/rotation/scale properties. I've tried to use this with matrixAutoUpdate = false, but that doesn't seem to work either.

The result I am trying to accomplish seems like something that should be simple to do, so I hope I am missing something obvious. Can anybody give me a clue on how do do this?

Thanks!

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

EDIT: You can use the built-in method Object3D.attach():

// add object as a child of parent, while maintaining the object's world transform

parent.attach( object );

three.js r.109


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

...