Prechádzať zdrojové kódy

add InstancedLinesMesh

Julien Barrois 6 rokov pred
rodič
commit
edc5ddad30

+ 2 - 2
src/Mesh/babylon.abstractMesh.ts

@@ -1361,7 +1361,7 @@ module BABYLON {
          */
          */
         public intersects(ray: Ray, fastCheck?: boolean): PickingInfo {
         public intersects(ray: Ray, fastCheck?: boolean): PickingInfo {
             var pickingInfo = new PickingInfo();
             var pickingInfo = new PickingInfo();
-            const intersectionTreshold = this.getClassName() === "LinesMesh" ? (<LinesMesh>(this as any)).intersectionThreshold : 0;
+            const intersectionTreshold = this instanceof LinesMesh || this instanceof InstancedLinesMesh ? this.intersectionThreshold : 0;
             const boundingInfo = this._boundingInfo;
             const boundingInfo = this._boundingInfo;
             if (!this.subMeshes || !boundingInfo || !ray.intersectsSphere(boundingInfo.boundingSphere, intersectionTreshold) || !ray.intersectsBox(boundingInfo.boundingBox, intersectionTreshold)) {
             if (!this.subMeshes || !boundingInfo || !ray.intersectsSphere(boundingInfo.boundingSphere, intersectionTreshold) || !ray.intersectsBox(boundingInfo.boundingBox, intersectionTreshold)) {
                 return pickingInfo;
                 return pickingInfo;
@@ -1509,7 +1509,7 @@ module BABYLON {
             });
             });
 
 
             // SubMeshes
             // SubMeshes
-            if (this.getClassName() !== "InstancedMesh") {
+            if (this.getClassName() !== "InstancedMesh" && this.getClassName() !== "InstancedLinesMesh") {
                 this.releaseSubMeshes();
                 this.releaseSubMeshes();
             }
             }
 
 

+ 36 - 17
src/Mesh/babylon.linesMesh.ts

@@ -17,24 +17,9 @@ module BABYLON {
          * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.
          * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.
          * This margin is expressed in world space coordinates, so its value may vary.
          * This margin is expressed in world space coordinates, so its value may vary.
          * Default value is 0.1
          * Default value is 0.1
-         * @returns the intersection Threshold value.
          */
          */
-        public get intersectionThreshold(): number {
-            return this._intersectionThreshold;
-        }
-
-        /**
-         * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.
-         * This margin is expressed in world space coordinates, so its value may vary.
-         */
-        public set intersectionThreshold(value: number) {
-            if (this._intersectionThreshold === value) {
-                return;
-            }
-            this._intersectionThreshold = value;
-        }
+        public intersectionThreshold: number;
 
 
-        private _intersectionThreshold: number;
         private _colorShader: ShaderMaterial;
         private _colorShader: ShaderMaterial;
 
 
         /**
         /**
@@ -73,7 +58,7 @@ module BABYLON {
                 this.useVertexAlpha = source.useVertexAlpha;
                 this.useVertexAlpha = source.useVertexAlpha;
             }
             }
 
 
-            this._intersectionThreshold = 0.1;
+            this.intersectionThreshold = 0.1;
 
 
             var defines: string[] = [];
             var defines: string[] = [];
             var options = {
             var options = {
@@ -169,5 +154,39 @@ module BABYLON {
         public clone(name: string, newParent?: Node, doNotCloneChildren?: boolean): LinesMesh {
         public clone(name: string, newParent?: Node, doNotCloneChildren?: boolean): LinesMesh {
             return new LinesMesh(name, this.getScene(), newParent, this, doNotCloneChildren);
             return new LinesMesh(name, this.getScene(), newParent, this, doNotCloneChildren);
         }
         }
+
+        /**
+         * Creates a new InstancedLinesMesh object from the mesh model.
+         * @see http://doc.babylonjs.com/how_to/how_to_use_instances
+         * @param name defines the name of the new instance
+         * @returns a new InstancedMesh
+         */
+        public createInstance(name: string): InstancedLinesMesh {
+            return new InstancedLinesMesh(name, this);
+        }
+    }
+
+    /**
+     * Creates an instance based on a source LinesMesh
+     */
+    export class InstancedLinesMesh extends InstancedMesh {
+        /**
+         * The intersection Threshold is the margin applied when intersection a segment of the LinesMesh with a Ray.
+         * This margin is expressed in world space coordinates, so its value may vary.
+         * Initilized with the intersectionThreshold value of the source LinesMesh
+         */
+        public intersectionThreshold: number;
+
+        constructor(name: string, source: LinesMesh) {
+            super(name, source);
+            this.intersectionThreshold = this.intersectionThreshold;
+        }
+
+        /**
+         * Returns the string "InstancedLinesMesh".
+         */
+        public getClassName(): string {
+            return "InstancedLinesMesh";
+        }
     }
     }
 }
 }

+ 0 - 1
src/Mesh/babylon.mesh.ts

@@ -2308,7 +2308,6 @@ module BABYLON {
 
 
         /**
         /**
          * Creates a new InstancedMesh object from the mesh model.
          * Creates a new InstancedMesh object from the mesh model.
-         * Warning : this method is not supported for Line mesh and LineSystem
          * @see http://doc.babylonjs.com/how_to/how_to_use_instances
          * @see http://doc.babylonjs.com/how_to/how_to_use_instances
          * @param name defines the name of the new instance
          * @param name defines the name of the new instance
          * @returns a new InstancedMesh
          * @returns a new InstancedMesh

+ 2 - 4
src/Mesh/babylon.subMesh.ts

@@ -344,10 +344,8 @@ module BABYLON {
 
 
             // LineMesh first as it's also a Mesh...
             // LineMesh first as it's also a Mesh...
             if (LinesMesh) {
             if (LinesMesh) {
-                const mesh = this._mesh instanceof InstancedMesh ? (<InstancedMesh>this._mesh).sourceMesh : this._mesh;
-                if (mesh instanceof LinesMesh) {
-                    const linesMesh = <LinesMesh>mesh;
-                    return this._intersectLines(ray, positions, indices, linesMesh.intersectionThreshold, fastCheck);
+                if (this._mesh instanceof LinesMesh || this._mesh instanceof InstancedLinesMesh) {
+                    return this._intersectLines(ray, positions, indices, this._mesh.intersectionThreshold, fastCheck);
                 }
                 }
             }
             }
 
 

+ 1 - 1
src/babylon.scene.ts

@@ -2231,7 +2231,7 @@ module BABYLON {
                     return false;
                     return false;
                 }
                 }
 
 
-                let hardwareInstancedRendering = mesh.getClassName() === "InstancedMesh" || engine.getCaps().instancedArrays && (<Mesh>mesh).instances.length > 0;
+                let hardwareInstancedRendering = mesh.getClassName() === "InstancedMesh" || mesh.getClassName() === "InstancedLinesMesh" || engine.getCaps().instancedArrays && (<Mesh>mesh).instances.length > 0;
                 // Is Ready For Mesh
                 // Is Ready For Mesh
                 for (let step of this._isReadyForMeshStage) {
                 for (let step of this._isReadyForMeshStage) {
                     if (!step.action(mesh, hardwareInstancedRendering)) {
                     if (!step.action(mesh, hardwareInstancedRendering)) {