Prechádzať zdrojové kódy

when no submesh can be picked, then fallback to bbox intersection

Cedric Guillemet 4 rokov pred
rodič
commit
3dfd2080b7
1 zmenil súbory, kde vykonal 26 pridanie a 0 odobranie
  1. 26 0
      src/Meshes/abstractMesh.ts

+ 26 - 0
src/Meshes/abstractMesh.ts

@@ -1535,6 +1535,32 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
 
         var subMeshes = this._scene.getIntersectingSubMeshCandidates(this, ray);
         var len: number = subMeshes.length;
+
+        // Check if all submeshes are using a material that don't allow picking (point/lines rendering)
+        // if no submesh can be picked that way, then fallback to BBox picking
+        var anySubmeshSupportInterect = false;
+        for (var index = 0; index < len; index++) {
+            var subMesh = subMeshes.data[index];
+            var material = subMesh.getMaterial();
+            if (!material) {
+                continue;
+            }
+            if (this.getIndices() && (material.fillMode == Constants.MATERIAL_TriangleStripDrawMode)) {
+                anySubmeshSupportInterect = true;
+                break;
+            }
+        }
+
+        // no sub mesh support intersection, fallback to BBox that has already be done
+        if (!anySubmeshSupportInterect) {
+            pickingInfo.hit = true;
+            pickingInfo.pickedMesh = this;
+            pickingInfo.distance = Vector3.Distance(ray.origin, boundingInfo.boundingSphere.center);
+            pickingInfo.subMeshId = 0;
+            return pickingInfo;
+        }
+
+        // at least 1 submesh supports intersection, keep going
         for (var index = 0; index < len; index++) {
             var subMesh = subMeshes.data[index];