Kaynağa Gözat

Add rain system + fix AWFUL bug in webgl states management

David Catuhe 7 yıl önce
ebeveyn
işleme
b38d246278

Dosya farkı çok büyük olduğundan ihmal edildi
+ 7593 - 7575
Playground/babylon.d.txt


+ 378 - 0
assets/particles/systems/rain.json

@@ -0,0 +1,378 @@
+{
+    "systems":
+    [
+        {
+            "name": "rainDense",
+            "id": "rainDense",
+            "capacity": 3000,
+            "emitter":
+            [
+                0,
+                30,
+                0
+            ],
+            "particleEmitterType":
+            {
+                "type": "BoxParticleEmitter",
+                "direction1":
+                [
+                    0,
+                    -1,
+                    0
+                ],
+                "direction2":
+                [
+                    0,
+                    -1,
+                    0
+                ],
+                "minEmitBox":
+                [
+                    -30,
+                    0,
+                    -30
+                ],
+                "maxEmitBox":
+                [
+                    30,
+                    0,
+                    30
+                ]
+            },
+            "textureName": "rain/Rain.png",
+            "animations": [],
+            "startDelay": 0,
+            "renderingGroupId": 0,
+            "isBillboardBased": true,
+            "billboardMode": 2,
+            "minAngularSpeed": 0,
+            "maxAngularSpeed": 0,
+            "minSize": 1,
+            "maxSize": 1,
+            "minScaleX": 0.25,
+            "maxScaleX": 0.25,
+            "minScaleY": 0.3,
+            "maxScaleY": 0.3,
+            "minEmitPower": 10,
+            "maxEmitPower": 12,
+            "minLifeTime": 3,
+            "maxLifeTime": 3,
+            "emitRate": 600,
+            "gravity":
+            [
+                0,
+                0,
+                0
+            ],
+            "noiseStrength":
+            [
+                10,
+                10,
+                10
+            ],
+            "color1":
+            [
+                1,
+                1,
+                1,
+                1
+            ],
+            "color2":
+            [
+                1,
+                1,
+                1,
+                1
+            ],
+            "colorDead":
+            [
+                1,
+                1,
+                1,
+                0
+            ],
+            "updateSpeed": 0.03333333333333333,
+            "targetStopDuration": 0,
+            "blendMode": 1,
+            "preWarmCycles": 50,
+            "preWarmStepOffset": 1,
+            "minInitialRotation": 0,
+            "maxInitialRotation": 0,
+            "startSpriteCellID": 0,
+            "endSpriteCellID": 3,
+            "spriteCellChangeSpeed": 0,
+            "spriteCellWidth": 128,
+            "spriteCellHeight": 512,
+            "spriteRandomStartCell": true,
+            "isAnimationSheetEnabled": true,
+            "colorGradients":
+            [
+                {
+                    "gradient": 0,
+                    "color1":
+                    [
+                        1,
+                        1,
+                        1,
+                        0.3
+                    ]
+                },
+                {
+                    "gradient": 1,
+                    "color1":
+                    [
+                        1,
+                        1,
+                        1,
+                        0.3
+                    ]
+                }
+            ],
+            "textureMask":
+            [
+                1,
+                1,
+                1,
+                1
+            ],
+            "customShader": null,
+            "preventAutoStart": false
+        },
+        {
+            "name": "rainSplash",
+            "id": "rainSplash",
+            "capacity": 100,
+            "emitter":
+            [
+                0,
+                30,
+                0
+            ],
+            "particleEmitterType":
+            {
+                "type": "BoxParticleEmitter",
+                "direction1":
+                [
+                    0,
+                    -1,
+                    0
+                ],
+                "direction2":
+                [
+                    0,
+                    -1,
+                    0
+                ],
+                "minEmitBox":
+                [
+                    -20,
+                    0,
+                    -20
+                ],
+                "maxEmitBox":
+                [
+                    50,
+                    0,
+                    50
+                ]
+            },
+            "textureName": "rain/Rain.png",
+            "animations": [],
+            "startDelay": 0,
+            "renderingGroupId": 0,
+            "isBillboardBased": true,
+            "billboardMode": 2,
+            "minAngularSpeed": 0,
+            "maxAngularSpeed": 0,
+            "minSize": 1,
+            "maxSize": 1,
+            "minScaleX": 0.25,
+            "maxScaleX": 0.25,
+            "minScaleY": 0.3,
+            "maxScaleY": 0.3,
+            "minEmitPower": 10,
+            "maxEmitPower": 10,
+            "minLifeTime": 2.95,
+            "maxLifeTime": 2.95,
+            "emitRate": 50,
+            "gravity":
+            [
+                0,
+                0,
+                0
+            ],
+            "noiseStrength":
+            [
+                10,
+                10,
+                10
+            ],
+            "color1":
+            [
+                1,
+                1,
+                1,
+                1
+            ],
+            "color2":
+            [
+                1,
+                1,
+                1,
+                1
+            ],
+            "colorDead":
+            [
+                1,
+                1,
+                1,
+                0
+            ],
+            "updateSpeed": 0.03333333333333333,
+            "targetStopDuration": 0,
+            "blendMode": 1,
+            "preWarmCycles": 0,
+            "preWarmStepOffset": 1,
+            "minInitialRotation": 0,
+            "maxInitialRotation": 0,
+            "startSpriteCellID": 0,
+            "endSpriteCellID": 3,
+            "spriteCellChangeSpeed": 0,
+            "spriteCellWidth": 128,
+            "spriteCellHeight": 512,
+            "spriteRandomStartCell": true,
+            "isAnimationSheetEnabled": true,
+            "colorGradients":
+            [
+                {
+                    "gradient": 0,
+                    "color1":
+                    [
+                        1,
+                        1,
+                        1,
+                        0.3
+                    ]
+                },
+                {
+                    "gradient": 1,
+                    "color1":
+                    [
+                        1,
+                        1,
+                        1,
+                        0.3
+                    ]
+                }
+            ],
+            "textureMask":
+            [
+                1,
+                1,
+                1,
+                1
+            ],
+            "customShader": null,
+            "preventAutoStart": false,
+            "subEmitters":
+            [
+                [
+                    {
+                        "type": 1,
+                        "inheritDirection": false,
+                        "inheritedVelocityAmount": 0,
+                        "particleSystem":
+                        {
+                            "name": "splash",
+                            "id": "splash",
+                            "capacity": 200,
+                            "emitterId": "",
+                            "particleEmitterType":
+                            {
+                                "type": "ConeParticleEmitter",
+                                "radius": 0.2,
+                                "angle": 3,
+                                "directionRandomizer": 0
+                            },
+                            "textureName": "rain/Rain.png",
+                            "animations": [],
+                            "startDelay": 0,
+                            "renderingGroupId": 0,
+                            "isBillboardBased": true,
+                            "billboardMode": 8,
+                            "minAngularSpeed": 0,
+                            "maxAngularSpeed": 0,
+                            "minSize": 0.05,
+                            "maxSize": 0.12,
+                            "minScaleX": 1,
+                            "maxScaleX": 1,
+                            "minScaleY": 1,
+                            "maxScaleY": 1,
+                            "minEmitPower": 1,
+                            "maxEmitPower": 2,
+                            "minLifeTime": 0.2,
+                            "maxLifeTime": 0.4,
+                            "emitRate": 60,
+                            "gravity":
+                            [
+                                0,
+                                0,
+                                0
+                            ],
+                            "noiseStrength":
+                            [
+                                10,
+                                10,
+                                10
+                            ],
+                            "color1":
+                            [
+                                1,
+                                1,
+                                1,
+                                1
+                            ],
+                            "color2":
+                            [
+                                1,
+                                1,
+                                1,
+                                1
+                            ],
+                            "colorDead":
+                            [
+                                1,
+                                1,
+                                1,
+                                0
+                            ],
+                            "updateSpeed": 0.03333333333333333,
+                            "targetStopDuration": 0.3,
+                            "blendMode": 1,
+                            "preWarmCycles": 0,
+                            "preWarmStepOffset": 1,
+                            "minInitialRotation": 0,
+                            "maxInitialRotation": 0,
+                            "startSpriteCellID": 0,
+                            "endSpriteCellID": 3,
+                            "spriteCellChangeSpeed": 0,
+                            "spriteCellWidth": 128,
+                            "spriteCellHeight": 512,
+                            "spriteRandomStartCell": true,
+                            "isAnimationSheetEnabled": true,
+                            "textureMask":
+                            [
+                                1,
+                                1,
+                                1,
+                                1
+                            ],
+                            "customShader": null,
+                            "preventAutoStart": false
+                        }
+                    }
+                ]
+            ]
+        }
+    ]
+}

