Browse Source

More depedencies

sebastien 6 years ago
parent
commit
b67fcfda7e
56 changed files with 1329 additions and 1164 deletions
  1. 1 1
      src/Collisions/collisionCoordinator.ts
  2. 1 1
      src/Collisions/pickingInfo.ts
  3. 7 2
      src/Engine/engine.ts
  4. 4 5
      src/Engine/nullEngine.ts
  5. 1 1
      src/Layer/effectLayer.ts
  6. 1 1
      src/Layer/glowLayer.ts
  7. 1 1
      src/Layer/highlightLayer.ts
  8. 1 1
      src/Layer/layer.ts
  9. 1 1
      src/LensFlare/lensFlareSystem.ts
  10. 3 2
      src/Lights/Shadows/shadowGenerator.ts
  11. 3 2
      src/Loading/Plugins/babylonFileLoader.ts
  12. 2 2
      src/Materials/Background/backgroundMaterial.ts
  13. 3 2
      src/Materials/PBR/pbrBaseMaterial.ts
  14. 1 1
      src/Materials/Textures/Procedurals/proceduralTexture.ts
  15. 85 77
      src/Materials/Textures/texture.ts
  16. 5 0
      src/Materials/colorCurves.ts
  17. 6 0
      src/Materials/fresnelParameters.ts
  18. 6 1
      src/Materials/imageProcessingConfiguration.ts
  19. 7 263
      src/Materials/material.ts
  20. 225 0
      src/Materials/materialDefines.ts
  21. 1 1
      src/Materials/materialHelper.ts
  22. 28 0
      src/Materials/multiMaterial.ts
  23. 1 1
      src/Materials/shaderMaterial.ts
  24. 3 2
      src/Materials/standardMaterial.ts
  25. 3 2
      src/Mesh/abstractMesh.ts
  26. 463 3
      src/Mesh/buffer.ts
  27. 1 1
      src/Mesh/csg.ts
  28. 1 1
      src/Mesh/geometry.ts
  29. 6 1
      src/Mesh/groundMesh.ts
  30. 1 3
      src/Mesh/index.ts
  31. 4 0
      src/Mesh/instancedMesh.ts
  32. 1 1
      src/Mesh/linesMesh.ts
  33. 82 241
      src/Mesh/mesh.ts
  34. 37 19
      src/Mesh/mesh.vertexData.ts
  35. 269 1
      src/Mesh/meshBuilder.ts
  36. 0 19
      src/Mesh/meshLODLevel.ts
  37. 1 1
      src/Mesh/meshSimplification.ts
  38. 1 1
      src/Mesh/polygonMesh.ts
  39. 12 12
      src/Mesh/subMesh.ts
  40. 0 462
      src/Mesh/vertexBuffer.ts
  41. 1 1
      src/Morph/morphTarget.ts
  42. 1 1
      src/Particles/gpuParticleSystem.ts
  43. 1 1
      src/Particles/particleSystem.ts
  44. 1 1
      src/Particles/solidParticleSystem.ts
  45. 1 1
      src/Physics/Plugins/cannonJSPlugin.ts
  46. 1 1
      src/PostProcess/postProcessManager.ts
  47. 1 1
      src/PostProcess/volumetricLightScatteringPostProcess.ts
  48. 1 1
      src/Rendering/boundingBoxRenderer.ts
  49. 1 1
      src/Rendering/depthRenderer.ts
  50. 1 1
      src/Rendering/edgesRenderer.ts
  51. 1 1
      src/Rendering/geometryBufferRenderer.ts
  52. 1 1
      src/Rendering/lineEdgesRenderer.ts
  53. 1 1
      src/Rendering/outlineRenderer.ts
  54. 1 1
      src/Sprites/spriteManager.ts
  55. 32 11
      src/Tools/decorators.ts
  56. 4 3
      src/node.ts

+ 1 - 1
src/Collisions/collisionCoordinator.ts

@@ -7,7 +7,7 @@ import { Collider } from "./collider";
 import { WorkerIncluded } from "./collisionWorker";
 import { WorkerIncluded } from "./collisionWorker";
 import { TransformNode } from "Mesh/transformNode";
 import { TransformNode } from "Mesh/transformNode";
 import { Geometry } from "Mesh/geometry";
 import { Geometry } from "Mesh/geometry";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { InstancedMesh } from "Mesh/instancedMesh";
 import { InstancedMesh } from "Mesh/instancedMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";

+ 1 - 1
src/Collisions/pickingInfo.ts

