Deltakosh hace 11 años
padre
commit
0e58b28617

+ 5 - 4
Babylon/Materials/textures/babylon.cubeTexture.js

@@ -3,16 +3,17 @@
 var BABYLON = BABYLON || {};
 
 (function () {    
-    BABYLON.CubeTexture = function (rootUrl, scene, extensions) {
+    BABYLON.CubeTexture = function (rootUrl, scene, extensions, noMipmap) {
         this._scene = scene;
         this._scene.textures.push(this);
         
         this.name = rootUrl;
         this.url = rootUrl;
+        this._noMipmap = noMipmap;
         this.hasAlpha = false;
         this.coordinatesMode = BABYLON.Texture.CUBIC_MODE;
 
-        this._texture = this._getFromCache(rootUrl);
+        this._texture = this._getFromCache(rootUrl, noMipmap);
 
         if (!extensions) {
             extensions = ["_px.jpg", "_py.jpg", "_pz.jpg", "_nx.jpg", "_ny.jpg", "_nz.jpg"];
@@ -22,7 +23,7 @@ var BABYLON = BABYLON || {};
         
         if (!this._texture) {
             if (!scene.useDelayedTextureLoading) {
-                this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, extensions);
+                this._texture = scene.getEngine().createCubeTexture(rootUrl, scene, extensions, noMipmap);
             } else {
                 this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
             }            
@@ -42,7 +43,7 @@ var BABYLON = BABYLON || {};
         }
 
         this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
-        this._texture = this._getFromCache(this.url);
+        this._texture = this._getFromCache(this.url, this._noMipmap);
 
         if (!this._texture) {
             this._texture = this._scene.getEngine().createCubeTexture(this.url, this._scene, this._extensions);

+ 9 - 0
Babylon/Math/babylon.math.js

@@ -247,6 +247,10 @@ var BABYLON = BABYLON || {};
     BABYLON.Color3.FromArray = function (array) {
         return new BABYLON.Color3(array[0], array[1], array[2]);
     };
+    
+    BABYLON.Color3.FromInts = function (r, g, b) {
+        return new BABYLON.Color3(r / 255.0, g / 255.0, b / 255.0);
+    };
 
     ////////////////////////////////// Color4 //////////////////////////////////
 
@@ -340,6 +344,11 @@ var BABYLON = BABYLON || {};
 
         return new BABYLON.Color4(array[offset], array[offset + 1], array[offset + 2], array[offset + 3]);
     };
+    
+    BABYLON.Color4.FromInts = function (r, g, b, a) {
+        return new BABYLON.Color4(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
+    };
+
 
     ////////////////////////////////// Vector2 //////////////////////////////////
 

+ 30 - 6
Babylon/Mesh/babylon.csg.js

@@ -15,7 +15,10 @@ var BABYLON = BABYLON || {};
 
     // Convert BABYLON.Mesh to BABYLON.CSG
     BABYLON.CSG.FromMesh = function (mesh) {
-        var vertex, normal, uv, position, polygon, polygons = [], vertices;
+        var vertex, normal, uv, position,
+            polygon,
+            polygons = [],
+            vertices;
 
         if (mesh instanceof BABYLON.Mesh) {
             mesh.computeWorldMatrix(true);
@@ -49,7 +52,11 @@ var BABYLON = BABYLON || {};
                 }
 
                 polygon = new BABYLON.CSG.Polygon(vertices, { subMeshId: sm, meshId: _currentCSGMeshId, materialIndex: subMeshes[sm].materialIndex });
-                polygons.push(polygon);
+
+                // To handle the case of degenerated triangle
+                // polygon.plane == null <=> the polygon does not represent 1 single plane <=> the triangle is degenerated
+                if (polygon.plane)
+                    polygons.push(polygon);
             }
         }
 
@@ -333,6 +340,10 @@ var BABYLON = BABYLON || {};
             return Math.sqrt(this.dot(this));
         },
 
+        lengthSq: function () {
+            return this.dot(this);
+        },
+
         unit: function () {
             return this.dividedBy(this.length());
         },
@@ -400,6 +411,13 @@ var BABYLON = BABYLON || {};
     BABYLON.CSG.Plane.EPSILON = 1e-5;
 
     BABYLON.CSG.Plane.fromPoints = function (a, b, c) {
+        var v0 = c.minus(a);
+        var v1 = b.minus(a);
+
+        if (v0.lengthSq() === 0 || v1.lengthSq() === 0) {
+            return null;
+        }
+
         var n = c.minus(a).cross(b.minus(a)).unit();
         return new BABYLON.CSG.Plane(n, n.dot(a));
     };
@@ -484,6 +502,7 @@ var BABYLON = BABYLON || {};
         this.vertices = vertices;
         this.shared = shared;
         this.plane = BABYLON.CSG.Plane.fromPoints(vertices[0].pos, vertices[1].pos, vertices[2].pos);
+
     };
 
     BABYLON.CSG.Polygon.prototype = {
@@ -530,8 +549,12 @@ var BABYLON = BABYLON || {};
                 this.polygons[i].flip();
             }
             this.plane.flip();
-            if (this.front) this.front.invert();
-            if (this.back) this.back.invert();
+            if (this.front) {
+                this.front.invert();
+            }
+            if (this.back) {
+                this.back.invert();
+            }
             var temp = this.front;
             this.front = this.back;
             this.back = temp;
@@ -545,7 +568,9 @@ var BABYLON = BABYLON || {};
             for (var i = 0; i < polygons.length; i++) {
                 this.plane.splitPolygon(polygons[i], front, back, front, back);
             }
-            if (this.front) front = this.front.clipPolygons(front);
+            if (this.front) {
+                front = this.front.clipPolygons(front);
+            }
             if (this.back) {
                 back = this.back.clipPolygons(back);
             } else {
@@ -591,5 +616,4 @@ var BABYLON = BABYLON || {};
             }
         }
     };
-
 })();

+ 6 - 3
Babylon/babylon.engine.js

@@ -865,7 +865,7 @@ var BABYLON = BABYLON || {};
         scene._addPendingData(img);
     };
 
-    BABYLON.Engine.prototype.createCubeTexture = function (rootUrl, scene, extensions) {
+    BABYLON.Engine.prototype.createCubeTexture = function (rootUrl, scene, extensions, noMipmap) {
         var gl = this._gl;
 
         var texture = gl.createTexture();
@@ -895,9 +895,12 @@ var BABYLON = BABYLON || {};
                 gl.texImage2D(faces[index], 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, that._workingCanvas);
             }
 
-            gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
+            if (!noMipmap) {
+                gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
+            }
+            
             gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
-            gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
+            gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, noMipmap ? gl.LINEAR : gl.LINEAR_MIPMAP_LINEAR);
             gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
             gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);