浏览代码

Fixing instances and cache issue

David Catuhe 9 年之前
父节点
当前提交
fa45b0a8c0

文件差异内容过多而无法显示
+ 24 - 17
dist/preview release/babylon.core.js


+ 306 - 296
dist/preview release/babylon.d.ts

@@ -2267,6 +2267,25 @@ declare module BABYLON {
 }
 
 declare module BABYLON {
+    class Layer {
+        name: string;
+        texture: Texture;
+        isBackground: boolean;
+        color: Color4;
+        onDispose: () => void;
+        private _scene;
+        private _vertexDeclaration;
+        private _vertexStrideSize;
+        private _vertexBuffer;
+        private _indexBuffer;
+        private _effect;
+        constructor(name: string, imgUrl: string, scene: Scene, isBackground?: boolean, color?: Color4);
+        render(): void;
+        dispose(): void;
+    }
+}
+
+declare module BABYLON {
     class DebugLayer {
         private _scene;
         private _camera;
@@ -2324,25 +2343,6 @@ declare module BABYLON {
 }
 
 declare module BABYLON {
-    class Layer {
-        name: string;
-        texture: Texture;
-        isBackground: boolean;
-        color: Color4;
-        onDispose: () => void;
-        private _scene;
-        private _vertexDeclaration;
-        private _vertexStrideSize;
-        private _vertexBuffer;
-        private _indexBuffer;
-        private _effect;
-        constructor(name: string, imgUrl: string, scene: Scene, isBackground?: boolean, color?: Color4);
-        render(): void;
-        dispose(): void;
-    }
-}
-
-declare module BABYLON {
     class LensFlare {
         size: number;
         position: number;
@@ -2779,7 +2779,7 @@ declare module BABYLON {
         needAlphaTesting(): boolean;
         private _shouldUseAlphaFromDiffuseTexture();
         getAlphaTestTexture(): BaseTexture;
-        private _checkCache(scene, mesh?);
+        private _checkCache(scene, mesh?, useInstances?);
         isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean;
         unbind(): void;
         bindOnlyWorldMatrix(world: Matrix): void;
@@ -3326,203 +3326,6 @@ declare module BABYLON {
 }
 
 declare module BABYLON {
-    class Particle {
-        position: Vector3;
-        direction: Vector3;
-        color: Color4;
-        colorStep: Color4;
-        lifeTime: number;
-        age: number;
-        size: number;
-        angle: number;
-        angularSpeed: number;
-        copyTo(other: Particle): void;
-    }
-}
-
-declare module BABYLON {
-    class ParticleSystem implements IDisposable {
-        name: string;
-        static BLENDMODE_ONEONE: number;
-        static BLENDMODE_STANDARD: number;
-        id: string;
-        renderingGroupId: number;
-        emitter: any;
-        emitRate: number;
-        manualEmitCount: number;
-        updateSpeed: number;
-        targetStopDuration: number;
-        disposeOnStop: boolean;
-        minEmitPower: number;
-        maxEmitPower: number;
-        minLifeTime: number;
-        maxLifeTime: number;
-        minSize: number;
-        maxSize: number;
-        minAngularSpeed: number;
-        maxAngularSpeed: number;
-        particleTexture: Texture;
-        layerMask: number;
-        onDispose: () => void;
-        updateFunction: (particles: Particle[]) => void;
-        blendMode: number;
-        forceDepthWrite: boolean;
-        gravity: Vector3;
-        direction1: Vector3;
-        direction2: Vector3;
-        minEmitBox: Vector3;
-        maxEmitBox: Vector3;
-        color1: Color4;
-        color2: Color4;
-        colorDead: Color4;
-        textureMask: Color4;
-        startDirectionFunction: (emitPower: number, worldMatrix: Matrix, directionToUpdate: Vector3) => void;
-        startPositionFunction: (worldMatrix: Matrix, positionToUpdate: Vector3) => void;
-        private particles;
-        private _capacity;
-        private _scene;
-        private _vertexDeclaration;
-        private _vertexStrideSize;
-        private _stockParticles;
-        private _newPartsExcess;
-        private _vertexBuffer;
-        private _indexBuffer;
-        private _vertices;
-        private _effect;
-        private _customEffect;
-        private _cachedDefines;
-        private _scaledColorStep;
-        private _colorDiff;
-        private _scaledDirection;
-        private _scaledGravity;
-        private _currentRenderId;
-        private _alive;
-        private _started;
-        private _stopped;
-        private _actualFrame;
-        private _scaledUpdateSpeed;
-        constructor(name: string, capacity: number, scene: Scene, customEffect?: Effect);
-        recycleParticle(particle: Particle): void;
-        getCapacity(): number;
-        isAlive(): boolean;
-        isStarted(): boolean;
-        start(): void;
-        stop(): void;
-        _appendParticleVertex(index: number, particle: Particle, offsetX: number, offsetY: number): void;
-        private _update(newParticles);
-        private _getEffect();
-        animate(): void;
-        render(): number;
-        dispose(): void;
-        clone(name: string, newEmitter: any): ParticleSystem;
-    }
-}
-
-declare module BABYLON {
-    class SolidParticle {
-        idx: number;
-        color: Color4;
-        position: Vector3;
-        rotation: Vector3;
-        quaternion: Vector4;
-        scale: Vector3;
-        uvs: Vector4;
-        velocity: Vector3;
-        alive: boolean;
-        _pos: number;
-        _shape: Vector3[];
-        _shapeUV: number[];
-        shapeId: number;
-        previous: SolidParticle;
-        next: SolidParticle;
-        idxInShape: number;
-        constructor(particleIndex: number, positionIndex: number, shape: Vector3[], shapeUV: number[], shapeId: number, idxInShape: number);
-    }
-}
-
-declare module BABYLON {
-    class SolidParticleSystem implements IDisposable {
-        particles: SolidParticle[];
-        nbParticles: number;
-        billboard: boolean;
-        counter: number;
-        name: string;
-        mesh: Mesh;
-        private _scene;
-        private _positions;
-        private _indices;
-        private _normals;
-        private _colors;
-        private _uvs;
-        private _positions32;
-        private _normals32;
-        private _colors32;
-        private _uvs32;
-        private _index;
-        private _shapeCounter;
-        private _copy;
-        private _color;
-        private _computeParticleColor;
-        private _computeParticleTexture;
-        private _computeParticleRotation;
-        private _computeParticleVertex;
-        private _cam_axisZ;
-        private _cam_axisY;
-        private _cam_axisX;
-        private _axisX;
-        private _axisY;
-        private _axisZ;
-        private _camera;
-        private _particle;
-        private _previousParticle;
-        private _fakeCamPos;
-        private _rotMatrix;
-        private _invertedMatrix;
-        private _rotated;
-        private _quaternion;
-        private _vertex;
-        private _yaw;
-        private _pitch;
-        private _roll;
-        private _halfroll;
-        private _halfpitch;
-        private _halfyaw;
-        private _sinRoll;
-        private _cosRoll;
-        private _sinPitch;
-        private _cosPitch;
-        private _sinYaw;
-        private _cosYaw;
-        constructor(name: string, scene: Scene);
-        buildMesh(upgradable?: boolean): Mesh;
-        private _resetCopy();
-        private _meshBuilder(p, shape, positions, meshInd, indices, meshUV, uvs, meshCol, colors, idxInShape, options);
-        private _posToShape(positions);
-        private _uvsToShapeUV(uvs);
-        private _addParticle(p, idxpos, shape, shapeUV, shapeId, idxInShape);
-        addShape(mesh: Mesh, nb: number, options?: {
-            positionFunction?: any;
-            vertexFunction?: any;
-        }): number;
-        resetParticle(particle: SolidParticle): void;
-        setParticles(start?: number, end?: number, update?: boolean): void;
-        private _quaternionRotationYPR();
-        private _quaternionToRotationMatrix();
-        dispose(): void;
-        computeParticleRotation: boolean;
-        computeParticleColor: boolean;
-        computeParticleTexture: boolean;
-        computeParticleVertex: boolean;
-        initParticles(): void;
-        recycleParticle(particle: SolidParticle): SolidParticle;
-        updateParticle(particle: SolidParticle): SolidParticle;
-        updateParticleVertex(particle: SolidParticle, vertex: Vector3, pt: number): Vector3;
-        beforeUpdateParticles(start?: number, stop?: number, update?: boolean): void;
-        afterUpdateParticles(start?: number, stop?: number, update?: boolean): void;
-    }
-}
-
-declare module BABYLON {
     class AbstractMesh extends Node implements IDisposable {
         private static _BILLBOARDMODE_NONE;
         private static _BILLBOARDMODE_X;
@@ -4825,31 +4628,217 @@ declare module BABYLON {
 }
 
 declare module BABYLON {
-    class ReflectionProbe {
-        name: string;
-        private _scene;
-        private _renderTargetTexture;
-        private _projectionMatrix;
-        private _viewMatrix;
-        private _target;
-        private _add;
-        private _attachedMesh;
+    class Particle {
         position: Vector3;
-        constructor(name: string, size: number, scene: Scene, generateMipMaps?: boolean);
-        refreshRate: number;
-        getScene(): Scene;
-        cubeTexture: RenderTargetTexture;
-        renderList: AbstractMesh[];
-        attachToMesh(mesh: AbstractMesh): void;
-        dispose(): void;
-    }
-}
-
-declare module BABYLON {
-    class AnaglyphPostProcess extends PostProcess {
-        constructor(name: string, ratio: number, camera: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean);
-    }
-}
+        direction: Vector3;
+        color: Color4;
+        colorStep: Color4;
+        lifeTime: number;
+        age: number;
+        size: number;
+        angle: number;
+        angularSpeed: number;
+        copyTo(other: Particle): void;
+    }
+}
+
+declare module BABYLON {
+    class ParticleSystem implements IDisposable {
+        name: string;
+        static BLENDMODE_ONEONE: number;
+        static BLENDMODE_STANDARD: number;
+        id: string;
+        renderingGroupId: number;
+        emitter: any;
+        emitRate: number;
+        manualEmitCount: number;
+        updateSpeed: number;
+        targetStopDuration: number;
+        disposeOnStop: boolean;
+        minEmitPower: number;
+        maxEmitPower: number;
+        minLifeTime: number;
+        maxLifeTime: number;
+        minSize: number;
+        maxSize: number;
+        minAngularSpeed: number;
+        maxAngularSpeed: number;
+        particleTexture: Texture;
+        layerMask: number;
+        onDispose: () => void;
+        updateFunction: (particles: Particle[]) => void;
+        blendMode: number;
+        forceDepthWrite: boolean;
+        gravity: Vector3;
+        direction1: Vector3;
+        direction2: Vector3;
+        minEmitBox: Vector3;
+        maxEmitBox: Vector3;
+        color1: Color4;
+        color2: Color4;
+        colorDead: Color4;
+        textureMask: Color4;
+        startDirectionFunction: (emitPower: number, worldMatrix: Matrix, directionToUpdate: Vector3) => void;
+        startPositionFunction: (worldMatrix: Matrix, positionToUpdate: Vector3) => void;
+        private particles;
+        private _capacity;
+        private _scene;
+        private _vertexDeclaration;
+        private _vertexStrideSize;
+        private _stockParticles;
+        private _newPartsExcess;
+        private _vertexBuffer;
+        private _indexBuffer;
+        private _vertices;
+        private _effect;
+        private _customEffect;
+        private _cachedDefines;
+        private _scaledColorStep;
+        private _colorDiff;
+        private _scaledDirection;
+        private _scaledGravity;
+        private _currentRenderId;
+        private _alive;
+        private _started;
+        private _stopped;
+        private _actualFrame;
+        private _scaledUpdateSpeed;
+        constructor(name: string, capacity: number, scene: Scene, customEffect?: Effect);
+        recycleParticle(particle: Particle): void;
+        getCapacity(): number;
+        isAlive(): boolean;
+        isStarted(): boolean;
+        start(): void;
+        stop(): void;
+        _appendParticleVertex(index: number, particle: Particle, offsetX: number, offsetY: number): void;
+        private _update(newParticles);
+        private _getEffect();
+        animate(): void;
+        render(): number;
+        dispose(): void;
+        clone(name: string, newEmitter: any): ParticleSystem;
+    }
+}
+
+declare module BABYLON {
+    class SolidParticle {
+        idx: number;
+        color: Color4;
+        position: Vector3;
+        rotation: Vector3;
+        quaternion: Vector4;
+        scale: Vector3;
+        uvs: Vector4;
+        velocity: Vector3;
+        alive: boolean;
+        _pos: number;
+        _model: ModelShape;
+        shapeId: number;
+        previous: SolidParticle;
+        next: SolidParticle;
+        idxInShape: number;
+        constructor(particleIndex: number, positionIndex: number, model: ModelShape, shapeId: number, idxInShape: number);
+    }
+    class ModelShape {
+        shapeID: number;
+        _shape: Vector3[];
+        _shapeUV: number[];
+        _positionFunction: (particle: SolidParticle, i: number, s: number) => void;
+        _vertexFunction: (particle: SolidParticle, vertex: Vector3, i: number) => void;
+        constructor(id: number, shape: Vector3[], shapeUV: number[], posFunction: (particle: SolidParticle, i: number, s: number) => void, vtxFunction: (particle: SolidParticle, vertex: Vector3, i: number) => void);
+    }
+}
+
+declare module BABYLON {
+    class SolidParticleSystem implements IDisposable {
+        particles: SolidParticle[];
+        nbParticles: number;
+        billboard: boolean;
+        counter: number;
+        name: string;
+        mesh: Mesh;
+        private _scene;
+        private _positions;
+        private _indices;
+        private _normals;
+        private _colors;
+        private _uvs;
+        private _positions32;
+        private _normals32;
+        private _colors32;
+        private _uvs32;
+        private _index;
+        private _shapeCounter;
+        private _copy;
+        private _shape;
+        private _shapeUV;
+        private _color;
+        private _computeParticleColor;
+        private _computeParticleTexture;
+        private _computeParticleRotation;
+        private _computeParticleVertex;
+        private _cam_axisZ;
+        private _cam_axisY;
+        private _cam_axisX;
+        private _axisX;
+        private _axisY;
+        private _axisZ;
+        private _camera;
+        private _particle;
+        private _previousParticle;
+        private _fakeCamPos;
+        private _rotMatrix;
+        private _invertedMatrix;
+        private _rotated;
+        private _quaternion;
+        private _vertex;
+        private _yaw;
+        private _pitch;
+        private _roll;
+        private _halfroll;
+        private _halfpitch;
+        private _halfyaw;
+        private _sinRoll;
+        private _cosRoll;
+        private _sinPitch;
+        private _cosPitch;
+        private _sinYaw;
+        private _cosYaw;
+        constructor(name: string, scene: Scene);
+        buildMesh(upgradable?: boolean): Mesh;
+        private _resetCopy();
+        private _meshBuilder(p, shape, positions, meshInd, indices, meshUV, uvs, meshCol, colors, idx, idxInShape, options);
+        private _posToShape(positions);
+        private _uvsToShapeUV(uvs);
+        private _addParticle(p, idxpos, model, shapeId, idxInShape);
+        addShape(mesh: Mesh, nb: number, options?: {
+            positionFunction?: any;
+            vertexFunction?: any;
+        }): number;
+        private _rebuildParticle(particle);
+        rebuildMesh(): void;
+        setParticles(start?: number, end?: number, update?: boolean): void;
+        private _quaternionRotationYPR();
+        private _quaternionToRotationMatrix();
+        dispose(): void;
+        computeParticleRotation: boolean;
+        computeParticleColor: boolean;
+        computeParticleTexture: boolean;
+        computeParticleVertex: boolean;
+        initParticles(): void;
+        recycleParticle(particle: SolidParticle): SolidParticle;
+        updateParticle(particle: SolidParticle): SolidParticle;
+        updateParticleVertex(particle: SolidParticle, vertex: Vector3, pt: number): Vector3;
+        beforeUpdateParticles(start?: number, stop?: number, update?: boolean): void;
+        afterUpdateParticles(start?: number, stop?: number, update?: boolean): void;
+    }
+}
+
+declare module BABYLON {
+    class AnaglyphPostProcess extends PostProcess {
+        constructor(name: string, ratio: number, camera: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean);
+    }
+}
 
 declare module BABYLON {
     class BlackAndWhitePostProcess extends PostProcess {
@@ -5568,6 +5557,27 @@ declare module BABYLON {
     }
 }
 
+declare module BABYLON {
+    class ReflectionProbe {
+        name: string;
+        private _scene;
+        private _renderTargetTexture;
+        private _projectionMatrix;
+        private _viewMatrix;
+        private _target;
+        private _add;
+        private _attachedMesh;
+        position: Vector3;
+        constructor(name: string, size: number, scene: Scene, generateMipMaps?: boolean);
+        refreshRate: number;
+        getScene(): Scene;
+        cubeTexture: RenderTargetTexture;
+        renderList: AbstractMesh[];
+        attachToMesh(mesh: AbstractMesh): void;
+        dispose(): void;
+    }
+}
+
 declare module BABYLON.Internals {
     class AndOrNotEvaluator {
         static Eval(query: string, evaluateCallback: (val: any) => boolean): boolean;
@@ -6563,61 +6573,6 @@ declare module BABYLON {
 }
 
 declare module BABYLON {
-    class CannonJSPlugin implements IPhysicsEnginePlugin {
-        private _world;
-        private _registeredMeshes;
-        private _physicsMaterials;
-        initialize(iterations?: number): void;
-        private _checkWithEpsilon(value);
-        runOneStep(delta: number): void;
-        setGravity(gravity: Vector3): void;
-        registerMesh(mesh: AbstractMesh, impostor: number, options?: PhysicsBodyCreationOptions): any;
-        private _createShape(mesh, impostor, options?);
-        private _createConvexPolyhedron(rawVerts, rawFaces, mesh, options?);
-        private _addMaterial(friction, restitution);
-        private _createRigidBodyFromShape(shape, mesh, mass, friction, restitution);
-        registerMeshesAsCompound(parts: PhysicsCompoundBodyPart[], options: PhysicsBodyCreationOptions): any;
-        private _unbindBody(body);
-        unregisterMesh(mesh: AbstractMesh): void;
-        applyImpulse(mesh: AbstractMesh, force: Vector3, contactPoint: Vector3): void;
-        updateBodyPosition: (mesh: AbstractMesh) => void;
-        createLink(mesh1: AbstractMesh, mesh2: AbstractMesh, pivot1: Vector3, pivot2: Vector3): boolean;
-        dispose(): void;
-        isSupported(): boolean;
-        getWorldObject(): any;
-        getPhysicsBodyOfMesh(mesh: AbstractMesh): any;
-    }
-}
-
-declare module BABYLON {
-    class OimoJSPlugin implements IPhysicsEnginePlugin {
-        private _world;
-        private _registeredMeshes;
-        private _checkWithEpsilon(value);
-        initialize(iterations?: number): void;
-        setGravity(gravity: Vector3): void;
-        registerMesh(mesh: AbstractMesh, impostor: number, options: PhysicsBodyCreationOptions): any;
-        registerMeshesAsCompound(parts: PhysicsCompoundBodyPart[], options: PhysicsBodyCreationOptions): any;
-        private _createBodyAsCompound(part, options, initialMesh);
-        unregisterMesh(mesh: AbstractMesh): void;
-        private _unbindBody(body);
-        /**
-         * Update the body position according to the mesh position
-         * @param mesh
-         */
-        updateBodyPosition: (mesh: AbstractMesh) => void;
-        applyImpulse(mesh: AbstractMesh, force: Vector3, contactPoint: Vector3): void;
-        createLink(mesh1: AbstractMesh, mesh2: AbstractMesh, pivot1: Vector3, pivot2: Vector3, options?: any): boolean;
-        dispose(): void;
-        isSupported(): boolean;
-        getWorldObject(): any;
-        getPhysicsBodyOfMesh(mesh: AbstractMesh): any;
-        private _getLastShape(body);
-        runOneStep(time: number): void;
-    }
-}
-
-declare module BABYLON {
     class PostProcessRenderEffect {
         private _engine;
         private _postProcesses;
@@ -6716,6 +6671,61 @@ declare module BABYLON {
 }
 
 declare module BABYLON {
+    class CannonJSPlugin implements IPhysicsEnginePlugin {
+        private _world;
+        private _registeredMeshes;
+        private _physicsMaterials;
+        initialize(iterations?: number): void;
+        private _checkWithEpsilon(value);
+        runOneStep(delta: number): void;
+        setGravity(gravity: Vector3): void;
+        registerMesh(mesh: AbstractMesh, impostor: number, options?: PhysicsBodyCreationOptions): any;
+        private _createShape(mesh, impostor, options?);
+        private _createConvexPolyhedron(rawVerts, rawFaces, mesh, options?);
+        private _addMaterial(friction, restitution);
+        private _createRigidBodyFromShape(shape, mesh, mass, friction, restitution);
+        registerMeshesAsCompound(parts: PhysicsCompoundBodyPart[], options: PhysicsBodyCreationOptions): any;
+        private _unbindBody(body);
+        unregisterMesh(mesh: AbstractMesh): void;
+        applyImpulse(mesh: AbstractMesh, force: Vector3, contactPoint: Vector3): void;
+        updateBodyPosition: (mesh: AbstractMesh) => void;
+        createLink(mesh1: AbstractMesh, mesh2: AbstractMesh, pivot1: Vector3, pivot2: Vector3): boolean;
+        dispose(): void;
+        isSupported(): boolean;
+        getWorldObject(): any;
+        getPhysicsBodyOfMesh(mesh: AbstractMesh): any;
+    }
+}
+
+declare module BABYLON {
+    class OimoJSPlugin implements IPhysicsEnginePlugin {
+        private _world;
+        private _registeredMeshes;
+        private _checkWithEpsilon(value);
+        initialize(iterations?: number): void;
+        setGravity(gravity: Vector3): void;
+        registerMesh(mesh: AbstractMesh, impostor: number, options: PhysicsBodyCreationOptions): any;
+        registerMeshesAsCompound(parts: PhysicsCompoundBodyPart[], options: PhysicsBodyCreationOptions): any;
+        private _createBodyAsCompound(part, options, initialMesh);
+        unregisterMesh(mesh: AbstractMesh): void;
+        private _unbindBody(body);
+        /**
+         * Update the body position according to the mesh position
+         * @param mesh
+         */
+        updateBodyPosition: (mesh: AbstractMesh) => void;
+        applyImpulse(mesh: AbstractMesh, force: Vector3, contactPoint: Vector3): void;
+        createLink(mesh1: AbstractMesh, mesh2: AbstractMesh, pivot1: Vector3, pivot2: Vector3, options?: any): boolean;
+        dispose(): void;
+        isSupported(): boolean;
+        getWorldObject(): any;
+        getPhysicsBodyOfMesh(mesh: AbstractMesh): any;
+        private _getLastShape(body);
+        runOneStep(time: number): void;
+    }
+}
+
+declare module BABYLON {
     class CustomProceduralTexture extends ProceduralTexture {
         private _animate;
         private _time;

文件差异内容过多而无法显示
+ 32 - 24
dist/preview release/babylon.js


文件差异内容过多而无法显示
+ 105 - 41
dist/preview release/babylon.max.js


文件差异内容过多而无法显示
+ 31 - 23
dist/preview release/babylon.noworker.js


+ 0 - 1
src/Materials/babylon.effect.js

@@ -233,7 +233,6 @@ var BABYLON;
                 this._valueCache[uniformName].m[index] = matrix.m[index];
             }
         };
-        ;
         Effect.prototype._cacheFloat2 = function (uniformName, x, y) {
             if (!this._valueCache[uniformName]) {
                 this._valueCache[uniformName] = [x, y];

+ 1 - 1
src/Materials/babylon.effect.ts

@@ -480,4 +480,4 @@
         // Statics
         public static ShadersStore = {};
     }
-} 
+} 

+ 5 - 2
src/Materials/babylon.standardMaterial.js

@@ -148,10 +148,13 @@ var BABYLON;
             return this.diffuseTexture;
         };
         // Methods   
-        StandardMaterial.prototype._checkCache = function (scene, mesh) {
+        StandardMaterial.prototype._checkCache = function (scene, mesh, useInstances) {
             if (!mesh) {
                 return true;
             }
+            if (this._defines.INSTANCES !== useInstances) {
+                return false;
+            }
             if (mesh._materialDefines && mesh._materialDefines.isEqual(this._defines)) {
                 return true;
             }
@@ -166,7 +169,7 @@ var BABYLON;
             var scene = this.getScene();
             if (!this.checkReadyOnEveryCall) {
                 if (this._renderId === scene.getRenderId()) {
-                    if (this._checkCache(scene, mesh)) {
+                    if (this._checkCache(scene, mesh, useInstances)) {
                         return true;
                     }
                 }

+ 6 - 2
src/Materials/babylon.standardMaterial.ts

@@ -171,11 +171,15 @@
         }
 
         // Methods   
-        private _checkCache(scene: Scene, mesh?: AbstractMesh): boolean {
+        private _checkCache(scene: Scene, mesh?: AbstractMesh, useInstances?: boolean): boolean {
             if (!mesh) {
                 return true;
             }
 
+            if (this._defines.INSTANCES !== useInstances) {
+                return false;
+            }
+
             if (mesh._materialDefines && mesh._materialDefines.isEqual(this._defines)) {
                 return true;
             }
@@ -194,7 +198,7 @@
 
             if (!this.checkReadyOnEveryCall) {
                 if (this._renderId === scene.getRenderId()) {
-                    if (this._checkCache(scene, mesh)) {
+                    if (this._checkCache(scene, mesh, useInstances)) {
                         return true;
                     }
                 }

+ 1 - 1
src/Mesh/babylon.instancedMesh.js

@@ -82,7 +82,7 @@ var BABYLON;
         });
         InstancedMesh.prototype.refreshBoundingInfo = function () {
             var meshBB = this._sourceMesh.getBoundingInfo();
-            this._boundingInfo = new BABYLON.BoundingInfo(meshBB.minimum, meshBB.maximum);
+            this._boundingInfo = new BABYLON.BoundingInfo(meshBB.minimum.clone(), meshBB.maximum.clone());
             this._updateBoundingInfo();
         };
         InstancedMesh.prototype._preActivate = function () {

+ 1 - 1
src/Mesh/babylon.instancedMesh.ts

@@ -74,7 +74,7 @@
         public refreshBoundingInfo(): void {
             var meshBB = this._sourceMesh.getBoundingInfo();
 
-            this._boundingInfo = new BoundingInfo(meshBB.minimum, meshBB.maximum);
+            this._boundingInfo = new BoundingInfo(meshBB.minimum.clone(), meshBB.maximum.clone());
 
             this._updateBoundingInfo();
         }

+ 1 - 0
src/Mesh/babylon.meshBuilder.js

@@ -330,6 +330,7 @@ var BABYLON;
             var updatable = options.updatable;
             var sideOrientation = options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
             var instance = options.instance;
+            options.arc = (options.arc < 0) ? 1 : options.arc || 1;
             // tube geometry
             var tubePathArray = function (path, path3D, circlePaths, radius, tessellation, radiusFunction, cap, arc) {
                 var tangents = path3D.getTangents();

+ 1 - 0
src/Mesh/babylon.meshBuilder.ts

@@ -783,3 +783,4 @@
         }
     }
 }
+

+ 13 - 3
src/Particles/babylon.solidParticle.js

@@ -1,7 +1,7 @@
 var BABYLON;
 (function (BABYLON) {
     var SolidParticle = (function () {
-        function SolidParticle(particleIndex, positionIndex, shape, shapeUV, shapeId, idxInShape) {
+        function SolidParticle(particleIndex, positionIndex, model, shapeId, idxInShape) {
             this.color = new BABYLON.Color4(1, 1, 1, 1); // color
             this.position = BABYLON.Vector3.Zero(); // position
             this.rotation = BABYLON.Vector3.Zero(); // rotation
@@ -11,12 +11,22 @@ var BABYLON;
             this.alive = true; // alive
             this.idx = particleIndex;
             this._pos = positionIndex;
-            this._shape = shape;
-            this._shapeUV = shapeUV;
+            this._model = model;
             this.shapeId = shapeId;
             this.idxInShape = idxInShape;
         }
         return SolidParticle;
     })();
     BABYLON.SolidParticle = SolidParticle;
+    var ModelShape = (function () {
+        function ModelShape(id, shape, shapeUV, posFunction, vtxFunction) {
+            this.shapeID = id;
+            this._shape = shape;
+            this._shapeUV = shapeUV;
+            this._positionFunction = posFunction;
+            this._vertexFunction = vtxFunction;
+        }
+        return ModelShape;
+    })();
+    BABYLON.ModelShape = ModelShape;
 })(BABYLON || (BABYLON = {}));

+ 1 - 0
src/Particles/babylon.solidParticle.ts

@@ -43,3 +43,4 @@ module BABYLON {
     }
 }
 
+

+ 70 - 20
src/Particles/babylon.solidParticleSystem.js

@@ -14,7 +14,7 @@ var BABYLON;
             this._uvs = new Array();
             this._index = 0; // indices index
             this._shapeCounter = 0;
-            this._copy = new BABYLON.SolidParticle(null, null, null, null, null, null);
+            this._copy = new BABYLON.SolidParticle(null, null, null, null, null);
             this._color = new BABYLON.Color4(0, 0, 0, 0);
             this._computeParticleColor = true;
             this._computeParticleTexture = true;
@@ -101,13 +101,13 @@ var BABYLON;
             this._copy.color = null;
         };
         // _meshBuilder : inserts the shape model in the global SPS mesh
-        SolidParticleSystem.prototype._meshBuilder = function (p, shape, positions, meshInd, indices, meshUV, uvs, meshCol, colors, idxInShape, options) {
+        SolidParticleSystem.prototype._meshBuilder = function (p, shape, positions, meshInd, indices, meshUV, uvs, meshCol, colors, idx, idxInShape, options) {
             var i;
             var u = 0;
             var c = 0;
             this._resetCopy();
             if (options && options.positionFunction) {
-                options.positionFunction(this._copy, p, idxInShape);
+                options.positionFunction(this._copy, idx, idxInShape);
             }
             if (this._copy.quaternion) {
                 this._quaternion.x = this._copy.quaternion.x;
@@ -178,8 +178,8 @@ var BABYLON;
             return shapeUV;
         };
         // adds a new particle object in the particles array and double links the particle (next/previous)
-        SolidParticleSystem.prototype._addParticle = function (p, idxpos, shape, shapeUV, shapeId, idxInShape) {
-            this._particle = new BABYLON.SolidParticle(p, idxpos, shape, shapeUV, shapeId, idxInShape);
+        SolidParticleSystem.prototype._addParticle = function (p, idxpos, model, shapeId, idxInShape) {
+            this._particle = new BABYLON.SolidParticle(p, idxpos, model, shapeId, idxInShape);
             this.particles.push(this._particle);
             this._particle.previous = this._previousParticle;
             if (this._previousParticle) {
@@ -195,25 +195,73 @@ var BABYLON;
             var meshCol = mesh.getVerticesData(BABYLON.VertexBuffer.ColorKind);
             var shape = this._posToShape(meshPos);
             var shapeUV = this._uvsToShapeUV(meshUV);
+            var posfunc = options ? options.positionFunction : null;
+            var vtxfunc = options ? options.vertexFunction : null;
+            var modelShape = new BABYLON.ModelShape(this._shapeCounter, shape, shapeUV, posfunc, vtxfunc);
             // particles
             for (var i = 0; i < nb; i++) {
-                this._meshBuilder(this._index, shape, this._positions, meshInd, this._indices, meshUV, this._uvs, meshCol, this._colors, i, options);
-                this._addParticle(this.nbParticles + i, this._positions.length, shape, shapeUV, this._shapeCounter, i);
+                this._meshBuilder(this._index, shape, this._positions, meshInd, this._indices, meshUV, this._uvs, meshCol, this._colors, this.nbParticles + i, i, options);
+                this._addParticle(this.nbParticles + i, this._positions.length, modelShape, this._shapeCounter, i);
                 this._index += shape.length;
             }
             this.nbParticles += nb;
             this._shapeCounter++;
             return this._shapeCounter;
         };
-        // resets a particle back to its just built status
-        SolidParticleSystem.prototype.resetParticle = function (particle) {
-            for (var pt = 0; pt < particle._shape.length; pt++) {
-                this._positions[particle._pos + pt * 3] = particle._shape[pt].x;
-                this._positions[particle._pos + pt * 3 + 1] = particle._shape[pt].y;
-                this._positions[particle._pos + pt * 3 + 2] = particle._shape[pt].z;
+        // rebuilds a particle back to its just built status : if needed, recomputes the custom positions and vertices
+        SolidParticleSystem.prototype._rebuildParticle = function (particle) {
+            this._resetCopy();
+            if (particle._model._positionFunction) {
+                particle._model._positionFunction(this._copy, particle.idx, particle.idxInShape);
+            }
+            if (this._copy.quaternion) {
+                this._quaternion.x = this._copy.quaternion.x;
+                this._quaternion.y = this._copy.quaternion.y;
+                this._quaternion.z = this._copy.quaternion.z;
+                this._quaternion.w = this._copy.quaternion.w;
+            }
+            else {
+                this._yaw = this._copy.rotation.y;
+                this._pitch = this._copy.rotation.x;
+                this._roll = this._copy.rotation.z;
+                this._quaternionRotationYPR();
+            }
+            this._quaternionToRotationMatrix();
+            this._shape = particle._model._shape;
+            for (var pt = 0; pt < this._shape.length; pt++) {
+                this._vertex.x = this._shape[pt].x;
+                this._vertex.y = this._shape[pt].y;
+                this._vertex.z = this._shape[pt].z;
+                if (particle._model._vertexFunction) {
+                    particle._model._vertexFunction(this._copy, this._vertex, pt); // recall to stored vertexFunction
+                }
+                this._vertex.x *= this._copy.scale.x;
+                this._vertex.y *= this._copy.scale.y;
+                this._vertex.z *= this._copy.scale.z;
+                BABYLON.Vector3.TransformCoordinatesToRef(this._vertex, this._rotMatrix, this._rotated);
+                this._positions32[particle._pos + pt * 3] = this._copy.position.x + this._rotated.x;
+                this._positions32[particle._pos + pt * 3 + 1] = this._copy.position.y + this._rotated.y;
+                this._positions32[particle._pos + pt * 3 + 2] = this._copy.position.z + this._rotated.z;
+            }
+            particle.position.x = 0;
+            particle.position.y = 0;
+            particle.position.z = 0;
+            particle.rotation.x = 0;
+            particle.rotation.y = 0;
+            particle.rotation.z = 0;
+            particle.quaternion = null;
+            particle.scale.x = 1;
+            particle.scale.y = 1;
+            particle.scale.z = 1;
+        };
+        // rebuilds the whole mesh and updates the VBO : custom positions and vertices are recomputed if needed
+        SolidParticleSystem.prototype.rebuildMesh = function () {
+            for (var p = 0; p < this.particles.length; p++) {
+                this._rebuildParticle(this.particles[p]);
             }
+            this.mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, this._positions32, false, false);
         };
-        // sets all the particles
+        // sets all the particles : updates the VBO
         SolidParticleSystem.prototype.setParticles = function (start, end, update) {
             if (start === void 0) { start = 0; }
             if (end === void 0) { end = this.nbParticles - 1; }
@@ -257,6 +305,8 @@ var BABYLON;
             // particle loop
             for (var p = start; p <= end; p++) {
                 this._particle = this.particles[p];
+                this._shape = this._particle._model._shape;
+                this._shapeUV = this._particle._model._shapeUV;
                 // call to custom user function to update the particle properties
                 this.updateParticle(this._particle);
                 // particle rotation matrix
@@ -279,13 +329,13 @@ var BABYLON;
                     }
                     this._quaternionToRotationMatrix();
                 }
-                for (var pt = 0; pt < this._particle._shape.length; pt++) {
+                for (var pt = 0; pt < this._shape.length; pt++) {
                     idx = index + pt * 3;
                     colidx = colorIndex + pt * 4;
                     uvidx = uvIndex + pt * 2;
-                    this._vertex.x = this._particle._shape[pt].x;
-                    this._vertex.y = this._particle._shape[pt].y;
-                    this._vertex.z = this._particle._shape[pt].z;
+                    this._vertex.x = this._shape[pt].x;
+                    this._vertex.y = this._shape[pt].y;
+                    this._vertex.z = this._shape[pt].z;
                     if (this._computeParticleVertex) {
                         this.updateParticleVertex(this._particle, this._vertex, pt);
                     }
@@ -303,8 +353,8 @@ var BABYLON;
                         this._colors32[colidx + 3] = this._particle.color.a;
                     }
                     if (this._computeParticleTexture) {
-                        this._uvs32[uvidx] = this._particle._shapeUV[pt * 2] * (this._particle.uvs.z - this._particle.uvs.x) + this._particle.uvs.x;
-                        this._uvs32[uvidx + 1] = this._particle._shapeUV[pt * 2 + 1] * (this._particle.uvs.w - this._particle.uvs.y) + this._particle.uvs.y;
+                        this._uvs32[uvidx] = this._shapeUV[pt * 2] * (this._particle.uvs.z - this._particle.uvs.x) + this._particle.uvs.x;
+                        this._uvs32[uvidx + 1] = this._shapeUV[pt * 2 + 1] * (this._particle.uvs.w - this._particle.uvs.y) + this._particle.uvs.y;
                     }
                 }
                 index = idx + 3;

+ 3 - 2
src/Particles/babylon.solidParticleSystem.ts

@@ -227,7 +227,7 @@ module BABYLON {
 
             var posfunc = options ? options.positionFunction : null;
             var vtxfunc = options ? options.vertexFunction : null;
- 
+
             var modelShape = new ModelShape(this._shapeCounter, shape, shapeUV, posfunc, vtxfunc);
 
             // particles
@@ -259,7 +259,7 @@ module BABYLON {
                 this._roll = this._copy.rotation.z;
                 this._quaternionRotationYPR();
             }
-            this._quaternionToRotationMatrix(); 
+            this._quaternionToRotationMatrix();
 
             this._shape = particle._model._shape;
             for (var pt = 0; pt < this._shape.length; pt++) {
@@ -548,3 +548,4 @@ module BABYLON {
 }
 
 
+

+ 13 - 12
src/Physics/Plugins/babylon.oimoJSPlugin.js

@@ -10,25 +10,26 @@ var BABYLON;
             this.updateBodyPosition = function (mesh) {
                 for (var index = 0; index < this._registeredMeshes.length; index++) {
                     var registeredMesh = this._registeredMeshes[index];
+                    var body = registeredMesh.body.body;
+                    var updated = false;
+                    var newPosition;
                     if (registeredMesh.mesh === mesh || registeredMesh.mesh === mesh.parent) {
-                        var body = registeredMesh.body.body;
                         mesh.computeWorldMatrix(true);
-                        var center = mesh.getBoundingInfo().boundingBox.center;
-                        body.setPosition(new OIMO.Vec3(center.x, center.y, center.z));
-                        body.setQuaternion(mesh.rotationQuaternion);
-                        body.sleeping = false;
-                        return;
+                        newPosition = mesh.getBoundingInfo().boundingBox.center;
+                        updated = true;
                     }
-                    // Case where the parent has been updated
-                    if (registeredMesh.mesh.parent === mesh) {
+                    else if (registeredMesh.mesh.parent === mesh) {
                         mesh.computeWorldMatrix(true);
                         registeredMesh.mesh.computeWorldMatrix(true);
-                        var absolutePosition = registeredMesh.mesh.getAbsolutePosition();
-                        body = registeredMesh.body.body;
-                        body.setPosition(new OIMO.Vec3(absolutePosition.x, absolutePosition.y, absolutePosition.z));
+                        newPosition = registeredMesh.mesh.getAbsolutePosition();
+                        updated = true;
+                    }
+                    if (updated) {
+                        body.setPosition(new OIMO.Vec3(newPosition.x, newPosition.y, newPosition.z));
                         body.setQuaternion(mesh.rotationQuaternion);
                         body.sleeping = false;
-                        return;
+                        //force Oimo to update the body's position
+                        body.updatePosition(1);
                     }
                 }
             };

+ 16 - 15
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -33,7 +33,7 @@ module BABYLON {
             var deltaPosition = mesh.position.subtract(bbox.center);
             
             //calculate rotation to fit Oimo's needs (Euler...)
-            var rot = new OIMO.Euler().setFromQuaternion({ x: mesh.rotationQuaternion.x, y: mesh.rotationQuaternion.y, z: mesh.rotationQuaternion.z, s: mesh.rotationQuaternion.w }, "YZX");
+            var rot = new OIMO.Euler().setFromQuaternion({ x: mesh.rotationQuaternion.x, y: mesh.rotationQuaternion.y, z: mesh.rotationQuaternion.z, s: mesh.rotationQuaternion.w });
 
             //get the correct bounding box
             var oldQuaternion = mesh.rotationQuaternion;
@@ -131,7 +131,7 @@ module BABYLON {
             });
             
             //Reset the body's rotation to be of the initial mesh's.
-            var rot = new OIMO.Euler().setFromQuaternion({ x: initialMesh.rotationQuaternion.x, y: initialMesh.rotationQuaternion.y, z: initialMesh.rotationQuaternion.z, s: initialMesh.rotationQuaternion.w }, "YZX");
+            var rot = new OIMO.Euler().setFromQuaternion({ x: initialMesh.rotationQuaternion.x, y: initialMesh.rotationQuaternion.y, z: initialMesh.rotationQuaternion.z, s: initialMesh.rotationQuaternion.w });
 
             body.resetRotation(rot.x / OIMO.TO_RAD, rot.y / OIMO.TO_RAD, rot.z / OIMO.TO_RAD);
 
@@ -153,7 +153,7 @@ module BABYLON {
             // We need the bounding box/sphere info to compute the physics body
             mesh.computeWorldMatrix(true);
 
-            var rot = new OIMO.Euler().setFromQuaternion({ x: mesh.rotationQuaternion.x, y: mesh.rotationQuaternion.y, z: mesh.rotationQuaternion.z, s: mesh.rotationQuaternion.w }, "YZX");
+            var rot = new OIMO.Euler().setFromQuaternion({ x: mesh.rotationQuaternion.x, y: mesh.rotationQuaternion.y, z: mesh.rotationQuaternion.z, s: mesh.rotationQuaternion.w });
 
             var bodyParameters: any = {
                 pos: [mesh.position.x, mesh.position.y, mesh.position.z],
@@ -238,13 +238,13 @@ module BABYLON {
             for (var index = 0; index < this._registeredMeshes.length; index++) {
                 var registeredMesh = this._registeredMeshes[index];
                 var body = registeredMesh.body.body;
-                var updated : boolean = false;
-                var newPosition : Vector3;
+                var updated: boolean = false;
+                var newPosition: Vector3;
                 if (registeredMesh.mesh === mesh || registeredMesh.mesh === mesh.parent) {
                     mesh.computeWorldMatrix(true);
-                    
+
                     newPosition = mesh.getBoundingInfo().boundingBox.center;
-                    
+
                     updated = true;
                 }
                 // Case where the parent has been updated
@@ -253,16 +253,16 @@ module BABYLON {
                     registeredMesh.mesh.computeWorldMatrix(true);
 
                     newPosition = registeredMesh.mesh.getAbsolutePosition();
-                    
+
                     updated = true;
                 }
-                
-                if(updated) {
-                	body.setPosition(new OIMO.Vec3(newPosition.x, newPosition.y, newPosition.z));
-                    	body.setQuaternion(mesh.rotationQuaternion);
-                    	body.sleeping = false;
-                    	//force Oimo to update the body's position
-                    	body.updatePosition(1);
+
+                if (updated) {
+                    body.setPosition(new OIMO.Vec3(newPosition.x, newPosition.y, newPosition.z));
+                    body.setQuaternion(mesh.rotationQuaternion);
+                    body.sleeping = false;
+                    //force Oimo to update the body's position
+                    body.updatePosition(1);
                 }
             }
         }
@@ -384,3 +384,4 @@ module BABYLON {
     }
 }
 
+

+ 0 - 4
src/Physics/babylon.physicsEngine.ts

@@ -90,10 +90,6 @@
         public getPhysicsBodyOfMesh(mesh: AbstractMesh) {
             return this._currentPlugin.getPhysicsBodyOfMesh(mesh);
         }
-        
-        public getWorldObject() {
-            return this._currentPlugin.getWorldObject();
-        }
 
         // Statics
         public static NoImpostor = 0;