@@ -1,7 +1,7 @@
 import { Nullable, FloatArray } from "types";
 import { Nullable, FloatArray } from "types";
 import { Vector3, Vector2, Tmp } from "Math/math";
 import { Vector3, Vector2, Tmp } from "Math/math";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { Ray } from "Culling/ray";
 import { Ray } from "Culling/ray";
 import { Sprite } from "Sprites/sprite";
 import { Sprite } from "Sprites/sprite";
     /**
     /**

+ 7 - 2
src/Engine/engine.ts

@@ -1,4 +1,9 @@
-import { Observer, Observable, Tools, ICustomAnimationFrameRequester, PerfCounter, PerformanceMonitor, StringDictionary, IFileRequest, PromisePolyfill, DDSTools, DDSInfo } from "Tools";
+import { Observer, Observable } from "Tools/observable";
+import { PerformanceMonitor } from "Tools/performanceMonitor";
+import { StringDictionary } from "Tools/stringDictionary";
+import { PromisePolyfill } from "Tools/promise";
+import { DDSTools, DDSInfo } from "Tools/dds";
+import { Tools, ICustomAnimationFrameRequester, PerfCounter, IFileRequest } from "Tools/tools";
 import { Nullable, FloatArray, DataArray, IndicesArray } from "types";
 import { Nullable, FloatArray, DataArray, IndicesArray } from "types";
 import { Camera } from "Cameras/camera";
 import { Camera } from "Cameras/camera";
 import { Scene } from "scene";
 import { Scene } from "scene";
@@ -6,7 +11,7 @@ import { Matrix, Color3, Color4, Viewport, Size, Vector4 } from "Math/math";
 import { Scalar } from "Math/math.scalar";
 import { Scalar } from "Math/math.scalar";
 import { SphericalPolynomial } from "Math/sphericalPolynomial";
 import { SphericalPolynomial } from "Math/sphericalPolynomial";
 import { IDisplayChangedEventArgs } from "Engine/engine";
 import { IDisplayChangedEventArgs } from "Engine/engine";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { UniformBuffer } from "Materials/uniformBuffer";
 import { UniformBuffer } from "Materials/uniformBuffer";
 import { Effect, EffectCreationOptions, EffectFallbacks } from "Materials/effect";
 import { Effect, EffectCreationOptions, EffectFallbacks } from "Materials/effect";
 import { Material } from "Materials/material";
 import { Material } from "Materials/material";

+ 4 - 5
src/Engine/nullEngine.ts

@@ -3,9 +3,8 @@ import { Nullable, FloatArray, IndicesArray } from "types";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Matrix, Color3, Color4, Viewport } from "Math/math";
 import { Matrix, Color3, Color4, Viewport } from "Math/math";
 import { Engine, EngineCapabilities, RenderTargetCreationOptions } from "Engine/engine";
 import { Engine, EngineCapabilities, RenderTargetCreationOptions } from "Engine/engine";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { InternalTexture } from "Materials/Textures/internalTexture";
 import { InternalTexture } from "Materials/Textures/internalTexture";
-import { Texture } from "Materials/Textures/texture";
 import { Effect } from "Materials/effect";
 import { Effect } from "Materials/effect";
 import { _TimeToken } from "Instrumentation/timeToken";
 import { _TimeToken } from "Instrumentation/timeToken";
 import { _DepthCullingState, _StencilState, _AlphaState } from "States";
 import { _DepthCullingState, _StencilState, _AlphaState } from "States";
@@ -336,7 +335,7 @@ import { _DepthCullingState, _StencilState, _AlphaState } from "States";
         public _releaseTexture(texture: InternalTexture): void {
         public _releaseTexture(texture: InternalTexture): void {
         }
         }
 
 
-        public createTexture(urlArg: string, noMipmap: boolean, invertY: boolean, scene: Scene, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE, onLoad: Nullable<() => void> = null, onError: Nullable<(message: string, exception: any) => void> = null, buffer: Nullable<ArrayBuffer | HTMLImageElement> = null, fallBack?: InternalTexture, format?: number): InternalTexture {
+        public createTexture(urlArg: string, noMipmap: boolean, invertY: boolean, scene: Scene, samplingMode: number = Engine.TEXTURE_TRILINEAR_SAMPLINGMODE, onLoad: Nullable<() => void> = null, onError: Nullable<(message: string, exception: any) => void> = null, buffer: Nullable<ArrayBuffer | HTMLImageElement> = null, fallBack?: InternalTexture, format?: number): InternalTexture {
             var texture = new InternalTexture(this, InternalTexture.DATASOURCE_URL);
             var texture = new InternalTexture(this, InternalTexture.DATASOURCE_URL);
             var url = String(urlArg);
             var url = String(urlArg);
 
 
@@ -371,13 +370,13 @@ import { _DepthCullingState, _StencilState, _AlphaState } from "States";
                 fullOptions.generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;
                 fullOptions.generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;
                 fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && options.generateStencilBuffer;
                 fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && options.generateStencilBuffer;
                 fullOptions.type = options.type === undefined ? Engine.TEXTURETYPE_UNSIGNED_INT : options.type;
                 fullOptions.type = options.type === undefined ? Engine.TEXTURETYPE_UNSIGNED_INT : options.type;
-                fullOptions.samplingMode = options.samplingMode === undefined ? Texture.TRILINEAR_SAMPLINGMODE : options.samplingMode;
+                fullOptions.samplingMode = options.samplingMode === undefined ? Engine.TEXTURE_TRILINEAR_SAMPLINGMODE : options.samplingMode;
             } else {
             } else {
                 fullOptions.generateMipMaps = <boolean>options;
                 fullOptions.generateMipMaps = <boolean>options;
                 fullOptions.generateDepthBuffer = true;
                 fullOptions.generateDepthBuffer = true;
                 fullOptions.generateStencilBuffer = false;
                 fullOptions.generateStencilBuffer = false;
                 fullOptions.type = Engine.TEXTURETYPE_UNSIGNED_INT;
                 fullOptions.type = Engine.TEXTURETYPE_UNSIGNED_INT;
-                fullOptions.samplingMode = Texture.TRILINEAR_SAMPLINGMODE;
+                fullOptions.samplingMode = Engine.TEXTURE_TRILINEAR_SAMPLINGMODE;
             }
             }
             var texture = new InternalTexture(this, InternalTexture.DATASOURCE_RENDERTARGET);
             var texture = new InternalTexture(this, InternalTexture.DATASOURCE_RENDERTARGET);
 
 

+ 1 - 1
src/Layer/effectLayer.ts

@@ -7,7 +7,7 @@ import { Camera } from "Cameras/camera";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Color4, ISize } from "Math/math";
 import { Color4, ISize } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";

+ 1 - 1
src/Layer/glowLayer.ts

@@ -5,7 +5,7 @@ import { Camera } from "Cameras/camera";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Vector2, Color4 } from "Math/math";
 import { Vector2, Color4 } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";

+ 1 - 1
src/Layer/highlightLayer.ts

@@ -6,7 +6,7 @@ import { Camera } from "Cameras/camera";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Vector2, Color3, Color4 } from "Math/math";
 import { Vector2, Color3, Color4 } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";

+ 1 - 1
src/Layer/layer.ts

@@ -3,7 +3,7 @@ import { Nullable } from "types";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Vector2, Color4 } from "Math/math";
 import { Vector2, Color4 } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { Effect } from "Materials/effect";
 import { Effect } from "Materials/effect";
 import { Material } from "Materials/material";
 import { Material } from "Materials/material";
 import { Texture } from "Materials/Textures/texture";
 import { Texture } from "Materials/Textures/texture";

+ 1 - 1
src/LensFlare/lensFlareSystem.ts

@@ -5,7 +5,7 @@ import { Matrix, Vector3, Color3, Viewport } from "Math/math";
 import { Scalar } from "Math/math.scalar";
 import { Scalar } from "Math/math.scalar";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { Ray } from "Culling/ray";
 import { Ray } from "Culling/ray";
 import { Effect } from "Materials/effect";
 import { Effect } from "Materials/effect";
 import { Material } from "Materials/material";
 import { Material } from "Materials/material";

+ 3 - 2
src/Lights/Shadows/shadowGenerator.ts

@@ -3,7 +3,7 @@ import { Nullable } from "types";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Matrix, Vector3, Vector2, Color4 } from "Math/math";
 import { Matrix, Vector3, Vector2, Color4 } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";
@@ -12,7 +12,8 @@ import { IShadowLight } from "Lights/shadowLight";
 import { Light } from "Lights/light";
 import { Light } from "Lights/light";
 import { ShadowGeneratorSceneComponent } from "./shadowGeneratorSceneComponent";
 import { ShadowGeneratorSceneComponent } from "./shadowGeneratorSceneComponent";
 
 
-import { Material, MaterialDefines } from "Materials/material";
+import { Material } from "Materials/material";
+import { MaterialDefines } from "Materials/materialDefines";
 import { MaterialHelper } from "Materials/materialHelper";
 import { MaterialHelper } from "Materials/materialHelper";
 import { Effect } from "Materials/effect";
 import { Effect } from "Materials/effect";
 import { Texture } from "Materials/Textures/texture";
 import { Texture } from "Materials/Textures/texture";

+ 3 - 2
src/Loading/Plugins/babylonFileLoader.ts

@@ -8,6 +8,7 @@ import { AbstractMesh } from "Mesh/abstractMesh";
 import { Geometry, BoxGeometry, SphereGeometry, CylinderGeometry, TorusGeometry, GroundGeometry, PlaneGeometry, TorusKnotGeometry } from "Mesh/geometry";
 import { Geometry, BoxGeometry, SphereGeometry, CylinderGeometry, TorusGeometry, GroundGeometry, PlaneGeometry, TorusKnotGeometry } from "Mesh/geometry";
 import { TransformNode } from "Mesh/transformNode";
 import { TransformNode } from "Mesh/transformNode";
 import { Material } from "Materials/material";
 import { Material } from "Materials/material";
+import { MultiMaterial } from "Materials/multiMaterial";
 import { CubeTexture } from "Materials/Textures/cubeTexture";
 import { CubeTexture } from "Materials/Textures/cubeTexture";
 import { HDRCubeTexture } from "Materials/Textures/hdrCubeTexture";
 import { HDRCubeTexture } from "Materials/Textures/hdrCubeTexture";
 import { Animation } from "Animations/animation";
 import { Animation } from "Animations/animation";
@@ -106,7 +107,7 @@ import { CannonJSPlugin, OimoJSPlugin } from "Physics";
             if (parsedData.multiMaterials !== undefined && parsedData.multiMaterials !== null) {
             if (parsedData.multiMaterials !== undefined && parsedData.multiMaterials !== null) {
                 for (index = 0, cache = parsedData.multiMaterials.length; index < cache; index++) {
                 for (index = 0, cache = parsedData.multiMaterials.length; index < cache; index++) {
                     var parsedMultiMaterial = parsedData.multiMaterials[index];
                     var parsedMultiMaterial = parsedData.multiMaterials[index];
-                    var mmat = Material.ParseMultiMaterial(parsedMultiMaterial, scene);
+                    var mmat = MultiMaterial.ParseMultiMaterial(parsedMultiMaterial, scene);
                     container.multiMaterials.push(mmat);
                     container.multiMaterials.push(mmat);
                     log += (index === 0 ? "\n\tMultiMaterials:" : "");
                     log += (index === 0 ? "\n\tMultiMaterials:" : "");
                     log += "\n\t\t" + mmat.toString(fullDetails);
                     log += "\n\t\t" + mmat.toString(fullDetails);
@@ -471,7 +472,7 @@ import { CannonJSPlugin, OimoJSPlugin } from "Physics";
                                                 }
                                                 }
                                             }
                                             }
                                             loadedMaterialsIds.push(parsedMultiMaterial.id);
                                             loadedMaterialsIds.push(parsedMultiMaterial.id);
-                                            var mmat = Material.ParseMultiMaterial(parsedMultiMaterial, scene);
+                                            var mmat = MultiMaterial.ParseMultiMaterial(parsedMultiMaterial, scene);
                                             if (mmat) {
                                             if (mmat) {
                                                 materialFound = true;
                                                 materialFound = true;
                                                 log += "\n\tMulti-Material " + mmat.toString(fullDetails);
                                                 log += "\n\tMulti-Material " + mmat.toString(fullDetails);

+ 2 - 2
src/Materials/Background/backgroundMaterial.ts

@@ -6,13 +6,13 @@ import { Nullable, int, float } from "types";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Matrix, Vector3, Color3, Vector4 } from "Math/math";
 import { Matrix, Vector3, Color3, Vector4 } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";
 import { Effect, EffectFallbacks, EffectCreationOptions } from "Materials/effect";
 import { Effect, EffectFallbacks, EffectCreationOptions } from "Materials/effect";
 import { MaterialHelper } from "Materials/materialHelper";
 import { MaterialHelper } from "Materials/materialHelper";
-import { MaterialDefines } from "Materials/material";
+import { MaterialDefines } from "Materials/materialDefines";
 import { PushMaterial } from "Materials/pushMaterial";
 import { PushMaterial } from "Materials/pushMaterial";
 import { StandardMaterial } from "Materials/standardMaterial";
 import { StandardMaterial } from "Materials/standardMaterial";
 import { ColorCurves } from "Materials/colorCurves";
 import { ColorCurves } from "Materials/colorCurves";

+ 3 - 2
src/Materials/PBR/pbrBaseMaterial.ts

@@ -8,7 +8,7 @@ import { Camera } from "Cameras/camera";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Matrix, Color3, Vector4, Tmp } from "Math/math";
 import { Matrix, Color3, Vector4, Tmp } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";
@@ -17,7 +17,8 @@ import { _DepthCullingState, _StencilState, _AlphaState } from "States";
 
 
 import { ImageProcessingConfiguration, IImageProcessingConfigurationDefines } from "Materials/imageProcessingConfiguration";
 import { ImageProcessingConfiguration, IImageProcessingConfigurationDefines } from "Materials/imageProcessingConfiguration";
 import { Effect, EffectFallbacks, EffectCreationOptions } from "Materials/effect";
 import { Effect, EffectFallbacks, EffectCreationOptions } from "Materials/effect";
-import { Material, MaterialDefines } from "Materials/material";
+import { Material } from "Materials/material";
+import { MaterialDefines } from "Materials/materialDefines";
 import { PushMaterial } from "Materials/pushMaterial";
 import { PushMaterial } from "Materials/pushMaterial";
 import { MaterialHelper } from "Materials/materialHelper";
 import { MaterialHelper } from "Materials/materialHelper";
 
 

+ 1 - 1
src/Materials/Textures/Procedurals/proceduralTexture.ts

@@ -4,7 +4,7 @@ import { Nullable } from "types";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Matrix, Vector3, Vector2, Color3, Color4 } from "Math/math";
 import { Matrix, Vector3, Vector2, Color3, Color4 } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SceneComponentConstants } from "sceneComponent";
 import { SceneComponentConstants } from "sceneComponent";
 import { _TimeToken } from "Instrumentation/timeToken";
 import { _TimeToken } from "Instrumentation/timeToken";
 import { _DepthCullingState, _StencilState, _AlphaState } from "States";
 import { _DepthCullingState, _StencilState, _AlphaState } from "States";

+ 85 - 77
src/Materials/Textures/texture.ts

@@ -3,15 +3,19 @@ import { Observable } from "Tools/observable";
 import { Tools } from "Tools/tools";
 import { Tools } from "Tools/tools";
 import { Nullable } from "types";
 import { Nullable } from "types";
 import { Scene } from "scene";
 import { Scene } from "scene";
-import { Matrix, Vector3, Plane } from "Math/math";
-import { Engine } from "Engine";
-import { Animation } from "Animations/animation";
+import { Matrix, Vector3 } from "Math/math";
+import { Engine } from "Engine/engine";
 import { Material } from "Materials/material";
 import { Material } from "Materials/material";
 import { BaseTexture } from "Materials/Textures/baseTexture";
 import { BaseTexture } from "Materials/Textures/baseTexture";
 
 
-import { RenderTargetTexture } from "Materials/Textures/renderTargetTexture";
-import { MirrorTexture } from "Materials/Textures/mirrorTexture";
-import { CubeTexture } from "Materials/Textures/cubeTexture";
+// import { Animation } from "Animations/animation";
+// import { RenderTargetTexture } from "Materials/Textures/renderTargetTexture";
+// import { MirrorTexture } from "Materials/Textures/mirrorTexture";
+// import { CubeTexture } from "Materials/Textures/cubeTexture";
+
+SerializationHelper._TextureParser = (sourceProperty: any, scene: Scene, rootUrl: string): Nullable<BaseTexture> => {
+    return Texture.Parse(sourceProperty, scene, rootUrl);
+};
 
 
     /**
     /**
      * This represents a texture in babylon. It can be easily loaded from a network, base64 or html input.
      * This represents a texture in babylon. It can be easily loaded from a network, base64 or html input.
@@ -594,77 +598,81 @@ import { CubeTexture } from "Materials/Textures/cubeTexture";
          * @returns The parsed texture if successful
          * @returns The parsed texture if successful
          */
          */
         public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): Nullable<BaseTexture> {
         public static Parse(parsedTexture: any, scene: Scene, rootUrl: string): Nullable<BaseTexture> {
-            if (parsedTexture.customType) {
-                var customTexture = Tools.Instantiate(parsedTexture.customType);
-                // Update Sampling Mode
-                var parsedCustomTexture: any = customTexture.Parse(parsedTexture, scene, rootUrl);
-                if (parsedTexture.samplingMode && parsedCustomTexture.updateSamplingMode && parsedCustomTexture._samplingMode) {
-                    if (parsedCustomTexture._samplingMode !== parsedTexture.samplingMode) {
-                        parsedCustomTexture.updateSamplingMode(parsedTexture.samplingMode);
-                    }
-                }
-                return parsedCustomTexture;
-            }
-
-            if (parsedTexture.isCube) {
-                return CubeTexture.Parse(parsedTexture, scene, rootUrl);
-            }
-
-            if (!parsedTexture.name && !parsedTexture.isRenderTarget) {
-                return null;
-            }
-
-            var texture = SerializationHelper.Parse(() => {
-                var generateMipMaps: boolean = true;
-                if (parsedTexture.noMipmap) {
-                    generateMipMaps = false;
-                }
-                if (parsedTexture.mirrorPlane) {
-                    var mirrorTexture = new MirrorTexture(parsedTexture.name, parsedTexture.renderTargetSize, scene, generateMipMaps);
-                    mirrorTexture._waitingRenderList = parsedTexture.renderList;
-                    mirrorTexture.mirrorPlane = Plane.FromArray(parsedTexture.mirrorPlane);
-
-                    return mirrorTexture;
-                } else if (parsedTexture.isRenderTarget) {
-                    var renderTargetTexture = new RenderTargetTexture(parsedTexture.name, parsedTexture.renderTargetSize, scene, generateMipMaps);
-                    renderTargetTexture._waitingRenderList = parsedTexture.renderList;
-
-                    return renderTargetTexture;
-                } else {
-                    var texture: Texture;
-                    if (parsedTexture.base64String) {
-                        texture = Texture.CreateFromBase64String(parsedTexture.base64String, parsedTexture.name, scene, !generateMipMaps);
-                    } else {
-                        let url = rootUrl + parsedTexture.name;
-
-                        if (Texture.UseSerializedUrlIfAny && parsedTexture.url) {
-                            url = parsedTexture.url;
-                        }
-                        texture = new Texture(url, scene, !generateMipMaps, parsedTexture.invertY);
-                    }
-
-                    return texture;
-                }
-            }, parsedTexture, scene);
-
-            // Update Sampling Mode
-            if (parsedTexture.samplingMode) {
-                var sampling: number = parsedTexture.samplingMode;
-                if (texture._samplingMode !== sampling) {
-                    texture.updateSamplingMode(sampling);
-                }
-            }
-
-            // Animations
-            if (parsedTexture.animations) {
-                for (var animationIndex = 0; animationIndex < parsedTexture.animations.length; animationIndex++) {
-                    var parsedAnimation = parsedTexture.animations[animationIndex];
-
-                    texture.animations.push(Animation.Parse(parsedAnimation));
-                }
-            }
-
-            return texture;
+            // if (parsedTexture.customType) {
+            //     var customTexture = Tools.Instantiate(parsedTexture.customType);
+            //     // Update Sampling Mode
+            //     var parsedCustomTexture: any = customTexture.Parse(parsedTexture, scene, rootUrl);
+            //     if (parsedTexture.samplingMode && parsedCustomTexture.updateSamplingMode && parsedCustomTexture._samplingMode) {
+            //         if (parsedCustomTexture._samplingMode !== parsedTexture.samplingMode) {
+            //             parsedCustomTexture.updateSamplingMode(parsedTexture.samplingMode);
+            //         }
+            //     }
+            //     return parsedCustomTexture;
+            // }
+
+            // if (parsedTexture.isCube) {
+            //     //return CubeTexture.Parse(parsedTexture, scene, rootUrl);
+            //     return <any> 0;
+            // }
+
+            // if (!parsedTexture.name && !parsedTexture.isRenderTarget) {
+            //     return null;
+            // }
+
+            // var texture = SerializationHelper.Parse(() => {
+            //     var generateMipMaps: boolean = true;
+            //     if (parsedTexture.noMipmap) {
+            //         generateMipMaps = false;
+            //     }
+            //     if (parsedTexture.mirrorPlane) {
+            //         // var mirrorTexture = new MirrorTexture(parsedTexture.name, parsedTexture.renderTargetSize, scene, generateMipMaps);
+            //         // mirrorTexture._waitingRenderList = parsedTexture.renderList;
+            //         // mirrorTexture.mirrorPlane = Plane.FromArray(parsedTexture.mirrorPlane);
+
+            //         // return mirrorTexture;
+            //         return;
+            //     } else if (parsedTexture.isRenderTarget) {
+            //         // var renderTargetTexture = new RenderTargetTexture(parsedTexture.name, parsedTexture.renderTargetSize, scene, generateMipMaps);
+            //         // renderTargetTexture._waitingRenderList = parsedTexture.renderList;
+
+            //         // return renderTargetTexture;
+            //         return;
+            //     } else {
+            //         var texture: Texture;
+            //         if (parsedTexture.base64String) {
+            //             texture = Texture.CreateFromBase64String(parsedTexture.base64String, parsedTexture.name, scene, !generateMipMaps);
+            //         } else {
+            //             let url = rootUrl + parsedTexture.name;
+
+            //             if (Texture.UseSerializedUrlIfAny && parsedTexture.url) {
+            //                 url = parsedTexture.url;
+            //             }
+            //             texture = new Texture(url, scene, !generateMipMaps, parsedTexture.invertY);
+            //         }
+
+            //         return texture;
+            //     }
+            // }, parsedTexture, scene);
+
+            // // Update Sampling Mode
+            // if (parsedTexture.samplingMode) {
+            //     var sampling: number = parsedTexture.samplingMode;
+            //     if (texture._samplingMode !== sampling) {
+            //         texture.updateSamplingMode(sampling);
+            //     }
+            // }
+
+            // // Animations
+            // if (parsedTexture.animations) {
+            //     for (var animationIndex = 0; animationIndex < parsedTexture.animations.length; animationIndex++) {
+            //         var parsedAnimation = parsedTexture.animations[animationIndex];
+
+            //         texture.animations.push(Animation.Parse(parsedAnimation));
+            //     }
+            // }
+
+            // return texture;
+            return <any>0;
         }
         }
 
 
         /**
         /**

+ 5 - 0
src/Materials/colorCurves.ts

@@ -2,6 +2,11 @@ import { serialize } from "Tools/decorators";
 import { SerializationHelper } from "Tools";
 import { SerializationHelper } from "Tools";
 import { Color4 } from "Math";
 import { Color4 } from "Math";
 import { Effect } from "Materials";
 import { Effect } from "Materials";
+
+SerializationHelper._ColorCurvesParser = (sourceProperty: any): ColorCurves => {
+    return ColorCurves.Parse(sourceProperty);
+};
+
     /**
     /**
      * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
      * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
      * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
      * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.

+ 6 - 0
src/Materials/fresnelParameters.ts

@@ -2,6 +2,12 @@ import { Tools } from "Tools/tools";
 import { Color3 } from "Math/math";
 import { Color3 } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
 import { Material } from "Materials/material";
 import { Material } from "Materials/material";
+import { SerializationHelper } from "Tools/decorators";
+
+SerializationHelper._FresnelParametersParser = (sourceProperty: any) => {
+    return FresnelParameters.Parse(sourceProperty);
+};
+
     /**
     /**
      * This represents all the required information to add a fresnel effect on a material:
      * This represents all the required information to add a fresnel effect on a material:
      * @see http://doc.babylonjs.com/how_to/how_to_use_fresnelparameters
      * @see http://doc.babylonjs.com/how_to/how_to_use_fresnelparameters

+ 6 - 1
src/Materials/imageProcessingConfiguration.ts

@@ -3,10 +3,15 @@ import { Observable } from "Tools/observable";
 import { Tools } from "Tools/tools";
 import { Tools } from "Tools/tools";
 import { Nullable } from "types";
 import { Nullable } from "types";
 import { Color4 } from "Math/math";
 import { Color4 } from "Math/math";
-import { MaterialDefines } from "Materials/material";
+import { MaterialDefines } from "Materials/materialDefines";
 import { Effect } from "Materials/effect";
 import { Effect } from "Materials/effect";
 import { BaseTexture } from "Materials/Textures/baseTexture";
 import { BaseTexture } from "Materials/Textures/baseTexture";
 import { ColorCurves } from "Materials/colorCurves";
 import { ColorCurves } from "Materials/colorCurves";
+
+SerializationHelper._ImageProcessingConfigurationParser = (sourceProperty: any) => {
+    return ImageProcessingConfiguration.Parse(sourceProperty);
+};
+
     /**
     /**
      * Interface to follow in your material defines to integrate easily the
      * Interface to follow in your material defines to integrate easily the
      * Image proccessing functions.
      * Image proccessing functions.

+ 7 - 263
src/Materials/material.ts

@@ -2,7 +2,6 @@ import { serialize, SerializationHelper } from "Tools/decorators";
 import { Tools, IAnimatable } from "Tools/tools";
 import { Tools, IAnimatable } from "Tools/tools";
 import { SmartArray } from "Tools/smartArray";
 import { SmartArray } from "Tools/smartArray";
 import { Observer, Observable } from "Tools/observable";
 import { Observer, Observable } from "Tools/observable";
-import { Tags } from "Tools/tags";
 import { Nullable } from "types";
 import { Nullable } from "types";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Plane, Matrix } from "Math/math";
 import { Plane, Matrix } from "Math/math";
@@ -11,240 +10,14 @@ import { BaseSubMesh, SubMesh } from "Mesh/subMesh";
 import { Geometry } from "Mesh/geometry";
 import { Geometry } from "Mesh/geometry";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";
-import { StandardMaterial } from "Materials/standardMaterial";
-import { MultiMaterial } from "Materials/multiMaterial";
-import { UniformBuffer } from "Materials/uniformBuffer";
-import { Effect } from "Materials/effect";
+import { UniformBuffer } from "./uniformBuffer";
+import { Effect } from "./effect";
 import { BaseTexture } from "Materials/Textures/baseTexture";
 import { BaseTexture } from "Materials/Textures/baseTexture";
 import { RenderTargetTexture } from "Materials/Textures/renderTargetTexture";
 import { RenderTargetTexture } from "Materials/Textures/renderTargetTexture";
 import { Animation } from "Animations/animation";
 import { Animation } from "Animations/animation";
+import { MaterialDefines } from "./materialDefines";
 
 
 declare var BABYLON: any;
 declare var BABYLON: any;
-    /**
-     * Manages the defines for the Material
-     */
-    export class MaterialDefines {
-        private _keys: string[];
-        private _isDirty = true;
-        /** @hidden */
-        public _renderId: number;
-
-        /** @hidden */
-        public _areLightsDirty = true;
-        /** @hidden */
-        public _areAttributesDirty = true;
-        /** @hidden */
-        public _areTexturesDirty = true;
-        /** @hidden */
-        public _areFresnelDirty = true;
-        /** @hidden */
-        public _areMiscDirty = true;
-        /** @hidden */
-        public _areImageProcessingDirty = true;
-
-        /** @hidden */
-        public _normals = false;
-        /** @hidden */
-        public _uvs = false;
-
-        /** @hidden */
-        public _needNormals = false;
-        /** @hidden */
-        public _needUVs = false;
-
-        /**
-         * Specifies if the material needs to be re-calculated
-         */
-        public get isDirty(): boolean {
-            return this._isDirty;
-        }
-
-        /**
-         * Marks the material to indicate that it has been re-calculated
-         */
-        public markAsProcessed() {
-            this._isDirty = false;
-            this._areAttributesDirty = false;
-            this._areTexturesDirty = false;
-            this._areFresnelDirty = false;
-            this._areLightsDirty = false;
-            this._areMiscDirty = false;
-            this._areImageProcessingDirty = false;
-        }
-
-        /**
-         * Marks the material to indicate that it needs to be re-calculated
-         */
-        public markAsUnprocessed() {
-            this._isDirty = true;
-        }
-
-        /**
-         * Marks the material to indicate all of its defines need to be re-calculated
-         */
-        public markAllAsDirty() {
-            this._areTexturesDirty = true;
-            this._areAttributesDirty = true;
-            this._areLightsDirty = true;
-            this._areFresnelDirty = true;
-            this._areMiscDirty = true;
-            this._areImageProcessingDirty = true;
-            this._isDirty = true;
-        }
-
-        /**
-         * Marks the material to indicate that image processing needs to be re-calculated
-         */
-        public markAsImageProcessingDirty() {
-            this._areImageProcessingDirty = true;
-            this._isDirty = true;
-        }
-
-        /**
-         * Marks the material to indicate the lights need to be re-calculated
-         */
-        public markAsLightDirty() {
-            this._areLightsDirty = true;
-            this._isDirty = true;
-        }
-
-        /**
-         * Marks the attribute state as changed
-         */
-        public markAsAttributesDirty() {
-            this._areAttributesDirty = true;
-            this._isDirty = true;
-        }
-
-        /**
-         * Marks the texture state as changed
-         */
-        public markAsTexturesDirty() {
-            this._areTexturesDirty = true;
-            this._isDirty = true;
-        }
-
-        /**
-         * Marks the fresnel state as changed
-         */
-        public markAsFresnelDirty() {
-            this._areFresnelDirty = true;
-            this._isDirty = true;
-        }
-
-        /**
-         * Marks the misc state as changed
-         */
-        public markAsMiscDirty() {
-            this._areMiscDirty = true;
-            this._isDirty = true;
-        }
-
-        /**
-         * Rebuilds the material defines
-         */
-        public rebuild() {
-            if (this._keys) {
-                delete this._keys;
-            }
-
-            this._keys = [];
-
-            for (var key of Object.keys(this)) {
-                if (key[0] === "_") {
-                    continue;
-                }
-
-                this._keys.push(key);
-            }
-        }
-
-        /**
-         * Specifies if two material defines are equal
-         * @param other - A material define instance to compare to
-         * @returns - Boolean indicating if the material defines are equal (true) or not (false)
-         */
-        public isEqual(other: MaterialDefines): boolean {
-            if (this._keys.length !== other._keys.length) {
-                return false;
-            }
-
-            for (var index = 0; index < this._keys.length; index++) {
-                var prop = this._keys[index];
-
-                if ((<any>this)[prop] !== (<any>other)[prop]) {
-                    return false;
-                }
-            }
-
-            return true;
-        }
-
-        /**
-         * Clones this instance's defines to another instance
-         * @param other - material defines to clone values to
-         */
-        public cloneTo(other: MaterialDefines): void {
-            if (this._keys.length !== other._keys.length) {
-                other._keys = this._keys.slice(0);
-            }
-
-            for (var index = 0; index < this._keys.length; index++) {
-                var prop = this._keys[index];
-
-                (<any>other)[prop] = (<any>this)[prop];
-            }
-        }
-
-        /**
-         * Resets the material define values
-         */
-        public reset(): void {
-            for (var index = 0; index < this._keys.length; index++) {
-                var prop = this._keys[index];
-                var type = typeof (<any>this)[prop];
-
-                switch (type) {
-                    case "number":
-                        (<any>this)[prop] = 0;
-                        break;
-                    case "string":
-                        (<any>this)[prop] = "";
-                        break;
-                    default:
-                        (<any>this)[prop] = false;
-                        break;
-                }
-            }
-        }
-
-        /**
-         * Converts the material define values to a string
-         * @returns - String of material define information
-         */
-        public toString(): string {
-            var result = "";
-            for (var index = 0; index < this._keys.length; index++) {
-                var prop = this._keys[index];
-                var value = (<any>this)[prop];
-                var type = typeof value;
-
-                switch (type) {
-                    case "number":
-                    case "string":
-                        result += "#define " + prop + " " + value + "\n";
-                        break;
-                    default:
-                        if (value) {
-                            result += "#define " + prop + "\n";
-                        }
-                        break;
-                }
-            }
-
-            return result;
-        }
-    }
 
 
     /**
     /**
      * Base class for the main features of a material in Babylon.js
      * Base class for the main features of a material in Babylon.js
@@ -1409,34 +1182,6 @@ declare var BABYLON: any;
         }
         }
 
 
         /**
         /**
-         * Creates a MultiMaterial from parsed MultiMaterial data.
-         * @param parsedMultiMaterial defines parsed MultiMaterial data.
-         * @param scene defines the hosting scene
-         * @returns a new MultiMaterial
-         */
-        public static ParseMultiMaterial(parsedMultiMaterial: any, scene: Scene): MultiMaterial {
-            var multiMaterial = new MultiMaterial(parsedMultiMaterial.name, scene);
-
-            multiMaterial.id = parsedMultiMaterial.id;
-
-            if (Tags) {
-                Tags.AddTagsTo(multiMaterial, parsedMultiMaterial.tags);
-            }
-
-            for (var matIndex = 0; matIndex < parsedMultiMaterial.materials.length; matIndex++) {
-                var subMatId = parsedMultiMaterial.materials[matIndex];
-
-                if (subMatId) {
-                    multiMaterial.subMaterials.push(scene.getMaterialByID(subMatId));
-                } else {
-                    multiMaterial.subMaterials.push(null);
-                }
-            }
-
-            return multiMaterial;
-        }
-
-        /**
          * Creates a material from parsed material data
          * Creates a material from parsed material data
          * @param parsedMaterial defines parsed material data
          * @param parsedMaterial defines parsed material data
          * @param scene defines the hosting scene
          * @param scene defines the hosting scene
@@ -1444,13 +1189,12 @@ declare var BABYLON: any;
          * @returns a new material
          * @returns a new material
          */
          */
         public static Parse(parsedMaterial: any, scene: Scene, rootUrl: string): any {
         public static Parse(parsedMaterial: any, scene: Scene, rootUrl: string): any {
-            if (!parsedMaterial.customType || parsedMaterial.customType === "BABYLON.StandardMaterial") {
-                return StandardMaterial.Parse(parsedMaterial, scene, rootUrl);
+            if (!parsedMaterial.customType) {
+                parsedMaterial.customType = "BABYLON.StandardMaterial";
             }
             }
-
-            if (parsedMaterial.customType === "BABYLON.PBRMaterial" && parsedMaterial.overloadedAlbedo) {
+            else if (parsedMaterial.customType === "BABYLON.PBRMaterial" && parsedMaterial.overloadedAlbedo) {
                 parsedMaterial.customType = "BABYLON.LegacyPBRMaterial";
                 parsedMaterial.customType = "BABYLON.LegacyPBRMaterial";
-                if (!(<any>BABYLON).LegacyPBRMaterial) {
+                if (!BABYLON.LegacyPBRMaterial) {
                     Tools.Error("Your scene is trying to load a legacy version of the PBRMaterial, please, include it from the materials library.");
                     Tools.Error("Your scene is trying to load a legacy version of the PBRMaterial, please, include it from the materials library.");
                     return;
                     return;
                 }
                 }

+ 225 - 0
src/Materials/materialDefines.ts

@@ -0,0 +1,225 @@
+/**
+ * Manages the defines for the Material
+ */
+export class MaterialDefines {
+    private _keys: string[];
+    private _isDirty = true;
+    /** @hidden */
+    public _renderId: number;
+
+    /** @hidden */
+    public _areLightsDirty = true;
+    /** @hidden */
+    public _areAttributesDirty = true;
+    /** @hidden */
+    public _areTexturesDirty = true;
+    /** @hidden */
+    public _areFresnelDirty = true;
+    /** @hidden */
+    public _areMiscDirty = true;
+    /** @hidden */
+    public _areImageProcessingDirty = true;
+
+    /** @hidden */
+    public _normals = false;
+    /** @hidden */
+    public _uvs = false;
+
+    /** @hidden */
+    public _needNormals = false;
+    /** @hidden */
+    public _needUVs = false;
+
+    /**
+     * Specifies if the material needs to be re-calculated
+     */
+    public get isDirty(): boolean {
+        return this._isDirty;
+    }
+
+    /**
+     * Marks the material to indicate that it has been re-calculated
+     */
+    public markAsProcessed() {
+        this._isDirty = false;
+        this._areAttributesDirty = false;
+        this._areTexturesDirty = false;
+        this._areFresnelDirty = false;
+        this._areLightsDirty = false;
+        this._areMiscDirty = false;
+        this._areImageProcessingDirty = false;
+    }
+
+    /**
+     * Marks the material to indicate that it needs to be re-calculated
+     */
+    public markAsUnprocessed() {
+        this._isDirty = true;
+    }
+
+    /**
+     * Marks the material to indicate all of its defines need to be re-calculated
+     */
+    public markAllAsDirty() {
+        this._areTexturesDirty = true;
+        this._areAttributesDirty = true;
+        this._areLightsDirty = true;
+        this._areFresnelDirty = true;
+        this._areMiscDirty = true;
+        this._areImageProcessingDirty = true;
+        this._isDirty = true;
+    }
+
+    /**
+     * Marks the material to indicate that image processing needs to be re-calculated
+     */
+    public markAsImageProcessingDirty() {
+        this._areImageProcessingDirty = true;
+        this._isDirty = true;
+    }
+
+    /**
+     * Marks the material to indicate the lights need to be re-calculated
+     */
+    public markAsLightDirty() {
+        this._areLightsDirty = true;
+        this._isDirty = true;
+    }
+
+    /**
+     * Marks the attribute state as changed
+     */
+    public markAsAttributesDirty() {
+        this._areAttributesDirty = true;
+        this._isDirty = true;
+    }
+
+    /**
+     * Marks the texture state as changed
+     */
+    public markAsTexturesDirty() {
+        this._areTexturesDirty = true;
+        this._isDirty = true;
+    }
+
+    /**
+     * Marks the fresnel state as changed
+     */
+    public markAsFresnelDirty() {
+        this._areFresnelDirty = true;
+        this._isDirty = true;
+    }
+
+    /**
+     * Marks the misc state as changed
+     */
+    public markAsMiscDirty() {
+        this._areMiscDirty = true;
+        this._isDirty = true;
+    }
+
+    /**
+     * Rebuilds the material defines
+     */
+    public rebuild() {
+        if (this._keys) {
+            delete this._keys;
+        }
+
+        this._keys = [];
+
+        for (var key of Object.keys(this)) {
+            if (key[0] === "_") {
+                continue;
+            }
+
+            this._keys.push(key);
+        }
+    }
+
+    /**
+     * Specifies if two material defines are equal
+     * @param other - A material define instance to compare to
+     * @returns - Boolean indicating if the material defines are equal (true) or not (false)
+     */
+    public isEqual(other: MaterialDefines): boolean {
+        if (this._keys.length !== other._keys.length) {
+            return false;
+        }
+
+        for (var index = 0; index < this._keys.length; index++) {
+            var prop = this._keys[index];
+
+            if ((<any>this)[prop] !== (<any>other)[prop]) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * Clones this instance's defines to another instance
+     * @param other - material defines to clone values to
+     */
+    public cloneTo(other: MaterialDefines): void {
+        if (this._keys.length !== other._keys.length) {
+            other._keys = this._keys.slice(0);
+        }
+
+        for (var index = 0; index < this._keys.length; index++) {
+            var prop = this._keys[index];
+
+            (<any>other)[prop] = (<any>this)[prop];
+        }
+    }
+
+    /**
+     * Resets the material define values
+     */
+    public reset(): void {
+        for (var index = 0; index < this._keys.length; index++) {
+            var prop = this._keys[index];
+            var type = typeof (<any>this)[prop];
+
+            switch (type) {
+                case "number":
+                    (<any>this)[prop] = 0;
+                    break;
+                case "string":
+                    (<any>this)[prop] = "";
+                    break;
+                default:
+                    (<any>this)[prop] = false;
+                    break;
+            }
+        }
+    }
+
+    /**
+     * Converts the material define values to a string
+     * @returns - String of material define information
+     */
+    public toString(): string {
+        var result = "";
+        for (var index = 0; index < this._keys.length; index++) {
+            var prop = this._keys[index];
+            var value = (<any>this)[prop];
+            var type = typeof value;
+
+            switch (type) {
+                case "number":
+                case "string":
+                    result += "#define " + prop + " " + value + "\n";
+                    break;
+                default:
+                    if (value) {
+                        result += "#define " + prop + "\n";
+                    }
+                    break;
+            }
+        }
+
+        return result;
+    }
+}

+ 1 - 1
src/Materials/materialHelper.ts

@@ -6,7 +6,7 @@ import { Tmp, Color3 } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { Light } from "Lights/light";
 import { Light } from "Lights/light";
 
 
 import { UniformBuffer } from "./uniformBuffer";
 import { UniformBuffer } from "./uniformBuffer";

+ 28 - 0
src/Materials/multiMaterial.ts

@@ -203,4 +203,32 @@ import { Tags } from "Tools/tags";
 
 
             super.dispose(forceDisposeEffect, forceDisposeTextures);
             super.dispose(forceDisposeEffect, forceDisposeTextures);
         }
         }
+
+        /**
+         * Creates a MultiMaterial from parsed MultiMaterial data.
+         * @param parsedMultiMaterial defines parsed MultiMaterial data.
+         * @param scene defines the hosting scene
+         * @returns a new MultiMaterial
+         */
+        public static ParseMultiMaterial(parsedMultiMaterial: any, scene: Scene): MultiMaterial {
+            var multiMaterial = new MultiMaterial(parsedMultiMaterial.name, scene);
+
+            multiMaterial.id = parsedMultiMaterial.id;
+
+            if (Tags) {
+                Tags.AddTagsTo(multiMaterial, parsedMultiMaterial.tags);
+            }
+
+            for (var matIndex = 0; matIndex < parsedMultiMaterial.materials.length; matIndex++) {
+                var subMatId = parsedMultiMaterial.materials[matIndex];
+
+                if (subMatId) {
+                    multiMaterial.subMaterials.push(scene.getMaterialByID(subMatId));
+                } else {
+                    multiMaterial.subMaterials.push(null);
+                }
+            }
+
+            return multiMaterial;
+        }
     }
     }

+ 1 - 1
src/Materials/shaderMaterial.ts

@@ -3,7 +3,7 @@ import { Scene } from "scene";
 import { Matrix, Vector3, Vector2, Color3, Color4, Vector4 } from "Math/math";
 import { Matrix, Vector3, Vector2, Color3, Color4, Vector4 } from "Math/math";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { BaseTexture } from "Materials/Textures/baseTexture";
 import { BaseTexture } from "Materials/Textures/baseTexture";
 import { Texture } from "Materials/Textures/texture";
 import { Texture } from "Materials/Textures/texture";
 import { MaterialHelper } from "./materialHelper";
 import { MaterialHelper } from "./materialHelper";

+ 3 - 2
src/Materials/standardMaterial.ts

@@ -3,7 +3,7 @@ import { Nullable } from "types";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Matrix, Color3 } from "Math/math";
 import { Matrix, Color3 } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";
@@ -12,7 +12,8 @@ import { ImageProcessingConfiguration, IImageProcessingConfigurationDefines } fr
 import { ColorCurves } from "./colorCurves";
 import { ColorCurves } from "./colorCurves";
 import { FresnelParameters } from "./fresnelParameters";
 import { FresnelParameters } from "./fresnelParameters";
 import { EffectFallbacks, EffectCreationOptions } from "./effect";
 import { EffectFallbacks, EffectCreationOptions } from "./effect";
-import { Material, MaterialDefines } from "./material";
+import { Material } from "./material";
+import { MaterialDefines } from "Materials/materialDefines";
 import { PushMaterial } from "./pushMaterial";
 import { PushMaterial } from "./pushMaterial";
 import { MaterialHelper } from "./materialHelper";
 import { MaterialHelper } from "./materialHelper";
 
 

+ 3 - 2
src/Mesh/abstractMesh.ts

@@ -6,7 +6,7 @@ import { Scene, IDisposable } from "scene";
 import { Quaternion, Matrix, Vector3, Color3, Color4, Plane, Tmp, Epsilon, Axis, Vector2 } from "Math/math";
 import { Quaternion, Matrix, Vector3, Color3, Color4, Plane, Tmp, Epsilon, Axis, Vector2 } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
 import { Node } from "node";
 import { Node } from "node";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { VertexData, IGetSetVerticesData } from "Mesh/mesh.vertexData";
 import { VertexData, IGetSetVerticesData } from "Mesh/mesh.vertexData";
 import { TransformNode } from "Mesh/transformNode";
 import { TransformNode } from "Mesh/transformNode";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
@@ -14,7 +14,8 @@ import { PickingInfo, IntersectionInfo } from "Collisions/pickingInfo";
 import { Collider } from "Collisions/collider";
 import { Collider } from "Collisions/collider";
 import { Ray } from "Culling/ray";
 import { Ray } from "Culling/ray";
 import { ICullable, BoundingInfo } from "Culling/boundingInfo";
 import { ICullable, BoundingInfo } from "Culling/boundingInfo";
-import { Material, MaterialDefines } from "Materials/material";
+import { Material } from "Materials/material";
+import { MaterialDefines } from "Materials/materialDefines";
 import { Light } from "Lights/light";
 import { Light } from "Lights/light";
 import { ActionManager } from "Actions/actionManager";
 import { ActionManager } from "Actions/actionManager";
 import { Skeleton } from "Bones/skeleton";
 import { Skeleton } from "Bones/skeleton";

+ 463 - 3
src/Mesh/buffer.ts

@@ -1,7 +1,6 @@
 import { Nullable, DataArray } from "types";
 import { Nullable, DataArray } from "types";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
-import { VertexBuffer } from "Mesh/vertexBuffer";
-import { Mesh } from "Mesh/mesh";
+
     /**
     /**
      * Class used to store data that will be store in GPU memory
      * Class used to store data that will be store in GPU memory
      */
      */
@@ -29,7 +28,7 @@ import { Mesh } from "Mesh/mesh";
          * @param useBytes set to true if the stride in in bytes (optional)
          * @param useBytes set to true if the stride in in bytes (optional)
          */
          */
         constructor(engine: any, data: DataArray, updatable: boolean, stride = 0, postponeInternalCreation = false, instanced = false, useBytes = false) {
         constructor(engine: any, data: DataArray, updatable: boolean, stride = 0, postponeInternalCreation = false, instanced = false, useBytes = false) {
-            if (engine instanceof Mesh) { // old versions of VertexBuffer accepted 'mesh' instead of 'engine'
+            if (engine.getScene) { // old versions of VertexBuffer accepted 'mesh' instead of 'engine'
                 this._engine = engine.getScene().getEngine();
                 this._engine = engine.getScene().getEngine();
             }
             }
             else {
             else {
@@ -176,3 +175,464 @@ import { Mesh } from "Mesh/mesh";
             }
             }
         }
         }
     }
     }
