HY! 我在三个j工作。我正在通过THREE.JSONLoader加载modells。现在,我选择这些物体及其脸部。这是工作。 但现在我想获取所选面的顶点,请检查下面的代码:
intersections = raycaster.intersectObjects( objects );
if ( intersections.length > 0 ) {
if ( intersected != intersections[ 0 ].object ) {
intersected = intersections[ 0 ].object;
/*HERE*/
console.log("Hit-face a @ " + intersections[0].face.a);
console.log("Hit-face b @ " + intersections[0].face.b);
console.log("Hit-face c @ " + intersections[0].face.c);
var faceColorMaterial = new THREE.MeshBasicMaterial(
{ color: 0xffffff, vertexColors: THREE.FaceColors } );
var sphereGeometry = new THREE.SphereGeometry( 0.1, 32, 16 );
var sphereGeometryf = new THREE.SphereGeometry( 3, 32, 16 );
var sphereGeometrys = new THREE.SphereGeometry( 3, 32, 16 );
var sphereGeometryt = new THREE.SphereGeometry( 3, 32, 16 );
var sphere = new THREE.Mesh( sphereGeometry, faceColorMaterial );
sphere.position.set(intersections[0].point.x, intersections[0].point.y, intersections[0].point.z);
var spheref = new THREE.Mesh( sphereGeometryf, faceColorMaterial );
spheref.position.set(intersections[0].object.geometry.vertices[intersections[0].face.a].x + intersections[0].object.position.x,
intersections[0].object.geometry.vertices[intersections[0].face.a].y + intersections[0].object.position.y,
intersections[0].object.geometry.vertices[intersections[0].face.a].z + intersections[0].object.position.z);
var spheres = new THREE.Mesh( sphereGeometrys, faceColorMaterial );
spheres.position.set(intersections[0].object.geometry.vertices[intersections[0].face.b].x + intersections[0].object.position.x,
intersections[0].object.geometry.vertices[intersections[0].face.b].y + intersections[0].object.position.y,
intersections[0].object.geometry.vertices[intersections[0].face.b].z + intersections[0].object.position.z);
var spheret = new THREE.Mesh( sphereGeometryt, faceColorMaterial );
spheret.position.set(intersections[0].object.geometry.vertices[intersections[0].face.c].x + intersections[0].object.position.x,
intersections[0].object.geometry.vertices[intersections[0].face.c].y + intersections[0].object.position.y,
intersections[0].object.geometry.vertices[intersections[0].face.c].z + intersections[0].object.position.z);
scene.add(sphere);
scene.add(spheref);
scene.add(spheres);
scene.add(spheret);
/*HERE*/
}
}
所以在这个示例代码中," sphere"是Ray与第一个对象相遇的交叉点。
spheref-spheres-spheret是顶点可视化,但当我将thece球体添加到thoose顶点时,它们会在其他地方(可见)。
上面使用此示例的方法,将onDocumentMouseDown事件替换为上面的代码:http://stemkoski.github.io/Three.js/Mouse-Click.html
但它不适用于加载的对象。
答案 0 :(得分:0)
好的,我解决了它^^ ......,问题在于规模......
所以问题是我用过这个: myobject.scale.set(3,3,3);
但是顶点坐标没有改变,所以我注释掉了这一行,我将导出3倍大的模式。但另一方面,如果你想使用scalled modell,那么你应该将x,y,z值加3次(根据你的比例增加x倍,其中x是数字)。
答案 1 :(得分:0)
您错过了将对象的WorldMatrix应用于您的观点。
以下是它应该如何运作:
首先,您获得原始网格的面部点,如下所示。
PointA = intersections[0].object.geometry.vertices[intersections[0].face.a]
在这一点上没有缩放,旋转,平移。因此,您需要将这些添加到您的位置以获得正确的位置。为此,您只需将对象的WorldMatrix应用于Point。
PointA.applyMatrix4(intersections[0].object.matrixWorld);
现在你有了真正的坐标,你必须把你的球体放在哪里。 (PointA.x, PointA.y, PointA.z)