Bläddra i källkod

New public animatable class

David Catuhe 11 år sedan
förälder
incheckning
89c70b1a44

+ 33 - 6
Babylon/Actions/babylon.actionManager.js

@@ -6,9 +6,9 @@
             this.actions = new Array();
             this._scene = scene;
         }
-        Object.defineProperty(ActionManager, "NoneTrigger", {
+        Object.defineProperty(ActionManager, "NothingTrigger", {
             get: function () {
-                return ActionManager._NoneTrigger;
+                return ActionManager._NothingTrigger;
             },
             enumerable: true,
             configurable: true
@@ -22,6 +22,30 @@
             configurable: true
         });
 
+        Object.defineProperty(ActionManager, "OnLeftPickTrigger", {
+            get: function () {
+                return ActionManager._OnLeftPickTrigger;
+            },
+            enumerable: true,
+            configurable: true
+        });
+
+        Object.defineProperty(ActionManager, "OnRightPickTrigger", {
+            get: function () {
+                return ActionManager._OnRightPickTrigger;
+            },
+            enumerable: true,
+            configurable: true
+        });
+
+        Object.defineProperty(ActionManager, "OnCenterPickTrigger", {
+            get: function () {
+                return ActionManager._OnCenterPickTrigger;
+            },
+            enumerable: true,
+            configurable: true
+        });
+
         Object.defineProperty(ActionManager, "OnPointerOverTrigger", {
             get: function () {
                 return ActionManager._OnPointerOverTrigger;
@@ -92,11 +116,14 @@
 
             return properties[properties.length - 1];
         };
-        ActionManager._NoneTrigger = 0;
+        ActionManager._NothingTrigger = 0;
         ActionManager._OnPickTrigger = 1;
-        ActionManager._OnPointerOverTrigger = 2;
-        ActionManager._OnPointerOutTrigger = 3;
-        ActionManager._OnEveryFrameTrigger = 4;
+        ActionManager._OnLeftPickTrigger = 2;
+        ActionManager._OnRightPickTrigger = 3;
+        ActionManager._OnCenterPickTrigger = 4;
+        ActionManager._OnPointerOverTrigger = 5;
+        ActionManager._OnPointerOutTrigger = 6;
+        ActionManager._OnEveryFrameTrigger = 7;
         return ActionManager;
     })();
     BABYLON.ActionManager = ActionManager;

+ 22 - 7
Babylon/Actions/babylon.actionManager.ts

@@ -1,20 +1,35 @@
 module BABYLON {
     export class ActionManager {
         // Statics
-        private static _NoneTrigger = 0;
+        private static _NothingTrigger = 0;
         private static _OnPickTrigger = 1;
-        private static _OnPointerOverTrigger = 2;
-        private static _OnPointerOutTrigger = 3;
-        private static _OnEveryFrameTrigger = 4;
-
-        public static get NoneTrigger(): number {
-            return ActionManager._NoneTrigger;
+        private static _OnLeftPickTrigger = 2;
+        private static _OnRightPickTrigger = 3;
+        private static _OnCenterPickTrigger = 4;
+        private static _OnPointerOverTrigger = 5;
+        private static _OnPointerOutTrigger = 6;
+        private static _OnEveryFrameTrigger = 7;
+
+        public static get NothingTrigger(): number {
+            return ActionManager._NothingTrigger;
         }
 
         public static get OnPickTrigger(): number {
             return ActionManager._OnPickTrigger;
         }
 
+        public static get OnLeftPickTrigger(): number {
+            return ActionManager._OnLeftPickTrigger;
+        }
+
+        public static get OnRightPickTrigger(): number {
+            return ActionManager._OnRightPickTrigger;
+        }
+
+        public static get OnCenterPickTrigger(): number {
+            return ActionManager._OnCenterPickTrigger;
+        }
+
         public static get OnPointerOverTrigger(): number {
             return ActionManager._OnPointerOverTrigger;
         }

+ 40 - 24
Babylon/Actions/babylon.condition.js

@@ -25,10 +25,10 @@ var BABYLON;
     })();
     BABYLON.Condition = Condition;
 
-    var StateCondition = (function (_super) {
-        __extends(StateCondition, _super);
-        function StateCondition(actionManager, target, propertyPath, value, operator) {
-            if (typeof operator === "undefined") { operator = StateCondition.IsEqual; }
+    var ValueCondition = (function (_super) {
+        __extends(ValueCondition, _super);
+        function ValueCondition(actionManager, target, propertyPath, value, operator) {
+            if (typeof operator === "undefined") { operator = ValueCondition.IsEqual; }
             _super.call(this, actionManager);
             this.propertyPath = propertyPath;
             this.value = value;
@@ -37,47 +37,47 @@ var BABYLON;
             this._target = this._getEffectiveTarget(target, this.propertyPath);
             this._property = this._getProperty(this.propertyPath);
         }
-        Object.defineProperty(StateCondition, "IsEqual", {
+        Object.defineProperty(ValueCondition, "IsEqual", {
             get: function () {
-                return StateCondition._IsEqual;
+                return ValueCondition._IsEqual;
             },
             enumerable: true,
             configurable: true
         });
 
-        Object.defineProperty(StateCondition, "IsDifferent", {
+        Object.defineProperty(ValueCondition, "IsDifferent", {
             get: function () {
-                return StateCondition._IsDifferent;
+                return ValueCondition._IsDifferent;
             },
             enumerable: true,
             configurable: true
         });
 
-        Object.defineProperty(StateCondition, "IsGreater", {
+        Object.defineProperty(ValueCondition, "IsGreater", {
             get: function () {
-                return StateCondition._IsGreater;
+                return ValueCondition._IsGreater;
             },
             enumerable: true,
             configurable: true
         });
 
-        Object.defineProperty(StateCondition, "IsLesser", {
+        Object.defineProperty(ValueCondition, "IsLesser", {
             get: function () {
-                return StateCondition._IsLesser;
+                return ValueCondition._IsLesser;
             },
             enumerable: true,
             configurable: true
         });
 
         // Methods
-        StateCondition.prototype.isValid = function () {
+        ValueCondition.prototype.isValid = function () {
             switch (this.operator) {
-                case StateCondition.IsGreater:
+                case ValueCondition.IsGreater:
                     return this._target[this._property] > this.value;
-                case StateCondition.IsLesser:
+                case ValueCondition.IsLesser:
                     return this._target[this._property] < this.value;
-                case StateCondition.IsEqual:
-                case StateCondition.IsDifferent:
+                case ValueCondition.IsEqual:
+                case ValueCondition.IsDifferent:
                     var check;
 
                     if (this.value.equals) {
@@ -85,18 +85,18 @@ var BABYLON;
                     } else {
                         check = this.value === this._target[this._property];
                     }
-                    return this.operator === StateCondition.IsEqual ? check : !check;
+                    return this.operator === ValueCondition.IsEqual ? check : !check;
             }
 
             return false;
         };
-        StateCondition._IsEqual = 0;
-        StateCondition._IsDifferent = 1;
-        StateCondition._IsGreater = 2;
-        StateCondition._IsLesser = 3;
-        return StateCondition;
+        ValueCondition._IsEqual = 0;
+        ValueCondition._IsDifferent = 1;
+        ValueCondition._IsGreater = 2;
+        ValueCondition._IsLesser = 3;
+        return ValueCondition;
     })(Condition);
-    BABYLON.StateCondition = StateCondition;
+    BABYLON.ValueCondition = ValueCondition;
 
     var PredicateCondition = (function (_super) {
         __extends(PredicateCondition, _super);
@@ -110,5 +110,21 @@ var BABYLON;
         return PredicateCondition;
     })(Condition);
     BABYLON.PredicateCondition = PredicateCondition;
+
+    var StateCondition = (function (_super) {
+        __extends(StateCondition, _super);
+        function StateCondition(actionManager, target, value) {
+            _super.call(this, actionManager);
+            this.value = value;
+
+            this._target = target;
+        }
+        // Methods
+        StateCondition.prototype.isValid = function () {
+            return this._target.state === this.value;
+        };
+        return StateCondition;
+    })(Condition);
+    BABYLON.StateCondition = StateCondition;
 })(BABYLON || (BABYLON = {}));
 //# sourceMappingURL=babylon.condition.js.map

+ 30 - 11
Babylon/Actions/babylon.condition.ts

@@ -22,7 +22,7 @@
         }
     }
 
-    export class StateCondition extends Condition {
+    export class ValueCondition extends Condition {
         // Statics
         private static _IsEqual = 0;
         private static _IsDifferent = 1;
@@ -30,19 +30,19 @@
         private static _IsLesser = 3;
 
         public static get IsEqual(): number {
-            return StateCondition._IsEqual;
+            return ValueCondition._IsEqual;
         }
 
         public static get IsDifferent(): number {
-            return StateCondition._IsDifferent;
+            return ValueCondition._IsDifferent;
         }
 
         public static get IsGreater(): number {
-            return StateCondition._IsGreater;
+            return ValueCondition._IsGreater;
         }
 
         public static get IsLesser(): number {
-            return StateCondition._IsLesser;
+            return ValueCondition._IsLesser;
         }
 
         // Members
@@ -51,7 +51,7 @@
         private _target: any;
         private _property: string;
 
-        constructor(actionManager: ActionManager, target: any, public propertyPath: string, public value: any, public operator: number = StateCondition.IsEqual) {
+        constructor(actionManager: ActionManager, target: any, public propertyPath: string, public value: any, public operator: number = ValueCondition.IsEqual) {
             super(actionManager);
 
             this._target = this._getEffectiveTarget(target, this.propertyPath);
@@ -61,12 +61,12 @@
         // Methods
         public isValid(): boolean {
             switch (this.operator) {
-                case StateCondition.IsGreater:
+                case ValueCondition.IsGreater:
                     return this._target[this._property] > this.value;
-                case StateCondition.IsLesser:
+                case ValueCondition.IsLesser:
                     return this._target[this._property] < this.value;
-                case StateCondition.IsEqual:
-                case StateCondition.IsDifferent:
+                case ValueCondition.IsEqual:
+                case ValueCondition.IsDifferent:
                     var check: boolean;
 
                     if (this.value.equals) {
@@ -74,7 +74,7 @@
                     } else {
                         check = this.value === this._target[this._property];
                     }
-                    return this.operator === StateCondition.IsEqual ? check: !check;
+                    return this.operator === ValueCondition.IsEqual ? check : !check;
             }
 
             return false;
@@ -94,4 +94,23 @@
             return this.predicate();
         }
     }
+
+    export class StateCondition extends Condition {
+        // Members
+        public _actionManager: ActionManager;
+
+        private _target: any;
+
+        constructor(actionManager: ActionManager, target: any, public value: string) {
+            super(actionManager);
+
+            this._target = target;
+        }
+
+        // Methods
+        public isValid(): boolean {
+            return this._target.state === this.value;
+        }
+    }
+
 }

+ 15 - 1
Babylon/Actions/babylon.directActions.js

@@ -25,6 +25,20 @@ var BABYLON;
     })(BABYLON.Action);
     BABYLON.SwitchBooleanAction = SwitchBooleanAction;
 
+    var SetStateAction = (function (_super) {
+        __extends(SetStateAction, _super);
+        function SetStateAction(trigger, target, value, condition) {
+            _super.call(this, trigger, condition);
+            this.value = value;
+            this._target = target;
+        }
+        SetStateAction.prototype.execute = function () {
+            this._target.state = this.value;
+        };
+        return SetStateAction;
+    })(BABYLON.Action);
+    BABYLON.SetStateAction = SetStateAction;
+
     var SetValueAction = (function (_super) {
         __extends(SetValueAction, _super);
         function SetValueAction(trigger, target, propertyPath, value, condition) {
@@ -109,7 +123,7 @@ var BABYLON;
     var DoNothingAction = (function (_super) {
         __extends(DoNothingAction, _super);
         function DoNothingAction(trigger, condition) {
-            if (typeof trigger === "undefined") { trigger = BABYLON.ActionManager.NoneTrigger; }
+            if (typeof trigger === "undefined") { trigger = BABYLON.ActionManager.NothingTrigger; }
             _super.call(this, trigger, condition);
         }
         DoNothingAction.prototype.execute = function () {

+ 14 - 1
Babylon/Actions/babylon.directActions.ts

@@ -18,6 +18,19 @@
         }
     }
 
+    export class SetStateAction extends Action {
+        private _target: any;
+
+        constructor(trigger: number, target: any, public value: string, condition?: Condition) {
+            super(trigger, condition);
+            this._target = target;
+        }
+
+        public execute(): void {
+            this._target.state = this.value;
+        }
+    }
+
     export class SetValueAction extends Action {
         private _target: any;
         private _property: string;
@@ -95,7 +108,7 @@
     }
 
     export class DoNothingAction extends Action {
-        constructor(trigger: number = ActionManager.NoneTrigger, condition?: Condition) {
+        constructor(trigger: number = ActionManager.NothingTrigger, condition?: Condition) {
             super(trigger, condition);
         }
 

+ 83 - 37
Babylon/Animations/babylon.animatable.js

@@ -1,45 +1,91 @@
 var BABYLON;
 (function (BABYLON) {
-    (function (Internals) {
-        var Animatable = (function () {
-            function Animatable(target, fromFrame, toFrame, loopAnimation, speedRatio, onAnimationEnd, animations) {
-                if (typeof fromFrame === "undefined") { fromFrame = 0; }
-                if (typeof toFrame === "undefined") { toFrame = 100; }
-                if (typeof loopAnimation === "undefined") { loopAnimation = false; }
-                if (typeof speedRatio === "undefined") { speedRatio = 1.0; }
-                this.target = target;
-                this.fromFrame = fromFrame;
-                this.toFrame = toFrame;
-                this.loopAnimation = loopAnimation;
-                this.speedRatio = speedRatio;
-                this.onAnimationEnd = onAnimationEnd;
-                this.animationStarted = false;
-                this._animations = animations;
-            }
-            // Methods
-            Animatable.prototype._animate = function (delay) {
-                if (!this._localDelayOffset) {
-                    this._localDelayOffset = delay;
-                }
+    var Animatable = (function () {
+        function Animatable(scene, target, fromFrame, toFrame, loopAnimation, speedRatio, onAnimationEnd, animations) {
+            if (typeof fromFrame === "undefined") { fromFrame = 0; }
+            if (typeof toFrame === "undefined") { toFrame = 100; }
+            if (typeof loopAnimation === "undefined") { loopAnimation = false; }
+            if (typeof speedRatio === "undefined") { speedRatio = 1.0; }
+            this.target = target;
+            this.fromFrame = fromFrame;
+            this.toFrame = toFrame;
+            this.loopAnimation = loopAnimation;
+            this.speedRatio = speedRatio;
+            this.onAnimationEnd = onAnimationEnd;
+            this._animations = new Array();
+            this._paused = false;
+            this.animationStarted = false;
+            if (animations) {
+                this.appendAnimations(animations);
+            }
 
-                // Animating
-                var running = false;
-                var animations = this._animations || this.target.animations;
-                for (var index = 0; index < animations.length; index++) {
-                    var isRunning = animations[index].animate(this.target, delay - this._localDelayOffset, this.fromFrame, this.toFrame, this.loopAnimation, this.speedRatio);
-                    running = running || isRunning;
-                }
+            this._scene = scene;
+            scene._activeAnimatables.push(this);
+        }
+        // Methods
+        Animatable.prototype.appendAnimations = function (animations) {
+            this._animations = this._animations.concat(animations);
+        };
 
-                if (!running && this.onAnimationEnd) {
-                    this.onAnimationEnd();
+        Animatable.prototype.getAnimationByTargetProperty = function (property) {
+            var animations = this._animations;
+
+            for (var index = 0; index < animations.length; index++) {
+                if (animations[index].targetProperty === property) {
+                    return animations[index];
                 }
+            }
+
+            return null;
+        };
+
+        Animatable.prototype.pause = function () {
+            this._paused = true;
+        };
+
+        Animatable.prototype.restart = function () {
+            this._paused = false;
+        };
+
+        Animatable.prototype.stop = function () {
+            var index = this._scene._activeAnimatables.indexOf(this);
+
+            if (index > -1) {
+                this._scene._activeAnimatables.splice(index, 1);
+            }
+
+            if (this.onAnimationEnd) {
+                this.onAnimationEnd();
+            }
+        };
+
+        Animatable.prototype._animate = function (delay) {
+            if (this._paused) {
+                return true;
+            }
+
+            if (!this._localDelayOffset) {
+                this._localDelayOffset = delay;
+            }
+
+            // Animating
+            var running = false;
+            var animations = this._animations;
+
+            for (var index = 0; index < animations.length; index++) {
+                var animation = animations[index];
+                var isRunning = animation.animate(this.target, delay - this._localDelayOffset, this.fromFrame, this.toFrame, this.loopAnimation, this.speedRatio);
+                running = running || isRunning;
+            }
+
+            if (!running && this.onAnimationEnd) {
+                this.onAnimationEnd();
+            }
 
-                return running;
-            };
-            return Animatable;
-        })();
-        Internals.Animatable = Animatable;
-    })(BABYLON.Internals || (BABYLON.Internals = {}));
-    var Internals = BABYLON.Internals;
+            return running;
+        };
+        return Animatable;
+    })();
+    BABYLON.Animatable = Animatable;
 })(BABYLON || (BABYLON = {}));
 //# sourceMappingURL=babylon.animatable.js.map

+ 55 - 6
Babylon/Animations/babylon.animatable.ts

@@ -1,25 +1,74 @@
-module BABYLON.Internals {
+module BABYLON {
     export class Animatable {
         private _localDelayOffset: number;
-        private _animations: any;
+        private _animations = new Array<Animation>();
+        private _paused = false;
+        private _scene: Scene;
 
         public animationStarted = false;
 
-        constructor(public target, public fromFrame: number = 0, public toFrame: number = 100, public loopAnimation: boolean = false, public speedRatio: number = 1.0, public onAnimationEnd?, animations?: any) {
-            this._animations = animations;
+        constructor(scene: Scene, public target, public fromFrame: number = 0, public toFrame: number = 100, public loopAnimation: boolean = false, public speedRatio: number = 1.0, public onAnimationEnd?, animations?: any) {
+            if (animations) {
+                this.appendAnimations(animations);
+            }
+
+            this._scene = scene;
+            scene._activeAnimatables.push(this);
         }
 
         // Methods
+        public appendAnimations(animations: Animation[]): void {
+            this._animations = this._animations.concat(animations);
+        }
+
+        public getAnimationByTargetProperty(property: string) {
+            var animations = this._animations;
+
+            for (var index = 0; index < animations.length; index++) {
+                if (animations[index].targetProperty === property) {
+                    return animations[index];
+                }
+            }
+
+            return null;
+        }
+
+        public pause(): void {
+            this._paused = true;
+        }
+
+        public restart(): void {
+            this._paused = false;
+        }
+
+        public stop(): void {
+            var index = this._scene._activeAnimatables.indexOf(this);
+
+            if (index > -1) {
+                this._scene._activeAnimatables.splice(index, 1);
+            }
+
+            if (this.onAnimationEnd) {
+                this.onAnimationEnd();
+            }
+        }
+
         public _animate(delay: number): boolean {
+            if (this._paused) {
+                return true;
+            }
+
             if (!this._localDelayOffset) {
                 this._localDelayOffset = delay;
             }
 
             // Animating
             var running = false;
-            var animations = this._animations || this.target.animations;
+            var animations = this._animations;
+
             for (var index = 0; index < animations.length; index++) {
-                var isRunning = animations[index].animate(this.target, delay - this._localDelayOffset, this.fromFrame, this.toFrame, this.loopAnimation, this.speedRatio);
+                var animation = animations[index];
+                var isRunning = animation.animate(this.target, delay - this._localDelayOffset, this.fromFrame, this.toFrame, this.loopAnimation, this.speedRatio);
                 running = running || isRunning;
             }
 

+ 10 - 0
Babylon/Animations/babylon.animation.js

@@ -9,11 +9,16 @@
             this.loopMode = loopMode;
             this._offsetsCache = {};
             this._highLimitsCache = {};
+            this._stopped = false;
             this.targetPropertyPath = targetProperty.split(".");
             this.dataType = dataType;
             this.loopMode = loopMode === undefined ? Animation.ANIMATIONLOOPMODE_CYCLE : loopMode;
         }
         // Methods
+        Animation.prototype.isStopped = function () {
+            return this._stopped;
+        };
+
         Animation.prototype.getKeys = function () {
             return this._keys;
         };
@@ -122,6 +127,7 @@
 
         Animation.prototype.animate = function (target, delay, from, to, loop, speedRatio) {
             if (!this.targetPropertyPath || this.targetPropertyPath.length < 1) {
+                this._stopped = true;
                 return false;
             }
 
@@ -210,6 +216,10 @@
                 target.markAsDirty(this.targetProperty);
             }
 
+            if (!returnValue) {
+                this._stopped = true;
+            }
+
             return returnValue;
         };
 

+ 10 - 0
Babylon/Animations/babylon.animation.ts

@@ -3,6 +3,7 @@
         private _keys: Array<any>;
         private _offsetsCache = {};
         private _highLimitsCache = {};
+        private _stopped = false;
 
         public targetPropertyPath: string[];
         public currentFrame: number;
@@ -14,6 +15,10 @@
         }
 
         // Methods   
+        public isStopped(): boolean {
+            return this._stopped;
+        }
+
         public getKeys(): any[] {
             return this._keys;
         }
@@ -123,6 +128,7 @@
 
         public animate(target, delay: number, from: number, to: number, loop: boolean, speedRatio: number): boolean {
             if (!this.targetPropertyPath || this.targetPropertyPath.length < 1) {
+                this._stopped = true;
                 return false;
             }
 
@@ -211,6 +217,10 @@
                 target.markAsDirty(this.targetProperty);
             }
 
+            if (!returnValue) {
+                this._stopped = true;
+            }
+
             return returnValue;
         }
 

+ 1 - 0
Babylon/Materials/babylon.material.js

@@ -5,6 +5,7 @@
             this.name = name;
             this.checkReadyOnEveryCall = true;
             this.checkReadyOnlyOnce = false;
+            this.state = "";
             this.alpha = 1.0;
             this.wireframe = false;
             this.backFaceCulling = true;

+ 1 - 0
Babylon/Materials/babylon.material.ts

@@ -3,6 +3,7 @@
         public id: string;
         public checkReadyOnEveryCall = true;
         public checkReadyOnlyOnce = false;
+        public state = "";
         public alpha = 1.0;
         public wireframe = false;
         public backFaceCulling = true;

+ 3 - 11
Babylon/Mesh/babylon.abstractMesh.js

@@ -48,8 +48,6 @@ var BABYLON;
             this._pivotMatrix = BABYLON.Matrix.Identity();
             this._isDisposed = false;
             this._renderId = 0;
-            this._traversalId = -1;
-            this._collisionTraversalId = 0;
 
             scene.meshes.push(this);
         }
@@ -539,6 +537,8 @@ var BABYLON;
             // Update octree
             var bbox = this.getBoundingInfo().boundingBox;
             this._submeshesOctree.update(bbox.minimumWorld, bbox.maximumWorld, this.subMeshes);
+
+            return this._submeshesOctree;
         };
 
         // Collisions
@@ -568,7 +568,7 @@ var BABYLON;
             // Octrees
             if (this._submeshesOctree && this.useOctreeForCollisions) {
                 var radius = collider.velocityWorldLength + Math.max(collider.radius.x, collider.radius.y, collider.radius.z);
-                var intersections = this._submeshesOctree.intersects(collider.basePointWorld, radius, true);
+                var intersections = this._submeshesOctree.intersects(collider.basePointWorld, radius);
 
                 len = intersections.length;
                 subMeshes = intersections.data;
@@ -577,17 +577,9 @@ var BABYLON;
                 len = subMeshes.length;
             }
 
-            this._collisionTraversalId++;
-
             for (var index = 0; index < len; index++) {
                 var subMesh = subMeshes[index];
 
-                if (subMesh._collisionTraversalId === this._collisionTraversalId) {
-                    continue;
-                }
-
-                subMesh._collisionTraversalId = this._collisionTraversalId;
-
                 // Bounding test
                 if (len > 1 && !subMesh._checkCollision(collider))
                     continue;

+ 4 - 12
Babylon/Mesh/babylon.abstractMesh.ts

@@ -79,8 +79,6 @@
         private _pivotMatrix = BABYLON.Matrix.Identity();
         public _isDisposed = false;
         public _renderId = 0;
-        public _traversalId = -1;
-        private _collisionTraversalId = 0;
 
         public subMeshes: SubMesh[];
         public _submeshesOctree: Octree<SubMesh>;
@@ -525,7 +523,7 @@
         * This function will create an octree to help select the right submeshes for rendering, picking and collisions
         * Please note that you must have a decent number of submeshes to get performance improvements when using octree
         */
-        public createOrUpdateSubmeshesOctree(capacity?: number): void {
+        public createOrUpdateSubmeshesOctree(capacity?: number): Octree<SubMesh> {
             if (!this._submeshesOctree) {
                 this._submeshesOctree = new BABYLON.Octree<SubMesh>(Octree.CreationFuncForSubMeshes, capacity);
             }
@@ -535,6 +533,8 @@
             // Update octree
             var bbox = this.getBoundingInfo().boundingBox;
             this._submeshesOctree.update(bbox.minimumWorld, bbox.maximumWorld, this.subMeshes);
+
+            return this._submeshesOctree;
         }
 
         // Collisions
@@ -562,7 +562,7 @@
             // Octrees
             if (this._submeshesOctree && this.useOctreeForCollisions) {
                 var radius = collider.velocityWorldLength + Math.max(collider.radius.x, collider.radius.y, collider.radius.z);
-                var intersections = this._submeshesOctree.intersects(collider.basePointWorld, radius, true);
+                var intersections = this._submeshesOctree.intersects(collider.basePointWorld, radius);
 
                 len = intersections.length;
                 subMeshes = intersections.data;
@@ -571,17 +571,9 @@
                 len = subMeshes.length;
             }
 
-            this._collisionTraversalId++;
-
             for (var index = 0; index < len; index++) {
                 var subMesh = subMeshes[index];
 
-                if (subMesh._collisionTraversalId === this._collisionTraversalId) {
-                    continue;
-                }
-
-                subMesh._collisionTraversalId = this._collisionTraversalId;
-
                 // Bounding test
                 if (len > 1 && !subMesh._checkCollision(collider))
                     continue;

+ 1 - 1
Babylon/Mesh/babylon.groundMesh.js

@@ -25,7 +25,7 @@ var BABYLON;
             if (state) {
                 this.subdivide(this._subdivisions);
 
-                this.createOrUpdateSubmeshesOctree(32);
+                this.createOrUpdateSubmeshesOctree();
             }
 
             _super.prototype._setReady.call(this, state);

+ 1 - 1
Babylon/Mesh/babylon.groundMesh.ts

@@ -17,7 +17,7 @@
             if (state) {
                 this.subdivide(this._subdivisions);
 
-                this.createOrUpdateSubmeshesOctree(32);
+                this.createOrUpdateSubmeshesOctree();
             }
 
             super._setReady(state);

+ 0 - 2
Babylon/Mesh/babylon.subMesh.js

@@ -9,8 +9,6 @@
             this.indexStart = indexStart;
             this.indexCount = indexCount;
             this._renderId = 0;
-            this._traversalId = -1;
-            this._collisionTraversalId = -1;
             this._mesh = mesh;
             this._renderingMesh = renderingMesh || mesh;
             mesh.subMeshes.push(this);

+ 0 - 2
Babylon/Mesh/babylon.subMesh.ts

@@ -11,8 +11,6 @@
         public _lastColliderTransformMatrix: Matrix;
 
         public _renderId = 0;
-        public _traversalId = -1;
-        public _collisionTraversalId = -1;
         public _distanceToCamera: number;
 
         constructor(public materialIndex: number, public verticesStart: number, public verticesCount: number, public indexStart, public indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh, createBoundingBox: boolean = true) {

+ 13 - 6
Babylon/Tools/babylon.smartArray.js

@@ -3,7 +3,9 @@
     var SmartArray = (function () {
         function SmartArray(capacity) {
             this.length = 0;
+            this._duplicateId = 0;
             this.data = new Array(capacity);
+            this._id = SmartArray._GlobalId++;
         }
         SmartArray.prototype.push = function (value) {
             this.data[this.length++] = value;
@@ -11,10 +13,16 @@
             if (this.length > this.data.length) {
                 this.data.length *= 2;
             }
+
+            if (!value.__smartArrayFlags) {
+                value.__smartArrayFlags = {};
+            }
+
+            value.__smartArrayFlags[this._id] = this._duplicateId;
         };
 
         SmartArray.prototype.pushNoDuplicate = function (value) {
-            if (this.indexOf(value) > -1) {
+            if (value.__smartArrayFlags && value.__smartArrayFlags[this._id] === this._duplicateId) {
                 return;
             }
             this.push(value);
@@ -26,6 +34,7 @@
 
         SmartArray.prototype.reset = function () {
             this.length = 0;
+            this._duplicateId++;
         };
 
         SmartArray.prototype.concat = function (array) {
@@ -51,11 +60,7 @@
 
             for (var index = 0; index < array.length; index++) {
                 var item = (array.data || array)[index];
-                var pos = this.data.indexOf(item);
-
-                if (pos === -1 || pos >= this.length) {
-                    this.data[this.length++] = item;
-                }
+                this.pushNoDuplicate(item);
             }
         };
 
@@ -68,6 +73,8 @@
 
             return position;
         };
+
+        SmartArray._GlobalId = 0;
         return SmartArray;
     })();
     BABYLON.SmartArray = SmartArray;

+ 16 - 6
Babylon/Tools/babylon.smartArray.ts

@@ -3,8 +3,12 @@
         public data: Array<T>;
         public length: number = 0;
 
+        private _id: number;
+        private _duplicateId = 0;
+
         constructor(capacity: number) {
             this.data = new Array(capacity);
+            this._id = SmartArray._GlobalId++;
         }
 
         public push(value): void {
@@ -13,10 +17,16 @@
             if (this.length > this.data.length) {
                 this.data.length *= 2;
             }
+
+            if (!value.__smartArrayFlags) {
+                value.__smartArrayFlags = {};
+            }
+
+            value.__smartArrayFlags[this._id] = this._duplicateId;
         }
 
         public pushNoDuplicate(value): void {
-            if (this.indexOf(value) > -1) {
+            if (value.__smartArrayFlags && value.__smartArrayFlags[this._id] === this._duplicateId) {
                 return;
             }
             this.push(value);
@@ -28,6 +38,7 @@
 
         public reset(): void {
             this.length = 0;
+            this._duplicateId++;
         }
 
         public concat(array: any): void {
@@ -53,11 +64,7 @@
 
             for (var index = 0; index < array.length; index++) {
                 var item = (array.data || array)[index];
-                var pos = this.data.indexOf(item);
-
-                if (pos === -1 || pos >= this.length) {
-                    this.data[this.length++] = item;
-                }
+                this.pushNoDuplicate(item);
             }
         }
 
@@ -70,5 +77,8 @@
 
             return position;
         }
+
+        // Statics
+        private static _GlobalId = 0;
     }
 } 

+ 1 - 0
Babylon/babylon.node.js

@@ -2,6 +2,7 @@
 (function (BABYLON) {
     var Node = (function () {
         function Node(name, scene) {
+            this.state = "";
             this.animations = new Array();
             this._childrenFlag = -1;
             this._isEnabled = true;

+ 1 - 0
Babylon/babylon.node.ts

@@ -3,6 +3,7 @@
         public parent: Node;
         public name: string;
         public id: string;
+        public state = "";
 
         public animations = new Array<Animation>();
 

+ 40 - 39
Babylon/babylon.scene.js

@@ -62,7 +62,6 @@
             this._spritesDuration = 0;
             this._animationRatio = 0;
             this._renderId = 0;
-            this._traversalId = 0;
             this._executeWhenReadyTimeoutId = -1;
             this._toBeDisposed = new BABYLON.SmartArray(256);
             this._onReadyCallbacks = new Array();
@@ -200,6 +199,17 @@
 
                 if (pickResult.hit) {
                     if (pickResult.pickedMesh.actionManager) {
+                        switch (evt.buttons) {
+                            case 1:
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger);
+                                break;
+                            case 2:
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger);
+                                break;
+                            case 3:
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger);
+                                break;
+                        }
                         pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger);
                     }
                 }
@@ -311,27 +321,31 @@
         };
 
         // Animations
-        Scene.prototype.beginAnimation = function (target, from, to, loop, speedRatio, onAnimationEnd) {
+        Scene.prototype.beginAnimation = function (target, from, to, loop, speedRatio, onAnimationEnd, animatable) {
             if (speedRatio === undefined) {
                 speedRatio = 1.0;
             }
 
-            // Local animations
-            if (target.animations) {
-                this.stopAnimation(target);
+            this.stopAnimation(target);
 
-                var animatable = new BABYLON.Internals.Animatable(target, from, to, loop, speedRatio, onAnimationEnd);
+            if (!animatable) {
+                animatable = new BABYLON.Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd);
+            }
 
-                this._activeAnimatables.push(animatable);
+            // Local animations
+            if (target.animations) {
+                animatable.appendAnimations(target.animations);
             }
 
             // Children animations
             if (target.getAnimatables) {
                 var animatables = target.getAnimatables();
                 for (var index = 0; index < animatables.length; index++) {
-                    this.beginAnimation(animatables[index], from, to, loop, speedRatio, onAnimationEnd);
+                    this.beginAnimation(animatables[index], from, to, loop, speedRatio, onAnimationEnd, animatable);
                 }
             }
+
+            return animatable;
         };
 
         Scene.prototype.beginDirectAnimation = function (target, animations, from, to, loop, speedRatio, onAnimationEnd) {
@@ -339,28 +353,26 @@
                 speedRatio = 1.0;
             }
 
-            var animatable = new BABYLON.Internals.Animatable(target, from, to, loop, speedRatio, onAnimationEnd, animations);
+            var animatable = new BABYLON.Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd, animations);
 
-            this._activeAnimatables.push(animatable);
+            return animatable;
         };
 
-        Scene.prototype.stopAnimation = function (target) {
-            // Local animations
-            if (target.animations) {
-                for (var index = 0; index < this._activeAnimatables.length; index++) {
-                    if (this._activeAnimatables[index].target === target) {
-                        this._activeAnimatables.splice(index, 1);
-                        return;
-                    }
+        Scene.prototype.getAnimatableByTarget = function (target) {
+            for (var index = 0; index < this._activeAnimatables.length; index++) {
+                if (this._activeAnimatables[index].target === target) {
+                    return this._activeAnimatables[index];
                 }
             }
 
-            // Children animations
-            if (target.getAnimatables) {
-                var animatables = target.getAnimatables();
-                for (index = 0; index < animatables.length; index++) {
-                    this.stopAnimation(animatables[index]);
-                }
+            return null;
+        };
+
+        Scene.prototype.stopAnimation = function (target) {
+            var animatable = this.getAnimatableByTarget(target);
+
+            if (animatable) {
+                animatable.stop();
             }
         };
 
@@ -638,7 +650,7 @@
             var len;
 
             if (this._selectionOctree) {
-                var selection = this._selectionOctree.select(this._frustumPlanes, true);
+                var selection = this._selectionOctree.select(this._frustumPlanes);
                 meshes = selection.data;
                 len = selection.length;
             } else {
@@ -646,16 +658,9 @@
                 meshes = this.meshes;
             }
 
-            this._traversalId++;
             for (var meshIndex = 0; meshIndex < len; meshIndex++) {
                 var mesh = meshes[meshIndex];
 
-                if (mesh._traversalId === this._traversalId) {
-                    continue;
-                }
-
-                mesh._traversalId = this._traversalId;
-
                 this._totalVertices += mesh.getTotalVertices();
 
                 if (!mesh.isReady()) {
@@ -707,7 +712,7 @@
                 var subMeshes;
 
                 if (mesh._submeshesOctree && mesh.useOctreeForRenderingSelection) {
-                    var intersections = mesh._submeshesOctree.select(this._frustumPlanes, true);
+                    var intersections = mesh._submeshesOctree.select(this._frustumPlanes);
 
                     len = intersections.length;
                     subMeshes = intersections.data;
@@ -719,12 +724,6 @@
                 for (var subIndex = 0; subIndex < len; subIndex++) {
                     var subMesh = subMeshes[subIndex];
 
-                    if (mesh._traversalId === subMesh._traversalId) {
-                        continue;
-                    }
-
-                    subMesh._traversalId = mesh._traversalId;
-
                     this._evaluateSubMesh(subMesh, mesh);
                 }
             }
@@ -1067,6 +1066,8 @@
 
             // Update octree
             this._selectionOctree.update(min, max, this.meshes);
+
+            return this._selectionOctree;
         };
 
         // Picking

+ 43 - 42
Babylon/babylon.scene.ts

@@ -114,7 +114,6 @@
         private _animationStartDate: number;
 
         private _renderId = 0;
-        private _traversalId = 0;
         private _executeWhenReadyTimeoutId = -1;
 
         public _toBeDisposed = new SmartArray<IDisposable>(256);
@@ -133,7 +132,7 @@
         private _renderingManager: RenderingManager;
         private _physicsEngine: PhysicsEngine;
 
-        private _activeAnimatables = new Array<Internals.Animatable>();
+        public _activeAnimatables = new Array<Animatable>();
 
         private _transformMatrix = Matrix.Zero();
         private _pickWithRayInverseMatrix: Matrix;
@@ -262,6 +261,17 @@
 
                 if (pickResult.hit) {
                     if (pickResult.pickedMesh.actionManager) {
+                        switch (evt.buttons) {
+                            case 1:
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger);
+                                break;
+                            case 2:
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger);
+                                break;
+                            case 3:
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger);
+                                break;
+                        }
                         pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger);
                     }
                 }
@@ -373,56 +383,58 @@
         }
 
         // Animations
-        public beginAnimation(target: any, from: number, to: number, loop?: boolean, speedRatio?: number, onAnimationEnd?: () => void): void {
+        public beginAnimation(target: any, from: number, to: number, loop?: boolean, speedRatio?: number, onAnimationEnd?: () => void, animatable?: Animatable): Animatable {
             if (speedRatio === undefined) {
                 speedRatio = 1.0;
             }
 
-            // Local animations
-            if (target.animations) {
-                this.stopAnimation(target);
+            this.stopAnimation(target);
 
-                var animatable = new BABYLON.Internals.Animatable(target, from, to, loop, speedRatio, onAnimationEnd);
+            if (!animatable) {
+                animatable = new Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd);
+            }
 
-                this._activeAnimatables.push(animatable);
+            // Local animations
+            if (target.animations) {
+                animatable.appendAnimations(target.animations);
             }
 
             // Children animations
             if (target.getAnimatables) {
                 var animatables = target.getAnimatables();
                 for (var index = 0; index < animatables.length; index++) {
-                    this.beginAnimation(animatables[index], from, to, loop, speedRatio, onAnimationEnd);
+                    this.beginAnimation(animatables[index], from, to, loop, speedRatio, onAnimationEnd, animatable);
                 }
             }
+
+            return animatable;
         }
 
-        public beginDirectAnimation(target: any, animations: Animation[], from: number, to: number, loop?: boolean, speedRatio?: number, onAnimationEnd?: () => void): void {
+        public beginDirectAnimation(target: any, animations: Animation[], from: number, to: number, loop?: boolean, speedRatio?: number, onAnimationEnd?: () => void): Animatable {
             if (speedRatio === undefined) {
                 speedRatio = 1.0;
             }
 
-            var animatable = new BABYLON.Internals.Animatable(target, from, to, loop, speedRatio, onAnimationEnd, animations);
+            var animatable = new BABYLON.Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd, animations);
 
-            this._activeAnimatables.push(animatable);
+            return animatable;
         }
 
-        public stopAnimation(target: any): void {
-            // Local animations
-            if (target.animations) {
-                for (var index = 0; index < this._activeAnimatables.length; index++) {
-                    if (this._activeAnimatables[index].target === target) {
-                        this._activeAnimatables.splice(index, 1);
-                        return;
-                    }
+        public getAnimatableByTarget(target: any): Animatable {
+            for (var index = 0; index < this._activeAnimatables.length; index++) {
+                if (this._activeAnimatables[index].target === target) {
+                    return this._activeAnimatables[index];
                 }
             }
 
-            // Children animations
-            if (target.getAnimatables) {
-                var animatables = target.getAnimatables();
-                for (index = 0; index < animatables.length; index++) {
-                    this.stopAnimation(animatables[index]);
-                }
+            return null;
+        }
+
+        public stopAnimation(target: any): void {
+            var animatable = this.getAnimatableByTarget(target);
+
+            if (animatable) {
+                animatable.stop();
             }
         }
 
@@ -699,7 +711,7 @@
             var len: number;
 
             if (this._selectionOctree) { // Octree
-                var selection = this._selectionOctree.select(this._frustumPlanes, true);
+                var selection = this._selectionOctree.select(this._frustumPlanes);
                 meshes = selection.data;
                 len = selection.length;
             } else { // Full scene traversal
@@ -707,16 +719,9 @@
                 meshes = this.meshes;
             }
 
-            this._traversalId++;
             for (var meshIndex = 0; meshIndex < len; meshIndex++) {
                 var mesh = meshes[meshIndex];
 
-                if (mesh._traversalId === this._traversalId) {
-                    continue;
-                }
-
-                mesh._traversalId = this._traversalId;
-
                 this._totalVertices += mesh.getTotalVertices();
 
                 if (!mesh.isReady()) {
@@ -768,7 +773,7 @@
                 var subMeshes: SubMesh[];
 
                 if (mesh._submeshesOctree && mesh.useOctreeForRenderingSelection) {
-                    var intersections = mesh._submeshesOctree.select(this._frustumPlanes, true);
+                    var intersections = mesh._submeshesOctree.select(this._frustumPlanes);
 
                     len = intersections.length;
                     subMeshes = intersections.data;
@@ -780,12 +785,6 @@
                 for (var subIndex = 0; subIndex < len; subIndex++) {
                     var subMesh = subMeshes[subIndex];
 
-                    if (mesh._traversalId === subMesh._traversalId) {
-                        continue;
-                    }
-
-                    subMesh._traversalId = mesh._traversalId;
-
                     this._evaluateSubMesh(subMesh, mesh);
                 }
             }
@@ -1123,7 +1122,7 @@
         }
 
         // Octrees
-        public createOrUpdateSelectionOctree(): void {
+        public createOrUpdateSelectionOctree(): Octree<AbstractMesh> {
             if (!this._selectionOctree) {
                 this._selectionOctree = new BABYLON.Octree<AbstractMesh>(Octree.CreationFuncForMeshes);
             }
@@ -1143,6 +1142,8 @@
 
             // Update octree
             this._selectionOctree.update(min, max, this.meshes);
+
+            return this._selectionOctree;
         }
 
         // Picking

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 12 - 12
babylon.1.12-beta.js