2014-11-15 6 views
0

3 가지로 움직이는 물체를 스케일하려고합니다. 그러나 그것을 스케일 할 때 물체를 스케일하고 다른 위치로 옮길 것입니다.Three JS - 움직이는 물체를 어떻게 스케일합니까?

나는 그러나 내 개체는 렌더링 애니메이션에 다음 코드에 대해 이동, 객체 객체에 대해 이동하지 않으면이 작동

// initiates the scale transition 
function doTriangleScale(intersection){ 
    var tween = new TWEEN.Tween(intersection.object.parent.scale) 
    .to({ 
    x: scaleSize, 
    y: scaleSize, 
    z: scaleSize, 
    }, scaleEase) 
    tween.start(); 

    // should have a check if the user is still on the object in question, no time for this now 
    setTimeout(function(){ 
    doTriangleScaleRevert(intersection); 
    }, 2000) 
} 

// triggers the scale revert to default 
function doTriangleScaleRevert(intersection) { 
    var tween = new TWEEN.Tween(intersection.object.parent.scale) 
    .to({ 
    x: 1, 
    y: 1, 
    z: 1 
    }, scaleEase) 
    tween.start(); 
} 

의 규모를 설정하려면 다음을 사용

scene.traverse(function (e) { 
    if (e instanceof THREE.Mesh && e.name != "pyramid") { 

     e.rotation.x += rotationSpeed; 
     e.rotation.y += rotationSpeed; 
     e.rotation.z += rotationSpeed; 

     if(triangleFloatLeft){ 
      e.position.x += 0.01; 
     }else{ 
      e.position.x -= 0.01; 
     } 
    } 
}); 

저는 중심에서 개체의 크기를 조정할 솔루션을 찾고 있습니다.

감사합니다.

답변

4

개체의 원점을 축척합니다. 큐브가있는 경우 예를 들어, : 지오메트리 geo와 메쉬를 확장 할 경우

var geo = new THREE.BoxGeometry(1, 1, 1); 

를, 그것의 중심 주위 성장할 것입니다. 그러나 기하 도형 원점을 이동하는 경우 :

geo.applyMatrix(new THREE.Matrix4().makeTranslation(0, 0.5, 0)); 

원점이 상자의 바닥으로 이동 했으므로 위쪽으로 자랍니다.

개체의 원점은 중심에 있지 않을 가능성이 큽니다. 모델 자체 (가져온 경우) 또는 위와 같이 Three.js에서 원점을 이동할 수 있습니다.

+0

빠른 답변 주셔서 감사합니다. 그래서 정적 인 경우 센터에서 확장하는 이유입니다. 원점도 움직이지 않을 것이기 때문에. 하지만 상자를 움직이면 원점이 움직이지 않을 것입니다. – DennisL

관련 문제