我想在三个 JS 中制作一个方向 View 立方体。
"View Cube"
在使用正交相机和 的场景中OrthographicTrackballControls .
我实际上做的是创建一个 View 立方体:
gizmoBox = new THREE.Object3D();
for (var x = -1; x <= 1; x+=1) {
for (var y = -1; y <= 1; y+=1) {
for (var z = -1; z <= 1; z+=1) {
if (/* is a corner coordinate */) {
corner = new THREE.Mesh(...);
...
gizmoBox.add(corner);
} else if (/*is a border coordinate*/) {
edge = new THREE.Mesh( ... );
...
gizmoBox.add(edge);
} else if (/*is a side coordinate */) {
side = new THREE.Mesh(...)
...
gizmoBox.add(side);
/*here, i added some text : FRONT, BACK, ...*/
}
}
}
}
并将其缩放到相机的右上角:
function render() {
...
var vec = new THREE.Vector3( 0.0145 / camera.zoom, 0.012 / camera.zoom, 0.01 / camera.zoom );
vec.applyQuaternion( camera.quaternion );
gizmoBox.position.copy( vec );
gizmoBox.scale.set(0.0015 / camera.zoom, 0.0015 / camera.zoom, 0.0015 / camera.zoom);
...
renderer.render( scene, camera );
}
然后我想使用 View 立方体(缩放前)每个部分的位置作为场景中的“引用点”来进行旋转。所以我在中添加了这个功能OrthographicTrackballControls .
this.rotateViewCube = function (refPoint) {
_rotateEnd.copy(refPoint);
_this.rotateCamera();
};
但它不能正常工作,相机移动但不像我预期的那样。有人作为一个想法?
最佳答案
我自己找到了解决方案。
我从 View Cube 的点击部分获得“引用点”,然后我修改了 中的默认相机位置OrthographicTrackballControls (由位置 0 引用)。最后我重置了它。
var position = intersects[0].object.refPoint;
controls.position0.copy(position);
controls.reset();
关于camera - "Orientation cube"在三个JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31021252/