获取飞机的世界位置

问题描述 投票:0回答:1

我对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对象和平面的位置不同?为什么.localToWorld()无法获得飞机的世界位置?

https://jsfiddle.net/sek0yzLp/

three.js
1个回答
0
投票

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

plane.position.set(0, 0.1, 0);
plane.updateMatrixWorld();
scene.add(plane);
© www.soinside.com 2019 - 2024. All rights reserved.