Ver código fonte

Picking support for UnIndexed meshes

Small change, but unsure if this should be done as a separate function or if/how much it'll impact picking perf, it does run like a million times..

PGs; (see console)
sphere is indexed, half-box is unindexed.
Without change:  https://playground.babylonjs.com/#8QNBES#3
With change; https://playground.babylonjs.com/#8QNBES#2
aWeirdo 6 anos atrás
pai
commit
80c5e87a79
1 arquivos alterados com 22 adições e 5 exclusões
  1. 22 5
      src/Meshes/subMesh.ts

+ 22 - 5
src/Meshes/subMesh.ts

@@ -404,11 +404,28 @@ export class SubMesh extends BaseSubMesh implements ICullable {
     private _intersectTriangles(ray: Ray, positions: Vector3[], indices: IndicesArray,
         fastCheck?: boolean, trianglePredicate?: TrianglePickingPredicate): Nullable<IntersectionInfo> {
         var intersectInfo: Nullable<IntersectionInfo> = null;
+        
+        var start = this.indexStart;
+        var count = this.indexCount;
+
+        if(!indices.length){
+            start = this.verticesStart;
+            count = this.verticesCount;
+        }
+
         // Triangles test
-        for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += 3) {
-            var p0 = positions[indices[index]];
-            var p1 = positions[indices[index + 1]];
-            var p2 = positions[indices[index + 2]];
+        var p0, p1, p2;
+        for (var index = start; index < start + count; index += 3) {
+            if(!indices.length){
+                p0 = positions[index];
+                p1 = positions[index + 1];
+                p2 = positions[index + 2];
+            }
+            else {
+                p0 = positions[indices[index]];
+                p1 = positions[indices[index + 1]];
+                p2 = positions[indices[index + 2]];
+            }
 
             if (trianglePredicate && !trianglePredicate(p0, p1, p2, ray)) {
                 continue;
@@ -518,4 +535,4 @@ export class SubMesh extends BaseSubMesh implements ICullable {
 
         return new SubMesh(materialIndex, minVertexIndex, maxVertexIndex - minVertexIndex + 1, startIndex, indexCount, mesh, renderingMesh);
     }
-}
+}