BIN
assets/particles/textures/rain/Rain.png


Dosya farkı çok büyük olduğundan ihmal edildi
+ 10218 - 10200
dist/preview release/babylon.d.ts


Dosya farkı çok büyük olduğundan ihmal edildi
+ 1 - 1
dist/preview release/babylon.js


+ 93 - 27
dist/preview release/babylon.max.js

@@ -10975,7 +10975,7 @@ var BABYLON;
             }
             // Alpha equation
             if (this._isBlendEquationParametersDirty) {
-                gl.blendEquationSeparate(this._isBlendEquationParametersDirty[0], this._isBlendEquationParametersDirty[1]);
+                gl.blendEquationSeparate(this._blendEquationParameters[0], this._blendEquationParameters[1]);
                 this._isBlendEquationParametersDirty = false;
             }
             // Constants
@@ -12709,7 +12709,6 @@ var BABYLON;
          */
         Engine.prototype.clear = function (color, backBuffer, depth, stencil) {
             if (stencil === void 0) { stencil = false; }
-            this.applyStates();
             var mode = 0;
             if (backBuffer && color) {
                 this._gl.clearColor(color.r, color.g, color.b, color.a !== undefined ? color.a : 1.0);
@@ -56999,9 +56998,9 @@ var BABYLON;
             this.textureMask = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0);
             /**
              * Gets or sets the billboard mode to use when isBillboardBased = true.
-             * Only BABYLON.AbstractMesh.BILLBOARDMODE_ALL and AbstractMesh.BILLBOARDMODE_Y are supported so far
+             * Value can be: ParticleSystem.BILLBOARDMODE_ALL, ParticleSystem.BILLBOARDMODE_Y, ParticleSystem.BILLBOARDMODE_STRETCHED
              */
-            this.billboardMode = BABYLON.AbstractMesh.BILLBOARDMODE_ALL;
+            this.billboardMode = BABYLON.ParticleSystem.BILLBOARDMODE_ALL;
             this._isBillboardBased = true;
             /**
              * Local cache of defines for image processing.
@@ -58264,23 +58263,8 @@ var BABYLON;
         ParticleSystem.prototype.isStarted = function () {
             return this._started;
         };
-        /**
-         * Starts the particle system and begins to emit
-         * @param delay defines the delay in milliseconds before starting the system (this.startDelay by default)
-         */
-        ParticleSystem.prototype.start = function (delay) {
+        ParticleSystem.prototype._prepareSubEmitterInternalArray = function () {
             var _this = this;
-            if (delay === void 0) { delay = this.startDelay; }
-            if (!this.targetStopDuration && this._hasTargetStopDurationDependantGradient()) {
-                throw "Particle system started with a targetStopDuration dependant gradient (eg. startSizeGradients) but no targetStopDuration set";
-            }
-            if (delay) {
-                setTimeout(function () {
-                    _this.start(0);
-                }, delay);
-                return;
-            }
-            // Convert the subEmitters field to the constant type field _subEmitters
             this._subEmitters = new Array();
             if (this.subEmitters) {
                 this.subEmitters.forEach(function (subEmitter) {
@@ -58300,6 +58284,25 @@ var BABYLON;
                     });
                 });
             }
+        };
+        /**
+         * Starts the particle system and begins to emit
+         * @param delay defines the delay in milliseconds before starting the system (this.startDelay by default)
+         */
+        ParticleSystem.prototype.start = function (delay) {
+            var _this = this;
+            if (delay === void 0) { delay = this.startDelay; }
+            if (!this.targetStopDuration && this._hasTargetStopDurationDependantGradient()) {
+                throw "Particle system started with a targetStopDuration dependant gradient (eg. startSizeGradients) but no targetStopDuration set";
+            }
+            if (delay) {
+                setTimeout(function () {
+                    _this.start(0);
+                }, delay);
+                return;
+            }
+            // Convert the subEmitters field to the constant type field _subEmitters
+            this._prepareSubEmitterInternalArray();
             this._started = true;
             this._stopped = false;
             this._actualFrame = 0;
@@ -59062,7 +59065,22 @@ var BABYLON;
             serializationObject.textureMask = this.textureMask.asArray();
             serializationObject.customShader = this.customShader;
             serializationObject.preventAutoStart = this.preventAutoStart;
-            serializationObject.isAnimationSheetEnabled = this._isAnimationSheetEnabled;
+            // SubEmitters
+            if (this.subEmitters) {
+                serializationObject.subEmitters = [];
+                if (!this._subEmitters) {
+                    this._prepareSubEmitterInternalArray();
+                }
+                for (var _i = 0, _a = this._subEmitters; _i < _a.length; _i++) {
+                    var subs = _a[_i];
+                    var cell = [];
+                    for (var _b = 0, subs_1 = subs; _b < subs_1.length; _b++) {
+                        var sub = subs_1[_b];
+                        cell.push(sub.serialize());
+                    }
+                    serializationObject.subEmitters.push(cell);
+                }
+            }
             return serializationObject;
         };
         /** @hidden */
