Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Three.js 如何在对缓冲区几何体进行光线投射时获得相交面_Three.js_Raycasting_Buffer Geometry - Fatal编程技术网

Three.js 如何在对缓冲区几何体进行光线投射时获得相交面

Three.js 如何在对缓冲区几何体进行光线投射时获得相交面,three.js,raycasting,buffer-geometry,Three.js,Raycasting,Buffer Geometry,我正在对一个场景进行光线投射 相交对象的几何体是缓冲几何体。 相交对象的一部分是 { distance: 494.77924415158327 face: Face3 {a: 732, b: 733, c: 734, normal: Vector3, vertexNormals: [], …}, faceIndex: 732, index: 732, object: Mesh {id: 16, uuid: "F1E299F1-927D-4CD8-ACF6-3A5AA528EA

我正在对一个场景进行光线投射

相交对象的几何体是缓冲几何体。 相交对象的一部分是

{
  distance: 494.77924415158327
  face: Face3 {a: 732, b: 733, c: 734, normal: Vector3, vertexNormals: [], …},
  faceIndex: 732,
  index: 732,
  object: Mesh {id: 16, uuid: "F1E299F1-927D-4CD8-ACF6-3A5AA528EACD", name: "collide_main", type: "Mesh", parent: Group, …},
  point: Vector3 {x: -3.025193341955971, y: 2.63172597487887, z: -4.237102099257478, isVector3: true, …},
  uv: Vector2 {x: 0.46554459963387684, y: 0.6888516128730314, isVector2: true, …}
 }
我需要弄清楚那个物体的表面。我这样做是为了这个

var geometry = new THREE.Geometry().fromBufferGeometry( INTERSECTED.object.geometry );
var faces = geometry.faces;
var intersectedFace = faces[INTERESECTED.faceIndex];
但许多时间相交的面包含一个面中没有的索引。例如,在上述情况下,INTERSECTED.faceIndex为732,但我获得的面仅包含200个面的数组


如何获取相交面。

使用相交面a、b、c属性从位置属性获取x、y、z:

let positionAttribute = bufferGeometry.attributes["position"];
let aVertex = new THREE.Vector3(positionAttribute.getX(intersection.face.a), positionAttribute.getY(intersection.face.a), positionAttribute.getZ(intersection.face.a));
let bVertex = ...;
let cVertex = ...;

你可以通过索引访问一个面的顶点,就像我看到的那样,原因是改变一个面的颜色;非索引几何体只是一个三角形汤:

var场景=新的三个场景; var摄像机=新的三视角摄像机60,window.innerWidth/window.innerHeight,11000; camera.position.set0,0,10; var renderer=new THREE.WebGLRenderer; renderer.setSizewindow.innerWidth,window.innerHeight; document.body.appendChildrender.doElement; var planeGeom=新的三个平面缓冲几何量10,10,10,10; var planeGeomNonIndexed=planeGeom.toNonIndexed; console.LogPlaneGeoNon索引; var颜色=[]; planeGeomNonIndexed.attributes.position.array.forEachp=>{ 颜色1,1,1; }; PlaneGeomNonIndex.addAttribute'color',新的3.BufferAttributenew Float32ArrayColor,3; var plane=新的3.MeshplaneGeomNonIndexed,新的3.MeshBasicMaterial{ 顶点颜色:三。顶点颜色 }; scene.addplane; scene.addnew THREE.MeshplaneGeom,new THREE.MeshBasicMaterial{ 颜色:黑色, 线框:正确 }; var raycaster=新的三个raycaster; var mouse=new THREE.Vector2; var相交=[]; window.addEventListenermousedown、onMouseDown、false; 函数onMouseDownevent{ mouse.x=event.clientX/window.innerWidth*2-1; mouse.y=-event.clientY/window.innerHeight*2+1; raycaster.setFromCameramouse,摄像机; 相交=光线投射器。相交对象平面; 如果相交,则返回.length==0; 让faceIndex=与[0]相交; PlaneGeomNonIndex.attributes.color.setXYZfaceIndex,1,0,0; PlaneGeomNonIndex.attributes.color.setXYZfaceIndex+1,1,0,0; PlaneGeomNonIndex.attributes.color.setXYZfaceIndex+2,1,0,0; planeGeomNonIndexed.attributes.color.needsUpdate=true; } 提供 函数渲染{ requestAnimationFramerender; renderer.renderscene,摄影机; } 身体{ 溢出:隐藏; 保证金:0; }
首先,你找到一个缓冲区几何体的面索引,然后你将该几何体转换成一个普通的几何体,并尝试将该面索引应用到与原始缓冲几何体没有任何共同点的新的普通几何体上。是的。如何为常用几何体获取新的面索引。缓冲区几何体是否未索引?是。内部缓冲区几何体索引为空。我认为这意味着它是非索引的。我应该如何使用aVertex、bVertex和cVertex从法线几何中获取面。你可以使用这些顶点来构造三角形并渲染它。如果首先有缓冲区几何体,为什么要处理法线几何体?