David Catuhe %!s(int64=7) %!d(string=hai) anos
pai
achega
9f7aa9b4f2

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 6749 - 6734
Playground/babylon.d.txt


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 5607 - 5597
dist/preview release/babylon.d.ts


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 29 - 29
dist/preview release/babylon.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 45 - 11
dist/preview release/babylon.max.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 45 - 11
dist/preview release/babylon.no-module.max.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 29 - 29
dist/preview release/babylon.worker.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 45 - 11
dist/preview release/es6.js


+ 0 - 1
dist/preview release/serializers/babylon.glTF2Serializer.d.ts

@@ -287,7 +287,6 @@ declare module BABYLON.GLTF2 {
          * @param binaryWriter Buffer to write binary data to
          */
         private createSceneAsync(babylonScene, binaryWriter);
-        private getRootNodes(babylonScene, nodes, shouldExportTransformNode);
         /**
          * Creates a mapping of Node unique id to node index and handles animations
          * @param babylonScene Babylon Scene

+ 7 - 31
dist/preview release/serializers/babylon.glTF2Serializer.js

@@ -874,7 +874,7 @@ var BABYLON;
                         for (var _a = 0, _b = bufferMesh.subMeshes; _a < _b.length; _a++) {
                             var submesh = _b[_a];
                             uvCoordsPresent = false;
-                            var babylonMaterial = submesh.getMaterial();
+                            var babylonMaterial = submesh.getMaterial() || bufferMesh.getScene().defaultMaterial;
                             var materialIndex = null;
                             if (babylonMaterial) {
                                 if (bufferMesh instanceof BABYLON.LinesMesh) {
@@ -891,8 +891,9 @@ var BABYLON;
                                     materialIndex = this._materials.length - 1;
                                 }
                                 else if (babylonMaterial instanceof BABYLON.MultiMaterial) {
-                                    babylonMaterial = babylonMaterial.subMaterials[submesh.materialIndex];
-                                    if (babylonMaterial) {
+                                    var subMaterial = babylonMaterial.subMaterials[submesh.materialIndex];
+                                    if (subMaterial) {
+                                        babylonMaterial = subMaterial;
                                         materialIndex = this._materialMap[babylonMaterial.uniqueId];
                                     }
                                 }
@@ -939,7 +940,7 @@ var BABYLON;
                                 meshPrimitive.indices = this._accessors.length - 1;
                             }
                             if (materialIndex != null && Object.keys(meshPrimitive.attributes).length > 0) {
-                                var sideOrientation = this._babylonScene.materials[materialIndex].sideOrientation;
+                                var sideOrientation = babylonMaterial.sideOrientation;
                                 if (this._convertToRightHandedSystem && sideOrientation === BABYLON.Material.ClockWiseSideOrientation) {
                                     //Overwrite the indices to be counter-clockwise
                                     var byteOffset = indexBufferViewIndex != null ? this._bufferViews[indexBufferViewIndex].byteOffset : null;
@@ -1037,18 +1038,6 @@ var BABYLON;
                     }
                 });
             };
-            _Exporter.prototype.getRootNodes = function (babylonScene, nodes, shouldExportTransformNode) {
-                var rootNodes = [];
-                for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
-                    var babylonTransformNode = nodes_2[_i];
-                    if (shouldExportTransformNode(babylonTransformNode)) {
-                        if (babylonTransformNode.parent == null) {
-                            rootNodes.push(babylonTransformNode);
-                        }
-                    }
-                }
-                return rootNodes;
-            };
             /**
              * Creates a mapping of Node unique id to node index and handles animations
              * @param babylonScene Babylon Scene
@@ -1068,23 +1057,10 @@ var BABYLON;
                 };
                 var idleGLTFAnimations = [];
                 var node;
-                var negScaleRootNode = null;
-                var rootNodes = this.getRootNodes(babylonScene, nodes, shouldExportTransformNode);
-                if (rootNodes.length === 1) {
-                    var node_1 = rootNodes[0];
-                    if (node_1.scaling.equalsToFloats(1, 1, -1)) {
-                        this._convertToRightHandedSystem = !this._convertToRightHandedSystem;
-                        negScaleRootNode = node_1;
-                    }
-                }
-                for (var _i = 0, nodes_3 = nodes; _i < nodes_3.length; _i++) {
-                    var babylonTransformNode = nodes_3[_i];
+                for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
+                    var babylonTransformNode = nodes_2[_i];
                     if (shouldExportTransformNode(babylonTransformNode)) {
                         node = this.createNode(babylonTransformNode, binaryWriter);
-                        if (negScaleRootNode && babylonTransformNode === negScaleRootNode) {
-                            node.scale = [1, 1, 1];
-                            node.rotation = [0, 0, 0, 1];
-                        }
                         var directDescendents = babylonTransformNode.getDescendants(true, function (node) { return (node instanceof BABYLON.TransformNode); });
                         if (directDescendents.length || node.mesh != null) {
                             this._nodes.push(node);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2 - 2
dist/preview release/serializers/babylon.glTF2Serializer.min.js


+ 0 - 1
dist/preview release/serializers/babylonjs.serializers.d.ts

@@ -295,7 +295,6 @@ declare module BABYLON.GLTF2 {
          * @param binaryWriter Buffer to write binary data to
          */
         private createSceneAsync(babylonScene, binaryWriter);
-        private getRootNodes(babylonScene, nodes, shouldExportTransformNode);
         /**
          * Creates a mapping of Node unique id to node index and handles animations
          * @param babylonScene Babylon Scene

+ 7 - 31
dist/preview release/serializers/babylonjs.serializers.js

@@ -1035,7 +1035,7 @@ var BABYLON;
                         for (var _a = 0, _b = bufferMesh.subMeshes; _a < _b.length; _a++) {
                             var submesh = _b[_a];
                             uvCoordsPresent = false;
-                            var babylonMaterial = submesh.getMaterial();
+                            var babylonMaterial = submesh.getMaterial() || bufferMesh.getScene().defaultMaterial;
                             var materialIndex = null;
                             if (babylonMaterial) {
                                 if (bufferMesh instanceof BABYLON.LinesMesh) {
@@ -1052,8 +1052,9 @@ var BABYLON;
                                     materialIndex = this._materials.length - 1;
                                 }
                                 else if (babylonMaterial instanceof BABYLON.MultiMaterial) {
-                                    babylonMaterial = babylonMaterial.subMaterials[submesh.materialIndex];
-                                    if (babylonMaterial) {
+                                    var subMaterial = babylonMaterial.subMaterials[submesh.materialIndex];
+                                    if (subMaterial) {
+                                        babylonMaterial = subMaterial;
                                         materialIndex = this._materialMap[babylonMaterial.uniqueId];
                                     }
                                 }
@@ -1100,7 +1101,7 @@ var BABYLON;
                                 meshPrimitive.indices = this._accessors.length - 1;
                             }
                             if (materialIndex != null && Object.keys(meshPrimitive.attributes).length > 0) {
-                                var sideOrientation = this._babylonScene.materials[materialIndex].sideOrientation;
+                                var sideOrientation = babylonMaterial.sideOrientation;
                                 if (this._convertToRightHandedSystem && sideOrientation === BABYLON.Material.ClockWiseSideOrientation) {
                                     //Overwrite the indices to be counter-clockwise
                                     var byteOffset = indexBufferViewIndex != null ? this._bufferViews[indexBufferViewIndex].byteOffset : null;
@@ -1198,18 +1199,6 @@ var BABYLON;
                     }
                 });
             };
-            _Exporter.prototype.getRootNodes = function (babylonScene, nodes, shouldExportTransformNode) {
-                var rootNodes = [];
-                for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
-                    var babylonTransformNode = nodes_2[_i];
-                    if (shouldExportTransformNode(babylonTransformNode)) {
-                        if (babylonTransformNode.parent == null) {
-                            rootNodes.push(babylonTransformNode);
-                        }
-                    }
-                }
-                return rootNodes;
-            };
             /**
              * Creates a mapping of Node unique id to node index and handles animations
              * @param babylonScene Babylon Scene
@@ -1229,23 +1218,10 @@ var BABYLON;
                 };
                 var idleGLTFAnimations = [];
                 var node;
-                var negScaleRootNode = null;
-                var rootNodes = this.getRootNodes(babylonScene, nodes, shouldExportTransformNode);
-                if (rootNodes.length === 1) {
-                    var node_1 = rootNodes[0];
-                    if (node_1.scaling.equalsToFloats(1, 1, -1)) {
-                        this._convertToRightHandedSystem = !this._convertToRightHandedSystem;
-                        negScaleRootNode = node_1;
-                    }
-                }
-                for (var _i = 0, nodes_3 = nodes; _i < nodes_3.length; _i++) {
-                    var babylonTransformNode = nodes_3[_i];
+                for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
+                    var babylonTransformNode = nodes_2[_i];
                     if (shouldExportTransformNode(babylonTransformNode)) {
                         node = this.createNode(babylonTransformNode, binaryWriter);
-                        if (negScaleRootNode && babylonTransformNode === negScaleRootNode) {
-                            node.scale = [1, 1, 1];
-                            node.rotation = [0, 0, 0, 1];
-                        }
                         var directDescendents = babylonTransformNode.getDescendants(true, function (node) { return (node instanceof BABYLON.TransformNode); });
                         if (directDescendents.length || node.mesh != null) {
                             this._nodes.push(node);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2 - 2
dist/preview release/serializers/babylonjs.serializers.min.js


+ 0 - 1
dist/preview release/serializers/babylonjs.serializers.module.d.ts

@@ -302,7 +302,6 @@ declare module BABYLON.GLTF2 {
          * @param binaryWriter Buffer to write binary data to
          */
         private createSceneAsync(babylonScene, binaryWriter);
-        private getRootNodes(babylonScene, nodes, shouldExportTransformNode);
         /**
          * Creates a mapping of Node unique id to node index and handles animations
          * @param babylonScene Babylon Scene

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 48 - 48
dist/preview release/viewer/babylon.viewer.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 60 - 21
dist/preview release/viewer/babylon.viewer.max.js


+ 8 - 0
src/Particles/babylon.IParticleSystem.ts

@@ -175,6 +175,14 @@ module BABYLON {
 
         /** Gets or sets a Vector2 used to move the pivot (by default (0,0)) */
         translationPivot: Vector2;
+
+        /**
+         * Gets or sets a texture used to add random noise to particle positions
+         */
+        noiseTexture: Nullable<BaseTexture>;
+
+        /** Gets or sets the strength to apply to the noise value (default is (10, 10, 10)) */
+        noiseStrength: Vector3;        
         
         /**
          * Gets or sets the billboard mode to use when isBillboardBased = true.

+ 27 - 5
src/Particles/babylon.gpuParticleSystem.ts

@@ -328,6 +328,14 @@
 
         /** Gets or sets a Vector2 used to move the pivot (by default (0,0)) */
         public translationPivot = new Vector2(0, 0);     
+
+        /**
+         * Gets or sets a texture used to add random noise to particle positions
+         */
+        public noiseTexture: Nullable<BaseTexture>;
+
+        /** Gets or sets the strength to apply to the noise value (default is (10, 10, 10)) */
+        public noiseStrength = new Vector3(10, 10, 10);        
         
         /**
          * Gets or sets the billboard mode to use when isBillboardBased = true.
@@ -718,9 +726,9 @@
                 attributes: ["position", "age", "life", "seed", "size", "color", "direction", "initialDirection", "angle", "cellIndex"],
                 uniformsNames: ["currentCount", "timeDelta", "emitterWM", "lifeTime", "color1", "color2", "sizeRange", "scaleRange","gravity", "emitPower",
                                 "direction1", "direction2", "minEmitBox", "maxEmitBox", "radius", "directionRandomizer", "height", "coneAngle", "stopFactor", 
-                                "angleRange", "radiusRange", "cellInfos"],
+                                "angleRange", "radiusRange", "cellInfos", "noiseStrength"],
                 uniformBuffersNames: [],
-                samplers:["randomSampler", "randomSampler2", "sizeGradientSampler", "angularSpeedGradientSampler", "velocityGradientSampler"],
+                samplers:["randomSampler", "randomSampler2", "sizeGradientSampler", "angularSpeedGradientSampler", "velocityGradientSampler", "noiseSampler"],
                 defines: "",
                 fallbacks: null,  
                 onCompiled: null,
@@ -972,7 +980,11 @@
             
             if (this.isAnimationSheetEnabled) {
                 defines += "\n#define ANIMATESHEET";
-            }             
+            }   
+            
+            if (this.noiseTexture) {
+                defines += "\n#define NOISE";
+            }
 
             if (this._updateEffect && this._updateEffectOptions.defines === defines) {
                 return;
@@ -1200,7 +1212,12 @@
             }
             if (this._isAnimationSheetEnabled) {
                 this._updateEffect.setFloat3("cellInfos", this.startSpriteCellID, this.endSpriteCellID, this.spriteCellChangeSpeed);
-            }            
+            }        
+            
+            if (this.noiseTexture) {
+                this._updateEffect.setTexture("noiseSampler", this.noiseTexture);  
+                this._updateEffect.setVector3("noiseStrength", this.noiseStrength);    
+            }
 
             let emitterWM: Matrix;
             if ((<AbstractMesh>this.emitter).position) {
@@ -1379,7 +1396,12 @@
             if (disposeTexture && this.particleTexture) {
                 this.particleTexture.dispose();
                 this.particleTexture = null;
-            }            
+            }    
+            
+            if (disposeTexture && this.noiseTexture) {
+                this.noiseTexture.dispose();
+                this.noiseTexture = null;
+            }
 
             // Callback
             this.onDisposeObservable.notifyObservers(this);

+ 30 - 11
src/Particles/babylon.particleSystem.ts

@@ -159,10 +159,7 @@
         /**
          * Gets or sets a texture used to add random noise to particle positions
          */
-        public noiseTexture: Texture;
-
-        /** Gets or sets the estimated area used by the system. It will be used to normalize the projection onto the noise texture (default is (1, 1)) */
-        public noiseGridSize = new Vector2(1, 1);
+        public noiseTexture: Nullable<BaseTexture>;
 
         /** Gets or sets the strength to apply to the noise value (default is (10, 10, 10)) */
         public noiseStrength = new Vector3(10, 10, 10);
@@ -563,6 +560,7 @@
                             }
                         }
 
