Procházet zdrojové kódy

BufferGeometry: return the number of hit triangle in raycast

We need triangle number that was hit during raycast.

* if indexed, we need triangle number in the meaning of it's position in
indices array. Originally ThreeJS does not return that information.
* if not indexed, we need that number in the meaning of it's position in
positions array.

Even that raycast of unindexed BufferGeometry provide that information
in face attribute, we want to have it as 'index' attribute too for
uniformity.
Pavel Vasev před 10 roky
rodič
revize
38b0521fcd
1 změnil soubory, kde provedl 3 přidání a 3 odebrání
  1. 3 3
      src/objects/Mesh.js

+ 3 - 3
src/objects/Mesh.js

@@ -160,9 +160,9 @@ THREE.Mesh.prototype.raycast = ( function () {
 							distance: distance,
 							point: intersectionPoint,
 							face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
-							faceIndex: null,
+							faceIndex: Math.floor(i/3), // triangle number in indices buffer semantics
 							object: this
-
+							
 						} );
 
 					}
@@ -206,7 +206,7 @@ THREE.Mesh.prototype.raycast = ( function () {
 						distance: distance,
 						point: intersectionPoint,
 						face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
-						faceIndex: null,
+						index: Math.floor(i/3), // triangle number in positions buffer semantics
 						object: this
 
 					} );