+
+/**
+     * Specialized buffer used to store vertex data
+     */
+    export class VertexBuffer {
+        /** @hidden */
+        public _buffer: Buffer;
+        private _kind: string;
+        private _size: number;
+        private _ownsBuffer: boolean;
+        private _instanced: boolean;
+        private _instanceDivisor: number;
+
+        /**
+         * The byte type.
+         */
+        public static readonly BYTE = 5120;
+
+        /**
+         * The unsigned byte type.
+         */
+        public static readonly UNSIGNED_BYTE = 5121;
+
+        /**
+         * The short type.
+         */
+        public static readonly SHORT = 5122;
+
+        /**
+         * The unsigned short type.
+         */
+        public static readonly UNSIGNED_SHORT = 5123;
+
+        /**
+         * The integer type.
+         */
+        public static readonly INT = 5124;
+
+        /**
+         * The unsigned integer type.
+         */
+        public static readonly UNSIGNED_INT = 5125;
+
+        /**
+         * The float type.
+         */
+        public static readonly FLOAT = 5126;
+
+        /**
+         * Gets or sets the instance divisor when in instanced mode
+         */
+        public get instanceDivisor(): number {
+            return this._instanceDivisor;
+        }
+
+        public set instanceDivisor(value: number) {
+            this._instanceDivisor = value;
+            if (value == 0) {
+                this._instanced = false;
+            } else {
+                this._instanced = true;
+            }
+        }
+
+        /**
+         * Gets the byte stride.
+         */
+        public readonly byteStride: number;
+
+        /**
+         * Gets the byte offset.
+         */
+        public readonly byteOffset: number;
+
+        /**
+         * Gets whether integer data values should be normalized into a certain range when being casted to a float.
+         */
+        public readonly normalized: boolean;
+
+        /**
+         * Gets the data type of each component in the array.
+         */
+        public readonly type: number;
+
+        /**
+         * Constructor
+         * @param engine the engine
+         * @param data the data to use for this vertex buffer
+         * @param kind the vertex buffer kind
+         * @param updatable whether the data is updatable
+         * @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)
+         * @param stride the stride (optional)
+         * @param instanced whether the buffer is instanced (optional)
+         * @param offset the offset of the data (optional)
+         * @param size the number of components (optional)
+         * @param type the type of the component (optional)
+         * @param normalized whether the data contains normalized data (optional)
+         * @param useBytes set to true if stride and offset are in bytes (optional)
+         */
+        constructor(engine: any, data: DataArray | Buffer, kind: string, updatable: boolean, postponeInternalCreation?: boolean, stride?: number, instanced?: boolean, offset?: number, size?: number, type?: number, normalized = false, useBytes = false) {
+            if (data instanceof Buffer) {
+                this._buffer = data;
+                this._ownsBuffer = false;
+            } else {
+                this._buffer = new Buffer(engine, data, updatable, stride, postponeInternalCreation, instanced, useBytes);
+                this._ownsBuffer = true;
+            }
+
+            this._kind = kind;
+
+            if (type == undefined) {
+                const data = this.getData();
+                this.type = VertexBuffer.FLOAT;
+                if (data instanceof Int8Array) { this.type = VertexBuffer.BYTE; }
+                else if (data instanceof Uint8Array) { this.type = VertexBuffer.UNSIGNED_BYTE; }
+                else if (data instanceof Int16Array) { this.type = VertexBuffer.SHORT; }
+                else if (data instanceof Uint16Array) { this.type = VertexBuffer.UNSIGNED_SHORT; }
+                else if (data instanceof Int32Array) { this.type = VertexBuffer.INT; }
+                else if (data instanceof Uint32Array) { this.type = VertexBuffer.UNSIGNED_INT; }
+            }
+            else {
+                this.type = type;
+            }
+
+            const typeByteLength = VertexBuffer.GetTypeByteLength(this.type);
+
+            if (useBytes) {
+                this._size = size || (stride ? (stride / typeByteLength) : VertexBuffer.DeduceStride(kind));
+                this.byteStride = stride || this._buffer.byteStride || (this._size * typeByteLength);
+                this.byteOffset = offset || 0;
+            }
+            else {
+                this._size = size || stride || VertexBuffer.DeduceStride(kind);
+                this.byteStride = stride ? (stride * typeByteLength) : (this._buffer.byteStride || (this._size * typeByteLength));
+                this.byteOffset = (offset || 0) * typeByteLength;
+            }
+
+            this.normalized = normalized;
+
+            this._instanced = instanced !== undefined ? instanced : false;
+            this._instanceDivisor = instanced ? 1 : 0;
+        }
+
+        /** @hidden */
+        public _rebuild(): void {
+            if (!this._buffer) {
+                return;
+            }
+
+            this._buffer._rebuild();
+        }
+
+        /**
+         * Returns the kind of the VertexBuffer (string)
+         * @returns a string
+         */
+        public getKind(): string {
+            return this._kind;
+        }
+
+        // Properties
+
+        /**
+         * Gets a boolean indicating if the VertexBuffer is updatable?
+         * @returns true if the buffer is updatable
+         */
+        public isUpdatable(): boolean {
+            return this._buffer.isUpdatable();
+        }
+
+        /**
+         * Gets current buffer's data
+         * @returns a DataArray or null
+         */
+        public getData(): Nullable<DataArray> {
+            return this._buffer.getData();
+        }
+
+        /**
+         * Gets underlying native buffer
+         * @returns underlying native buffer
+         */
+        public getBuffer(): Nullable<WebGLBuffer> {
+            return this._buffer.getBuffer();
+        }
+
+        /**
+         * Gets the stride in float32 units (i.e. byte stride / 4).
+         * May not be an integer if the byte stride is not divisible by 4.
+         * DEPRECATED. Use byteStride instead.
+         * @returns the stride in float32 units
+         */
+        public getStrideSize(): number {
+            return this.byteStride / VertexBuffer.GetTypeByteLength(this.type);
+        }
+
+        /**
+         * Returns the offset as a multiple of the type byte length.
+         * DEPRECATED. Use byteOffset instead.
+         * @returns the offset in bytes
+         */
+        public getOffset(): number {
+            return this.byteOffset / VertexBuffer.GetTypeByteLength(this.type);
+        }
+
+        /**
+         * Returns the number of components per vertex attribute (integer)
+         * @returns the size in float
+         */
+        public getSize(): number {
+            return this._size;
+        }
+
+        /**
+         * Gets a boolean indicating is the internal buffer of the VertexBuffer is instanced
+         * @returns true if this buffer is instanced
+         */
+        public getIsInstanced(): boolean {
+            return this._instanced;
+        }
+
+        /**
+         * Returns the instancing divisor, zero for non-instanced (integer).
+         * @returns a number
+         */
+        public getInstanceDivisor(): number {
+            return this._instanceDivisor;
+        }
+
+        // Methods
+
+        /**
+         * Store data into the buffer. If the buffer was already used it will be either recreated or updated depending on isUpdatable property
+         * @param data defines the data to store
+         */
+        public create(data?: DataArray): void {
+            this._buffer.create(data);
+        }
+
+        /**
+         * Updates the underlying buffer according to the passed numeric array or Float32Array.
+         * This function will create a new buffer if the current one is not updatable
+         * @param data defines the data to store
+         */
+        public update(data: DataArray): void {
+            this._buffer.update(data);
+        }
+
+        /**
+         * Updates directly the underlying WebGLBuffer according to the passed numeric array or Float32Array.
+         * Returns the directly updated WebGLBuffer.
+         * @param data the new data
+         * @param offset the new offset
+         * @param useBytes set to true if the offset is in bytes
+         */
+        public updateDirectly(data: DataArray, offset: number, useBytes: boolean = false): void {
+            this._buffer.updateDirectly(data, offset, undefined, useBytes);
+        }
+
+        /**
+         * Disposes the VertexBuffer and the underlying WebGLBuffer.
+         */
+        public dispose(): void {
+            if (this._ownsBuffer) {
+                this._buffer.dispose();
+            }
+        }
+
+        /**
+         * Enumerates each value of this vertex buffer as numbers.
+         * @param count the number of values to enumerate
+         * @param callback the callback function called for each value
+         */
+        public forEach(count: number, callback: (value: number, index: number) => void): void {
+            VertexBuffer.ForEach(this._buffer.getData()!, this.byteOffset, this.byteStride, this._size, this.type, count, this.normalized, callback);
+        }
+
+        // Enums
+        /**
+         * Positions
+         */
+        public static readonly PositionKind = "position";
+        /**
+         * Normals
+         */
+        public static readonly NormalKind = "normal";
+        /**
+         * Tangents
+         */
+        public static readonly TangentKind = "tangent";
+        /**
+         * Texture coordinates
+         */
+        public static readonly UVKind = "uv";
+        /**
+         * Texture coordinates 2
+         */
+        public static readonly UV2Kind = "uv2";
+        /**
+         * Texture coordinates 3
+         */
+        public static readonly UV3Kind = "uv3";
+        /**
+         * Texture coordinates 4
+         */
+        public static readonly UV4Kind = "uv4";
+        /**
+         * Texture coordinates 5
+         */
+        public static readonly UV5Kind = "uv5";
+        /**
+         * Texture coordinates 6
+         */
+        public static readonly UV6Kind = "uv6";
+        /**
+         * Colors
+         */
+        public static readonly ColorKind = "color";
+        /**
+         * Matrix indices (for bones)
+         */
+        public static readonly MatricesIndicesKind = "matricesIndices";
+        /**
+         * Matrix weights (for bones)
+         */
+        public static readonly MatricesWeightsKind = "matricesWeights";
+        /**
+         * Additional matrix indices (for bones)
+         */
+        public static readonly MatricesIndicesExtraKind = "matricesIndicesExtra";
+        /**
+         * Additional matrix weights (for bones)
+         */
+        public static readonly MatricesWeightsExtraKind = "matricesWeightsExtra";
+
+        /**
+         * Deduces the stride given a kind.
+         * @param kind The kind string to deduce
+         * @returns The deduced stride
+         */
+        public static DeduceStride(kind: string): number {
+            switch (kind) {
+                case VertexBuffer.UVKind:
+                case VertexBuffer.UV2Kind:
+                case VertexBuffer.UV3Kind:
+                case VertexBuffer.UV4Kind:
+                case VertexBuffer.UV5Kind:
+                case VertexBuffer.UV6Kind:
+                    return 2;
+                case VertexBuffer.NormalKind:
+                case VertexBuffer.PositionKind:
+                    return 3;
+                case VertexBuffer.ColorKind:
+                case VertexBuffer.MatricesIndicesKind:
+                case VertexBuffer.MatricesIndicesExtraKind:
+                case VertexBuffer.MatricesWeightsKind:
+                case VertexBuffer.MatricesWeightsExtraKind:
+                case VertexBuffer.TangentKind:
+                    return 4;
+                default:
+                    throw new Error("Invalid kind '" + kind + "'");
+            }
+        }
+
+        /**
+         * Gets the byte length of the given type.
+         * @param type the type
+         * @returns the number of bytes
+         */
+        public static GetTypeByteLength(type: number): number {
+            switch (type) {
+                case VertexBuffer.BYTE:
+                case VertexBuffer.UNSIGNED_BYTE:
+                    return 1;
+                case VertexBuffer.SHORT:
+                case VertexBuffer.UNSIGNED_SHORT:
+                    return 2;
+                case VertexBuffer.INT:
+                case VertexBuffer.FLOAT:
+                    return 4;
+                default:
+                    throw new Error(`Invalid type '${type}'`);
+            }
+        }
+
+        /**
+         * Enumerates each value of the given parameters as numbers.
+         * @param data the data to enumerate
+         * @param byteOffset the byte offset of the data
+         * @param byteStride the byte stride of the data
+         * @param componentCount the number of components per element
+         * @param componentType the type of the component
+         * @param count the total number of components
+         * @param normalized whether the data is normalized
+         * @param callback the callback function called for each value
+         */
+        public static ForEach(data: DataArray, byteOffset: number, byteStride: number, componentCount: number, componentType: number, count: number, normalized: boolean, callback: (value: number, index: number) => void): void {
+            if (data instanceof Array) {
+                let offset = byteOffset / 4;
+                const stride = byteStride / 4;
+                for (let index = 0; index < count; index += componentCount) {
+                    for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {
+                        callback(data[offset + componentIndex], index + componentIndex);
+                    }
+                    offset += stride;
+                }
+            }
+            else {
+                const dataView = data instanceof ArrayBuffer ? new DataView(data) : new DataView(data.buffer, data.byteOffset, data.byteLength);
+                const componentByteLength = VertexBuffer.GetTypeByteLength(componentType);
+                for (let index = 0; index < count; index += componentCount) {
+                    let componentByteOffset = byteOffset;
+                    for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {
+                        const value = VertexBuffer._GetFloatValue(dataView, componentType, componentByteOffset, normalized);
+                        callback(value, index + componentIndex);
+                        componentByteOffset += componentByteLength;
+                    }
+                    byteOffset += byteStride;
+                }
+            }
+        }
+
+        private static _GetFloatValue(dataView: DataView, type: number, byteOffset: number, normalized: boolean): number {
+            switch (type) {
+                case VertexBuffer.BYTE: {
+                    let value = dataView.getInt8(byteOffset);
+                    if (normalized) {
+                        value = Math.max(value / 127, -1);
+                    }
+                    return value;
+                }
+                case VertexBuffer.UNSIGNED_BYTE: {
+                    let value = dataView.getUint8(byteOffset);
+                    if (normalized) {
+                        value = value / 255;
+                    }
+                    return value;
+                }
+                case VertexBuffer.SHORT: {
+                    let value = dataView.getInt16(byteOffset, true);
+                    if (normalized) {
+                        value = Math.max(value / 16383, -1);
+                    }
+                    return value;
+                }
+                case VertexBuffer.UNSIGNED_SHORT: {
+                    let value = dataView.getUint16(byteOffset, true);
+                    if (normalized) {
+                        value = value / 65535;
+                    }
+                    return value;
+                }
+                case VertexBuffer.FLOAT: {
+                    return dataView.getFloat32(byteOffset, true);
+                }
+                default: {
+                    throw new Error(`Invalid component type ${type}`);
+                }
+            }
+        }
+    }