+                        // Angular speed
                         if (this._angularSpeedGradients && this._angularSpeedGradients.length > 0) {                  
                             Tools.GetCurrentGradient(ratio, this._angularSpeedGradients, (currentGradient, nextGradient, scale) => {
                                 if (currentGradient !== particle._currentAngularSpeedGradient) {
@@ -575,6 +573,7 @@
                         }                        
                         particle.angle += particle.angularSpeed * this._scaledUpdateSpeed;
 
+                        // Direction
                         let directionScale = this._scaledUpdateSpeed;
                         if (this._velocityGradients && this._velocityGradients.length > 0) {                  
                             Tools.GetCurrentGradient(ratio, this._velocityGradients, (currentGradient, nextGradient, scale) => {
@@ -589,20 +588,22 @@
                         particle.direction.scaleToRef(directionScale, this._scaledDirection);
                         particle.position.addInPlace(this._scaledDirection);
 
+                        // Noise
                         if (noiseTextureData && noiseTextureSize) {
-                            let fetchedColorR = Tools.FetchR(particle.position.x / this.noiseGridSize.x, particle.position.y / this.noiseGridSize.y, noiseTextureSize.width, noiseTextureSize.height,  noiseTextureData);
-                            let fetchedColorG = Tools.FetchR(particle.position.x / this.noiseGridSize.x + 0.33, particle.position.y / this.noiseGridSize.y + 0.66, noiseTextureSize.width, noiseTextureSize.height,  noiseTextureData);
-                            let fetchedColorB = Tools.FetchR(particle.position.x / this.noiseGridSize.x + 0.66, particle.position.y / this.noiseGridSize.y + 0.33, noiseTextureSize.width, noiseTextureSize.height,  noiseTextureData);
+                            let fetchedColorR = Tools.FetchR(particle.position.y, particle.position.z, noiseTextureSize.width, noiseTextureSize.height, noiseTextureData);
+                            let fetchedColorG = Tools.FetchR(particle.position.x + 0.33, particle.position.z + 0.33, noiseTextureSize.width, noiseTextureSize.height, noiseTextureData);
+                            let fetchedColorB = Tools.FetchR(particle.position.x - 0.33, particle.position.y - 0.33, noiseTextureSize.width, noiseTextureSize.height, noiseTextureData);
                             
                             let force = Tmp.Vector3[0];
                             let scaledForce = Tmp.Vector3[1];
 
-                            force.copyFromFloats((2 * fetchedColorR - 1) * this.noiseStrength.x, (2 * fetchedColorG - 1) * this.noiseStrength.x, (2 * fetchedColorB - 1) * this.noiseStrength.x);
+                            force.copyFromFloats((2 * fetchedColorR - 1) * this.noiseStrength.x, (2 * fetchedColorG - 1) * this.noiseStrength.y, (2 * fetchedColorB - 1) * this.noiseStrength.z);
 
                             force.scaleToRef(this._scaledUpdateSpeed, scaledForce);
                             particle.direction.addInPlace(scaledForce);
                         }
 
+                        // Gravity
                         this.gravity.scaleToRef(this._scaledUpdateSpeed, this._scaledGravity);
                         particle.direction.addInPlace(this._scaledGravity);
 
@@ -1529,6 +1530,11 @@
                 this.particleTexture = null;
             }
 
+            if (disposeTexture && this.noiseTexture) {
+                this.noiseTexture.dispose();
+                this.noiseTexture = null;
+            }
+
             this._removeFromRoot();
 
             // Remove from scene
@@ -1678,7 +1684,7 @@
             if (particleSystem.particleTexture) {
                 serializationObject.textureName = particleSystem.particleTexture.name;
             }
-            
+           
             // Animations
             Animation.AppendSerializedAnimations(particleSystem, serializationObject);
 
@@ -1699,6 +1705,7 @@
             serializationObject.maxLifeTime = particleSystem.maxLifeTime;
             serializationObject.emitRate = particleSystem.emitRate;
             serializationObject.gravity = particleSystem.gravity.asArray();
+            serializationObject.noiseStrength = particleSystem.noiseStrength.asArray();
             serializationObject.color1 = particleSystem.color1.asArray();
             serializationObject.color2 = particleSystem.color2.asArray();
             serializationObject.colorDead = particleSystem.colorDead.asArray();
@@ -1784,7 +1791,12 @@
 
                     serializationObject.velocityGradients.push(serializedGradient);
                 }
-            }              
+            }    
+            
+            if (particleSystem.noiseTexture && particleSystem.noiseTexture instanceof ProceduralTexture) {
+                const noiseTexture = particleSystem.noiseTexture as ProceduralTexture;
+                serializationObject.noiseTexture = noiseTexture.serialize();
+            }
         }
 
         /** @hidden */
@@ -1855,6 +1867,9 @@
             particleSystem.maxEmitPower = parsedParticleSystem.maxEmitPower;
             particleSystem.emitRate = parsedParticleSystem.emitRate;
             particleSystem.gravity = Vector3.FromArray(parsedParticleSystem.gravity);
+            if (parsedParticleSystem.noiseStrength) {
+                particleSystem.noiseStrength = Vector3.FromArray(parsedParticleSystem.noiseStrength);
+            }
             particleSystem.color1 = Color4.FromArray(parsedParticleSystem.color1);
             particleSystem.color2 = Color4.FromArray(parsedParticleSystem.color2);
             particleSystem.colorDead = Color4.FromArray(parsedParticleSystem.colorDead);
@@ -1885,7 +1900,11 @@
                 for (var velocityGradient of parsedParticleSystem.velocityGradients) {
                     particleSystem.addVelocityGradient(velocityGradient.gradient, velocityGradient.factor1 !== undefined ?  velocityGradient.factor1 : velocityGradient.factor, velocityGradient.factor2);
                 }
-            }              
+            }     
+            
+            if (parsedParticleSystem.noiseTexture) {
+                particleSystem.noiseTexture = ProceduralTexture.Parse(parsedParticleSystem.noiseTexture, scene, rootUrl);
+            }
             
             // Emitter
             let emitterType: IParticleEmitterType;

