Browse Source

Merge remote-tracking branch 'BabylonJS/master'

MackeyK24 8 years ago
parent
commit
887745d4c7

+ 3 - 0
Exporters/3ds Max/BabylonExport.Entities/BabylonStandardMaterial.cs

@@ -68,6 +68,9 @@ namespace BabylonExport.Entities
         [DataMember]
         public bool linkEmissiveWithDiffuse { get; set; }
 
+        [DataMember]
+        public bool twoSidedLighting { get; set; }
+
         public BabylonStandardMaterial() : base()
         {
             ambient = new[] {1.0f, 1.0f, 1.0f};

File diff suppressed because it is too large
+ 3960 - 3949
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 29 - 29
dist/preview release/babylon.js


File diff suppressed because it is too large
+ 90 - 10
dist/preview release/babylon.max.js


File diff suppressed because it is too large
+ 3960 - 3949
dist/preview release/babylon.module.d.ts


File diff suppressed because it is too large
+ 30 - 30
dist/preview release/babylon.worker.js


File diff suppressed because it is too large
+ 689 - 678
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


File diff suppressed because it is too large
+ 31 - 31
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 50 - 7
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -10040,7 +10040,7 @@ var BABYLON;
                     var minLODIndex = offset; // roughness = 0
                     var maxLODIndex = BABYLON.Scalar.Log2(width) * scale + offset; // roughness = 1
                     var lodIndex = minLODIndex + (maxLODIndex - minLODIndex) * roughness;
-                    var mipmapIndex = Math.min(Math.max(Math.round(lodIndex), 0), maxLODIndex);
+                    var mipmapIndex = Math.round(Math.min(Math.max(lodIndex, 0), maxLODIndex));
                     var glTextureFromLod = gl.createTexture();
                     glTextureFromLod.isCube = true;
                     _this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, glTextureFromLod);
@@ -24859,23 +24859,24 @@ var BABYLON;
         Material.prototype.forceCompilation = function (mesh, onCompiled, options) {
             var _this = this;
             var subMesh = new BABYLON.BaseSubMesh();
-            var scene = this.getScene();
-            var engine = scene.getEngine();
-            var beforeRenderCallback = function () {
+            var engine = this.getScene().getEngine();
+            var checkReady = function () {
                 if (subMesh._materialDefines) {
                     subMesh._materialDefines._renderId = -1;
                 }
                 var alphaTestState = engine.getAlphaTesting();
                 engine.setAlphaTesting(options ? options.alphaTest : _this.needAlphaTesting());
                 if (_this.isReadyForSubMesh(mesh, subMesh)) {
-                    scene.unregisterBeforeRender(beforeRenderCallback);
                     if (onCompiled) {
                         onCompiled(_this);
                     }
                 }
+                else {
+                    setTimeout(checkReady, 16);
+                }
                 engine.setAlphaTesting(alphaTestState);
             };
-            scene.registerBeforeRender(beforeRenderCallback);
+            checkReady();
         };
         Material.prototype.markAsDirty = function (flag) {
             if (flag & Material.TextureDirtyFlag) {
@@ -28506,9 +28507,11 @@ var BABYLON;
                     }
                 }
                 if (parsedGeometry.matricesWeights) {
+                    Geometry._CleanMatricesWeights(parsedGeometry.matricesWeights, parsedGeometry.numBoneInfluencers);
                     mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, parsedGeometry.matricesWeights, parsedGeometry.matricesWeights._updatable);
                 }
                 if (parsedGeometry.matricesWeightsExtra) {
+                    Geometry._CleanMatricesWeights(parsedGeometry.matricesWeightsExtra, parsedGeometry.numBoneInfluencers);
                     mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, parsedGeometry.matricesWeightsExtra, parsedGeometry.matricesWeights._updatable);
                 }
                 mesh.setIndices(parsedGeometry.indices);
@@ -28533,6 +28536,16 @@ var BABYLON;
                 scene['_selectionOctree'].addMesh(mesh);
             }
         };
