Przeglądaj źródła

New mesh type: BABYLON.LinesMesh

David Catuhe 11 lat temu
rodzic
commit
698b57afdf

+ 1 - 1
Babylon/Mesh/babylon.InstancedMesh.js

@@ -163,4 +163,4 @@ var BABYLON;
     })(BABYLON.AbstractMesh);
     BABYLON.InstancedMesh = InstancedMesh;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.InstancedMesh.js.map
+//# sourceMappingURL=babylon.instancedMesh.js.map

+ 62 - 0
Babylon/Mesh/babylon.linesMesh.js

@@ -0,0 +1,62 @@
+var __extends = this.__extends || function (d, b) {
+    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+    function __() { this.constructor = d; }
+    __.prototype = b.prototype;
+    d.prototype = new __();
+};
+var BABYLON;
+(function (BABYLON) {
+    var LinesMesh = (function (_super) {
+        __extends(LinesMesh, _super);
+        function LinesMesh(name, scene, updatable) {
+            if (typeof updatable === "undefined") { updatable = false; }
+            _super.call(this, name, scene);
+            this.color = new BABYLON.Color3(1, 1, 1);
+            this._indices = new Array();
+
+            this._colorShader = new BABYLON.ShaderMaterial("colorShader", scene, "color", {
+                attributes: ["position"],
+                uniforms: ["worldViewProjection", "color"]
+            });
+        }
+        Object.defineProperty(LinesMesh.prototype, "material", {
+            get: function () {
+                return this._colorShader;
+            },
+            enumerable: true,
+            configurable: true
+        });
+
+        LinesMesh.prototype._bind = function (subMesh, effect, wireframe) {
+            var engine = this.getScene().getEngine();
+
+            var indexToBind = this._geometry.getIndexBuffer();
+
+            // VBOs
+            engine.bindBuffers(this._geometry.getVertexBuffer(BABYLON.VertexBuffer.PositionKind).getBuffer(), indexToBind, [3], 3 * 4, this._colorShader.getEffect());
+
+            // Color
+            this._colorShader.setColor3("color", this.color);
+        };
+
+        LinesMesh.prototype._draw = function (subMesh, useTriangles, instancesCount) {
+            if (!this._geometry || !this._geometry.getVertexBuffers() || !this._geometry.getIndexBuffer()) {
+                return;
+            }
+
+            var engine = this.getScene().getEngine();
+
+            // Draw order
+            engine.draw(false, subMesh.indexStart, subMesh.indexCount);
+        };
+
+        LinesMesh.prototype.dispose = function (doNotRecurse) {
+            this._colorShader.dispose();
+
+            _super.prototype.dispose.call(this, doNotRecurse);
+        };
+        return LinesMesh;
+    })(BABYLON.Mesh);
+    BABYLON.LinesMesh = LinesMesh;
+})(BABYLON || (BABYLON = {}));
+//# sourceMappingURL=babylon.linesMesh.js.map

+ 11 - 0
Babylon/Mesh/babylon.mesh.js

@@ -777,6 +777,17 @@ var BABYLON;
             return torusKnot;
         };
 
+        // Lines
+        Mesh.CreateLines = function (name, points, scene, updatable) {
+            var lines = new BABYLON.LinesMesh(name, scene, updatable);
+
+            var vertexData = BABYLON.VertexData.CreateLines(points);
+
+            vertexData.applyToMesh(lines, updatable);
+
+            return lines;
+        };
+
         // Plane & ground
         Mesh.CreatePlane = function (name, size, scene, updatable) {
             var plane = new BABYLON.Mesh(name, scene);

+ 12 - 1
Babylon/Mesh/babylon.mesh.ts

@@ -786,6 +786,17 @@
             return torusKnot;
         }
 
+        // Lines
+        public static CreateLines(name: string, points: Vector3[], scene: Scene, updatable?: boolean): LinesMesh {
+            var lines = new LinesMesh(name, scene, updatable);
+
+            var vertexData = BABYLON.VertexData.CreateLines(points);
+
+            vertexData.applyToMesh(lines, updatable);
+
+            return lines;
+        }
+
         // Plane & ground
         public static CreatePlane(name: string, size: number, scene: Scene, updatable?: boolean): Mesh {
             var plane = new BABYLON.Mesh(name, scene);
@@ -810,7 +821,7 @@
             return ground;
         }
 
-        public static CreateGroundFromHeightMap(name: string, url: string, width: number, height: number, subdivisions: number, minHeight: number, maxHeight: number, scene: Scene, updatable?: boolean): Mesh {
+        public static CreateGroundFromHeightMap(name: string, url: string, width: number, height: number, subdivisions: number, minHeight: number, maxHeight: number, scene: Scene, updatable?: boolean): GroundMesh {
             var ground = new BABYLON.GroundMesh(name, scene);
             ground._subdivisions = subdivisions;
 

+ 22 - 0
Babylon/Mesh/babylon.mesh.vertexData.js

@@ -567,6 +567,28 @@
             return vertexData;
         };
 
+        VertexData.CreateLines = function (points) {
+            var indices = [];
+            var positions = [];
+
+            for (var index = 0; index < points.length; index++) {
+                positions.push(points[index].x, points[index].y, points[index].z);
+
+                if (index > 0) {
+                    indices.push(index - 1);
+                    indices.push(index);
+                }
+            }
+
+            // Result
+            var vertexData = new BABYLON.VertexData();
+
+            vertexData.indices = indices;
+            vertexData.positions = positions;
+
+            return vertexData;
+        };
+
         VertexData.CreateGround = function (width, height, subdivisions) {
             var indices = [];
             var positions = [];

+ 22 - 0
Babylon/Mesh/babylon.mesh.vertexData.ts

@@ -587,6 +587,28 @@
             return vertexData;
         }
 
+        public static CreateLines(points: Vector3[]): VertexData {
+            var indices = [];
+            var positions = [];
+
+            for (var index = 0; index < points.length; index++) {
+                positions.push(points[index].x, points[index].y, points[index].z);
+
+                if (index > 0) {
+                    indices.push(index - 1);
+                    indices.push(index);
+                }
+            }
+
+            // Result
+            var vertexData = new BABYLON.VertexData();
+
+            vertexData.indices = indices;
+            vertexData.positions = positions;
+
+            return vertexData;
+        }
+
         public static CreateGround(width: number, height: number, subdivisions: number): VertexData {
             var indices = [];
             var positions = [];

+ 1 - 0
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/babylonJS.xml

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8" ?>
 <files xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="babylonJS.xsd">
+  <script src="Babylon/Mesh/babylon.linesMesh.js"></script>
   <script src="Babylon/Tools/babylon.gamepads.js"></script>
   <script src="Babylon/Cameras/babylon.gamepadCamera.js"></script>
   <script src="Babylon/Mesh/babylon.GroundMesh.js"></script>

+ 1 - 0
Tools/Gulp/gulpfile.js

@@ -153,6 +153,7 @@ gulp.task('scripts', ['shaders'] ,function() {
       '../../Babylon/Mesh/babylon.instancedMesh.js',
       '../../Babylon/Tools/babylon.gamepads.js',
       '../../Babylon/Cameras/babylon.gamepadCamera.js',
+      '../../Babylon/Mesh/babylon.linesMesh.js'
     ])
     .pipe(concat('babylon.js'))
     .pipe(gulp.dest('build/'))

Plik diff jest za duży
+ 2 - 2
babylon.1.13-beta-debug.js


Plik diff jest za duży
+ 6 - 6
babylon.1.13-beta.js