+ 15 - 1
src/Shaders/gpuUpdateParticles.vertex.fx

@@ -100,6 +100,10 @@ uniform sampler2D angularSpeedGradientSampler;
 uniform sampler2D velocityGradientSampler;
 #endif
 
+#ifdef NOISE
+uniform vec3 noiseStrength;
+uniform sampler2D noiseSampler;
+#endif
 
 #ifdef ANIMATESHEET
 uniform vec3 cellInfos;
@@ -267,7 +271,17 @@ void main() {
 #ifndef BILLBOARD    
     outInitialDirection = initialDirection;
 #endif
-    outDirection = direction;// + gravity * timeDelta;
+    outDirection = direction + gravity * timeDelta;
+
+#ifdef NOISE
+    float fetchedR = texture(noiseSampler, vec2(outPosition.y, outPosition.z)).r;
+    float fetchedG = texture(noiseSampler, vec2(outPosition.x + 0.33, outPosition.z + 0.33)).r;
+    float fetchedB = texture(noiseSampler, vec2(outPosition.z - 0.33, outPosition.y - 0.33)).r;
+
+    vec3 force = vec3(2. * fetchedR - 1., 2. * fetchedG - 1., 2. * fetchedB - 1.) * noiseStrength;
+
+    outDirection = outDirection + force * timeDelta;
+#endif    
 
 #ifdef ANGULARSPEEDGRADIENTS
     float angularSpeed = texture(angularSpeedGradientSampler, vec2(ageGradient, 0)).r;

+ 10 - 2
src/Tools/babylon.tools.ts

@@ -181,8 +181,16 @@
          * @returns the R value
          */
         public static FetchR(u: number, v: number, width: number, height: number, pixels: Uint8Array): number {
-            let wrappedU = ((Math.abs(u) * width) % width) | 0;
-            let wrappedV = ((Math.abs(v) * height) % height) | 0;
+
+            u = Math.abs(u) + 0.5;
+            v = Math.abs(v) + 0.5;
+
+            let wrappedU = ((u * width) % width) | 0;
+            let wrappedV = ((v * height) % height) | 0;
+
+            // let wrappedU =  (Math.abs(u) - Math.floor(Math.abs(u))) * width | 0;
+            // let wrappedV =  (Math.abs(v) - Math.floor(Math.abs(v))) * height | 0;
+            
 
             let position = (wrappedU + wrappedV * width) * 4;
             return pixels[position] / 255;