+        Geometry._CleanMatricesWeights = function (matricesWeights, influencers) {
+            var size = matricesWeights.length;
+            for (var i = 0; i < size; i += influencers) {
+                var weight = 0;
+                for (var j = 0; j < influencers - 1; j++) {
+                    weight += matricesWeights[i + j];
+                }
+                matricesWeights[i + (influencers - 1)] = Math.max(0, 1.0 - weight);
+            }
+        };
         Geometry.Parse = function (parsedVertexData, scene, rootUrl) {
             if (scene.getGeometryByID(parsedVertexData.id)) {
                 return null; // null since geometry could be something else than a box...
@@ -38102,6 +38115,7 @@ var BABYLON;
             _this._floats = {};
             _this._floatsArrays = {};
             _this._colors3 = {};
+            _this._colors3Arrays = {};
             _this._colors4 = {};
             _this._vectors2 = {};
             _this._vectors3 = {};
@@ -38166,6 +38180,14 @@ var BABYLON;
             this._colors3[name] = value;
             return this;
         };
+        ShaderMaterial.prototype.setColor3Array = function (name, value) {
+            this._checkUniform(name);
+            this._colors3Arrays[name] = value.reduce(function (arr, color) {
+                color.toArray(arr, arr.length);
+                return arr;
+            }, []);
+            return this;
+        };
         ShaderMaterial.prototype.setColor4 = function (name, value) {
             this._checkUniform(name);
             this._colors4[name] = value;
@@ -38340,6 +38362,9 @@ var BABYLON;
                 for (name in this._colors3) {
                     this._effect.setColor3(name, this._colors3[name]);
                 }
+                for (name in this._colors3Arrays) {
+                    this._effect.setArray3(name, this._colors3Arrays[name]);
+                }
                 // Color4      
                 for (name in this._colors4) {
                     var color = this._colors4[name];
@@ -38463,6 +38488,11 @@ var BABYLON;
             for (name in this._colors3) {
                 serializationObject.colors3[name] = this._colors3[name].asArray();
             }
+            // Color3 array
+            serializationObject.colors3Arrays = {};
+            for (name in this._colors3Arrays) {
+                serializationObject.colors3Arrays[name] = this._colors3Arrays[name];
+            }
             // Color4  
             serializationObject.colors4 = {};
             for (name in this._colors4) {
@@ -38533,6 +38563,19 @@ var BABYLON;
             for (name in source.colors3) {
                 material.setColor3(name, BABYLON.Color3.FromArray(source.colors3[name]));
             }
+            // Color3 arrays
+            for (name in source.colors3Arrays) {
+                var colors = source.colors3Arrays[name].reduce(function (arr, num, i) {
+                    if (i % 3 === 0) {
+                        arr.push([num]);
+                    }
+                    else {
+                        arr[arr.length - 1].push(num);
+                    }
+                    return arr;
+                }, []).map(function (color) { return BABYLON.Color3.FromArray(color); });
+                material.setColor3Array(name, colors);
+            }
             // Color4      
             for (name in source.colors4) {
                 material.setColor4(name, BABYLON.Color4.FromArray(source.colors4[name]));
@@ -52063,11 +52106,11 @@ var BABYLON;
                         }
                         else {
                             var material = _this._gltf.materials[primitive.material];
-                            _this.addPendingData(material);
                             _this.loadMaterial(material, function (babylonMaterial, isNew) {
                                 if (isNew && _this._parent.onMaterialLoaded) {
                                     _this._parent.onMaterialLoaded(babylonMaterial);
                                 }
+                                _this.addPendingData(material);
                                 babylonMaterial.forceCompilation(babylonMesh, function (babylonMaterial) {
                                     babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                     _this.removePendingData(material);

File diff suppressed because it is too large
+ 689 - 678
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


+ 1 - 1
dist/preview release/loaders/babylon.glTF2FileLoader.js

@@ -639,11 +639,11 @@ var BABYLON;
                         }
                         else {
                             var material = _this._gltf.materials[primitive.material];
-                            _this.addPendingData(material);
                             _this.loadMaterial(material, function (babylonMaterial, isNew) {
                                 if (isNew && _this._parent.onMaterialLoaded) {
                                     _this._parent.onMaterialLoaded(babylonMaterial);
                                 }
+                                _this.addPendingData(material);
                                 babylonMaterial.forceCompilation(babylonMesh, function (babylonMaterial) {
                                     babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                     _this.removePendingData(material);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/loaders/babylon.glTF2FileLoader.min.js


+ 1 - 1
dist/preview release/loaders/babylon.glTFFileLoader.js

@@ -2797,11 +2797,11 @@ var BABYLON;
                         }
                         else {
                             var material = _this._gltf.materials[primitive.material];
-                            _this.addPendingData(material);
                             _this.loadMaterial(material, function (babylonMaterial, isNew) {
                                 if (isNew && _this._parent.onMaterialLoaded) {
                                     _this._parent.onMaterialLoaded(babylonMaterial);
                                 }
+                                _this.addPendingData(material);
                                 babylonMaterial.forceCompilation(babylonMesh, function (babylonMaterial) {
                                     babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                     _this.removePendingData(material);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/loaders/babylon.glTFFileLoader.min.js


+ 1 - 1
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -405,12 +405,12 @@ module BABYLON.GLTF2 {
                     }
                     else {
                         var material = this._gltf.materials[primitive.material];
-                        this.addPendingData(material);
                         this.loadMaterial(material, (babylonMaterial, isNew) => {
                             if (isNew && this._parent.onMaterialLoaded) {
                                 this._parent.onMaterialLoaded(babylonMaterial);
                             }
 
+                            this.addPendingData(material);
                             babylonMaterial.forceCompilation(babylonMesh, babylonMaterial => {
                                 babylonMultiMaterial.subMaterials[i] = babylonMaterial;
                                 this.removePendingData(material);

+ 8 - 8
src/Materials/babylon.material.ts

@@ -519,29 +519,29 @@
         // Force shader compilation including textures ready check
         public forceCompilation(mesh: AbstractMesh, onCompiled: (material: Material) => void, options?: { alphaTest: boolean }): void {
             var subMesh = new BaseSubMesh();
-            var scene = this.getScene();
-            var engine = scene.getEngine();
+            var engine = this.getScene().getEngine();
 
-            var beforeRenderCallback = () => {
+            var checkReady = () => {
                 if (subMesh._materialDefines) {
                     subMesh._materialDefines._renderId = -1;
                 }
-                
+
                 var alphaTestState = engine.getAlphaTesting();
                 engine.setAlphaTesting(options ? options.alphaTest : this.needAlphaTesting());
-                
-                if (this.isReadyForSubMesh(mesh, subMesh)) {
-                    scene.unregisterBeforeRender(beforeRenderCallback);
 
+                if (this.isReadyForSubMesh(mesh, subMesh)) {
                     if (onCompiled) {
                         onCompiled(this);
                     }
                 }
+                else {
+                    setTimeout(checkReady, 16);
+                }
 
                 engine.setAlphaTesting(alphaTestState);
             };
 
-            scene.registerBeforeRender(beforeRenderCallback);
+            checkReady();
         }
        
         public markAsDirty(flag: number): void {

+ 32 - 0
src/Materials/babylon.shaderMaterial.ts

@@ -7,6 +7,7 @@
         private _floats: { [name: string]: number } = {};
         private _floatsArrays: { [name: string]: number[] } = {};
         private _colors3: { [name: string]: Color3 } = {};
+        private _colors3Arrays: { [name: string]: number[] } = {};
         private _colors4: { [name: string]: Color4 } = {};
         private _vectors2: { [name: string]: Vector2 } = {};
         private _vectors3: { [name: string]: Vector3 } = {};
@@ -92,6 +93,14 @@
 
             return this;
         }
+        public setColor3Array(name: string, value: Color3[]): ShaderMaterial {
+            this._checkUniform(name);
+            this._colors3Arrays[name] = value.reduce((arr, color) => {
+                color.toArray(arr, arr.length);
+                return arr;
+            }, [])
+            return this;
+        }
 
         public setColor4(name: string, value: Color4): ShaderMaterial {
             this._checkUniform(name);
@@ -316,6 +325,10 @@
                     this._effect.setColor3(name, this._colors3[name]);
                 }
 
+                for (name in this._colors3Arrays) {
+                    this._effect.setArray3(name, this._colors3Arrays[name]);
+                }
+
                 // Color4      
                 for (name in this._colors4) {
                     var color = this._colors4[name];
@@ -471,6 +484,12 @@
                 serializationObject.colors3[name] = this._colors3[name].asArray();
             }
 
+            // Color3 array
+            serializationObject.colors3Arrays = {};
+            for (name in this._colors3Arrays) {
+                serializationObject.colors3Arrays[name] = this._colors3Arrays[name];
+            }
+
             // Color4  
             serializationObject.colors4 = {};
             for (name in this._colors4) {
@@ -558,6 +577,19 @@
                 material.setColor3(name, Color3.FromArray(source.colors3[name]));
             }
 
+            // Color3 arrays
+            for (name in source.colors3Arrays) {
+                const colors: Color3[] = source.colors3Arrays[name].reduce((arr, num, i) => {
+                    if (i % 3 === 0) {
+                        arr.push([num]);
+                    } else {
+                        arr[arr.length - 1].push(num);
+                    }
+                    return arr;
+                }, []).map(color => Color3.FromArray(color));
+                material.setColor3Array(name, colors);
+            }
+
             // Color4      
             for (name in source.colors4) {
                 material.setColor4(name, Color4.FromArray(source.colors4[name]));

+ 16 - 2
src/Mesh/babylon.geometry.ts

@@ -842,7 +842,7 @@
                 }
 
                 if (binaryInfo.matricesWeightsAttrDesc && binaryInfo.matricesWeightsAttrDesc.count > 0) {
-                    var matricesWeightsData = new Float32Array(parsedGeometry, binaryInfo.matricesWeightsAttrDesc.offset, binaryInfo.matricesWeightsAttrDesc.count);
+                    var matricesWeightsData = new Float32Array(parsedGeometry, binaryInfo.matricesWeightsAttrDesc.offset, binaryInfo.matricesWeightsAttrDesc.count);                    
                     mesh.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeightsData, false);
                 }
 
@@ -939,10 +939,12 @@
                 }
 
                 if (parsedGeometry.matricesWeights) {
+                    Geometry._CleanMatricesWeights(parsedGeometry.matricesWeights, parsedGeometry.numBoneInfluencers);
                     mesh.setVerticesData(VertexBuffer.MatricesWeightsKind, parsedGeometry.matricesWeights, parsedGeometry.matricesWeights._updatable);
                 }
 
-                if (parsedGeometry.matricesWeightsExtra) {
+                if (parsedGeometry.matricesWeightsExtra) {                    
+                    Geometry._CleanMatricesWeights(parsedGeometry.matricesWeightsExtra, parsedGeometry.numBoneInfluencers);
                     mesh.setVerticesData(VertexBuffer.MatricesWeightsExtraKind, parsedGeometry.matricesWeightsExtra, parsedGeometry.matricesWeights._updatable);
                 }
 
@@ -974,6 +976,18 @@
             }
         }
 
+        private static _CleanMatricesWeights(matricesWeights: number[], influencers: number): void {
+            let size = matricesWeights.length;
+            for (var i = 0; i < size; i += influencers) {
+                let weight = 0;
+                for (var j = 0; j < influencers - 1; j++) {
+                    weight += matricesWeights[i + j];
+                }
+
+                matricesWeights[i + (influencers - 1)] = Math.max(0, 1.0 - weight);
+            }
+        }
+
         public static Parse(parsedVertexData: any, scene: Scene, rootUrl: string): Geometry {
             if (scene.getGeometryByID(parsedVertexData.id)) {
                 return null; // null since geometry could be something else than a box...

+ 41 - 2
src/Tools/babylon.extendedGamepad.ts

@@ -3,6 +3,7 @@ module BABYLON {
     export enum PoseEnabledControllerType {
         VIVE,
         OCULUS,
+        WINDOWS,
         GENERIC
     }
 
@@ -14,12 +15,22 @@ module BABYLON {
 
     export class PoseEnabledControllerHelper {
         public static InitiateController(vrGamepad: any) {
-            // for now, only Oculus and Vive are supported
+            // Oculus Touch
             if (vrGamepad.id.indexOf('Oculus Touch') !== -1) {
                 return new OculusTouchController(vrGamepad);
-            } else {
+            }
+            // Windows Mixed Reality controllers 
+            // else if (vrGamepad.id.indexOf('Spatial Control') === 0) {
+            //     //return new WindowsMixedRealityController(vrGamepad);
+            // }
+            // HTC Vive
+            else if (vrGamepad.id.toLowerCase().indexOf('openvr') !== -1) {
                 return new ViveController(vrGamepad);
             }
+            // Generic 
+            else {
+                return new GenericController(vrGamepad);
+            }
         }
     }
 
@@ -197,6 +208,13 @@ module BABYLON {
         public abstract initControllerMesh(scene: Scene, meshLoaded?: (mesh: AbstractMesh) => void)
 
         private _setButtonValue(newState: ExtendedGamepadButton, currentState: ExtendedGamepadButton, buttonIndex: number) {
+            if (!newState) {
+                newState = {
+                    pressed: false,
+                    touched: false,
+                    value: 0
+                };
+            }  
             if (!currentState) {
                 this._buttons[buttonIndex] = {
                     pressed: newState.pressed,
@@ -440,7 +458,28 @@ module BABYLON {
         }
     }
 
+    export class GenericController extends WebVRController {
+        private _defaultModel: BABYLON.AbstractMesh;
+
+        constructor(vrGamepad) {
+            super(vrGamepad);
+        }
+
+        public initControllerMesh(scene: Scene, meshLoaded?: (mesh: AbstractMesh) => void) {
+            SceneLoader.ImportMesh("", "http://yoda.blob.core.windows.net/models/", "genericvrcontroller.babylon", scene, (newMeshes) => {
+                this._defaultModel = newMeshes[1];
+                if (meshLoaded) {
+                    meshLoaded(this._defaultModel);
+                }
+                this.attachToMesh(this._defaultModel);
+            });
+        }
 
+        protected handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
+            console.log("Button id: " + buttonIdx + "state: ");
+            console.dir(state);
+        }
+    }
 }
 
 interface ExtendedGamepadButton extends GamepadButton {

+ 1 - 1
src/babylon.engine.ts

@@ -3270,7 +3270,7 @@
                     let maxLODIndex = Scalar.Log2(width) * scale + offset; // roughness = 1
 
                     let lodIndex = minLODIndex + (maxLODIndex - minLODIndex) * roughness;
-                    let mipmapIndex = Math.min(Math.max(Math.round(lodIndex), 0), maxLODIndex);
+                    let mipmapIndex = Math.round(Math.min(Math.max(lodIndex, 0), maxLODIndex));
 
                     var glTextureFromLod = gl.createTexture();
                     glTextureFromLod.isCube = true;