获取飞机的世界位置

时间:2019-11-12 11:35:53

标签: three.js

我是three.js的新手,所以我确定我对这里的事情有所了解。

我以以下方式创建了飞机:

var planeGeom = new THREE.PlaneGeometry(0.2, 0.2);
planeGeom.rotateX(-Math.PI / 2);
var plane = new THREE.Mesh(planeGeom, new THREE.MeshBasicMaterial({color: 0xffff00, side: THREE.DoubleSide}));
plane.position.set(0, 0.1, 0);
scene.add(plane);

var mathPlane = new THREE.Plane();
planePointA.copy(plane.geometry.vertices[plane.geometry.faces[0].a]);
planePointB.copy(plane.geometry.vertices[plane.geometry.faces[0].b]);
planePointC.copy(plane.geometry.vertices[plane.geometry.faces[0].c]);
plane.localToWorld(planePointA);
plane.localToWorld(planePointB);
plane.localToWorld(planePointC);
mathPlane.setFromCoplanarPoints(planePointA, planePointB, planePointC);

var helper = new THREE.PlaneHelper( mathPlane, 1, 0xffff00 );
scene.add( helper );

为什么我的PlaneGeometry对象和Plane的位置不同?为什么.localToWorld()无法获得飞机的世界位置?

https://jsfiddle.net/sek0yzLp/

1 个答案:

答案 0 :(得分:1)

在设置其位置后,在.updateMatrixWorld()上使用plane

plane.position.set(0, 0.1, 0);
plane.updateMatrixWorld();
scene.add(plane);