+ 1 - 1
src/Mesh/csg.ts

@@ -1,7 +1,7 @@
 import { Nullable, FloatArray, IndicesArray } from "types";
 import { Nullable, FloatArray, IndicesArray } from "types";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Quaternion, Matrix, Vector3, Vector2 } from "Math/math";
 import { Quaternion, Matrix, Vector3, Vector2 } from "Math/math";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";

+ 1 - 1
src/Mesh/geometry.ts

@@ -4,7 +4,7 @@
     import { Vector3, Vector2, Color4 } from "Math/math";
     import { Vector3, Vector2, Color4 } from "Math/math";
     import { Engine } from "Engine/engine";
     import { Engine } from "Engine/engine";
     import { IGetSetVerticesData, VertexData } from "Mesh/mesh.vertexData";
     import { IGetSetVerticesData, VertexData } from "Mesh/mesh.vertexData";
-    import { VertexBuffer } from "Mesh/vertexBuffer";
+    import { VertexBuffer } from "Mesh/buffer";
     import { SubMesh } from "Mesh/subMesh";
     import { SubMesh } from "Mesh/subMesh";
     import { AbstractMesh } from "Mesh/abstractMesh";
     import { AbstractMesh } from "Mesh/abstractMesh";
     import { Mesh } from "Mesh/mesh";
     import { Mesh } from "Mesh/mesh";

+ 6 - 1
src/Mesh/groundMesh.ts

@@ -1,7 +1,12 @@
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Vector3, Vector2, Tmp, Vector4 } from "Math/math";
 import { Vector3, Vector2, Tmp, Vector4 } from "Math/math";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";
+
+Mesh._GroundMeshParser =  (parsedMesh: any, scene: Scene): Mesh => {
+    return GroundMesh.Parse(parsedMesh, scene);
+};
+
     /**
     /**
      * Mesh representing the gorund
      * Mesh representing the gorund
      */
      */

+ 1 - 3
src/Mesh/index.ts

@@ -9,10 +9,8 @@ export * from "./linesMesh";
 export * from "./mesh";
 export * from "./mesh";
 export * from "./mesh.vertexData";
 export * from "./mesh.vertexData";
 export * from "./meshBuilder";
 export * from "./meshBuilder";
-export * from "./meshLODLevel";
 export * from "./meshSimplification";
 export * from "./meshSimplification";
 export * from "./meshSimplificationSceneComponent";
 export * from "./meshSimplificationSceneComponent";
 export * from "./polygonMesh";
 export * from "./polygonMesh";
 export * from "./subMesh";
 export * from "./subMesh";
-export * from "./transformNode";
-export * from "./vertexBuffer";
+export * from "./transformNode";

+ 4 - 0
src/Mesh/instancedMesh.ts

@@ -8,6 +8,10 @@ import { Mesh } from "Mesh/mesh";
 import { Material } from "Materials/material";
 import { Material } from "Materials/material";
 import { Skeleton } from "Bones/skeleton";
 import { Skeleton } from "Bones/skeleton";
 
 
+Mesh._instancedMeshFactory = (name: string, mesh: Mesh): InstancedMesh => {
+    return new InstancedMesh(name, mesh);
+};
+
     /**
     /**
      * Creates an instance based on a source mesh.
      * Creates an instance based on a source mesh.
      */
      */

+ 1 - 1
src/Mesh/linesMesh.ts

@@ -2,7 +2,7 @@ import { Nullable } from "types";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Color3 } from "Math/math";
 import { Color3 } from "Math/math";
 import { Node } from "node";
 import { Node } from "node";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";
 import { InstancedMesh } from "Mesh/instancedMesh";
 import { InstancedMesh } from "Mesh/instancedMesh";

+ 82 - 241
src/Mesh/mesh.ts

@@ -7,19 +7,12 @@ import { Scene } from "scene";
 import { Quaternion, Matrix, Vector3, Vector2, Color3, Color4, Plane, Vector4, Path3D } from "Math/math";
 import { Quaternion, Matrix, Vector3, Vector2, Color3, Color4, Plane, Vector4, Path3D } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
 import { Node } from "node";
 import { Node } from "node";
-
-import { VertexBuffer } from "./vertexBuffer";
+import { VertexBuffer } from "./buffer";
 import { VertexData, IGetSetVerticesData } from "./mesh.vertexData";
 import { VertexData, IGetSetVerticesData } from "./mesh.vertexData";
 import { Buffer } from "./buffer";
 import { Buffer } from "./buffer";
 import { Geometry } from "./geometry";
 import { Geometry } from "./geometry";
 import { AbstractMesh } from "./abstractMesh";
 import { AbstractMesh } from "./abstractMesh";
 import { SubMesh } from "./subMesh";
 import { SubMesh } from "./subMesh";
-import { InstancedMesh } from "./instancedMesh";
-import { LinesMesh } from "./linesMesh";
-import { GroundMesh } from "./groundMesh";
-import { MeshBuilder } from "./meshBuilder";
-import { MeshLODLevel } from "./meshLODLevel";
-
 import { BoundingInfo } from "Culling/boundingInfo";
 import { BoundingInfo } from "Culling/boundingInfo";
 import { BoundingSphere } from "Culling/boundingSphere";
 import { BoundingSphere } from "Culling/boundingSphere";
 import { Effect } from "Materials/effect";
 import { Effect } from "Materials/effect";
@@ -29,6 +22,29 @@ import { SceneLoader } from "Loading/sceneLoader";
 import { Skeleton } from "Bones/skeleton";
 import { Skeleton } from "Bones/skeleton";
 import { MorphTargetManager } from "Morph/morphTargetManager";
 import { MorphTargetManager } from "Morph/morphTargetManager";
 import { PhysicsImpostor } from "Physics/physicsImpostor";
 import { PhysicsImpostor } from "Physics/physicsImpostor";
+
+declare type LinesMesh = import("./linesMesh").LinesMesh;
+declare type InstancedMesh = import("./instancedMesh").InstancedMesh;
+declare type GroundMesh = import("./groundMesh").GroundMesh;
+
+    /**
+     * Class used to represent a specific level of detail of a mesh
+     * @see http://doc.babylonjs.com/how_to/how_to_use_lod
+     */
+    export class MeshLODLevel {
+        /**
+         * Creates a new LOD level
+         * @param distance defines the distance where this level should star being displayed
+         * @param mesh defines the mesh to use to render this level
+         */
+        constructor(
+            /** Defines the distance where this level should star being displayed */
+            public distance: number,
+            /** Defines the mesh to use to render this level */
+            public mesh: Nullable<Mesh>) {
+        }
+    }
+
     /**
     /**
      * @hidden
      * @hidden
      **/
      **/
@@ -77,20 +93,20 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
         /**
         /**
          * Mesh side orientation : usually the external or front surface
          * Mesh side orientation : usually the external or front surface
          */
          */
-        public static readonly FRONTSIDE = 0;
+        public static readonly FRONTSIDE = VertexData.FRONTSIDE;
 
 
         /**
         /**
          * Mesh side orientation : usually the internal or back surface
          * Mesh side orientation : usually the internal or back surface
          */
          */
-        public static readonly BACKSIDE = 1;
+        public static readonly BACKSIDE = VertexData.BACKSIDE;
         /**
         /**
          * Mesh side orientation : both internal and external or front and back surfaces
          * Mesh side orientation : both internal and external or front and back surfaces
          */
          */
-        public static readonly DOUBLESIDE = 2;
+        public static readonly DOUBLESIDE = VertexData.DOUBLESIDE;
         /**
         /**
          * Mesh side orientation : by default, `FRONTSIDE`
          * Mesh side orientation : by default, `FRONTSIDE`
          */
          */
-        public static readonly DEFAULTSIDE = 0;
+        public static readonly DEFAULTSIDE = VertexData.DEFAULTSIDE;
         /**
         /**
          * Mesh cap setting : no cap
          * Mesh cap setting : no cap
          */
          */
@@ -2334,6 +2350,10 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
         }
         }
 
 
         // Instances
         // Instances