@@ -59092,6 +59110,7 @@ var BABYLON;
             serializationObject.startDelay = particleSystem.startDelay;
             serializationObject.renderingGroupId = particleSystem.renderingGroupId;
             serializationObject.isBillboardBased = particleSystem.isBillboardBased;
+            serializationObject.billboardMode = particleSystem.billboardMode;
             serializationObject.minAngularSpeed = particleSystem.minAngularSpeed;
             serializationObject.maxAngularSpeed = particleSystem.maxAngularSpeed;
             serializationObject.minSize = particleSystem.minSize;
@@ -59123,6 +59142,7 @@ var BABYLON;
             serializationObject.spriteCellWidth = particleSystem.spriteCellWidth;
             serializationObject.spriteCellHeight = particleSystem.spriteCellHeight;
             serializationObject.spriteRandomStartCell = particleSystem.spriteRandomStartCell;
+            serializationObject.isAnimationSheetEnabled = particleSystem.isAnimationSheetEnabled;
             var colorGradients = particleSystem.getColorGradients();
             if (colorGradients) {
                 serializationObject.colorGradients = [];
@@ -59298,7 +59318,7 @@ var BABYLON;
                 particleSystem.particleTexture.name = parsedParticleSystem.textureName;
             }
             // Emitter
-            if (parsedParticleSystem.emitterId === undefined) {
+            if (!parsedParticleSystem.emitterId && parsedParticleSystem.emitterId !== 0 && parsedParticleSystem.emitter === undefined) {
                 particleSystem.emitter = BABYLON.Vector3.Zero();
             }
             else if (parsedParticleSystem.emitterId) {
@@ -59314,6 +59334,9 @@ var BABYLON;
             if (parsedParticleSystem.isBillboardBased !== undefined) {
                 particleSystem.isBillboardBased = parsedParticleSystem.isBillboardBased;
             }
+            if (parsedParticleSystem.billboardMode !== undefined) {
+                particleSystem.billboardMode = parsedParticleSystem.billboardMode;
+            }
             // Animations
             if (parsedParticleSystem.animations) {
                 for (var animationIndex = 0; animationIndex < parsedParticleSystem.animations.length; animationIndex++) {
@@ -59491,6 +59514,19 @@ var BABYLON;
             if (parsedParticleSystem.id) {
                 particleSystem.id = parsedParticleSystem.id;
             }
+            // SubEmitters
+            if (parsedParticleSystem.subEmitters) {
+                particleSystem.subEmitters = [];
+                for (var _i = 0, _a = parsedParticleSystem.subEmitters; _i < _a.length; _i++) {
+                    var cell = _a[_i];
+                    var cellArray = [];
+                    for (var _b = 0, cell_1 = cell; _b < cell_1.length; _b++) {
+                        var sub = cell_1[_b];
+                        cellArray.push(BABYLON.SubEmitter.Parse(sub, scene, rootUrl));
+                    }
+                    particleSystem.subEmitters.push(cellArray);
+                }
+            }
             // Auto start
             if (parsedParticleSystem.preventAutoStart) {
                 particleSystem.preventAutoStart = parsedParticleSystem.preventAutoStart;
@@ -60645,6 +60681,33 @@ var BABYLON;
             clone.particleSystem.disposeOnStop = true;
             return clone;
         };
+        /**
+         * Serialize current object to a JSON object
+         * @returns the serialized object
+         */
+        SubEmitter.prototype.serialize = function () {
+            var serializationObject = {};
+            serializationObject.type = this.type;
+            serializationObject.inheritDirection = this.inheritDirection;
+            serializationObject.inheritedVelocityAmount = this.inheritedVelocityAmount;
+            serializationObject.particleSystem = this.particleSystem.serialize();
+            return serializationObject;
+        };
+        /**
+         * Creates a new SubEmitter from a serialized JSON version
+         * @param serializationObject defines the JSON object to read from
+         * @param scene defines the hosting scene
+         * @param rootUrl defines the rootUrl for data loading
+         * @returns a new SubEmitter
+         */
+        SubEmitter.Parse = function (serializationObject, scene, rootUrl) {
+            var system = serializationObject.particleSystem;
+            var subEmitter = new SubEmitter(BABYLON.ParticleSystem.Parse(system, scene, rootUrl));
+            subEmitter.type = serializationObject.type;
+            subEmitter.inheritDirection = serializationObject.inheritDirection;
+            subEmitter.inheritedVelocityAmount = serializationObject.inheritedVelocityAmount;
+            return subEmitter;
+        };
         /** Release associated resources */
         SubEmitter.prototype.dispose = function () {
             this.particleSystem.dispose();
@@ -74393,10 +74456,6 @@ var BABYLON;
                     mesh.parent = scene.getLastEntryByID(mesh._waitingParentId);
                     mesh._waitingParentId = null;
                 }
-                if (mesh._waitingActions) {
-                    BABYLON.ActionManager.Parse(mesh._waitingActions, mesh, scene);
-                    mesh._waitingActions = null;
-                }
             }
             // freeze world matrix application
             for (index = 0, cache = scene.meshes.length; index < cache; index++) {
@@ -74434,7 +74493,14 @@ var BABYLON;
                 }
             }
             BABYLON.AbstractScene.Parse(parsedData, scene, container, rootUrl);
-            // Actions (scene)
+            // Actions (scene) Done last as it can access other objects.
+            for (index = 0, cache = scene.meshes.length; index < cache; index++) {
+                var mesh = scene.meshes[index];
+                if (mesh._waitingActions) {
+                    BABYLON.ActionManager.Parse(mesh._waitingActions, mesh, scene);
+                    mesh._waitingActions = null;
+                }
+            }
             if (parsedData.actions !== undefined && parsedData.actions !== null) {
                 BABYLON.ActionManager.Parse(parsedData.actions, null, scene);
             }

+ 93 - 27
dist/preview release/babylon.no-module.max.js

@@ -10942,7 +10942,7 @@ var BABYLON;
             }
             // Alpha equation
             if (this._isBlendEquationParametersDirty) {
-                gl.blendEquationSeparate(this._isBlendEquationParametersDirty[0], this._isBlendEquationParametersDirty[1]);
+                gl.blendEquationSeparate(this._blendEquationParameters[0], this._blendEquationParameters[1]);
                 this._isBlendEquationParametersDirty = false;
             }
             // Constants
@@ -12676,7 +12676,6 @@ var BABYLON;
          */
         Engine.prototype.clear = function (color, backBuffer, depth, stencil) {
             if (stencil === void 0) { stencil = false; }
-            this.applyStates();
             var mode = 0;
             if (backBuffer && color) {
                 this._gl.clearColor(color.r, color.g, color.b, color.a !== undefined ? color.a : 1.0);
@@ -56966,9 +56965,9 @@ var BABYLON;
             this.textureMask = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0);
             /**
              * Gets or sets the billboard mode to use when isBillboardBased = true.
-             * Only BABYLON.AbstractMesh.BILLBOARDMODE_ALL and AbstractMesh.BILLBOARDMODE_Y are supported so far
+             * Value can be: ParticleSystem.BILLBOARDMODE_ALL, ParticleSystem.BILLBOARDMODE_Y, ParticleSystem.BILLBOARDMODE_STRETCHED
              */
-            this.billboardMode = BABYLON.AbstractMesh.BILLBOARDMODE_ALL;
+            this.billboardMode = BABYLON.ParticleSystem.BILLBOARDMODE_ALL;
             this._isBillboardBased = true;
             /**
              * Local cache of defines for image processing.
@@ -58231,23 +58230,8 @@ var BABYLON;
         ParticleSystem.prototype.isStarted = function () {
             return this._started;
         };
-        /**
-         * Starts the particle system and begins to emit
-         * @param delay defines the delay in milliseconds before starting the system (this.startDelay by default)
-         */
-        ParticleSystem.prototype.start = function (delay) {
+        ParticleSystem.prototype._prepareSubEmitterInternalArray = function () {
             var _this = this;
-            if (delay === void 0) { delay = this.startDelay; }
-            if (!this.targetStopDuration && this._hasTargetStopDurationDependantGradient()) {
-                throw "Particle system started with a targetStopDuration dependant gradient (eg. startSizeGradients) but no targetStopDuration set";
-            }
-            if (delay) {
-                setTimeout(function () {
-                    _this.start(0);
-                }, delay);
-                return;
-            }
-            // Convert the subEmitters field to the constant type field _subEmitters
             this._subEmitters = new Array();
             if (this.subEmitters) {
                 this.subEmitters.forEach(function (subEmitter) {
@@ -58267,6 +58251,25 @@ var BABYLON;
                     });
                 });
             }
+        };
+        /**
+         * Starts the particle system and begins to emit
+         * @param delay defines the delay in milliseconds before starting the system (this.startDelay by default)
+         */
+        ParticleSystem.prototype.start = function (delay) {
+            var _this = this;
+            if (delay === void 0) { delay = this.startDelay; }
+            if (!this.targetStopDuration && this._hasTargetStopDurationDependantGradient()) {
+                throw "Particle system started with a targetStopDuration dependant gradient (eg. startSizeGradients) but no targetStopDuration set";
+            }
+            if (delay) {
+                setTimeout(function () {
+                    _this.start(0);
+                }, delay);
+                return;
+            }
+            // Convert the subEmitters field to the constant type field _subEmitters
+            this._prepareSubEmitterInternalArray();
             this._started = true;
             this._stopped = false;
             this._actualFrame = 0;
@@ -59029,7 +59032,22 @@ var BABYLON;
             serializationObject.textureMask = this.textureMask.asArray();
             serializationObject.customShader = this.customShader;
             serializationObject.preventAutoStart = this.preventAutoStart;
-            serializationObject.isAnimationSheetEnabled = this._isAnimationSheetEnabled;
+            // SubEmitters
+            if (this.subEmitters) {
+                serializationObject.subEmitters = [];
+                if (!this._subEmitters) {
+                    this._prepareSubEmitterInternalArray();
+                }
+                for (var _i = 0, _a = this._subEmitters; _i < _a.length; _i++) {
+                    var subs = _a[_i];
+                    var cell = [];
+                    for (var _b = 0, subs_1 = subs; _b < subs_1.length; _b++) {
+                        var sub = subs_1[_b];
+                        cell.push(sub.serialize());
+                    }
+                    serializationObject.subEmitters.push(cell);
+                }
+            }
             return serializationObject;
         };
         /** @hidden */
@@ -59059,6 +59077,7 @@ var BABYLON;
             serializationObject.startDelay = particleSystem.startDelay;
             serializationObject.renderingGroupId = particleSystem.renderingGroupId;
             serializationObject.isBillboardBased = particleSystem.isBillboardBased;
+            serializationObject.billboardMode = particleSystem.billboardMode;
             serializationObject.minAngularSpeed = particleSystem.minAngularSpeed;
             serializationObject.maxAngularSpeed = particleSystem.maxAngularSpeed;
             serializationObject.minSize = particleSystem.minSize;
@@ -59090,6 +59109,7 @@ var BABYLON;
             serializationObject.spriteCellWidth = particleSystem.spriteCellWidth;
             serializationObject.spriteCellHeight = particleSystem.spriteCellHeight;
             serializationObject.spriteRandomStartCell = particleSystem.spriteRandomStartCell;
+            serializationObject.isAnimationSheetEnabled = particleSystem.isAnimationSheetEnabled;
             var colorGradients = particleSystem.getColorGradients();
             if (colorGradients) {
                 serializationObject.colorGradients = [];
@@ -59265,7 +59285,7 @@ var BABYLON;
                 particleSystem.particleTexture.name = parsedParticleSystem.textureName;
             }
             // Emitter
-            if (parsedParticleSystem.emitterId === undefined) {
+            if (!parsedParticleSystem.emitterId && parsedParticleSystem.emitterId !== 0 && parsedParticleSystem.emitter === undefined) {
                 particleSystem.emitter = BABYLON.Vector3.Zero();
             }
             else if (parsedParticleSystem.emitterId) {
@@ -59281,6 +59301,9 @@ var BABYLON;
             if (parsedParticleSystem.isBillboardBased !== undefined) {
                 particleSystem.isBillboardBased = parsedParticleSystem.isBillboardBased;
             }
+            if (parsedParticleSystem.billboardMode !== undefined) {
+                particleSystem.billboardMode = parsedParticleSystem.billboardMode;
+            }
             // Animations
             if (parsedParticleSystem.animations) {
                 for (var animationIndex = 0; animationIndex < parsedParticleSystem.animations.length; animationIndex++) {
@@ -59458,6 +59481,19 @@ var BABYLON;
             if (parsedParticleSystem.id) {
                 particleSystem.id = parsedParticleSystem.id;
             }
+            // SubEmitters
+            if (parsedParticleSystem.subEmitters) {
+                particleSystem.subEmitters = [];
+                for (var _i = 0, _a = parsedParticleSystem.subEmitters; _i < _a.length; _i++) {
+                    var cell = _a[_i];
+                    var cellArray = [];
+                    for (var _b = 0, cell_1 = cell; _b < cell_1.length; _b++) {
+                        var sub = cell_1[_b];
+                        cellArray.push(BABYLON.SubEmitter.Parse(sub, scene, rootUrl));
+                    }
+                    particleSystem.subEmitters.push(cellArray);
+                }
+            }
             // Auto start
             if (parsedParticleSystem.preventAutoStart) {
                 particleSystem.preventAutoStart = parsedParticleSystem.preventAutoStart;
@@ -60612,6 +60648,33 @@ var BABYLON;
             clone.particleSystem.disposeOnStop = true;
             return clone;
         };
+        /**
+         * Serialize current object to a JSON object
+         * @returns the serialized object
+         */
+        SubEmitter.prototype.serialize = function () {
+            var serializationObject = {};
+            serializationObject.type = this.type;
+            serializationObject.inheritDirection = this.inheritDirection;
+            serializationObject.inheritedVelocityAmount = this.inheritedVelocityAmount;
+            serializationObject.particleSystem = this.particleSystem.serialize();
+            return serializationObject;
+        };
+        /**
+         * Creates a new SubEmitter from a serialized JSON version
+         * @param serializationObject defines the JSON object to read from
+         * @param scene defines the hosting scene
+         * @param rootUrl defines the rootUrl for data loading
+         * @returns a new SubEmitter
+         */
+        SubEmitter.Parse = function (serializationObject, scene, rootUrl) {
+            var system = serializationObject.particleSystem;
+            var subEmitter = new SubEmitter(BABYLON.ParticleSystem.Parse(system, scene, rootUrl));
+            subEmitter.type = serializationObject.type;
+            subEmitter.inheritDirection = serializationObject.inheritDirection;
+            subEmitter.inheritedVelocityAmount = serializationObject.inheritedVelocityAmount;
+            return subEmitter;
+        };
         /** Release associated resources */
         SubEmitter.prototype.dispose = function () {
             this.particleSystem.dispose();
@@ -74360,10 +74423,6 @@ var BABYLON;
                     mesh.parent = scene.getLastEntryByID(mesh._waitingParentId);
                     mesh._waitingParentId = null;
                 }
-                if (mesh._waitingActions) {
-                    BABYLON.ActionManager.Parse(mesh._waitingActions, mesh, scene);
-                    mesh._waitingActions = null;
-                }
             }
             // freeze world matrix application
             for (index = 0, cache = scene.meshes.length; index < cache; index++) {
@@ -74401,7 +74460,14 @@ var BABYLON;
                 }
             }
             BABYLON.AbstractScene.Parse(parsedData, scene, container, rootUrl);
-            // Actions (scene)
+            // Actions (scene) Done last as it can access other objects.
+            for (index = 0, cache = scene.meshes.length; index < cache; index++) {
+                var mesh = scene.meshes[index];
+                if (mesh._waitingActions) {
+                    BABYLON.ActionManager.Parse(mesh._waitingActions, mesh, scene);
+                    mesh._waitingActions = null;
+                }
+            }
             if (parsedData.actions !== undefined && parsedData.actions !== null) {
                 BABYLON.ActionManager.Parse(parsedData.actions, null, scene);
             }

Dosya farkı çok büyük olduğundan ihmal edildi
+ 1 - 1
dist/preview release/babylon.worker.js


+ 93 - 27
dist/preview release/es6.js

@@ -10942,7 +10942,7 @@ var BABYLON;
             }
             // Alpha equation
             if (this._isBlendEquationParametersDirty) {
-                gl.blendEquationSeparate(this._isBlendEquationParametersDirty[0], this._isBlendEquationParametersDirty[1]);
+                gl.blendEquationSeparate(this._blendEquationParameters[0], this._blendEquationParameters[1]);
                 this._isBlendEquationParametersDirty = false;
             }
             // Constants
@@ -12676,7 +12676,6 @@ var BABYLON;
          */
         Engine.prototype.clear = function (color, backBuffer, depth, stencil) {
             if (stencil === void 0) { stencil = false; }
-            this.applyStates();
             var mode = 0;
             if (backBuffer && color) {
                 this._gl.clearColor(color.r, color.g, color.b, color.a !== undefined ? color.a : 1.0);
@@ -56966,9 +56965,9 @@ var BABYLON;
             this.textureMask = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0);
             /**
              * Gets or sets the billboard mode to use when isBillboardBased = true.
-             * Only BABYLON.AbstractMesh.BILLBOARDMODE_ALL and AbstractMesh.BILLBOARDMODE_Y are supported so far
+             * Value can be: ParticleSystem.BILLBOARDMODE_ALL, ParticleSystem.BILLBOARDMODE_Y, ParticleSystem.BILLBOARDMODE_STRETCHED
              */
-            this.billboardMode = BABYLON.AbstractMesh.BILLBOARDMODE_ALL;
+            this.billboardMode = BABYLON.ParticleSystem.BILLBOARDMODE_ALL;
             this._isBillboardBased = true;
             /**
              * Local cache of defines for image processing.
@@ -58231,23 +58230,8 @@ var BABYLON;
         ParticleSystem.prototype.isStarted = function () {
             return this._started;
         };
-        /**
-         * Starts the particle system and begins to emit
-         * @param delay defines the delay in milliseconds before starting the system (this.startDelay by default)
-         */
-        ParticleSystem.prototype.start = function (delay) {
+        ParticleSystem.prototype._prepareSubEmitterInternalArray = function () {
             var _this = this;
-            if (delay === void 0) { delay = this.startDelay; }
-            if (!this.targetStopDuration && this._hasTargetStopDurationDependantGradient()) {
-                throw "Particle system started with a targetStopDuration dependant gradient (eg. startSizeGradients) but no targetStopDuration set";
-            }
-            if (delay) {
-                setTimeout(function () {
-                    _this.start(0);
-                }, delay);
-                return;
-            }
-            // Convert the subEmitters field to the constant type field _subEmitters
             this._subEmitters = new Array();
             if (this.subEmitters) {
                 this.subEmitters.forEach(function (subEmitter) {
@@ -58267,6 +58251,25 @@ var BABYLON;
                     });
                 });
             }
+        };
+        /**
+         * Starts the particle system and begins to emit
+         * @param delay defines the delay in milliseconds before starting the system (this.startDelay by default)
+         */
+        ParticleSystem.prototype.start = function (delay) {
+            var _this = this;
+            if (delay === void 0) { delay = this.startDelay; }
+            if (!this.targetStopDuration && this._hasTargetStopDurationDependantGradient()) {
+                throw "Particle system started with a targetStopDuration dependant gradient (eg. startSizeGradients) but no targetStopDuration set";
+            }
+            if (delay) {
+                setTimeout(function () {
+                    _this.start(0);
+                }, delay);
+                return;
+            }
+            // Convert the subEmitters field to the constant type field _subEmitters
+            this._prepareSubEmitterInternalArray();
             this._started = true;
             this._stopped = false;
             this._actualFrame = 0;
@@ -59029,7 +59032,22 @@ var BABYLON;
             serializationObject.textureMask = this.textureMask.asArray();
             serializationObject.customShader = this.customShader;
             serializationObject.preventAutoStart = this.preventAutoStart;
-            serializationObject.isAnimationSheetEnabled = this._isAnimationSheetEnabled;
+            // SubEmitters
+            if (this.subEmitters) {
+                serializationObject.subEmitters = [];
+                if (!this._subEmitters) {
+                    this._prepareSubEmitterInternalArray();
+                }
+                for (var _i = 0, _a = this._subEmitters; _i < _a.length; _i++) {
+                    var subs = _a[_i];
+                    var cell = [];
+                    for (var _b = 0, subs_1 = subs; _b < subs_1.length; _b++) {
+                        var sub = subs_1[_b];
+                        cell.push(sub.serialize());
+                    }
+                    serializationObject.subEmitters.push(cell);
+                }
+            }
             return serializationObject;
         };
         /** @hidden */
@@ -59059,6 +59077,7 @@ var BABYLON;
             serializationObject.startDelay = particleSystem.startDelay;
             serializationObject.renderingGroupId = particleSystem.renderingGroupId;
             serializationObject.isBillboardBased = particleSystem.isBillboardBased;
+            serializationObject.billboardMode = particleSystem.billboardMode;
             serializationObject.minAngularSpeed = particleSystem.minAngularSpeed;
             serializationObject.maxAngularSpeed = particleSystem.maxAngularSpeed;
             serializationObject.minSize = particleSystem.minSize;
@@ -59090,6 +59109,7 @@ var BABYLON;
             serializationObject.spriteCellWidth = particleSystem.spriteCellWidth;
             serializationObject.spriteCellHeight = particleSystem.spriteCellHeight;
             serializationObject.spriteRandomStartCell = particleSystem.spriteRandomStartCell;
+            serializationObject.isAnimationSheetEnabled = particleSystem.isAnimationSheetEnabled;
             var colorGradients = particleSystem.getColorGradients();
             if (colorGradients) {
                 serializationObject.colorGradients = [];
@@ -59265,7 +59285,7 @@ var BABYLON;
                 particleSystem.particleTexture.name = parsedParticleSystem.textureName;
             }
             // Emitter
-            if (parsedParticleSystem.emitterId === undefined) {
+            if (!parsedParticleSystem.emitterId && parsedParticleSystem.emitterId !== 0 && parsedParticleSystem.emitter === undefined) {
                 particleSystem.emitter = BABYLON.Vector3.Zero();
             }
             else if (parsedParticleSystem.emitterId) {
@@ -59281,6 +59301,9 @@ var BABYLON;
             if (parsedParticleSystem.isBillboardBased !== undefined) {
                 particleSystem.isBillboardBased = parsedParticleSystem.isBillboardBased;
             }
+            if (parsedParticleSystem.billboardMode !== undefined) {
+                particleSystem.billboardMode = parsedParticleSystem.billboardMode;
+            }
             // Animations
             if (parsedParticleSystem.animations) {
                 for (var animationIndex = 0; animationIndex < parsedParticleSystem.animations.length; animationIndex++) {
@@ -59458,6 +59481,19 @@ var BABYLON;
             if (parsedParticleSystem.id) {
                 particleSystem.id = parsedParticleSystem.id;
             }
+            // SubEmitters
+            if (parsedParticleSystem.subEmitters) {
+                particleSystem.subEmitters = [];
+                for (var _i = 0, _a = parsedParticleSystem.subEmitters; _i < _a.length; _i++) {
+                    var cell = _a[_i];
+                    var cellArray = [];
+                    for (var _b = 0, cell_1 = cell; _b < cell_1.length; _b++) {
+                        var sub = cell_1[_b];
+                        cellArray.push(BABYLON.SubEmitter.Parse(sub, scene, rootUrl));
+                    }
+                    particleSystem.subEmitters.push(cellArray);
+                }
+            }
             // Auto start
             if (parsedParticleSystem.preventAutoStart) {
                 particleSystem.preventAutoStart = parsedParticleSystem.preventAutoStart;
@@ -60612,6 +60648,33 @@ var BABYLON;
             clone.particleSystem.disposeOnStop = true;
             return clone;
         };
+        /**
+         * Serialize current object to a JSON object
+         * @returns the serialized object
+         */
+        SubEmitter.prototype.serialize = function () {
+            var serializationObject = {};
+            serializationObject.type = this.type;
+            serializationObject.inheritDirection = this.inheritDirection;
+            serializationObject.inheritedVelocityAmount = this.inheritedVelocityAmount;
+            serializationObject.particleSystem = this.particleSystem.serialize();
+            return serializationObject;
+        };
+        /**
+         * Creates a new SubEmitter from a serialized JSON version
+         * @param serializationObject defines the JSON object to read from
+         * @param scene defines the hosting scene
+         * @param rootUrl defines the rootUrl for data loading
+         * @returns a new SubEmitter
+         */
+        SubEmitter.Parse = function (serializationObject, scene, rootUrl) {
+            var system = serializationObject.particleSystem;
+            var subEmitter = new SubEmitter(BABYLON.ParticleSystem.Parse(system, scene, rootUrl));
+            subEmitter.type = serializationObject.type;
+            subEmitter.inheritDirection = serializationObject.inheritDirection;
+            subEmitter.inheritedVelocityAmount = serializationObject.inheritedVelocityAmount;
+            return subEmitter;
+        };
         /** Release associated resources */
         SubEmitter.prototype.dispose = function () {
             this.particleSystem.dispose();
@@ -74360,10 +74423,6 @@ var BABYLON;
                     mesh.parent = scene.getLastEntryByID(mesh._waitingParentId);
                     mesh._waitingParentId = null;
                 }
-                if (mesh._waitingActions) {
-                    BABYLON.ActionManager.Parse(mesh._waitingActions, mesh, scene);
-                    mesh._waitingActions = null;
-                }
             }
             // freeze world matrix application
             for (index = 0, cache = scene.meshes.length; index < cache; index++) {
@@ -74401,7 +74460,14 @@ var BABYLON;
                 }
             }
             BABYLON.AbstractScene.Parse(parsedData, scene, container, rootUrl);
-            // Actions (scene)
+            // Actions (scene) Done last as it can access other objects.
+            for (index = 0, cache = scene.meshes.length; index < cache; index++) {
+                var mesh = scene.meshes[index];
+                if (mesh._waitingActions) {
+                    BABYLON.ActionManager.Parse(mesh._waitingActions, mesh, scene);
+                    mesh._waitingActions = null;
+                }
+            }
             if (parsedData.actions !== undefined && parsedData.actions !== null) {
                 BABYLON.ActionManager.Parse(parsedData.actions, null, scene);
             }

Dosya farkı çok büyük olduğundan ihmal edildi
+ 1 - 1
dist/preview release/viewer/babylon.viewer.js


Dosya farkı çok büyük olduğundan ihmal edildi
+ 1 - 1
dist/preview release/viewer/babylon.viewer.max.js


+ 7 - 2
src/Particles/babylon.IParticleSystem.ts

@@ -179,7 +179,12 @@ module BABYLON {
         /**
          * This allows the system to random pick the start cell ID between startSpriteCellID and endSpriteCellID
          */
-        spriteRandomStartCell: boolean;            
+        spriteRandomStartCell: boolean;        
+        
+        /**
+         * Gets or sets a boolean indicating if a spritesheet is used to animate the particles texture
+         */
+        isAnimationSheetEnabled: boolean;
 
         /** Gets or sets a Vector2 used to move the pivot (by default (0,0)) */
         translationPivot: Vector2;
@@ -194,7 +199,7 @@ module BABYLON {
         
         /**
          * Gets or sets the billboard mode to use when isBillboardBased = true.
-         * Only BABYLON.AbstractMesh.BILLBOARDMODE_ALL and AbstractMesh.BILLBOARDMODE_Y are supported so far
+         * Value can be: ParticleSystem.BILLBOARDMODE_ALL, ParticleSystem.BILLBOARDMODE_Y, ParticleSystem.BILLBOARDMODE_STRETCHED
          */
         billboardMode: number;
 

+ 2 - 2
src/Particles/babylon.baseParticleSystem.ts

@@ -478,9 +478,9 @@ module BABYLON {
 
         /**
          * Gets or sets the billboard mode to use when isBillboardBased = true.
-         * Only BABYLON.AbstractMesh.BILLBOARDMODE_ALL and AbstractMesh.BILLBOARDMODE_Y are supported so far
+         * Value can be: ParticleSystem.BILLBOARDMODE_ALL, ParticleSystem.BILLBOARDMODE_Y, ParticleSystem.BILLBOARDMODE_STRETCHED
          */
-        public billboardMode = AbstractMesh.BILLBOARDMODE_ALL;        
+        public billboardMode = ParticleSystem.BILLBOARDMODE_ALL;        
         
         protected _isBillboardBased = true;
         /**

+ 57 - 17
src/Particles/babylon.particleSystem.ts

@@ -994,21 +994,7 @@
             return this._started;
         }
 
-        /**
-         * Starts the particle system and begins to emit
-         * @param delay defines the delay in milliseconds before starting the system (this.startDelay by default)
-         */
-        public start(delay = this.startDelay): void {
-            if(!this.targetStopDuration && this._hasTargetStopDurationDependantGradient()){
-                throw "Particle system started with a targetStopDuration dependant gradient (eg. startSizeGradients) but no targetStopDuration set";
-            }
-            if (delay) {
-                setTimeout(() => {
-                    this.start(0);
-                }, delay);
-                return;
-            }
-            // Convert the subEmitters field to the constant type field _subEmitters
+        private _prepareSubEmitterInternalArray() {
             this._subEmitters = new Array<Array<SubEmitter>>();
             if (this.subEmitters) {
                 this.subEmitters.forEach((subEmitter) => {
@@ -1026,6 +1012,24 @@
                     })
                 });
             }
+        }
+
+        /**
+         * Starts the particle system and begins to emit
+         * @param delay defines the delay in milliseconds before starting the system (this.startDelay by default)
+         */
+        public start(delay = this.startDelay): void {
+            if(!this.targetStopDuration && this._hasTargetStopDurationDependantGradient()){
+                throw "Particle system started with a targetStopDuration dependant gradient (eg. startSizeGradients) but no targetStopDuration set";
+            }
+            if (delay) {
+                setTimeout(() => {
+                    this.start(0);
+                }, delay);
+                return;
+            }
+            // Convert the subEmitters field to the constant type field _subEmitters
+            this._prepareSubEmitterInternalArray();
 
             this._started = true;
             this._stopped = false;
@@ -1960,7 +1964,23 @@
             serializationObject.customShader = this.customShader;
             serializationObject.preventAutoStart = this.preventAutoStart;
 
-            serializationObject.isAnimationSheetEnabled = this._isAnimationSheetEnabled;
+            // SubEmitters
+            if (this.subEmitters) {
+                serializationObject.subEmitters = [];
+
+                if (!this._subEmitters) {
+                    this._prepareSubEmitterInternalArray();
+                }
+                
+                for (var subs of this._subEmitters) {
+                    let cell = [];
+                    for (var sub of subs) {
+                        cell.push(sub.serialize());
+                    }
+
+                    serializationObject.subEmitters.push(cell);
+                }
+            }
 
             return serializationObject;
         }
@@ -1997,6 +2017,7 @@
             serializationObject.startDelay = particleSystem.startDelay;
             serializationObject.renderingGroupId = particleSystem.renderingGroupId;
             serializationObject.isBillboardBased = particleSystem.isBillboardBased;
+            serializationObject.billboardMode = particleSystem.billboardMode;
             serializationObject.minAngularSpeed = particleSystem.minAngularSpeed;
             serializationObject.maxAngularSpeed = particleSystem.maxAngularSpeed;
             serializationObject.minSize = particleSystem.minSize;
@@ -2028,6 +2049,7 @@
             serializationObject.spriteCellWidth = particleSystem.spriteCellWidth;
             serializationObject.spriteCellHeight = particleSystem.spriteCellHeight;
             serializationObject.spriteRandomStartCell = particleSystem.spriteRandomStartCell;
+            serializationObject.isAnimationSheetEnabled = particleSystem.isAnimationSheetEnabled;
 
             let colorGradients = particleSystem.getColorGradients();
             if (colorGradients) {
@@ -2237,7 +2259,7 @@
             }
 
             // Emitter
-            if (parsedParticleSystem.emitterId === undefined) {
+            if (!parsedParticleSystem.emitterId && parsedParticleSystem.emitterId !== 0 && parsedParticleSystem.emitter === undefined) {
                 particleSystem.emitter = Vector3.Zero();
             }
             else if (parsedParticleSystem.emitterId) {
@@ -2255,6 +2277,10 @@
                 particleSystem.isBillboardBased = parsedParticleSystem.isBillboardBased;
             }
 
+            if (parsedParticleSystem.billboardMode !== undefined) {
+                particleSystem.billboardMode = parsedParticleSystem.billboardMode;
+            }
+
             // Animations
             if (parsedParticleSystem.animations) {
                 for (var animationIndex = 0; animationIndex < parsedParticleSystem.animations.length; animationIndex++) {
@@ -2445,6 +2471,20 @@
                 particleSystem.id = parsedParticleSystem.id;
             }
 
+            // SubEmitters
+            if (parsedParticleSystem.subEmitters) {
+                particleSystem.subEmitters = [];
+                for (var cell of parsedParticleSystem.subEmitters) {
+                    let cellArray = [];
+                    for (var sub of cell) {
+                        cellArray.push(SubEmitter.Parse(sub, scene, rootUrl));
+                    }
+
+                    particleSystem.subEmitters.push(cellArray);
+                }
+            }
+            
+
             // Auto start
             if (parsedParticleSystem.preventAutoStart) {
                 particleSystem.preventAutoStart = parsedParticleSystem.preventAutoStart;

+ 32 - 0
src/Particles/babylon.subEmitter.ts

@@ -67,6 +67,38 @@ module BABYLON {
             return clone;
         }
 
+        /**
+         * Serialize current object to a JSON object
+         * @returns the serialized object
+         */
+        public serialize(): any {
+            let serializationObject: any = {};
+
+            serializationObject.type = this.type;
+            serializationObject.inheritDirection = this.inheritDirection;
+            serializationObject.inheritedVelocityAmount = this.inheritedVelocityAmount;
+            serializationObject.particleSystem = this.particleSystem.serialize();
+
+            return serializationObject;
+        }
+
+        /**
+         * Creates a new SubEmitter from a serialized JSON version
+         * @param serializationObject defines the JSON object to read from
+         * @param scene defines the hosting scene
+         * @param rootUrl defines the rootUrl for data loading
+         * @returns a new SubEmitter
+         */
+        public static Parse(serializationObject: any, scene: Scene, rootUrl: string): SubEmitter {
+            let system = serializationObject.particleSystem;
+            let subEmitter = new SubEmitter(ParticleSystem.Parse(system, scene, rootUrl));
+            subEmitter.type = serializationObject.type;
+            subEmitter.inheritDirection = serializationObject.inheritDirection;
+            subEmitter.inheritedVelocityAmount = serializationObject.inheritedVelocityAmount;
+
+            return subEmitter;
+        }
+
         /** Release associated resources */
         public dispose() {
             this.particleSystem.dispose();

+ 1 - 1
src/States/babylon.alphaCullingState.ts

@@ -132,7 +132,7 @@
 
             // Alpha equation
             if (this._isBlendEquationParametersDirty) {
-                gl.blendEquationSeparate((<any>this._isBlendEquationParametersDirty)[0], (<any>this._isBlendEquationParametersDirty)[1]);
+                gl.blendEquationSeparate(this._blendEquationParameters[0]!, this._blendEquationParameters[1]!);
                 this._isBlendEquationParametersDirty = false;
             }