飞机宽度为800px:
geometry = new THREE.PlaneGeometry( 800, 20, 0, 0 );
material = new THREE.MeshBasicMaterial({
color:0xFFFFFF,
side:THREE.DoubleSide
});
mesh = new THREE.Mesh(geometry, material);
mesh.updateMatrixWorld();
scene.add(mesh);
当我尝试操纵它时,使坐标系统成为其他垃圾
mesh.geometry.vertices[0].setY(0);
mesh.geometry.vertices[0].setX(0);
mesh.geometry.vertices[0].setZ(0);
mesh.geometry.vertices[1].setY(0);
mesh.geometry.vertices[1].setX(800);
mesh.geometry.vertices[1].setZ(0);
mesh.geometry.vertices[2].setY(20);
mesh.geometry.vertices[2].setX(0);
mesh.geometry.vertices[2].setZ(0);
mesh.geometry.vertices[3].setY(20);
mesh.geometry.vertices[3].setX(800);
mesh.geometry.vertices[3].setZ(0);
mesh.geometry.verticesNeedUpdate = true;
我可以将几何对象的坐标系调整到相机框架的坐标系吗?
0px = 0
答案 0 :(得分:1)
如果这不是您正在寻找的,我道歉。如果你的意思是你需要将3d世界中的vector3位置转换为屏幕上的2d像素位置,这是一个典型的转换:
getScreenTranslation = function (obj, renderer, camera) {
var vector = new THREE.Vector3();
var widthHalf = 0.5 * renderer.context.canvas.width;
var heightHalf = 0.5 * renderer.context.canvas.height;
vector.setFromMatrixPosition(obj.matrixWorld);
vector.project(camera);
vector.x = vector.x * widthHalf + widthHalf;
vector.y = -(vector.y * heightHalf) + heightHalf;
return {
x: vector.x,
y: vector.y
};
};
请记住,您可能需要在网页中补偿canvas元素的位置。