2014-04-11 1 views
0

두 개의 메시가 추가 된 THREE.ScenemeshAmeshB이며, 각각 다른 방식으로 회전되었습니다. 제 목표는 meshB을 장면에서 제거하고 meshA의 하위 항목으로 다시 추가하는 것입니다. 글로벌 위치와 순환 게재를 유지하는 것, 즉 meshB의 위치와 순환은이 코드 전후에 동일하게 나타나야합니다. 다음과 같이Three.js - 상대 회전 계산

나의 현재 거의 작업 시도는 다음과 같습니다

var globalOffset = new THREE.Vector3().subVectors(meshB.position, meshA.position); 
var localOffset = meshA.worldToLocal(meshB.position); 

var rotationOffset = meshA.quaternion.clone().inverse(); 
var rotation = meshB.quaternion.clone().multiply(rotationOffset); 

scene.remove(meshB); 
meshA.add(meshB); 

meshB.position = localOffset; 
meshB.rotation.setFromQuaternion(rotation); 

위치 결정이 잘 작동; 회전은 meshAmeshB이 모두 같은 축을 중심으로 회전 한 경우에만 작동합니다. meshAmeshB을 다른 축을 중심으로 회전하면 meshB이이 코드 전후로 회전을 전환하는 것처럼 보입니다.

위의 코드 (또는 다른 접근법에 대한 아이디어)를 수정하여 이전에 동일한 "전역"회전을 제거하고 장면에 다시 추가 한 아이디어가 있습니까?

감사합니다.

답변

2

그냥 작업을 수행하는 three.js를 도구를 사용할 수 있습니다

THREE.SceneUtils.detach(child, parent, scene); // remove child from parent and add to scene 

THREE.SceneUtils.attach(child, scene, parent); // remove child from scene and add to parent 

글로벌 방향이 변경되지 않습니다.

3j.r.66