浏览代码

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

Cedric Guillemet 4 年之前
父节点
当前提交
3dfd2080b7
共有 1 个文件被更改,包括 26 次插入0 次删除
  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];