瀏覽代碼

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 6 年之前
父節點
當前提交
196280e375
共有 4 個文件被更改,包括 48 次插入9 次删除
  1. 2 1
      dist/preview release/what's new.md
  2. 9 2
      src/Meshes/linesMesh.ts
  3. 1 1
      src/Meshes/mesh.ts
  4. 36 5
      src/Meshes/subMesh.ts

+ 2 - 1
dist/preview release/what's new.md

@@ -137,7 +137,7 @@
 - Added LoadScriptAsync tools helper function [MackeyK24](https://github.com/mackeyk24))
 - Added customShaderNameResolve to PBRMaterialBase to allow subclasses to specify custom shader information [MackeyK24](https://github.com/mackeyk24))
 - Added PBRCustomMaterial to material library to allow easy subclassing of PBR materials [MackeyK24](https://github.com/mackeyk24))
-- Added custom defines for roughness and microsurface in PBRCustomMaterial [Lockphase](https://github.com/lockphase)) 
+- Added custom defines for roughness and microsurface in PBRCustomMaterial [Lockphase](https://github.com/lockphase))
 - Added `auto-exposure` support in `StandardRenderingPipeline` when `HDR` is enabled ([julien-moreau](https://github.com/julien-moreau))
 - Add `EquiRectangularCubeTexture` class to enable the usage of browser-canvas supported images as `CubeTexture`'s ([Dennis Dervisis](https://github.com/ddervisis))
 - Add `EquiRectangularCubeTextureAssetTask` to be able to load `EquiRectangularCubeTextures`s via Asset Manager ([Dennis Dervisis](https://github.com/ddervisis))
@@ -264,6 +264,7 @@
 - Fix a bug causing `Mesh.clone` to crash if no physicsEngineComponent is used  ([barroij](https://github.com/barroij))
 - Fix zoom inertia making it difficult to zoom out with ArcRotateCamera ([TrevorDev](https://github.com/TrevorDev))
 - Option for isInFrustum to check rigCameras, viewMatrix updates for rigCameras will notify their parent ([TrevorDev](https://github.com/TrevorDev))
+- Handle properly unindexed `LinesMesh` (rendering + picking) ([barroij](https://github.com/barroij))
 
 ### Loaders
 

+ 9 - 2
src/Meshes/linesMesh.ts

@@ -172,7 +172,8 @@ export class LinesMesh extends Mesh {
         const colorEffect = this._colorShader.getEffect();
 
         // VBOs
-        this._geometry._bind(colorEffect);
+        const indexToBind = this.isUnIndexed ? null : this._geometry.getIndexBuffer();
+        this._geometry._bind(colorEffect, indexToBind);
 
         // Color
         if (!this.useVertexColor) {
@@ -193,7 +194,13 @@ export class LinesMesh extends Mesh {
         var engine = this.getScene().getEngine();
 
         // Draw order
-        engine.drawElementsType(Material.LineListDrawMode, subMesh.indexStart, subMesh.indexCount, instancesCount);
+
+        if (this._unIndexed) {
+            engine.drawArraysType(Material.LineListDrawMode, subMesh.verticesStart, subMesh.verticesCount, instancesCount);
+        }
+        else {
+            engine.drawElementsType(Material.LineListDrawMode, subMesh.indexStart, subMesh.indexCount, instancesCount);
+        }
         return this;
     }
 

+ 1 - 1
src/Meshes/mesh.ts

@@ -1289,7 +1289,7 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
                     break;
                 default:
                 case Material.TriangleFillMode:
-                    indexToBind = this._unIndexed ? null : this._geometry.getIndexBuffer();
+                    indexToBind = this._geometry.getIndexBuffer();
                     break;
             }
         }

+ 36 - 5
src/Meshes/subMesh.ts

@@ -369,15 +369,20 @@ export class SubMesh extends BaseSubMesh implements ICullable {
 
         // LineMesh first as it's also a Mesh...
         if (this._mesh.getClassName() === "InstancedLinesMesh" || this._mesh.getClassName() === "LinesMesh") {
+            // Check if mesh is unindexed
+            if (!indices.length) {
+                return this._intersectUnIndexedLines(ray, positions, indices, (this._mesh as any).intersectionThreshold, fastCheck);
+            }
             return this._intersectLines(ray, positions, indices, (this._mesh as any).intersectionThreshold, fastCheck);
         }
+        else {
+            // Check if mesh is unindexed
+            if (!indices.length) {
+                return this._intersectUnIndexedTriangles(ray, positions, indices, fastCheck, trianglePredicate);
+            }
 
-        // Check if mesh is unindexed
-        if (!indices.length) {
-            return this._intersectUnIndexedTriangles(ray, positions, indices, fastCheck, trianglePredicate);
+            return this._intersectTriangles(ray, positions, indices, fastCheck, trianglePredicate);
         }
-
-        return this._intersectTriangles(ray, positions, indices, fastCheck, trianglePredicate);
     }
 
     /** @hidden */
@@ -406,6 +411,32 @@ export class SubMesh extends BaseSubMesh implements ICullable {
     }
 
     /** @hidden */
+    private _intersectUnIndexedLines(ray: Ray, positions: Vector3[], indices: IndicesArray, intersectionThreshold: number, fastCheck?: boolean): Nullable<IntersectionInfo> {
+        var intersectInfo: Nullable<IntersectionInfo> = null;
+
+        // Line test
+        for (var index = this.verticesStart; index < this.verticesStart + this.verticesCount; index += 2) {
+            var p0 = positions[index];
+            var p1 = positions[index + 1];
+
+            var length = ray.intersectionSegment(p0, p1, intersectionThreshold);
+            if (length < 0) {
+                continue;
+            }
+
+            if (fastCheck || !intersectInfo || length < intersectInfo.distance) {
+                intersectInfo = new IntersectionInfo(null, null, length);
+                intersectInfo.faceId = index / 2;
+                if (fastCheck) {
+                    break;
+                }
+            }
+        }
+
+        return intersectInfo;
+    }
+
+    /** @hidden */
     private _intersectTriangles(ray: Ray, positions: Vector3[], indices: IndicesArray,
         fastCheck?: boolean, trianglePredicate?: TrianglePickingPredicate): Nullable<IntersectionInfo> {
         var intersectInfo: Nullable<IntersectionInfo> = null;