瀏覽代碼

Cleaning code for PBR

David Catuhe 9 年之前
父節點
當前提交
534f87a3f7

+ 0 - 1
Tools/Gulp/config.json

@@ -170,7 +170,6 @@
       "../../src/PostProcess/babylon.hdrRenderingPipeline.js",
       "../../src/Rendering/babylon.edgesRenderer.js",
       "../../src/PostProcess/babylon.tonemapPostProcess.js",
-      "../../src/Materials/babylon.pbrMaterial.js",
       "../../src/Probes/babylon.reflectionProbe.js",
       "../../src/Particles/babylon.solidParticle.js",
       "../../src/Particles/babylon.solidParticleSystem.js"

文件差異過大導致無法顯示
+ 20 - 20
dist/preview release/babylon.core.js


文件差異過大導致無法顯示
+ 555 - 560
dist/preview release/babylon.d.ts


文件差異過大導致無法顯示
+ 27 - 27
dist/preview release/babylon.js


文件差異過大導致無法顯示
+ 31 - 76
dist/preview release/babylon.max.js


文件差異過大導致無法顯示
+ 27 - 27
dist/preview release/babylon.noworker.js


+ 0 - 24
src/Math/babylon.math.js

@@ -1,7 +1,5 @@
 var BABYLON;
 (function (BABYLON) {
-    var ToGammaSpace = 1 / 2.2;
-    var ToLinearSpace = 2.2;
     var Color3 = (function () {
         function Color3(r, g, b) {
             if (r === void 0) { r = 0; }
@@ -99,28 +97,6 @@ var BABYLON;
             var intB = (this.b * 255) | 0;
             return "#" + BABYLON.Tools.ToHex(intR) + BABYLON.Tools.ToHex(intG) + BABYLON.Tools.ToHex(intB);
         };
-        Color3.prototype.toLinearSpace = function () {
-            var convertedColor = new Color3();
-            this.toLinearSpaceToRef(convertedColor);
-            return convertedColor;
-        };
-        Color3.prototype.toLinearSpaceToRef = function (convertedColor) {
-            convertedColor.r = Math.pow(this.r, ToLinearSpace);
-            convertedColor.g = Math.pow(this.g, ToLinearSpace);
-            convertedColor.b = Math.pow(this.b, ToLinearSpace);
-            return this;
-        };
-        Color3.prototype.toGammaSpace = function () {
-            var convertedColor = new Color3();
-            this.toGammaSpaceToRef(convertedColor);
-            return convertedColor;
-        };
-        Color3.prototype.toGammaSpaceToRef = function (convertedColor) {
-            convertedColor.r = Math.pow(this.r, ToGammaSpace);
-            convertedColor.g = Math.pow(this.g, ToGammaSpace);
-            convertedColor.b = Math.pow(this.b, ToGammaSpace);
-            return this;
-        };
         // Statics
         Color3.FromHexString = function (hex) {
             if (hex.substring(0, 1) !== "#" || hex.length !== 7) {

+ 0 - 31
src/Math/babylon.math.ts

@@ -2,9 +2,6 @@
 
     declare var SIMD;
 
-    const ToGammaSpace = 1 / 2.2;
-    const ToLinearSpace = 2.2;
-
     export class Color3 {
         constructor(public r: number = 0, public g: number = 0, public b: number = 0) {
         }
@@ -126,34 +123,6 @@
             return "#" + Tools.ToHex(intR) + Tools.ToHex(intG) + Tools.ToHex(intB);
         }
 
-        public toLinearSpace(): Color3 {
-            var convertedColor = new Color3();
-            this.toLinearSpaceToRef(convertedColor);
-            return convertedColor;
-        }
-
-        public toLinearSpaceToRef(convertedColor: Color3): Color3 {
-            convertedColor.r = Math.pow(this.r, ToLinearSpace);
-            convertedColor.g = Math.pow(this.g, ToLinearSpace);
-            convertedColor.b = Math.pow(this.b, ToLinearSpace);
-
-            return this;
-        }
-
-        public toGammaSpace(): Color3 {
-            var convertedColor = new Color3();
-            this.toGammaSpaceToRef(convertedColor);
-            return convertedColor;
-        }
-
-        public toGammaSpaceToRef(convertedColor: Color3): Color3 {
-            convertedColor.r = Math.pow(this.r, ToGammaSpace);
-            convertedColor.g = Math.pow(this.g, ToGammaSpace);
-            convertedColor.b = Math.pow(this.b, ToGammaSpace);
-
-            return this;
-        }
-
         // Statics
         public static FromHexString(hex: string): Color3 {
             if (hex.substring(0, 1) !== "#" || hex.length !== 7) {

+ 1 - 3
src/Mesh/babylon.abstractMesh.js

@@ -354,7 +354,7 @@ var BABYLON;
             if (this._isDirty) {
                 return false;
             }
-            if (this.billboardMode !== this._cache.billboardMode || this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE)
+            if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE)
                 return false;
             if (this._cache.pivotMatrixUpdated) {
                 return false;
@@ -383,7 +383,6 @@ var BABYLON;
             this._cache.scaling = BABYLON.Vector3.Zero();
             this._cache.rotation = BABYLON.Vector3.Zero();
             this._cache.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 0);
-            this._cache.billboardMode = -1;
         };
         AbstractMesh.prototype.markAsDirty = function (property) {
             if (property === "rotation") {
@@ -416,7 +415,6 @@ var BABYLON;
             this._cache.position.copyFrom(this.position);
             this._cache.scaling.copyFrom(this.scaling);
             this._cache.pivotMatrixUpdated = false;
-            this._cache.billboardMode = this.billboardMode;
             this._currentRenderId = this.getScene().getRenderId();
             this._isDirty = false;
             // Scaling

+ 1 - 3
src/Mesh/babylon.abstractMesh.ts

@@ -376,7 +376,7 @@
                 return false;
             }
 
-            if (this.billboardMode !== this._cache.billboardMode || this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE)
+            if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE)
                 return false;
 
             if (this._cache.pivotMatrixUpdated) {
@@ -412,7 +412,6 @@
             this._cache.scaling = Vector3.Zero();
             this._cache.rotation = Vector3.Zero();
             this._cache.rotationQuaternion = new Quaternion(0, 0, 0, 0);
-            this._cache.billboardMode = -1;
         }
 
         public markAsDirty(property: string): void {
@@ -455,7 +454,6 @@
             this._cache.position.copyFrom(this.position);
             this._cache.scaling.copyFrom(this.scaling);
             this._cache.pivotMatrixUpdated = false;
-            this._cache.billboardMode = this.billboardMode;
             this._currentRenderId = this.getScene().getRenderId();
             this._isDirty = false;
 

+ 3 - 12
src/Mesh/babylon.mesh.js

@@ -1100,14 +1100,6 @@ var BABYLON;
         };
         // Cylinder and cone
         Mesh.CreateCylinder = function (name, height, diameterTop, diameterBottom, tessellation, subdivisions, scene, updatable, sideOrientation) {
-            if (scene === undefined || !(scene instanceof BABYLON.Scene)) {
-                if (scene !== undefined) {
-                    sideOrientation = updatable || Mesh.DEFAULTSIDE;
-                    updatable = scene;
-                }
-                scene = subdivisions;
-                subdivisions = 1;
-            }
             var options = {
                 height: height,
                 diameterTop: diameterTop,
@@ -1197,7 +1189,7 @@ var BABYLON;
             var options = {
                 shape: shape,
                 radius: radius,
-                tessellation: tessellation,
+                tesselation: tessellation,
                 sideOrientation: sideOrientation,
                 updatable: updatable
             };
@@ -1351,9 +1343,8 @@ var BABYLON;
             var matWeightIdx = 0;
             var inf;
             for (var index = 0; index < positionsData.length; index += 3, matWeightIdx += 4) {
-                var weight;
                 for (inf = 0; inf < 4; inf++) {
-                    weight = matricesWeightsData[matWeightIdx + inf];
+                    var weight = matricesWeightsData[matWeightIdx + inf];
                     if (weight > 0) {
                         BABYLON.Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesData[matWeightIdx + inf] * 16, weight, tempMatrix);
                         finalMatrix.addToSelf(tempMatrix);
@@ -1363,7 +1354,7 @@ var BABYLON;
                 }
                 if (needExtras) {
                     for (inf = 0; inf < 4; inf++) {
-                        weight = matricesWeightsExtraData[matWeightIdx + inf];
+                        var weight = matricesWeightsExtraData[matWeightIdx + inf];
                         if (weight > 0) {
                             BABYLON.Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesExtraData[matWeightIdx + inf] * 16, weight, tempMatrix);
                             finalMatrix.addToSelf(tempMatrix);

+ 6 - 17
src/Mesh/babylon.mesh.ts

@@ -1288,15 +1288,6 @@
 
         // Cylinder and cone
         public static CreateCylinder(name: string, height: number, diameterTop: number, diameterBottom: number, tessellation: number, subdivisions: any, scene: Scene, updatable?: any, sideOrientation?: number): Mesh {
-            if (scene === undefined || !(scene instanceof Scene)) {
-                if (scene !== undefined) {
-                    sideOrientation = updatable || Mesh.DEFAULTSIDE;
-                    updatable = scene;
-                }
-                scene = <Scene>subdivisions;
-                subdivisions = 1;
-            }
-
             var options = {
                 height: height,
                 diameterTop: diameterTop,
@@ -1398,7 +1389,7 @@
             var options = {
                 shape: shape,
                 radius: radius,
-                tessellation: tessellation,
+                tesselation: tessellation,
                 sideOrientation: sideOrientation,
                 updatable: updatable
             };
@@ -1580,11 +1571,10 @@
             var tempMatrix = new Matrix();
 
             var matWeightIdx = 0;
-            var inf: number;
+            var inf : number;
             for (var index = 0; index < positionsData.length; index += 3, matWeightIdx += 4) {
-                var weight: number;
                 for (inf = 0; inf < 4; inf++) {
-                    weight = matricesWeightsData[matWeightIdx + inf];
+                    var weight = matricesWeightsData[matWeightIdx + inf];
                     if (weight > 0) {
                         Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesData[matWeightIdx + inf] * 16, weight, tempMatrix);
                         finalMatrix.addToSelf(tempMatrix);
@@ -1593,15 +1583,15 @@
                 }
                 if (needExtras) {
                     for (inf = 0; inf < 4; inf++) {
-                        weight = matricesWeightsExtraData[matWeightIdx + inf];
+                        var weight = matricesWeightsExtraData[matWeightIdx + inf];
                         if (weight > 0) {
                             Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesExtraData[matWeightIdx + inf] * 16, weight, tempMatrix);
                             finalMatrix.addToSelf(tempMatrix);
 
-                        } else break;
+                        } else break;           
                     }
                 }
-
+                
                 Vector3.TransformCoordinatesFromFloatsToRef(this._sourcePositions[index], this._sourcePositions[index + 1], this._sourcePositions[index + 2], finalMatrix, tempVector3);
                 tempVector3.toArray(positionsData, index);
 
@@ -1716,4 +1706,3 @@
 
 
 
-

+ 25 - 35
src/Mesh/babylon.mesh.vertexData.js

@@ -662,7 +662,6 @@ var BABYLON;
             var diameterBottom = options.diameterBottom || options.diameter || 1;
             var tessellation = options.tessellation || 24;
             var subdivisions = options.subdivisions || 1;
-            var hasRings = options.hasRings;
             var arc = (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
             var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
             var faceUV = options.faceUV || new Array(3);
@@ -691,43 +690,36 @@ var BABYLON;
             // positions, normals, uvs
             var i;
             var j;
-            var r;
-            var ringIdx = 1;
             for (i = 0; i <= subdivisions; i++) {
                 h = i / subdivisions;
                 radius = (h * (diameterTop - diameterBottom) + diameterBottom) / 2;
-                ringIdx = (hasRings && i !== 0 && i !== subdivisions) ? 2 : 1;
-                for (r = 0; r < ringIdx; r++) {
-                    for (j = 0; j <= tessellation; j++) {
-                        angle = j * angle_step;
-                        ringVertex.x = Math.cos(-angle) * radius;
-                        ringVertex.y = -height / 2 + h * height;
-                        ringVertex.z = Math.sin(-angle) * radius;
-                        if (diameterTop === 0 && i === subdivisions) {
-                            // if no top cap, reuse former normals
-                            ringNormal.x = normals[normals.length - (tessellation + 1) * 3];
-                            ringNormal.y = normals[normals.length - (tessellation + 1) * 3 + 1];
-                            ringNormal.z = normals[normals.length - (tessellation + 1) * 3 + 2];
-                        }
-                        else {
-                            ringNormal.x = ringVertex.x;
-                            ringNormal.z = ringVertex.z;
-                            ringNormal.y = Math.sqrt(ringNormal.x * ringNormal.x + ringNormal.z * ringNormal.z) * tan;
-                            ringNormal.normalize();
-                        }
-                        positions.push(ringVertex.x, ringVertex.y, ringVertex.z);
-                        normals.push(ringNormal.x, ringNormal.y, ringNormal.z);
-                        uvs.push(faceUV[1].x + (faceUV[1].z - faceUV[1].x) * j / tessellation, faceUV[1].y + (faceUV[1].w - faceUV[1].y) * h);
-                        if (faceColors) {
-                            colors.push(faceColors[1].r, faceColors[1].g, faceColors[1].b, faceColors[1].a);
-                        }
+                for (j = 0; j <= tessellation; j++) {
+                    angle = j * angle_step;
+                    ringVertex.x = Math.cos(-angle) * radius;
+                    ringVertex.y = -height / 2 + h * height;
+                    ringVertex.z = Math.sin(-angle) * radius;
+                    if (diameterTop === 0 && i === subdivisions) {
+                        // if no top cap, reuse former normals
+                        ringNormal.x = normals[normals.length - (tessellation + 1) * 3];
+                        ringNormal.y = normals[normals.length - (tessellation + 1) * 3 + 1];
+                        ringNormal.z = normals[normals.length - (tessellation + 1) * 3 + 2];
+                    }
+                    else {
+                        ringNormal.x = ringVertex.x;
+                        ringNormal.z = ringVertex.z;
+                        ringNormal.y = Math.sqrt(ringNormal.x * ringNormal.x + ringNormal.z * ringNormal.z) * tan;
+                        ringNormal.normalize();
+                    }
+                    positions.push(ringVertex.x, ringVertex.y, ringVertex.z);
+                    normals.push(ringNormal.x, ringNormal.y, ringNormal.z);
+                    uvs.push(faceUV[1].x + (faceUV[1].z - faceUV[1].x) * j / tessellation, faceUV[1].y + (faceUV[1].w - faceUV[1].y) * h);
+                    if (faceColors) {
+                        colors.push(faceColors[1].r, faceColors[1].g, faceColors[1].b, faceColors[1].a);
                     }
                 }
             }
             // indices
-            var s;
-            i = 0;
-            for (s = 0; s < subdivisions; s++) {
+            for (i = 0; i < subdivisions; i++) {
                 for (j = 0; j < tessellation; j++) {
                     var i0 = i * (tessellation + 1) + j;
                     var i1 = (i + 1) * (tessellation + 1) + j;
@@ -736,7 +728,6 @@ var BABYLON;
                     indices.push(i0, i1, i2);
                     indices.push(i3, i2, i1);
                 }
-                i = (hasRings) ? (i + 2) : (i + 1);
             }
             // Caps
             var createCylinderCap = function (isTop) {
@@ -1191,15 +1182,14 @@ var BABYLON;
             // prepare array of 3 vector (empty) (to be worked in place, shared for each face)
             var face_vertex_pos = new Array(3);
             var face_vertex_uv = new Array(3);
-            var v012;
-            for (v012 = 0; v012 < 3; v012++) {
+            for (var v012 = 0; v012 < 3; v012++) {
                 face_vertex_pos[v012] = BABYLON.Vector3.Zero();
                 face_vertex_uv[v012] = BABYLON.Vector2.Zero();
             }
             // create all with normals
             for (var face = 0; face < 20; face++) {
                 // 3 vertex per face
-                for (v012 = 0; v012 < 3; v012++) {
+                for (var v012 = 0; v012 < 3; v012++) {
                     // look up vertex 0,1,2 to its index in 0 to 11
                     var v_id = ico_indices[3 * face + v012];
                     // vertex have 3D position (x,y,z)

+ 33 - 39
src/Mesh/babylon.mesh.vertexData.ts

@@ -805,13 +805,12 @@
         }
 
         // Cylinder and cone 
-        public static CreateCylinder(options: { height?: number, diameterTop?: number, diameterBottom?: number, diameter?: number, tessellation?: number, subdivisions?: number, arc?: number, faceColors?: Color4[], faceUV?: Vector4[], hasRings?: boolean, sideOrientation?: number }): VertexData {
+        public static CreateCylinder(options: { height?: number, diameterTop?: number, diameterBottom?: number, diameter?: number, tessellation?: number, subdivisions?: number, arc?: number, faceColors?: Color4[], faceUV?: Vector4[], sideOrientation?: number }): VertexData {
             var height: number = options.height || 2;
             var diameterTop: number = (options.diameterTop === 0) ? 0 : options.diameterTop || options.diameter || 1;
             var diameterBottom: number = options.diameterBottom || options.diameter || 1;
             var tessellation: number = options.tessellation || 24;
             var subdivisions: number = options.subdivisions || 1;
-            var hasRings: boolean = options.hasRings;
             var arc: number = (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
             var sideOrientation: number = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
             var faceUV: Vector4[] = options.faceUV || new Array<Vector4>(3);
@@ -843,44 +842,37 @@
             // positions, normals, uvs
             var i: number;
             var j: number;
-            var r: number;
-            var ringIdx = 1;
             for (i = 0; i <= subdivisions; i++) {
                 h = i / subdivisions;
                 radius = (h * (diameterTop - diameterBottom) + diameterBottom) / 2;
-                ringIdx = (hasRings && i !== 0 && i !== subdivisions) ? 2 : 1;
-                for (r = 0; r < ringIdx; r++) {
-                    for (j = 0; j <= tessellation; j++) {
-                        angle = j * angle_step;
-                        ringVertex.x = Math.cos(-angle) * radius;
-                        ringVertex.y = -height / 2 + h * height;
-                        ringVertex.z = Math.sin(-angle) * radius;
-                        if (diameterTop === 0 && i === subdivisions) {
-                            // if no top cap, reuse former normals
-                            ringNormal.x = normals[normals.length - (tessellation + 1) * 3];
-                            ringNormal.y = normals[normals.length - (tessellation + 1) * 3 + 1];
-                            ringNormal.z = normals[normals.length - (tessellation + 1) * 3 + 2];
-                        }
-                        else {
-                            ringNormal.x = ringVertex.x;
-                            ringNormal.z = ringVertex.z;
-                            ringNormal.y = Math.sqrt(ringNormal.x * ringNormal.x + ringNormal.z * ringNormal.z) * tan;
-                            ringNormal.normalize();
-                        }
-                        positions.push(ringVertex.x, ringVertex.y, ringVertex.z);
-                        normals.push(ringNormal.x, ringNormal.y, ringNormal.z);
-                        uvs.push(faceUV[1].x + (faceUV[1].z - faceUV[1].x) * j / tessellation, faceUV[1].y + (faceUV[1].w - faceUV[1].y) * h);
-                        if (faceColors) {
-                            colors.push(faceColors[1].r, faceColors[1].g, faceColors[1].b, faceColors[1].a);
-                        }
+                for (j = 0; j <= tessellation; j++) {
+                    angle = j * angle_step;
+                    ringVertex.x = Math.cos(-angle) * radius;
+                    ringVertex.y = -height / 2 + h * height;
+                    ringVertex.z = Math.sin(-angle) * radius;
+                    if (diameterTop === 0 && i === subdivisions) {
+                        // if no top cap, reuse former normals
+                        ringNormal.x = normals[normals.length - (tessellation + 1) * 3];
+                        ringNormal.y = normals[normals.length - (tessellation + 1) * 3 + 1];
+                        ringNormal.z = normals[normals.length - (tessellation + 1) * 3 + 2];
+                    }
+                    else {
+                        ringNormal.x = ringVertex.x;
+                        ringNormal.z = ringVertex.z;
+                        ringNormal.y = Math.sqrt(ringNormal.x * ringNormal.x + ringNormal.z * ringNormal.z) * tan;
+                        ringNormal.normalize();
+                    }
+                    positions.push(ringVertex.x, ringVertex.y, ringVertex.z);
+                    normals.push(ringNormal.x, ringNormal.y, ringNormal.z);
+                    uvs.push(faceUV[1].x + (faceUV[1].z - faceUV[1].x) * j / tessellation, faceUV[1].y + (faceUV[1].w - faceUV[1].y) * h);
+                    if (faceColors) {
+                        colors.push(faceColors[1].r, faceColors[1].g, faceColors[1].b, faceColors[1].a);
                     }
                 }
             }
 
             // indices
-            var s;
-            i = 0;
-            for (s = 0; s < subdivisions; s++) {
+            for (i = 0; i < subdivisions; i++) {
                 for (j = 0; j < tessellation; j++) {
                     var i0 = i * (tessellation + 1) + j;
                     var i1 = (i + 1) * (tessellation + 1) + j;
@@ -889,7 +881,6 @@
                     indices.push(i0, i1, i2);
                     indices.push(i3, i2, i1);
                 }
-                i = (hasRings) ? (i + 2) : (i + 1);
             }
 
             // Caps
@@ -1394,7 +1385,7 @@
             return vertexData;
         }
 
-        public static CreateIcoSphere(options: { radius?: number, radiusX?: number, radiusY?: number, radiusZ?: number, flat?: number, subdivisions?: number, sideOrientation?: number }): VertexData {
+        public static CreateIcoSphere(options: {radius?: number, radiusX?: number, radiusY?: number, radiusZ?: number, flat?: number, subdivisions?: number, sideOrientation?: number}): VertexData {
             var sideOrientation = options.sideOrientation || Mesh.DEFAULTSIDE;
             var radius = options.radius || 1;
             var flat = (options.flat === undefined) ? true : options.flat;
@@ -1451,15 +1442,14 @@
             // prepare array of 3 vector (empty) (to be worked in place, shared for each face)
             var face_vertex_pos = new Array(3);
             var face_vertex_uv = new Array(3);
-            var v012: number;
-            for (v012 = 0; v012 < 3; v012++) {
+            for (var v012 = 0; v012 < 3; v012++) {
                 face_vertex_pos[v012] = Vector3.Zero();
                 face_vertex_uv[v012] = Vector2.Zero();
             }
             // create all with normals
             for (var face = 0; face < 20; face++) {
                 // 3 vertex per face
-                for (v012 = 0; v012 < 3; v012++) {
+                for (var v012 = 0; v012 < 3; v012++) {
                     // look up vertex 0,1,2 to its index in 0 to 11
                     var v_id = ico_indices[3 * face + v012];
                     // vertex have 3D position (x,y,z)
@@ -1534,7 +1524,7 @@
                 // centroid of triangle is needed to get help normal computation
                 //  (c1,c2) are used for centroid location
 
-                var interp_vertex = (i1: number, i2: number, c1: number, c2: number) => {
+                var interp_vertex = (i1: number, i2: number, c1: number, c2: number) =>{
                     // vertex is interpolated from
                     //   - face_vertex_pos[0..2]
                     //   - face_vertex_uv[0..2]
@@ -1939,4 +1929,8 @@
             }
         }
     }
-}
+}
+
+
+
+