+        /** @hidden */
+        public static _instancedMeshFactory = (name: string, mesh: Mesh): InstancedMesh => {
+            throw "Import InstancedMesh before creating instances.";
+        }
 
 
         /**
         /**
          * Creates a new InstancedMesh object from the mesh model.
          * Creates a new InstancedMesh object from the mesh model.
@@ -2342,7 +2362,7 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @returns a new InstancedMesh
          * @returns a new InstancedMesh
          */
          */
         public createInstance(name: string): InstancedMesh {
         public createInstance(name: string): InstancedMesh {
-            return new InstancedMesh(name, this);
+            return Mesh._instancedMeshFactory(name, this);
         }
         }
 
 
         /**
         /**
@@ -2620,6 +2640,10 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
         }
         }
 
 
         // Statics
         // Statics
+        /** @hidden */
+        public static _GroundMeshParser = (parsedMesh: any, scene: Scene): Mesh => {
+            throw "Import GroundMesh before trying to parse it.";
+        }
 
 
         /**
         /**
          * Returns a new Mesh object parsed from the source provided.
          * Returns a new Mesh object parsed from the source provided.
@@ -2632,7 +2656,7 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
             var mesh: Mesh;
             var mesh: Mesh;
 
 
             if (parsedMesh.type && parsedMesh.type === "GroundMesh") {
             if (parsedMesh.type && parsedMesh.type === "GroundMesh") {
-                mesh = GroundMesh.Parse(parsedMesh, scene);
+                mesh = Mesh._GroundMeshParser(parsedMesh, scene);
             } else {
             } else {
                 mesh = new Mesh(parsedMesh.name, scene);
                 mesh = new Mesh(parsedMesh.name, scene);
             }
             }
@@ -2925,16 +2949,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param instance defines an instance of an existing Ribbon object to be updated with the passed `pathArray` parameter (http://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#ribbon)
          * @param instance defines an instance of an existing Ribbon object to be updated with the passed `pathArray` parameter (http://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#ribbon)
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static CreateRibbon(name: string, pathArray: Vector3[][], closeArray: boolean = false, closePath: boolean, offset: number, scene?: Scene, updatable: boolean = false, sideOrientation?: number, instance?: Mesh): Mesh {
-            return MeshBuilder.CreateRibbon(name, {
-                pathArray: pathArray,
-                closeArray: closeArray,
-                closePath: closePath,
-                offset: offset,
-                updatable: updatable,
-                sideOrientation: sideOrientation,
-                instance: instance
-            }, scene);
+        public static CreateRibbon = (name: string, pathArray: Vector3[][], closeArray: boolean, closePath: boolean, offset: number, scene?: Scene, updatable?: boolean, sideOrientation?: number, instance?: Mesh): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -2947,15 +2963,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
           * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
           * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
           * @returns a new Mesh
           * @returns a new Mesh
           */
           */
