有几个优秀的堆栈问题(1,2)关于three.js所unprojecting,那就是如何转换(X,Y)鼠标在浏览器中的(X,Y,Z)坐标three.js所帆布空间坐标.他们大多遵循这种模式:
var elem = renderer.domElement,
boundingRect = elem.getBoundingClientRect(),
x = (event.clientX - boundingRect.left) * (elem.width / boundingRect.width),
y = (event.clientY - boundingRect.top) * (elem.height / boundingRect.height);
var vector = new THREE.Vector3(
( x / WIDTH ) * 2 - 1,
- ( y / HEIGHT ) * 2 + 1,
0.5
);
projector.unprojectVector( vector, camera );
var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
var intersects = ray.intersectObjects( scene.children );
Run Code Online (Sandbox Code Playgroud)
我一直试图反过来 - 而不是从"屏幕到世界"空间,从"世界到屏幕"空间.如果我知道Three.js中对象的位置,我该如何确定它在屏幕上的位置?
似乎没有任何已发布的解决方案来解决此问题. …