3 回答

TA貢獻(xiàn)1735條經(jīng)驗 獲得超5個贊
您可以使用以下模式將3D位置轉(zhuǎn)換為屏幕坐標(biāo):
var vector = new THREE.Vector3();
var canvas = renderer.domElement;
vector.set( 1, 2, 3 );
// map to normalized device coordinate (NDC) space
vector.project( camera );
// map to 2D screen space
vector.x = Math.round( ( vector.x + 1 ) * canvas.width / 2 );
vector.y = Math.round( ( - vector.y + 1 ) * canvas.height / 2 );
vector.z = 0;
three.js r.69

TA貢獻(xiàn)1810條經(jīng)驗 獲得超5個贊
對我來說,此功能有效(Three.js版本69):
function createVector(x, y, z, camera, width, height) {
var p = new THREE.Vector3(x, y, z);
var vector = p.project(camera);
vector.x = (vector.x + 1) / 2 * width;
vector.y = -(vector.y - 1) / 2 * height;
return vector;
}
添加回答
舉報