-        public static CreateDisc(name: string, radius: number, tessellation: number, scene: Nullable<Scene> = null, updatable?: boolean, sideOrientation?: number): Mesh {
-            var options = {
-                radius: radius,
-                tessellation: tessellation,
-                sideOrientation: sideOrientation,
-                updatable: updatable
-            };
-
-            return MeshBuilder.CreateDisc(name, options, scene);
+        public static CreateDisc = (name: string, radius: number, tessellation: number, scene: Nullable<Scene> = null, updatable?: boolean, sideOrientation?: number): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -2967,14 +2976,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static CreateBox(name: string, size: number, scene: Nullable<Scene> = null, updatable?: boolean, sideOrientation?: number): Mesh {
-            var options = {
-                size: size,
-                sideOrientation: sideOrientation,
-                updatable: updatable
-            };
-
-            return MeshBuilder.CreateBox(name, options, scene);
+        public static CreateBox = (name: string, size: number, scene: Nullable<Scene> = null, updatable?: boolean, sideOrientation?: number): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -2987,17 +2990,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
           * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
           * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
           * @returns a new Mesh
           * @returns a new Mesh
           */
           */
-        public static CreateSphere(name: string, segments: number, diameter: number, scene?: Scene, updatable?: boolean, sideOrientation?: number): Mesh {
-            var options = {
-                segments: segments,
-                diameterX: diameter,
-                diameterY: diameter,
-                diameterZ: diameter,
-                sideOrientation: sideOrientation,
-                updatable: updatable
-            };
-
-            return MeshBuilder.CreateSphere(name, options, scene);
+        public static CreateSphere = (name: string, segments: number, diameter: number, scene?: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3013,27 +3007,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static CreateCylinder(name: string, height: number, diameterTop: number, diameterBottom: number, tessellation: number, subdivisions: any, scene?: Scene, updatable?: any, sideOrientation?: number): Mesh {
-            if (scene === undefined || !(scene instanceof Scene)) {
-                if (scene !== undefined) {
-                    sideOrientation = updatable || Mesh.DEFAULTSIDE;
-                    updatable = scene;
-                }
-                scene = <Scene>subdivisions;
-                subdivisions = 1;
-            }
-
-            var options = {
-                height: height,
-                diameterTop: diameterTop,
-                diameterBottom: diameterBottom,
-                tessellation: tessellation,
-                subdivisions: subdivisions,
-                sideOrientation: sideOrientation,
-                updatable: updatable
-            };
-
-            return MeshBuilder.CreateCylinder(name, options, scene);
+        public static CreateCylinder = (name: string, height: number, diameterTop: number, diameterBottom: number, tessellation: number, subdivisions: any, scene?: Scene, updatable?: any, sideOrientation?: number): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         // Torus  (Code from SharpDX.org)
         // Torus  (Code from SharpDX.org)
@@ -3048,16 +3023,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static CreateTorus(name: string, diameter: number, thickness: number, tessellation: number, scene?: Scene, updatable?: boolean, sideOrientation?: number): Mesh {
-            var options = {
-                diameter: diameter,
-                thickness: thickness,
-                tessellation: tessellation,
-                sideOrientation: sideOrientation,
-                updatable: updatable
-            };
-
-            return MeshBuilder.CreateTorus(name, options, scene);
+        public static CreateTorus = (name: string, diameter: number, thickness: number, tessellation: number, scene?: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3074,19 +3041,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static CreateTorusKnot(name: string, radius: number, tube: number, radialSegments: number, tubularSegments: number, p: number, q: number, scene?: Scene, updatable?: boolean, sideOrientation?: number): Mesh {
-            var options = {
-                radius: radius,
-                tube: tube,
-                radialSegments: radialSegments,
-                tubularSegments: tubularSegments,
-                p: p,
-                q: q,
-                sideOrientation: sideOrientation,
-                updatable: updatable
-            };
-
-            return MeshBuilder.CreateTorusKnot(name, options, scene);
+        public static CreateTorusKnot = (name: string, radius: number, tube: number, radialSegments: number, tubularSegments: number, p: number, q: number, scene?: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3098,13 +3054,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param instance is an instance of an existing LineMesh object to be updated with the passed `points` parameter (http://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#lines-and-dashedlines).
          * @param instance is an instance of an existing LineMesh object to be updated with the passed `points` parameter (http://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#lines-and-dashedlines).
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static CreateLines(name: string, points: Vector3[], scene: Nullable<Scene> = null, updatable: boolean = false, instance: Nullable<LinesMesh> = null): LinesMesh {
-            var options = {
-                points: points,
-                updatable: updatable,
-                instance: instance
-            };
-            return MeshBuilder.CreateLines(name, options, scene);
+        public static CreateLines = (name: string, points: Vector3[], scene: Nullable<Scene> = null, updatable: boolean = false, instance: Nullable<LinesMesh> = null): LinesMesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3119,30 +3070,17 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param instance is an instance of an existing LineMesh object to be updated with the passed `points` parameter (http://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#lines-and-dashedlines)
          * @param instance is an instance of an existing LineMesh object to be updated with the passed `points` parameter (http://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#lines-and-dashedlines)
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static CreateDashedLines(name: string, points: Vector3[], dashSize: number, gapSize: number, dashNb: number, scene: Nullable<Scene> = null, updatable?: boolean, instance?: LinesMesh): LinesMesh {
-            var options = {
-                points: points,
-                dashSize: dashSize,
-                gapSize: gapSize,
-                dashNb: dashNb,
-                updatable: updatable,
-                instance: instance
-            };
-            return MeshBuilder.CreateDashedLines(name, options, scene);
+        public static CreateDashedLines = (name: string, points: Vector3[], dashSize: number, gapSize: number, dashNb: number, scene: Nullable<Scene> = null, updatable?: boolean, instance?: LinesMesh): LinesMesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
-         * Creates a polygon mesh.
-         * Please consider using the same method from the MeshBuilder class instead.
+         * Creates a polygon mesh.Please consider using the same method from the MeshBuilder class instead
          * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh.
          * The polygon's shape will depend on the input parameters and is constructed parallel to a ground mesh.
          * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors.
          * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors.
          * You can set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE
          * You can set the mesh side orientation with the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE
          * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
          * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
          * Remember you can only change the shape positions, not their number when updating a polygon.
          * Remember you can only change the shape positions, not their number when updating a polygon.
-         */
-
-        /**
-         * Creates a polygon mesh.Please consider using the same method from the MeshBuilder class instead
          * @see http://doc.babylonjs.com/how_to/parametric_shapes#non-regular-polygon
          * @see http://doc.babylonjs.com/how_to/parametric_shapes#non-regular-polygon
          * @param name defines the name of the mesh to create
          * @param name defines the name of the mesh to create
          * @param shape is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors
          * @param shape is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors
@@ -3152,14 +3090,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static CreatePolygon(name: string, shape: Vector3[], scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number): Mesh {
-            var options = {
-                shape: shape,
-                holes: holes,
-                updatable: updatable,
-                sideOrientation: sideOrientation
-            };
-            return MeshBuilder.CreatePolygon(name, options, scene);
+        public static CreatePolygon = (name: string, shape: Vector3[], scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3174,15 +3106,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static ExtrudePolygon(name: string, shape: Vector3[], depth: number, scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number): Mesh {
-            var options = {
-                shape: shape,
-                holes: holes,
-                depth: depth,
-                updatable: updatable,
-                sideOrientation: sideOrientation
-            };
-            return MeshBuilder.ExtrudePolygon(name, options, scene);
+        public static ExtrudePolygon = (name: string, shape: Vector3[], depth: number, scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3202,19 +3127,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param instance is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters (http://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#extruded-shape)
          * @param instance is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters (http://doc.babylonjs.com/how_to/How_to_dynamically_morph_a_mesh#extruded-shape)
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static ExtrudeShape(name: string, shape: Vector3[], path: Vector3[], scale: number, rotation: number, cap: number, scene: Nullable<Scene> = null, updatable?: boolean, sideOrientation?: number, instance?: Mesh): Mesh {
-            var options = {
-                shape: shape,
-                path: path,
-                scale: scale,
-                rotation: rotation,
-                cap: (cap === 0) ? 0 : cap || Mesh.NO_CAP,
-                sideOrientation: sideOrientation,
-                instance: instance,
-                updatable: updatable
-            };
-
-            return MeshBuilder.ExtrudeShape(name, options, scene);
+        public static ExtrudeShape = (name: string, shape: Vector3[], path: Vector3[], scale: number, rotation: number, cap: number, scene: Nullable<Scene> = null, updatable?: boolean, sideOrientation?: number, instance?: Mesh): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3237,21 +3151,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param instance is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters (http://doc.babylonjs.com/how_to/how_to_dynamically_morph_a_mesh#extruded-shape)
          * @param instance is an instance of an existing ExtrudedShape object to be updated with the passed `shape`, `path`, `scale` or `rotation` parameters (http://doc.babylonjs.com/how_to/how_to_dynamically_morph_a_mesh#extruded-shape)
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static ExtrudeShapeCustom(name: string, shape: Vector3[], path: Vector3[], scaleFunction: Function, rotationFunction: Function, ribbonCloseArray: boolean, ribbonClosePath: boolean, cap: number, scene: Scene, updatable?: boolean, sideOrientation?: number, instance?: Mesh): Mesh {
-            var options = {
-                shape: shape,
-                path: path,
-                scaleFunction: scaleFunction,
-                rotationFunction: rotationFunction,
-                ribbonCloseArray: ribbonCloseArray,
-                ribbonClosePath: ribbonClosePath,
-                cap: (cap === 0) ? 0 : cap || Mesh.NO_CAP,
-                sideOrientation: sideOrientation,
-                instance: instance,
-                updatable: updatable
-            };
-
-            return MeshBuilder.ExtrudeShapeCustom(name, options, scene);
+        public static ExtrudeShapeCustom = (name: string, shape: Vector3[], path: Vector3[], scaleFunction: Function, rotationFunction: Function, ribbonCloseArray: boolean, ribbonClosePath: boolean, cap: number, scene: Scene, updatable?: boolean, sideOrientation?: number, instance?: Mesh): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3267,16 +3168,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static CreateLathe(name: string, shape: Vector3[], radius: number, tessellation: number, scene: Scene, updatable?: boolean, sideOrientation?: number): Mesh {
-            var options = {
-                shape: shape,
-                radius: radius,
-                tessellation: tessellation,
-                sideOrientation: sideOrientation,
-                updatable: updatable
-            };
-
-            return MeshBuilder.CreateLathe(name, options, scene);
+        public static CreateLathe = (name: string, shape: Vector3[], radius: number, tessellation: number, scene: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3288,16 +3181,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @param sideOrientation defines the mesh side orientation (http://doc.babylonjs.com/babylon101/discover_basic_elements#side-orientation)
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static CreatePlane(name: string, size: number, scene: Scene, updatable?: boolean, sideOrientation?: number): Mesh {
-            var options = {
-                size: size,
-                width: size,
-                height: size,
-                sideOrientation: sideOrientation,
-                updatable: updatable
-            };
-
-            return MeshBuilder.CreatePlane(name, options, scene);
+        public static CreatePlane = (name: string, size: number, scene: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3312,14 +3197,7 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
         public static CreateGround(name: string, width: number, height: number, subdivisions: number, scene?: Scene, updatable?: boolean): Mesh {
         public static CreateGround(name: string, width: number, height: number, subdivisions: number, scene?: Scene, updatable?: boolean): Mesh {
-            var options = {
-                width: width,
-                height: height,
-                subdivisions: subdivisions,
-                updatable: updatable
-            };
-
-            return MeshBuilder.CreateGround(name, options, scene);
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3337,17 +3215,7 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
         public static CreateTiledGround(name: string, xmin: number, zmin: number, xmax: number, zmax: number, subdivisions: { w: number; h: number; }, precision: { w: number; h: number; }, scene: Scene, updatable?: boolean): Mesh {
         public static CreateTiledGround(name: string, xmin: number, zmin: number, xmax: number, zmax: number, subdivisions: { w: number; h: number; }, precision: { w: number; h: number; }, scene: Scene, updatable?: boolean): Mesh {
-            var options = {
-                xmin: xmin,
-                zmin: zmin,
-                xmax: xmax,
-                zmax: zmax,
-                subdivisions: subdivisions,
-                precision: precision,
-                updatable: updatable
-            };
-
-            return MeshBuilder.CreateTiledGround(name, options, scene);
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3367,19 +3235,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param alphaFilter will filter any data where the alpha channel is below this value, defaults 0 (all data visible)
          * @param alphaFilter will filter any data where the alpha channel is below this value, defaults 0 (all data visible)
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static CreateGroundFromHeightMap(name: string, url: string, width: number, height: number, subdivisions: number, minHeight: number, maxHeight: number, scene: Scene, updatable?: boolean, onReady?: (mesh: GroundMesh) => void, alphaFilter?: number): GroundMesh {
-            var options = {
-                width: width,
-                height: height,
-                subdivisions: subdivisions,
-                minHeight: minHeight,
-                maxHeight: maxHeight,
-                updatable: updatable,
-                onReady: onReady,
-                alphaFilter: alphaFilter
-            };
-
-            return MeshBuilder.CreateGroundFromHeightMap(name, url, options, scene);
+        public static CreateGroundFromHeightMap = (name: string, url: string, width: number, height: number, subdivisions: number, minHeight: number, maxHeight: number, scene: Scene, updatable?: boolean, onReady?: (mesh: GroundMesh) => void, alphaFilter?: number): GroundMesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3401,18 +3258,7 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
         public static CreateTube(name: string, path: Vector3[], radius: number, tessellation: number, radiusFunction: { (i: number, distance: number): number; }, cap: number, scene: Scene, updatable?: boolean, sideOrientation?: number, instance?: Mesh): Mesh {
         public static CreateTube(name: string, path: Vector3[], radius: number, tessellation: number, radiusFunction: { (i: number, distance: number): number; }, cap: number, scene: Scene, updatable?: boolean, sideOrientation?: number, instance?: Mesh): Mesh {
-            var options = {
-                path: path,
-                radius: radius,
-                tessellation: tessellation,
-                radiusFunction: radiusFunction,
-                arc: 1,
-                cap: cap,
-                updatable: updatable,
-                sideOrientation: sideOrientation,
-                instance: instance
-            };
-            return MeshBuilder.CreateTube(name, options, scene);
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3434,8 +3280,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
           * @param scene defines the hosting scene
           * @param scene defines the hosting scene
           * @returns a new Mesh
           * @returns a new Mesh
           */
           */
-        public static CreatePolyhedron(name: string, options: { type?: number, size?: number, sizeX?: number, sizeY?: number, sizeZ?: number, custom?: any, faceUV?: Vector4[], faceColors?: Color4[], updatable?: boolean, sideOrientation?: number }, scene: Scene): Mesh {
-            return MeshBuilder.CreatePolyhedron(name, options, scene);
+        public static CreatePolyhedron = (name: string, options: { type?: number, size?: number, sizeX?: number, sizeY?: number, sizeZ?: number, custom?: any, faceUV?: Vector4[], faceColors?: Color4[], updatable?: boolean, sideOrientation?: number }, scene: Scene): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3453,8 +3299,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @returns a new Mesh
          * @returns a new Mesh
          * @see http://doc.babylonjs.com/how_to/polyhedra_shapes#icosphere
          * @see http://doc.babylonjs.com/how_to/polyhedra_shapes#icosphere
          */
          */
-        public static CreateIcoSphere(name: string, options: { radius?: number, flat?: boolean, subdivisions?: number, sideOrientation?: number, updatable?: boolean }, scene: Scene): Mesh {
-            return MeshBuilder.CreateIcoSphere(name, options, scene);
+        public static CreateIcoSphere = (name: string, options: { radius?: number, flat?: boolean, subdivisions?: number, sideOrientation?: number, updatable?: boolean }, scene: Scene): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         /**
         /**
@@ -3469,15 +3315,8 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
          * @param angle sets the angle to rotate the decal
          * @param angle sets the angle to rotate the decal
          * @returns a new Mesh
          * @returns a new Mesh
          */
          */
-        public static CreateDecal(name: string, sourceMesh: AbstractMesh, position: Vector3, normal: Vector3, size: Vector3, angle: number): Mesh {
-            var options = {
-                position: position,
-                normal: normal,
-                size: size,
-                angle: angle
-            };
-
-            return MeshBuilder.CreateDecal(name, sourceMesh, options);
+        public static CreateDecal = (name: string, sourceMesh: AbstractMesh, position: Vector3, normal: Vector3, size: Vector3, angle: number): Mesh => {
+            throw "Import MeshBuilder before creating meshes.";
         }
         }
 
 
         // Skeletons
         // Skeletons
@@ -3797,3 +3636,5 @@ import { PhysicsImpostor } from "Physics/physicsImpostor";
             }
             }
         }
         }
     }
     }
+
+//import { MeshBuilder } from "./meshBuilder";

+ 37 - 19
src/Mesh/mesh.vertexData.ts

@@ -1,8 +1,10 @@
 import { Nullable, FloatArray, IndicesArray } from "types";
 import { Nullable, FloatArray, IndicesArray } from "types";
 import { Matrix, Vector3, Vector2, Color3, Color4, Vector4, Axis, Epsilon } from "Math/math";
 import { Matrix, Vector3, Vector2, Color3, Color4, Vector4, Axis, Epsilon } from "Math/math";
-import { VertexBuffer } from "Mesh/vertexBuffer";
-import { Geometry } from "Mesh/geometry";
-import { Mesh } from "Mesh/mesh";
+import { VertexBuffer } from "Mesh/buffer";
+
+declare type Geometry = import("Mesh/geometry").Geometry;
+declare type Mesh = import("Mesh/mesh").Mesh;
+
     /**
     /**
      * Define an interface for all classes that will get and set the data on vertices
      * Define an interface for all classes that will get and set the data on vertices
      */
      */
@@ -69,6 +71,22 @@ import { Mesh } from "Mesh/mesh";
      * This class contains the various kinds of data on every vertex of a mesh used in determining its shape and appearance
      * This class contains the various kinds of data on every vertex of a mesh used in determining its shape and appearance
      */
      */
     export class VertexData {
     export class VertexData {
+        /**
+         * Mesh side orientation : usually the external or front surface
+         */
+        public static readonly FRONTSIDE = 0;
+        /**
+         * Mesh side orientation : usually the internal or back surface
+         */
+        public static readonly BACKSIDE = 1;
+        /**
+         * Mesh side orientation : both internal and external or front and back surfaces
+         */
+        public static readonly DOUBLESIDE = 2;
+        /**
+         * Mesh side orientation : by default, `FRONTSIDE`
+         */
+        public static readonly DEFAULTSIDE = 0;
 
 
         /**
         /**
          * An array of the x, y, z position of each vertex  [...., x, y, z, .....]
          * An array of the x, y, z position of each vertex  [...., x, y, z, .....]
@@ -758,7 +776,7 @@ import { Mesh } from "Mesh/mesh";
             var defaultOffset: number = Math.floor(pathArray[0].length / 2);
             var defaultOffset: number = Math.floor(pathArray[0].length / 2);
             var offset: number = options.offset || defaultOffset;
             var offset: number = options.offset || defaultOffset;
             offset = offset > defaultOffset ? defaultOffset : Math.floor(offset); // offset max allowed : defaultOffset
             offset = offset > defaultOffset ? defaultOffset : Math.floor(offset); // offset max allowed : defaultOffset
-            var sideOrientation: number = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation: number = (options.sideOrientation === 0) ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;
             var customUV = options.uvs;
             var customUV = options.uvs;
             var customColors = options.colors;
             var customColors = options.colors;
 
 
@@ -1012,7 +1030,7 @@ import { Mesh } from "Mesh/mesh";
             var width = options.width || options.size || 1;
             var width = options.width || options.size || 1;
             var height = options.height || options.size || 1;
             var height = options.height || options.size || 1;
             var depth = options.depth || options.size || 1;
             var depth = options.depth || options.size || 1;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;
             var faceUV: Vector4[] = options.faceUV || new Array<Vector4>(6);
             var faceUV: Vector4[] = options.faceUV || new Array<Vector4>(6);
             var faceColors = options.faceColors;
             var faceColors = options.faceColors;
             var colors = [];
             var colors = [];
@@ -1093,7 +1111,7 @@ import { Mesh } from "Mesh/mesh";
             vertexData.uvs = uvs;
             vertexData.uvs = uvs;
 
 
             if (faceColors) {
             if (faceColors) {
-                var totalColors = (sideOrientation === Mesh.DOUBLESIDE) ? colors.concat(colors) : colors;
+                var totalColors = (sideOrientation === VertexData.DOUBLESIDE) ? colors.concat(colors) : colors;
                 vertexData.colors = totalColors;
                 vertexData.colors = totalColors;
             }
             }
 
 
@@ -1122,7 +1140,7 @@ import { Mesh } from "Mesh/mesh";
             var diameterZ: number = options.diameterZ || options.diameter || 1;
             var diameterZ: number = options.diameterZ || options.diameter || 1;
             var arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
             var arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
             var slice: number = options.slice && (options.slice <= 0) ? 1.0 : options.slice || 1.0;
             var slice: number = options.slice && (options.slice <= 0) ? 1.0 : options.slice || 1.0;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;
 
 
             var radius = new Vector3(diameterX / 2, diameterY / 2, diameterZ / 2);
             var radius = new Vector3(diameterX / 2, diameterY / 2, diameterZ / 2);
 
 
@@ -1212,7 +1230,7 @@ import { Mesh } from "Mesh/mesh";
             var hasRings: boolean = options.hasRings ? true : false;
             var hasRings: boolean = options.hasRings ? true : false;
             var enclose: boolean = options.enclose ? true : false;
             var enclose: boolean = options.enclose ? true : false;
             var arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
             var arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
-            var sideOrientation: number = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation: number = (options.sideOrientation === 0) ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;
             var faceUV: Vector4[] = options.faceUV || new Array<Vector4>(3);
             var faceUV: Vector4[] = options.faceUV || new Array<Vector4>(3);
             var faceColors = options.faceColors;
             var faceColors = options.faceColors;
             // default face colors and UV if undefined
             // default face colors and UV if undefined
@@ -1474,7 +1492,7 @@ import { Mesh } from "Mesh/mesh";
             var diameter = options.diameter || 1;
             var diameter = options.diameter || 1;
             var thickness = options.thickness || 0.5;
             var thickness = options.thickness || 0.5;
             var tessellation = options.tessellation || 16;
             var tessellation = options.tessellation || 16;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;
 
 
             var stride = tessellation + 1;
             var stride = tessellation + 1;
 
 
@@ -1893,7 +1911,7 @@ import { Mesh } from "Mesh/mesh";
 
 
             var width: number = options.width || options.size || 1;
             var width: number = options.width || options.size || 1;
             var height: number = options.height || options.size || 1;
             var height: number = options.height || options.size || 1;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;
 
 
             // Vertices
             // Vertices
             var halfWidth = width / 2.0;
             var halfWidth = width / 2.0;
@@ -1958,7 +1976,7 @@ import { Mesh } from "Mesh/mesh";
             var radius = options.radius || 0.5;
             var radius = options.radius || 0.5;
             var tessellation = options.tessellation || 64;
             var tessellation = options.tessellation || 64;
             var arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
             var arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;
 
 
             // positions and uvs
             // positions and uvs
             positions.push(0, 0, 0);    // disc center first
             positions.push(0, 0, 0);    // disc center first
@@ -2065,7 +2083,7 @@ import { Mesh } from "Mesh/mesh";
             vertexData.uvs = uvs;
             vertexData.uvs = uvs;
 
 
             if (faceColors) {
             if (faceColors) {
-                var totalColors = (sideOrientation === Mesh.DOUBLESIDE) ? colors.concat(colors) : colors;
+                var totalColors = (sideOrientation === VertexData.DOUBLESIDE) ? colors.concat(colors) : colors;
                 vertexData.colors = totalColors;
                 vertexData.colors = totalColors;
             }
             }
 
 
@@ -2088,7 +2106,7 @@ import { Mesh } from "Mesh/mesh";
          * @returns the VertexData of the IcoSphere
          * @returns the VertexData of the IcoSphere
          */
          */
         public static CreateIcoSphere(options: { radius?: number, radiusX?: number, radiusY?: number, radiusZ?: number, flat?: boolean, subdivisions?: number, sideOrientation?: number, frontUVs?: Vector4, backUVs?: Vector4 }): VertexData {
         public static CreateIcoSphere(options: { radius?: number, radiusX?: number, radiusY?: number, radiusZ?: number, flat?: boolean, subdivisions?: number, sideOrientation?: number, frontUVs?: Vector4, backUVs?: Vector4 }): VertexData {
-            var sideOrientation = options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation = options.sideOrientation || VertexData.DEFAULTSIDE;
             var radius = options.radius || 1;
             var radius = options.radius || 1;
             var flat = (options.flat === undefined) ? true : options.flat;
             var flat = (options.flat === undefined) ? true : options.flat;
             var subdivisions = options.subdivisions || 4;
             var subdivisions = options.subdivisions || 4;
@@ -2408,7 +2426,7 @@ import { Mesh } from "Mesh/mesh";
             var faceUV = options.faceUV || new Array(nbfaces);
             var faceUV = options.faceUV || new Array(nbfaces);
             var faceColors = options.faceColors;
             var faceColors = options.faceColors;
             var flat = (options.flat === undefined) ? true : options.flat;
             var flat = (options.flat === undefined) ? true : options.flat;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;
 
 
             var positions = new Array<number>();
             var positions = new Array<number>();
             var indices = new Array<number>();
             var indices = new Array<number>();
@@ -2522,7 +2540,7 @@ import { Mesh } from "Mesh/mesh";
             var tubularSegments = options.tubularSegments || 32;
             var tubularSegments = options.tubularSegments || 32;
             var p = options.p || 2;
             var p = options.p || 2;
             var q = options.q || 3;
             var q = options.q || 3;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;
 
 
             // Helper
             // Helper
             var getPos = (angle: number) => {
             var getPos = (angle: number) => {
@@ -2834,15 +2852,15 @@ import { Mesh } from "Mesh/mesh";
             var ln: number = normals.length;
             var ln: number = normals.length;
             var i: number;
             var i: number;
             var n: number;
             var n: number;
-            sideOrientation = sideOrientation || Mesh.DEFAULTSIDE;
+            sideOrientation = sideOrientation || VertexData.DEFAULTSIDE;
 
 
             switch (sideOrientation) {
             switch (sideOrientation) {
 
 
-                case Mesh.FRONTSIDE:
+                case VertexData.FRONTSIDE:
                     // nothing changed
                     // nothing changed
                     break;
                     break;
 
 
-                case Mesh.BACKSIDE:
+                case VertexData.BACKSIDE:
                     var tmp: number;
                     var tmp: number;
                     // indices
                     // indices
                     for (i = 0; i < li; i += 3) {
                     for (i = 0; i < li; i += 3) {
@@ -2856,7 +2874,7 @@ import { Mesh } from "Mesh/mesh";
                     }
                     }
                     break;
                     break;
 
 
-                case Mesh.DOUBLESIDE:
+                case VertexData.DOUBLESIDE:
                     // positions
                     // positions
                     var lp: number = positions.length;
                     var lp: number = positions.length;
                     var l: number = lp / 3;
                     var l: number = lp / 3;

+ 269 - 1
src/Mesh/meshBuilder.ts

@@ -5,13 +5,281 @@ import { Scene } from "scene";
 import { Matrix, Vector3, Vector2, Color3, Color4, Plane, Tmp, Epsilon, Vector4, Axis, Path3D, PositionNormalVertex } from "Math/math";
 import { Matrix, Vector3, Vector2, Color3, Color4, Plane, Tmp, Epsilon, Vector4, Axis, Path3D, PositionNormalVertex } from "Math/math";
 import { Mesh, _CreationDataStorage } from "./mesh";
 import { Mesh, _CreationDataStorage } from "./mesh";
 import { AbstractMesh } from "./abstractMesh";
 import { AbstractMesh } from "./abstractMesh";
-import { VertexBuffer } from "./VertexBuffer";
+import { VertexBuffer } from "./buffer";
 import { LinesMesh } from "./linesMesh";
 import { LinesMesh } from "./linesMesh";
 import { VertexData } from "./mesh.vertexData";
 import { VertexData } from "./mesh.vertexData";
 import { GroundMesh } from "./groundMesh";
 import { GroundMesh } from "./groundMesh";
 import { PolygonMeshBuilder } from "./polygonMesh";
 import { PolygonMeshBuilder } from "./polygonMesh";
 import { BoundingInfo } from "Culling/boundingInfo";
 import { BoundingInfo } from "Culling/boundingInfo";
 
 
+Mesh.CreateRibbon = (name: string, pathArray: Vector3[][], closeArray: boolean = false, closePath: boolean, offset: number, scene?: Scene, updatable: boolean = false, sideOrientation?: number, instance?: Mesh) => {
+    return MeshBuilder.CreateRibbon(name, {
+        pathArray: pathArray,
+        closeArray: closeArray,
+        closePath: closePath,
+        offset: offset,
+        updatable: updatable,
+        sideOrientation: sideOrientation,
+        instance: instance
+    }, scene);
+};
+
+Mesh.CreateDisc = (name: string, radius: number, tessellation: number, scene: Nullable<Scene> = null, updatable?: boolean, sideOrientation?: number): Mesh => {
+    var options = {
+        radius: radius,
+        tessellation: tessellation,
+        sideOrientation: sideOrientation,
+        updatable: updatable
+    };
+
+    return MeshBuilder.CreateDisc(name, options, scene);
+};
+
+Mesh.CreateBox = (name: string, size: number, scene: Nullable<Scene> = null, updatable?: boolean, sideOrientation?: number): Mesh => {
+    var options = {
+        size: size,
+        sideOrientation: sideOrientation,
+        updatable: updatable
+    };
+
+    return MeshBuilder.CreateBox(name, options, scene);
+};
+
+Mesh.CreateSphere = (name: string, segments: number, diameter: number, scene?: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {
+    var options = {
+        segments: segments,
+        diameterX: diameter,
+        diameterY: diameter,
+        diameterZ: diameter,
+        sideOrientation: sideOrientation,
+        updatable: updatable
+    };
+
+    return MeshBuilder.CreateSphere(name, options, scene);
+};
+
+Mesh.CreateCylinder = (name: string, height: number, diameterTop: number, diameterBottom: number, tessellation: number, subdivisions: any, scene?: Scene, updatable?: any, sideOrientation?: number): Mesh => {
+    if (scene === undefined || !(scene instanceof Scene)) {
+        if (scene !== undefined) {
+            sideOrientation = updatable || Mesh.DEFAULTSIDE;
+            updatable = scene;
+        }
+        scene = <Scene>subdivisions;
+        subdivisions = 1;
+    }
+
+    var options = {
+        height: height,
+        diameterTop: diameterTop,
+        diameterBottom: diameterBottom,
+        tessellation: tessellation,
+        subdivisions: subdivisions,
+        sideOrientation: sideOrientation,
+        updatable: updatable
+    };
+
+    return MeshBuilder.CreateCylinder(name, options, scene);
+};
+
+Mesh.CreateTorus = (name: string, diameter: number, thickness: number, tessellation: number, scene?: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {
+    var options = {
+        diameter: diameter,
+        thickness: thickness,
+        tessellation: tessellation,
+        sideOrientation: sideOrientation,
+        updatable: updatable
+    };
+
+    return MeshBuilder.CreateTorus(name, options, scene);
+};
+
+Mesh.CreateTorusKnot = (name: string, radius: number, tube: number, radialSegments: number, tubularSegments: number, p: number, q: number, scene?: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {
+    var options = {
+        radius: radius,
+        tube: tube,
+        radialSegments: radialSegments,
+        tubularSegments: tubularSegments,
+        p: p,
+        q: q,
+        sideOrientation: sideOrientation,
+        updatable: updatable
+    };
+
+    return MeshBuilder.CreateTorusKnot(name, options, scene);
+};
+
+Mesh.CreateLines = (name: string, points: Vector3[], scene: Nullable<Scene> = null, updatable: boolean = false, instance: Nullable<LinesMesh> = null): LinesMesh => {
+    var options = {
+        points: points,
+        updatable: updatable,
+        instance: instance
+    };
+    return MeshBuilder.CreateLines(name, options, scene);
+};
+
+Mesh.CreateDashedLines = (name: string, points: Vector3[], dashSize: number, gapSize: number, dashNb: number, scene: Nullable<Scene> = null, updatable?: boolean, instance?: LinesMesh): LinesMesh => {
+    var options = {
+        points: points,
+        dashSize: dashSize,
+        gapSize: gapSize,
+        dashNb: dashNb,
+        updatable: updatable,
+        instance: instance
+    };
+    return MeshBuilder.CreateDashedLines(name, options, scene);
+};
+
+Mesh.CreatePolygon = (name: string, shape: Vector3[], scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number): Mesh => {
+    var options = {
+        shape: shape,
+        holes: holes,
+        updatable: updatable,
+        sideOrientation: sideOrientation
+    };
+    return MeshBuilder.CreatePolygon(name, options, scene);
+};
+
+Mesh.ExtrudePolygon = (name: string, shape: Vector3[], depth: number, scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number): Mesh => {
+    var options = {
+        shape: shape,
+        holes: holes,
+        depth: depth,
+        updatable: updatable,
+        sideOrientation: sideOrientation
+    };
+    return MeshBuilder.ExtrudePolygon(name, options, scene);
+};
+
+Mesh.ExtrudeShape = (name: string, shape: Vector3[], path: Vector3[], scale: number, rotation: number, cap: number, scene: Nullable<Scene> = null, updatable?: boolean, sideOrientation?: number, instance?: Mesh): Mesh => {
+    var options = {
+        shape: shape,
+        path: path,
+        scale: scale,
+        rotation: rotation,
+        cap: (cap === 0) ? 0 : cap || Mesh.NO_CAP,
+        sideOrientation: sideOrientation,
+        instance: instance,
+        updatable: updatable
+    };
+
+    return MeshBuilder.ExtrudeShape(name, options, scene);
+};
+
+Mesh.ExtrudeShapeCustom = (name: string, shape: Vector3[], path: Vector3[], scaleFunction: Function, rotationFunction: Function, ribbonCloseArray: boolean, ribbonClosePath: boolean, cap: number, scene: Scene, updatable?: boolean, sideOrientation?: number, instance?: Mesh): Mesh => {
+    var options = {
+        shape: shape,
+        path: path,
+        scaleFunction: scaleFunction,
+        rotationFunction: rotationFunction,
+        ribbonCloseArray: ribbonCloseArray,
+        ribbonClosePath: ribbonClosePath,
+        cap: (cap === 0) ? 0 : cap || Mesh.NO_CAP,
+        sideOrientation: sideOrientation,
+        instance: instance,
+        updatable: updatable
+    };
+
+    return MeshBuilder.ExtrudeShapeCustom(name, options, scene);
+};
+
+Mesh.CreateLathe = (name: string, shape: Vector3[], radius: number, tessellation: number, scene: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {
+    var options = {
+        shape: shape,
+        radius: radius,
+        tessellation: tessellation,
+        sideOrientation: sideOrientation,
+        updatable: updatable
+    };
+
+    return MeshBuilder.CreateLathe(name, options, scene);
+};
+
+Mesh.CreatePlane = (name: string, size: number, scene: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {
+    var options = {
+        size: size,
+        width: size,
+        height: size,
+        sideOrientation: sideOrientation,
+        updatable: updatable
+    };
+
+    return MeshBuilder.CreatePlane(name, options, scene);
+};
+
+Mesh.CreateGround = (name: string, width: number, height: number, subdivisions: number, scene?: Scene, updatable?: boolean): Mesh => {
+    var options = {
+        width: width,
+        height: height,
+        subdivisions: subdivisions,
+        updatable: updatable
+    };
+
+    return MeshBuilder.CreateGround(name, options, scene);
+};
+
+Mesh.CreateTiledGround = (name: string, xmin: number, zmin: number, xmax: number, zmax: number, subdivisions: { w: number; h: number; }, precision: { w: number; h: number; }, scene: Scene, updatable?: boolean): Mesh => {
+    var options = {
+        xmin: xmin,
+        zmin: zmin,
+        xmax: xmax,
+        zmax: zmax,
+        subdivisions: subdivisions,
+        precision: precision,
+        updatable: updatable
+    };
+
+    return MeshBuilder.CreateTiledGround(name, options, scene);
+};
+
+Mesh.CreateGroundFromHeightMap = (name: string, url: string, width: number, height: number, subdivisions: number, minHeight: number, maxHeight: number, scene: Scene, updatable?: boolean, onReady?: (mesh: GroundMesh) => void, alphaFilter?: number): GroundMesh => {
+    var options = {
+        width: width,
+        height: height,
+        subdivisions: subdivisions,
+        minHeight: minHeight,
+        maxHeight: maxHeight,
+        updatable: updatable,
+        onReady: onReady,
+        alphaFilter: alphaFilter
+    };
+
+    return MeshBuilder.CreateGroundFromHeightMap(name, url, options, scene);
+};
+
+Mesh.CreateTube = (name: string, path: Vector3[], radius: number, tessellation: number, radiusFunction: { (i: number, distance: number): number; }, cap: number, scene: Scene, updatable?: boolean, sideOrientation?: number, instance?: Mesh): Mesh => {
+    var options = {
+        path: path,
+        radius: radius,
+        tessellation: tessellation,
+        radiusFunction: radiusFunction,
+        arc: 1,
+        cap: cap,
+        updatable: updatable,
+        sideOrientation: sideOrientation,
+        instance: instance
+    };
+    return MeshBuilder.CreateTube(name, options, scene);
+};
+
+Mesh.CreatePolyhedron = (name: string, options: { type?: number, size?: number, sizeX?: number, sizeY?: number, sizeZ?: number, custom?: any, faceUV?: Vector4[], faceColors?: Color4[], updatable?: boolean, sideOrientation?: number }, scene: Scene): Mesh => {
+    return MeshBuilder.CreatePolyhedron(name, options, scene);
+};
+
+Mesh.CreateIcoSphere = (name: string, options: { radius?: number, flat?: boolean, subdivisions?: number, sideOrientation?: number, updatable?: boolean }, scene: Scene): Mesh => {
+    return MeshBuilder.CreateIcoSphere(name, options, scene);
+};
+
+Mesh.CreateDecal = (name: string, sourceMesh: AbstractMesh, position: Vector3, normal: Vector3, size: Vector3, angle: number): Mesh => {
+    var options = {
+        position: position,
+        normal: normal,
+        size: size,
+        angle: angle
+    };
+
+    return MeshBuilder.CreateDecal(name, sourceMesh, options);
+};
+
     /**
     /**
      * Class containing static functions to help procedurally build meshes
      * Class containing static functions to help procedurally build meshes
      */
      */

+ 0 - 19
src/Mesh/meshLODLevel.ts

@@ -1,19 +0,0 @@
-import { Nullable } from "types";
-import { Mesh } from "Mesh/mesh";
-    /**
-     * Class used to represent a specific level of detail of a mesh
-     * @see http://doc.babylonjs.com/how_to/how_to_use_lod
-     */
-    export class MeshLODLevel {
-        /**
-         * Creates a new LOD level
-         * @param distance defines the distance where this level should star being displayed
-         * @param mesh defines the mesh to use to render this level
-         */
-        constructor(
-            /** Defines the distance where this level should star being displayed */
-            public distance: number,
-            /** Defines the mesh to use to render this level */
-            public mesh: Nullable<Mesh>) {
-        }
-    }

+ 1 - 1
src/Mesh/meshSimplification.ts

@@ -1,6 +1,6 @@
 import { IndicesArray } from "types";
 import { IndicesArray } from "types";
 import { Vector3, Epsilon } from "Math/math";
 import { Vector3, Epsilon } from "Math/math";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";
 import { AsyncLoop } from "Tools/tools";
 import { AsyncLoop } from "Tools/tools";

+ 1 - 1
src/Mesh/polygonMesh.ts

@@ -1,7 +1,7 @@
 import { Tools } from "Tools/tools";
 import { Tools } from "Tools/tools";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Vector3, Vector2, Path2 } from "Math/math";
 import { Vector3, Vector2, Path2 } from "Math/math";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";
 
 
     declare var earcut: any;
     declare var earcut: any;

+ 12 - 12
src/Mesh/subMesh.ts

@@ -2,17 +2,19 @@ import { Tools } from "Tools/tools";
 import { Nullable, IndicesArray } from "types";
 import { Nullable, IndicesArray } from "types";
 import { Matrix, Vector3, Plane } from "Math/math";
 import { Matrix, Vector3, Plane } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
-import { Mesh } from "./mesh";
-import { AbstractMesh } from "./abstractMesh";
-import { LinesMesh } from "./linesMesh";
-import { VertexBuffer } from "./vertexBuffer";
+import { VertexBuffer } from "./buffer";
 import { Collider } from "Collisions/collider";
 import { Collider } from "Collisions/collider";
 import { IntersectionInfo } from "Collisions/pickingInfo";
 import { IntersectionInfo } from "Collisions/pickingInfo";
 import { Ray } from "Culling/ray";
 import { Ray } from "Culling/ray";
 import { ICullable, BoundingInfo } from "Culling/boundingInfo";
 import { ICullable, BoundingInfo } from "Culling/boundingInfo";
 import { Effect } from "Materials/effect";
 import { Effect } from "Materials/effect";
-import { Material, MaterialDefines } from "Materials/material";
+import { Material } from "Materials/material";
+import { MaterialDefines } from "Materials/materialDefines";
 import { MultiMaterial } from "Materials/multiMaterial";
 import { MultiMaterial } from "Materials/multiMaterial";
+
+declare type AbstractMesh = import("./abstractMesh").AbstractMesh;
+declare type Mesh = import("./mesh").Mesh;
+
     /**
     /**
      * Base class for submeshes
      * Base class for submeshes
      */
      */
@@ -357,10 +359,8 @@ import { MultiMaterial } from "Materials/multiMaterial";
             }
             }
 
 
             // LineMesh first as it's also a Mesh...
             // LineMesh first as it's also a Mesh...
-            if (LinesMesh) {
-                if (this._mesh.getClassName() === "InstancedLinesMesh" || this._mesh.getClassName() === "LinesMesh") {
-                    return this._intersectLines(ray, positions, indices, (this._mesh as any).intersectionThreshold, fastCheck);
-                }
+            if (this._mesh.getClassName() === "InstancedLinesMesh" || this._mesh.getClassName() === "LinesMesh") {
+                return this._intersectLines(ray, positions, indices, (this._mesh as any).intersectionThreshold, fastCheck);
             }
             }
 
 
             return this._intersectTriangles(ray, positions, indices, fastCheck);
             return this._intersectTriangles(ray, positions, indices, fastCheck);
@@ -488,8 +488,8 @@ import { MultiMaterial } from "Materials/multiMaterial";
             var minVertexIndex = Number.MAX_VALUE;
             var minVertexIndex = Number.MAX_VALUE;
             var maxVertexIndex = -Number.MAX_VALUE;
             var maxVertexIndex = -Number.MAX_VALUE;
 
 
-            renderingMesh = (<Mesh>(renderingMesh || <Mesh>mesh));
-            var indices = <IndicesArray>renderingMesh.getIndices();
+            const whatWillRender = (renderingMesh || mesh);
+            var indices = whatWillRender!.getIndices()!;
 
 
             for (var index = startIndex; index < startIndex + indexCount; index++) {
             for (var index = startIndex; index < startIndex + indexCount; index++) {
                 var vertexIndex = indices[index];
                 var vertexIndex = indices[index];
@@ -504,4 +504,4 @@ import { MultiMaterial } from "Materials/multiMaterial";
 
 
             return new SubMesh(materialIndex, minVertexIndex, maxVertexIndex - minVertexIndex + 1, startIndex, indexCount, mesh, renderingMesh);
             return new SubMesh(materialIndex, minVertexIndex, maxVertexIndex - minVertexIndex + 1, startIndex, indexCount, mesh, renderingMesh);
         }
         }
-    }
+    }

+ 0 - 462
src/Mesh/vertexBuffer.ts

@@ -1,462 +0,0 @@
-import { Nullable, DataArray } from "types";
-import { Buffer } from "./buffer";
-    /**
-     * Specialized buffer used to store vertex data
-     */
-    export class VertexBuffer {
-        /** @hidden */
-        public _buffer: Buffer;
-        private _kind: string;
-        private _size: number;
-        private _ownsBuffer: boolean;
-        private _instanced: boolean;
-        private _instanceDivisor: number;
-
-        /**
-         * The byte type.
-         */
-        public static readonly BYTE = 5120;
-
-        /**
-         * The unsigned byte type.
-         */
-        public static readonly UNSIGNED_BYTE = 5121;
-
-        /**
-         * The short type.
-         */
-        public static readonly SHORT = 5122;
-
-        /**
-         * The unsigned short type.
-         */
-        public static readonly UNSIGNED_SHORT = 5123;
-
-        /**
-         * The integer type.
-         */
-        public static readonly INT = 5124;
-
-        /**
-         * The unsigned integer type.
-         */
-        public static readonly UNSIGNED_INT = 5125;
-
-        /**
-         * The float type.
-         */
-        public static readonly FLOAT = 5126;
-
-        /**
-         * Gets or sets the instance divisor when in instanced mode
-         */
-        public get instanceDivisor(): number {
-            return this._instanceDivisor;
-        }
-
-        public set instanceDivisor(value: number) {
-            this._instanceDivisor = value;
-            if (value == 0) {
-                this._instanced = false;
-            } else {
-                this._instanced = true;
-            }
-        }
-
-        /**
-         * Gets the byte stride.
-         */
-        public readonly byteStride: number;
-
-        /**
-         * Gets the byte offset.
-         */
-        public readonly byteOffset: number;
-
-        /**
-         * Gets whether integer data values should be normalized into a certain range when being casted to a float.
-         */
-        public readonly normalized: boolean;
-
-        /**
-         * Gets the data type of each component in the array.
-         */
-        public readonly type: number;
-
-        /**
-         * Constructor
-         * @param engine the engine
-         * @param data the data to use for this vertex buffer
-         * @param kind the vertex buffer kind
-         * @param updatable whether the data is updatable
-         * @param postponeInternalCreation whether to postpone creating the internal WebGL buffer (optional)
-         * @param stride the stride (optional)
-         * @param instanced whether the buffer is instanced (optional)
-         * @param offset the offset of the data (optional)
-         * @param size the number of components (optional)
-         * @param type the type of the component (optional)
-         * @param normalized whether the data contains normalized data (optional)
-         * @param useBytes set to true if stride and offset are in bytes (optional)
-         */
-        constructor(engine: any, data: DataArray | Buffer, kind: string, updatable: boolean, postponeInternalCreation?: boolean, stride?: number, instanced?: boolean, offset?: number, size?: number, type?: number, normalized = false, useBytes = false) {
-            if (data instanceof Buffer) {
-                this._buffer = data;
-                this._ownsBuffer = false;
-            } else {
-                this._buffer = new Buffer(engine, data, updatable, stride, postponeInternalCreation, instanced, useBytes);
-                this._ownsBuffer = true;
-            }
-
-            this._kind = kind;
-
-            if (type == undefined) {
-                const data = this.getData();
-                this.type = VertexBuffer.FLOAT;
-                if (data instanceof Int8Array) { this.type = VertexBuffer.BYTE; }
-                else if (data instanceof Uint8Array) { this.type = VertexBuffer.UNSIGNED_BYTE; }
-                else if (data instanceof Int16Array) { this.type = VertexBuffer.SHORT; }
-                else if (data instanceof Uint16Array) { this.type = VertexBuffer.UNSIGNED_SHORT; }
-                else if (data instanceof Int32Array) { this.type = VertexBuffer.INT; }
-                else if (data instanceof Uint32Array) { this.type = VertexBuffer.UNSIGNED_INT; }
-            }
-            else {
-                this.type = type;
-            }
-
-            const typeByteLength = VertexBuffer.GetTypeByteLength(this.type);
-
-            if (useBytes) {
-                this._size = size || (stride ? (stride / typeByteLength) : VertexBuffer.DeduceStride(kind));
-                this.byteStride = stride || this._buffer.byteStride || (this._size * typeByteLength);
-                this.byteOffset = offset || 0;
-            }
-            else {
-                this._size = size || stride || VertexBuffer.DeduceStride(kind);
-                this.byteStride = stride ? (stride * typeByteLength) : (this._buffer.byteStride || (this._size * typeByteLength));
-                this.byteOffset = (offset || 0) * typeByteLength;
-            }
-
-            this.normalized = normalized;
-
-            this._instanced = instanced !== undefined ? instanced : false;
-            this._instanceDivisor = instanced ? 1 : 0;
-        }
-
-        /** @hidden */
-        public _rebuild(): void {
-            if (!this._buffer) {
-                return;
-            }
-
-            this._buffer._rebuild();
-        }
-
-        /**
-         * Returns the kind of the VertexBuffer (string)
-         * @returns a string
-         */
-        public getKind(): string {
-            return this._kind;
-        }
-
-        // Properties
-
-        /**
-         * Gets a boolean indicating if the VertexBuffer is updatable?
-         * @returns true if the buffer is updatable
-         */
-        public isUpdatable(): boolean {
-            return this._buffer.isUpdatable();
-        }
-
-        /**
-         * Gets current buffer's data
-         * @returns a DataArray or null
-         */
-        public getData(): Nullable<DataArray> {
-            return this._buffer.getData();
-        }
-
-        /**
-         * Gets underlying native buffer
-         * @returns underlying native buffer
-         */
-        public getBuffer(): Nullable<WebGLBuffer> {
-            return this._buffer.getBuffer();
-        }
-
-        /**
-         * Gets the stride in float32 units (i.e. byte stride / 4).
-         * May not be an integer if the byte stride is not divisible by 4.
-         * DEPRECATED. Use byteStride instead.
-         * @returns the stride in float32 units
-         */
-        public getStrideSize(): number {
-            return this.byteStride / VertexBuffer.GetTypeByteLength(this.type);
-        }
-
-        /**
-         * Returns the offset as a multiple of the type byte length.
-         * DEPRECATED. Use byteOffset instead.
-         * @returns the offset in bytes
-         */
-        public getOffset(): number {
-            return this.byteOffset / VertexBuffer.GetTypeByteLength(this.type);
-        }
-
-        /**
-         * Returns the number of components per vertex attribute (integer)
-         * @returns the size in float
-         */
-        public getSize(): number {
-            return this._size;
-        }
-
-        /**
-         * Gets a boolean indicating is the internal buffer of the VertexBuffer is instanced
-         * @returns true if this buffer is instanced
-         */
-        public getIsInstanced(): boolean {
-            return this._instanced;
-        }
-
-        /**
-         * Returns the instancing divisor, zero for non-instanced (integer).
-         * @returns a number
-         */
-        public getInstanceDivisor(): number {
-            return this._instanceDivisor;
-        }
-
-        // Methods
-
-        /**
-         * Store data into the buffer. If the buffer was already used it will be either recreated or updated depending on isUpdatable property
-         * @param data defines the data to store
-         */
-        public create(data?: DataArray): void {
-            this._buffer.create(data);
-        }
-
-        /**
-         * Updates the underlying buffer according to the passed numeric array or Float32Array.
-         * This function will create a new buffer if the current one is not updatable
-         * @param data defines the data to store
-         */
-        public update(data: DataArray): void {
-            this._buffer.update(data);
-        }
-
-        /**
-         * Updates directly the underlying WebGLBuffer according to the passed numeric array or Float32Array.
-         * Returns the directly updated WebGLBuffer.
-         * @param data the new data
-         * @param offset the new offset
-         * @param useBytes set to true if the offset is in bytes
-         */
-        public updateDirectly(data: DataArray, offset: number, useBytes: boolean = false): void {
-            this._buffer.updateDirectly(data, offset, undefined, useBytes);
-        }
-
-        /**
-         * Disposes the VertexBuffer and the underlying WebGLBuffer.
-         */
-        public dispose(): void {
-            if (this._ownsBuffer) {
-                this._buffer.dispose();
-            }
-        }
-
-        /**
-         * Enumerates each value of this vertex buffer as numbers.
-         * @param count the number of values to enumerate
-         * @param callback the callback function called for each value
-         */
-        public forEach(count: number, callback: (value: number, index: number) => void): void {
-            VertexBuffer.ForEach(this._buffer.getData()!, this.byteOffset, this.byteStride, this._size, this.type, count, this.normalized, callback);
-        }
-
-        // Enums
-        /**
-         * Positions
-         */
-        public static readonly PositionKind = "position";
-        /**
-         * Normals
-         */
-        public static readonly NormalKind = "normal";
-        /**
-         * Tangents
-         */
-        public static readonly TangentKind = "tangent";
-        /**
-         * Texture coordinates
-         */
-        public static readonly UVKind = "uv";
-        /**
-         * Texture coordinates 2
-         */
-        public static readonly UV2Kind = "uv2";
-        /**
-         * Texture coordinates 3
-         */
-        public static readonly UV3Kind = "uv3";
-        /**
-         * Texture coordinates 4
-         */
-        public static readonly UV4Kind = "uv4";
-        /**
-         * Texture coordinates 5
-         */
-        public static readonly UV5Kind = "uv5";
-        /**
-         * Texture coordinates 6
-         */
-        public static readonly UV6Kind = "uv6";
-        /**
-         * Colors
-         */
-        public static readonly ColorKind = "color";
-        /**
-         * Matrix indices (for bones)
-         */
-        public static readonly MatricesIndicesKind = "matricesIndices";
-        /**
-         * Matrix weights (for bones)
-         */
-        public static readonly MatricesWeightsKind = "matricesWeights";
-        /**
-         * Additional matrix indices (for bones)
-         */
-        public static readonly MatricesIndicesExtraKind = "matricesIndicesExtra";
-        /**
-         * Additional matrix weights (for bones)
-         */
-        public static readonly MatricesWeightsExtraKind = "matricesWeightsExtra";
-
-        /**
-         * Deduces the stride given a kind.
-         * @param kind The kind string to deduce
-         * @returns The deduced stride
-         */
-        public static DeduceStride(kind: string): number {
-            switch (kind) {
-                case VertexBuffer.UVKind:
-                case VertexBuffer.UV2Kind:
-                case VertexBuffer.UV3Kind:
-                case VertexBuffer.UV4Kind:
-                case VertexBuffer.UV5Kind:
-                case VertexBuffer.UV6Kind:
-                    return 2;
-                case VertexBuffer.NormalKind:
-                case VertexBuffer.PositionKind:
-                    return 3;
-                case VertexBuffer.ColorKind:
-                case VertexBuffer.MatricesIndicesKind:
-                case VertexBuffer.MatricesIndicesExtraKind:
-                case VertexBuffer.MatricesWeightsKind:
-                case VertexBuffer.MatricesWeightsExtraKind:
-                case VertexBuffer.TangentKind:
-                    return 4;
-                default:
-                    throw new Error("Invalid kind '" + kind + "'");
-            }
-        }
-
-        /**
-         * Gets the byte length of the given type.
-         * @param type the type
-         * @returns the number of bytes
-         */
-        public static GetTypeByteLength(type: number): number {
-            switch (type) {
-                case VertexBuffer.BYTE:
-                case VertexBuffer.UNSIGNED_BYTE:
-                    return 1;
-                case VertexBuffer.SHORT:
-                case VertexBuffer.UNSIGNED_SHORT:
-                    return 2;
-                case VertexBuffer.INT:
-                case VertexBuffer.FLOAT:
-                    return 4;
-                default:
-                    throw new Error(`Invalid type '${type}'`);
-            }
-        }
-
-        /**
-         * Enumerates each value of the given parameters as numbers.
-         * @param data the data to enumerate
-         * @param byteOffset the byte offset of the data
-         * @param byteStride the byte stride of the data
-         * @param componentCount the number of components per element
-         * @param componentType the type of the component
-         * @param count the total number of components
-         * @param normalized whether the data is normalized
-         * @param callback the callback function called for each value
-         */
-        public static ForEach(data: DataArray, byteOffset: number, byteStride: number, componentCount: number, componentType: number, count: number, normalized: boolean, callback: (value: number, index: number) => void): void {
-            if (data instanceof Array) {
-                let offset = byteOffset / 4;
-                const stride = byteStride / 4;
-                for (let index = 0; index < count; index += componentCount) {
-                    for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {
-                        callback(data[offset + componentIndex], index + componentIndex);
-                    }
-                    offset += stride;
-                }
-            }
-            else {
-                const dataView = data instanceof ArrayBuffer ? new DataView(data) : new DataView(data.buffer, data.byteOffset, data.byteLength);
-                const componentByteLength = VertexBuffer.GetTypeByteLength(componentType);
-                for (let index = 0; index < count; index += componentCount) {
-                    let componentByteOffset = byteOffset;
-                    for (let componentIndex = 0; componentIndex < componentCount; componentIndex++) {
-                        const value = VertexBuffer._GetFloatValue(dataView, componentType, componentByteOffset, normalized);
-                        callback(value, index + componentIndex);
-                        componentByteOffset += componentByteLength;
-                    }
-                    byteOffset += byteStride;
-                }
-            }
-        }
-
-        private static _GetFloatValue(dataView: DataView, type: number, byteOffset: number, normalized: boolean): number {
-            switch (type) {
-                case VertexBuffer.BYTE: {
-                    let value = dataView.getInt8(byteOffset);
-                    if (normalized) {
-                        value = Math.max(value / 127, -1);
-                    }
-                    return value;
-                }
-                case VertexBuffer.UNSIGNED_BYTE: {
-                    let value = dataView.getUint8(byteOffset);
-                    if (normalized) {
-                        value = value / 255;
-                    }
-                    return value;
-                }
-                case VertexBuffer.SHORT: {
-                    let value = dataView.getInt16(byteOffset, true);
-                    if (normalized) {
-                        value = Math.max(value / 16383, -1);
-                    }
-                    return value;
-                }
-                case VertexBuffer.UNSIGNED_SHORT: {
-                    let value = dataView.getUint16(byteOffset, true);
-                    if (normalized) {
-                        value = value / 65535;
-                    }
-                    return value;
-                }
-                case VertexBuffer.FLOAT: {
-                    return dataView.getFloat32(byteOffset, true);
-                }
-                default: {
-                    throw new Error(`Invalid component type ${type}`);
-                }
-            }
-        }
-    }

+ 1 - 1
src/Morph/morphTarget.ts

@@ -4,7 +4,7 @@ import { Nullable, FloatArray } from "types";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { Animation } from "Animations/animation";
 import { Animation } from "Animations/animation";
 import { AnimationPropertiesOverride } from "Animations/animationPropertiesOverride";
 import { AnimationPropertiesOverride } from "Animations/animationPropertiesOverride";
     /**
     /**

+ 1 - 1
src/Particles/gpuParticleSystem.ts

@@ -3,7 +3,7 @@ import { IAnimatable, Tools, IValueGradient, ColorGradient, FactorGradient, Colo
 import { Observable } from "Tools/observable";
 import { Observable } from "Tools/observable";
 import { Color4, Color3, Vector3, Matrix, Tmp } from "Math/math";
 import { Color4, Color3, Vector3, Matrix, Tmp } from "Math/math";
 import { Scalar } from "Math/math.scalar";
 import { Scalar } from "Math/math.scalar";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { Buffer } from "Mesh/buffer";
 import { Buffer } from "Mesh/buffer";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { IParticleSystem } from "./IParticleSystem";
 import { IParticleSystem } from "./IParticleSystem";

+ 1 - 1
src/Particles/particleSystem.ts

@@ -3,7 +3,7 @@ import { IAnimatable, Tools, FactorGradient, ColorGradient, Color3Gradient } fro
 import { Observable, Observer } from "Tools/observable";
 import { Observable, Observer } from "Tools/observable";
 import { Color4, Color3, Vector3, Matrix, Tmp, ISize, Vector4 } from "Math/math";
 import { Color4, Color3, Vector3, Matrix, Tmp, ISize, Vector4 } from "Math/math";
 import { Scalar } from "Math/math.scalar";
 import { Scalar } from "Math/math.scalar";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { Buffer } from "Mesh/buffer";
 import { Buffer } from "Mesh/buffer";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { Material } from "Materials/material";
 import { Material } from "Materials/material";

+ 1 - 1
src/Particles/solidParticleSystem.ts

@@ -1,6 +1,6 @@
 import { Nullable, IndicesArray, FloatArray } from "types";
 import { Nullable, IndicesArray, FloatArray } from "types";
 import { Color4, Vector3, Matrix, Tmp, Quaternion, Axis } from "Math/math";
 import { Color4, Vector3, Matrix, Tmp, Quaternion, Axis } from "Math/math";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { VertexData } from "Mesh/mesh.vertexData";
 import { VertexData } from "Mesh/mesh.vertexData";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";
 import { MeshBuilder } from "Mesh/meshBuilder";
 import { MeshBuilder } from "Mesh/meshBuilder";

+ 1 - 1
src/Physics/Plugins/cannonJSPlugin.ts

@@ -1,7 +1,7 @@
 import { Nullable, FloatArray } from "types";
 import { Nullable, FloatArray } from "types";
 import { Tools } from "Tools/tools";
 import { Tools } from "Tools/tools";
 import { Vector3, Matrix, Quaternion } from "Math/math";
 import { Vector3, Matrix, Quaternion } from "Math/math";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { IPhysicsEnginePlugin, PhysicsImpostor, PhysicsImpostorJoint, PhysicsJoint, DistanceJointData, SpringJointData, PhysicsEngine, IPhysicsEnabledObject, IMotorEnabledJoint } from "Physics";
 import { IPhysicsEnginePlugin, PhysicsImpostor, PhysicsImpostorJoint, PhysicsJoint, DistanceJointData, SpringJointData, PhysicsEngine, IPhysicsEnabledObject, IMotorEnabledJoint } from "Physics";
 
 

+ 1 - 1
src/PostProcess/postProcessManager.ts

@@ -4,7 +4,7 @@ import { InternalTexture } from "Materials/Textures/internalTexture";
 import { PostProcess } from "./postProcess";
 import { PostProcess } from "./postProcess";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
 import { Scene } from "scene";
 import { Scene } from "scene";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
     /**
     /**
 	 * PostProcessManager is used to manage one or more post processes or post process pipelines
 	 * PostProcessManager is used to manage one or more post processes or post process pipelines
      * See https://doc.babylonjs.com/how_to/how_to_use_postprocesses
      * See https://doc.babylonjs.com/how_to/how_to_use_postprocesses

+ 1 - 1
src/PostProcess/volumetricLightScatteringPostProcess.ts

@@ -2,7 +2,7 @@ import { serializeAsVector3, serialize, serializeAsMeshReference } from "Tools/d
 import { SmartArray } from "Tools/smartArray";
 import { SmartArray } from "Tools/smartArray";
 import { Tools } from "Tools/tools";
 import { Tools } from "Tools/tools";
 import { Color4, Color3, Vector2, Vector3, Matrix, Viewport } from "Math/math";
 import { Color4, Color3, Vector2, Vector3, Matrix, Viewport } from "Math/math";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";

+ 1 - 1
src/Rendering/boundingBoxRenderer.ts

@@ -1,5 +1,5 @@
 import { Scene } from "scene";
 import { Scene } from "scene";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { VertexData } from "Mesh/mesh.vertexData";
 import { VertexData } from "Mesh/mesh.vertexData";

+ 1 - 1
src/Rendering/depthRenderer.ts

@@ -1,7 +1,7 @@
 import { Nullable } from "types";
 import { Nullable } from "types";
 import { Color4 } from "Math/math";
 import { Color4 } from "Math/math";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SmartArray } from "Tools/smartArray";
 import { SmartArray } from "Tools/smartArray";
 import { Scene } from "scene";
 import { Scene } from "scene";
 import { Texture } from "Materials/Textures/texture";
 import { Texture } from "Materials/Textures/texture";

+ 1 - 1
src/Rendering/edgesRenderer.ts

@@ -1,5 +1,5 @@
 import { Nullable } from "types";
 import { Nullable } from "types";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { LinesMesh, InstancedLinesMesh } from "Mesh/linesMesh";
 import { LinesMesh, InstancedLinesMesh } from "Mesh/linesMesh";
 import { Vector3 } from "Math/math";
 import { Vector3 } from "Math/math";

+ 1 - 1
src/Rendering/geometryBufferRenderer.ts

@@ -1,5 +1,5 @@
 import { Matrix, Color4 } from "Math/math";
 import { Matrix, Color4 } from "Math/math";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { Mesh } from "Mesh/mesh";
 import { Mesh } from "Mesh/mesh";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";

+ 1 - 1
src/Rendering/lineEdgesRenderer.ts

@@ -1,4 +1,4 @@
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { Tmp, Vector3 } from "Math/math";
 import { Tmp, Vector3 } from "Math/math";
 import { EdgesRenderer } from "./edgesRenderer";
 import { EdgesRenderer } from "./edgesRenderer";

+ 1 - 1
src/Rendering/outlineRenderer.ts

@@ -1,4 +1,4 @@
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { SubMesh } from "Mesh/subMesh";
 import { SubMesh } from "Mesh/subMesh";
 import { _InstancesBatch } from "Mesh/mesh";
 import { _InstancesBatch } from "Mesh/mesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";

+ 1 - 1
src/Sprites/spriteManager.ts

@@ -2,7 +2,7 @@ import { IDisposable, Scene } from "scene";
 import { Nullable } from "types";
 import { Nullable } from "types";
 import { Observable, Observer } from "Tools/observable";
 import { Observable, Observer } from "Tools/observable";
 import { Buffer } from "Mesh/buffer";
 import { Buffer } from "Mesh/buffer";
-import { VertexBuffer } from "Mesh/vertexBuffer";
+import { VertexBuffer } from "Mesh/buffer";
 import { Vector3 } from "Math/math";
 import { Vector3 } from "Math/math";
 import { Sprite } from "./sprite";
 import { Sprite } from "./sprite";
 import { SpriteSceneComponent } from "./spriteSceneComponent";
 import { SpriteSceneComponent } from "./spriteSceneComponent";

+ 32 - 11
src/Tools/decorators.ts

@@ -1,12 +1,14 @@
-import { Tags } from ".";
+import { Tags } from "Tools/tags";
 import { Nullable } from "types";
 import { Nullable } from "types";
 import { Color4, Quaternion, Color3, Vector2, Vector3 } from "Math/math";
 import { Color4, Quaternion, Color3, Vector2, Vector3 } from "Math/math";
-import { ImageProcessingConfiguration } from "Materials/imageProcessingConfiguration";
-import { Camera } from "Cameras/camera";
-import { Scene } from "scene";
-import { Texture } from "Materials/Textures/texture";
-import { FresnelParameters } from "Materials/fresnelParameters";
-import { ColorCurves } from "Materials/colorCurves";
+
+declare type Scene = import("scene").Scene;
+declare type Camera = import("Cameras/camera").Camera;
+
+declare type ImageProcessingConfiguration = import("Materials/imageProcessingConfiguration").ImageProcessingConfiguration;
+declare type FresnelParameters = import("Materials/fresnelParameters").FresnelParameters;
+declare type ColorCurves = import("Materials/colorCurves").ColorCurves;
+declare type BaseTexture = import("Materials/Textures/baseTexture").BaseTexture;
 
 
     var __decoratorInitialStore = {};
     var __decoratorInitialStore = {};
     var __mergedStore = {};
     var __mergedStore = {};
@@ -204,6 +206,25 @@ import { ColorCurves } from "Materials/colorCurves";
      * Class used to help serialization objects
      * Class used to help serialization objects
      */
      */
     export class SerializationHelper {
     export class SerializationHelper {
+        /** hidden */
+        public static _ImageProcessingConfigurationParser = (sourceProperty: any): ImageProcessingConfiguration => {
+            throw "ImageProcessingConfiguration needs to be imported before being deserialized.";
+        }
+
+        /** hidden */
+        public static _FresnelParametersParser = (sourceProperty: any): FresnelParameters => {
+            throw "FresnelParameters needs to be imported before being deserialized.";
+        }
+
+        /** hidden */
+        public static _ColorCurvesParser = (sourceProperty: any): ColorCurves => {
+            throw "ColorCurves needs to be imported before being deserialized.";
+        }
+
+        /** hidden */
+        public static _TextureParser = (sourceProperty: any, scene: Scene, rootUrl: string): Nullable<BaseTexture> => {
+            throw "Texture needs to be imported before being deserialized.";
+        }
 
 
         /**
         /**
          * Static function used to serialized a specific entity
          * Static function used to serialized a specific entity
@@ -311,14 +332,14 @@ import { ColorCurves } from "Materials/colorCurves";
                             break;
                             break;
                         case 1:     // Texture
                         case 1:     // Texture
                             if (scene) {
                             if (scene) {
-                                dest[property] = Texture.Parse(sourceProperty, scene, rootUrl);
+                                dest[property] = SerializationHelper._TextureParser(sourceProperty, scene, rootUrl);
                             }
                             }
                             break;
                             break;
                         case 2:     // Color3
                         case 2:     // Color3
                             dest[property] = Color3.FromArray(sourceProperty);
                             dest[property] = Color3.FromArray(sourceProperty);
                             break;
                             break;
                         case 3:     // FresnelParameters
                         case 3:     // FresnelParameters
-                            dest[property] = FresnelParameters.Parse(sourceProperty);
+                            dest[property] = SerializationHelper._FresnelParametersParser(sourceProperty);
                             break;
                             break;
                         case 4:     // Vector2
                         case 4:     // Vector2
                             dest[property] = Vector2.FromArray(sourceProperty);
                             dest[property] = Vector2.FromArray(sourceProperty);
@@ -332,13 +353,13 @@ import { ColorCurves } from "Materials/colorCurves";
                             }
                             }
                             break;
                             break;
                         case 7:     // Color Curves
                         case 7:     // Color Curves
-                            dest[property] = ColorCurves.Parse(sourceProperty);
+                            dest[property] = SerializationHelper._ColorCurvesParser(sourceProperty);
                             break;
                             break;
                         case 8:     // Color 4
                         case 8:     // Color 4
                             dest[property] = Color4.FromArray(sourceProperty);
                             dest[property] = Color4.FromArray(sourceProperty);
                             break;
                             break;
                         case 9:     // Image Processing
                         case 9:     // Image Processing
-                            dest[property] = ImageProcessingConfiguration.Parse(sourceProperty);
+                            dest[property] = SerializationHelper._ImageProcessingConfigurationParser(sourceProperty);
                             break;
                             break;
                         case 10:    // Quaternion
                         case 10:    // Quaternion
                             dest[property] = Quaternion.FromArray(sourceProperty);
                             dest[property] = Quaternion.FromArray(sourceProperty);

+ 4 - 3
src/node.ts

@@ -5,11 +5,12 @@ import { Scene } from "scene";
 import { Nullable } from "types";
 import { Nullable } from "types";
 import { Matrix } from "Math/math";
 import { Matrix } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
-import { AbstractMesh } from "Mesh/abstractMesh";
 import { IBehaviorAware, Behavior } from "Behaviors/behavior";
 import { IBehaviorAware, Behavior } from "Behaviors/behavior";
 import { serialize } from "Tools/decorators";
 import { serialize } from "Tools/decorators";
 import { Observable, Observer } from "Tools/observable";
 import { Observable, Observer } from "Tools/observable";
 
 
+declare type AbstractMesh = import("Mesh/abstractMesh").AbstractMesh;
+
     /**
     /**
      * Defines how a node can be built from a string name.
      * Defines how a node can be built from a string name.
      */
      */
@@ -538,7 +539,7 @@ import { Observable, Observer } from "Tools/observable";
         public getChildMeshes(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): AbstractMesh[] {
         public getChildMeshes(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): AbstractMesh[] {
             var results: Array<AbstractMesh> = [];
             var results: Array<AbstractMesh> = [];
             this._getDescendants(results, directDescendantsOnly, (node: Node) => {
             this._getDescendants(results, directDescendantsOnly, (node: Node) => {
-                return ((!predicate || predicate(node)) && (node instanceof AbstractMesh));
+                return ((!predicate || predicate(node)) && ((<AbstractMesh>node).cullingStrategy !== undefined));
             });
             });
             return results;
             return results;
         }
         }
@@ -724,4 +725,4 @@ import { Observable, Observer } from "Tools/observable";
                 }
                 }
             }
             }
         }
         }
-    }
+    }