فهرست منبع

merge coreteam -> simon ferquel

Simon Ferquel 10 سال پیش
والد
کامیت
e9ccf03110
29فایلهای تغییر یافته به همراه565 افزوده شده و 198 حذف شده
  1. 4 4
      Babylon/Actions/babylon.actionManager.ts
  2. 10 11
      Babylon/Debug/babylon.debugLayer.js
  3. 1 1
      Babylon/Debug/babylon.debugLayer.js.map
  4. 10 12
      Babylon/Debug/babylon.debugLayer.ts
  5. 4 0
      Babylon/Lights/babylon.directionalLight.ts
  6. 4 0
      Babylon/Lights/babylon.light.ts
  7. 4 0
      Babylon/Lights/babylon.pointLight.ts
  8. 5 0
      Babylon/Lights/babylon.spotLight.ts
  9. 3 0
      Babylon/Loading/Plugins/babylon.babylonFileLoader.ts
  10. 48 0
      Babylon/Mesh/babylon.mesh.ts
  11. 8 8
      Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderEffect.ts
  12. 4 4
      Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPipeline.ts
  13. 2 2
      Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPipelineManager.ts
  14. 79 0
      Babylon/Tools/babylon.sceneOptimizer.ts
  15. 4 4
      Babylon/babylon.scene.js
  16. 4 4
      Babylon/babylon.scene.ts
  17. 3 0
      Exporters/3ds Max/BabylonExport.Entities/BabylonCamera.cs
  18. 24 25
      Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Camera.cs
  19. 23 23
      Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs
  20. 15 39
      Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Skeleton.cs
  21. 57 18
      Exporters/3ds Max/Max2Babylon/Forms/CameraPropertiesForm.Designer.cs
  22. 5 0
      Exporters/3ds Max/Max2Babylon/Forms/CameraPropertiesForm.cs
  23. 35 0
      Exporters/3ds Max/Max2Babylon/Tools/Tools.cs
  24. 4 0
      Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/babylonJS.xml
  25. 5 1
      Tools/Gulp/gulpfile.js
  26. 173 25
      babylon.2.0-alpha.debug.js
  27. 13 13
      babylon.2.0-alpha.js
  28. 13 4
      babylon.2.0.d.ts
  29. 1 0
      readme.md

+ 4 - 4
Babylon/Actions/babylon.actionManager.ts

@@ -2,15 +2,15 @@
 
     export class ActionEvent {
         constructor(public source: AbstractMesh, public pointerX: number, public pointerY: number, public meshUnderPointer: AbstractMesh, public sourceEvent?: any) {
-            
+
         }
 
-        public static CreateNew(source: AbstractMesh): ActionEvent {
+        public static CreateNew(source: AbstractMesh, evt?: Event): ActionEvent {
             var scene = source.getScene();
-            return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer);
+            return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt);
         }
 
-        public static CreateNewFromScene(scene: Scene, evt:Event): ActionEvent {
+        public static CreateNewFromScene(scene: Scene, evt: Event): ActionEvent {
             return new ActionEvent(null, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt);
         }
     }

+ 10 - 11
Babylon/Debug/babylon.debugLayer.js

@@ -38,7 +38,7 @@
                     _this._treeDiv.style.top = "10px";
                     _this._treeDiv.style.width = "300px";
                     _this._treeDiv.style.height = "auto";
-                    _this._treeSubsetDiv.style.maxHeight = (canvasRect.height - 420) + "px";
+                    _this._treeSubsetDiv.style.maxHeight = (canvasRect.height - 490) + "px";
                 }
 
                 _this._globalDiv.style.left = canvasRect.left + "px";
@@ -132,7 +132,7 @@
                             continue;
                         }
 
-                        projectedPosition = BABYLON.Vector3.Project(camera.position, _this._identityMatrix, _this._scene.getTransformMatrix(), globalViewport);
+                        projectedPosition = BABYLON.Vector3.Project(BABYLON.Vector3.Zero(), camera.getWorldMatrix(), _this._scene.getTransformMatrix(), globalViewport);
 
                         if (!_this.shouldDisplayLabel || _this.shouldDisplayLabel(camera)) {
                             _this._renderLabel(camera.name, projectedPosition, 12, function () {
@@ -151,7 +151,7 @@
                         var light = lights[index];
 
                         if (light.position) {
-                            projectedPosition = BABYLON.Vector3.Project(light.position, _this._identityMatrix, _this._scene.getTransformMatrix(), globalViewport);
+                            projectedPosition = BABYLON.Vector3.Project(light.getAbsolutePosition(), _this._identityMatrix, _this._scene.getTransformMatrix(), globalViewport);
 
                             if (!_this.shouldDisplayLabel || _this.shouldDisplayLabel(light)) {
                                 _this._renderLabel(light.name, projectedPosition, -20, function () {
@@ -329,8 +329,6 @@
 
             var engine = this._scene.getEngine();
 
-            this._scene.registerAfterRender(this._syncData);
-
             this._globalDiv = document.createElement("div");
 
             document.body.appendChild(this._globalDiv);
@@ -341,6 +339,7 @@
             engine.getRenderingCanvas().addEventListener("click", this._onCanvasClick);
 
             this._syncPositions();
+            this._scene.registerAfterRender(this._syncData);
         };
 
         DebugLayer.prototype._clearLabels = function () {
@@ -395,6 +394,7 @@
 
             leftPart.innerHTML = leftTitle;
             rightPart.innerHTML = rightTitle;
+            rightPart.style.maxWidth = "200px";
 
             container.appendChild(leftPart);
             container.appendChild(rightPart);
@@ -444,6 +444,11 @@
         DebugLayer.prototype._generateDOMelements = function () {
             var _this = this;
             this._globalDiv.id = "DebugLayer";
+            this._globalDiv.style.position = "absolute";
+
+            this._globalDiv.style.fontFamily = "Segoe UI, Arial";
+            this._globalDiv.style.fontSize = "14px";
+            this._globalDiv.style.color = "white";
 
             // Drawing canvas
             this._drawingCanvas = document.createElement("canvas");
@@ -639,16 +644,10 @@
                     _this._scene.texturesEnabled = element.checked;
                 });
 
-                // Global
-                this._globalDiv.style.position = "absolute";
                 this._globalDiv.appendChild(this._statsDiv);
                 this._globalDiv.appendChild(this._logDiv);
                 this._globalDiv.appendChild(this._optionsDiv);
                 this._globalDiv.appendChild(this._treeDiv);
-
-                this._globalDiv.style.fontFamily = "Segoe UI, Arial";
-                this._globalDiv.style.fontSize = "14px";
-                this._globalDiv.style.color = "white";
             }
         };
 

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
Babylon/Debug/babylon.debugLayer.js.map


+ 10 - 12
Babylon/Debug/babylon.debugLayer.ts

@@ -64,7 +64,7 @@
                     this._treeDiv.style.top = "10px";
                     this._treeDiv.style.width = "300px";
                     this._treeDiv.style.height = "auto";
-                    this._treeSubsetDiv.style.maxHeight = (canvasRect.height - 420) + "px";
+                    this._treeSubsetDiv.style.maxHeight = (canvasRect.height - 490) + "px";
                 }
 
                 this._globalDiv.style.left = canvasRect.left + "px";
@@ -161,7 +161,7 @@
                             continue;
                         }
 
-                        projectedPosition = Vector3.Project(camera.position, this._identityMatrix, this._scene.getTransformMatrix(), globalViewport);
+                        projectedPosition = Vector3.Project(Vector3.Zero(), camera.getWorldMatrix(), this._scene.getTransformMatrix(), globalViewport);
 
                         if (!this.shouldDisplayLabel || this.shouldDisplayLabel(camera)) {
                             this._renderLabel(camera.name, projectedPosition, 12,
@@ -181,7 +181,7 @@
 
                         if (light.position) {
 
-                            projectedPosition = Vector3.Project(light.position, this._identityMatrix, this._scene.getTransformMatrix(), globalViewport);
+                            projectedPosition = Vector3.Project(light.getAbsolutePosition(), this._identityMatrix, this._scene.getTransformMatrix(), globalViewport);
 
                             if (!this.shouldDisplayLabel || this.shouldDisplayLabel(light)) {
                                 this._renderLabel(light.name, projectedPosition, -20,
@@ -360,8 +360,6 @@
 
             var engine = this._scene.getEngine();
 
-            this._scene.registerAfterRender(this._syncData);
-
             this._globalDiv = document.createElement("div");
 
             document.body.appendChild(this._globalDiv);
@@ -372,6 +370,7 @@
             engine.getRenderingCanvas().addEventListener("click", this._onCanvasClick);
 
             this._syncPositions();
+            this._scene.registerAfterRender(this._syncData);
         }
 
         private _clearLabels(): void {
@@ -425,6 +424,7 @@
 
             leftPart.innerHTML = leftTitle;
             rightPart.innerHTML = rightTitle;
+            rightPart.style.maxWidth = "200px";
 
             container.appendChild(leftPart);
             container.appendChild(rightPart);
@@ -471,6 +471,11 @@
 
         private _generateDOMelements(): void {
             this._globalDiv.id = "DebugLayer";
+            this._globalDiv.style.position = "absolute";
+
+            this._globalDiv.style.fontFamily = "Segoe UI, Arial";
+            this._globalDiv.style.fontSize = "14px";
+            this._globalDiv.style.color = "white";
 
             // Drawing canvas
             this._drawingCanvas = document.createElement("canvas");
@@ -621,17 +626,10 @@
                 this._generateCheckBox(this._optionsSubsetDiv, "Skeletons", this._scene.skeletonsEnabled, (element) => { this._scene.skeletonsEnabled = element.checked });
                 this._generateCheckBox(this._optionsSubsetDiv, "Textures", this._scene.texturesEnabled, (element) => { this._scene.texturesEnabled = element.checked });
 
-                // Global
-
-                this._globalDiv.style.position = "absolute";
                 this._globalDiv.appendChild(this._statsDiv);
                 this._globalDiv.appendChild(this._logDiv);
                 this._globalDiv.appendChild(this._optionsDiv);
                 this._globalDiv.appendChild(this._treeDiv);
-
-                this._globalDiv.style.fontFamily = "Segoe UI, Arial";
-                this._globalDiv.style.fontSize = "14px";
-                this._globalDiv.style.color = "white";
             }
         }
 

+ 4 - 0
Babylon/Lights/babylon.directionalLight.ts

@@ -12,6 +12,10 @@
             this.position = direction.scale(-1);
         }
 
+        public getAbsolutePosition(): Vector3 {
+            return this._transformedPosition ? this._transformedPosition : this.position;
+        }
+
         public setDirectionToTarget(target: Vector3): Vector3 {
             this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
             return this.direction;

+ 4 - 0
Babylon/Lights/babylon.light.ts

@@ -22,6 +22,10 @@
             return this._shadowGenerator;
         }
 
+        public getAbsolutePosition(): Vector3 {
+            return Vector3.Zero();
+        }
+
         public transferToEffect(effect: Effect, uniformName0?: string, uniformName1?: string): void {
         }
 

+ 4 - 0
Babylon/Lights/babylon.pointLight.ts

@@ -7,6 +7,10 @@
             super(name, scene);
         }
 
+        public getAbsolutePosition(): Vector3 {
+            return this._transformedPosition ? this._transformedPosition : this.position;
+        }
+
         public transferToEffect(effect: Effect, positionUniformName: string): void {
             if (this.parent && this.parent.getWorldMatrix) {
                 if (!this._transformedPosition) {

+ 5 - 0
Babylon/Lights/babylon.spotLight.ts

@@ -9,6 +9,10 @@
             super(name, scene);
         }
 
+        public getAbsolutePosition(): Vector3 {
+            return this._transformedPosition ? this._transformedPosition : this.position;
+        }
+
         public setDirectionToTarget(target: Vector3): Vector3 {
             this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
             return this.direction;
@@ -21,6 +25,7 @@
                 if (!this._transformedDirection) {
                     this._transformedDirection = BABYLON.Vector3.Zero();
                 }
+
                 if (!this._transformedPosition) {
                     this._transformedPosition = BABYLON.Vector3.Zero();
                 }

+ 3 - 0
Babylon/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -412,6 +412,9 @@
         } else if (parsedCamera.type === "OculusCamera") {
             camera = new OculusCamera(parsedCamera.name, position, scene);
 
+        } else if (parsedCamera.type === "OculusGamepadCamera") {
+            camera = new OculusGamepadCamera(parsedCamera.name, position, scene);
+
         } else if (parsedCamera.type === "TouchCamera") {
             camera = new TouchCamera(parsedCamera.name, position, scene);
 

+ 48 - 0
Babylon/Mesh/babylon.mesh.ts

@@ -1148,5 +1148,53 @@
             var minMaxVector = meshesOrMinMaxVector.min !== undefined ? meshesOrMinMaxVector : BABYLON.Mesh.MinMax(meshesOrMinMaxVector);
             return BABYLON.Vector3.Center(minMaxVector.min, minMaxVector.max);
         }
+
+        public static MergeMeshes(meshes: Array<Mesh>, disposeSource = true, allow32BitsIndices?: boolean): Mesh {
+            var source = meshes[0];
+            var material = source.material;
+            var scene = source.getScene();
+            
+            if (!allow32BitsIndices) {
+                var totalVertices = 0;
+
+                // Counting vertices
+                for (var index = 0; index < meshes.length; index++) {
+                    totalVertices += meshes[index].getTotalVertices();
+
+                    if (totalVertices > 65536) {
+                        Tools.Warn("Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices");
+                        return null;
+                    }
+                }
+            }
+
+            // Merge
+            var vertexData = VertexData.ExtractFromMesh(source);
+            vertexData.transform(source.getWorldMatrix());
+
+            for (index = 1; index < meshes.length; index++) {
+                var otherVertexData = VertexData.ExtractFromMesh(meshes[index]);
+                otherVertexData.transform(meshes[index].getWorldMatrix());
+
+                vertexData.merge(otherVertexData);
+            }
+
+            var newMesh = new Mesh(source.name + "_merged", scene);
+
+            vertexData.applyToMesh(newMesh);
+
+            // Setting properties
+            newMesh.material = material;
+            newMesh.checkCollisions = source.checkCollisions;
+
+            // Cleaning
+            if (disposeSource) {
+                for (index = 0; index < meshes.length; index++) {
+                    meshes[index].dispose();
+                }
+            }
+
+            return newMesh;
+        }
     }
 } 

+ 8 - 8
Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderEffect.ts

@@ -2,7 +2,7 @@ module BABYLON {
     export class PostProcessRenderEffect {
         private _engine: Engine;
 
-        private _postProcesses: PostProcess[];
+        private _postProcesses: any;
         private _getPostProcess: () => PostProcess;
 
         private _singleInstance: boolean;
@@ -10,8 +10,8 @@ module BABYLON {
         private _cameras: Camera[];
         private _indicesForCamera: number[][];
 
-        private _renderPasses: PostProcessRenderPass[];
-        private _renderEffectAsPasses: PostProcessRenderEffect[];
+        private _renderPasses: any;
+        private _renderEffectAsPasses: any;
 
         // private
         public _name: string;
@@ -26,12 +26,12 @@ module BABYLON {
             this._getPostProcess = getPostProcess;
 
             this._cameras = [];
-
-            this._postProcesses = [];
             this._indicesForCamera = [];
 
-            this._renderPasses = [];
-            this._renderEffectAsPasses = [];
+            this._postProcesses = {};
+
+            this._renderPasses = {};
+            this._renderEffectAsPasses = {};
         }
 
         public _update(): void {
@@ -67,7 +67,7 @@ module BABYLON {
         }
 
         public emptyPasses(): void {
-            this._renderPasses.length = 0;
+            this._renderPasses = {};
 
             this._linkParameters();
         }

+ 4 - 4
Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPipeline.ts

@@ -2,8 +2,8 @@ module BABYLON {
     export class PostProcessRenderPipeline {
         private _engine: Engine;
 
-        private _renderEffects: PostProcessRenderEffect[];
-        private _renderEffectsForIsolatedPass: PostProcessRenderEffect[];
+        private _renderEffects: any;
+        private _renderEffectsForIsolatedPass: any;
 
         private _cameras: Camera[];
 
@@ -17,8 +17,8 @@ module BABYLON {
             this._engine = engine;
             this._name = name;
 
-            this._renderEffects = [];
-            this._renderEffectsForIsolatedPass = [];
+            this._renderEffects = {};
+            this._renderEffectsForIsolatedPass = {};
 
             this._cameras = [];
         }

+ 2 - 2
Babylon/PostProcess/RenderPipeline/babylon.postProcessRenderPipelineManager.ts

@@ -1,9 +1,9 @@
 module BABYLON {
     export class PostProcessRenderPipelineManager {
-        private _renderPipelines: Array<PostProcessRenderPipeline>;
+        private _renderPipelines: any;
 
         constructor() {
-            this._renderPipelines = new Array<PostProcessRenderPipeline>();
+            this._renderPipelines = {};
         }
 
         public addPipeline(renderPipeline: PostProcessRenderPipeline): void {

+ 79 - 0
Babylon/Tools/babylon.sceneOptimizer.ts

@@ -88,6 +88,82 @@
         };
     }
 
+    export class MergeMeshesOptimization extends SceneOptimization {
+
+        private _canBeMerged = (abstractMesh: AbstractMesh): boolean => {
+            if (!(abstractMesh instanceof Mesh)) {
+                return false;
+            }
+
+            var mesh = <Mesh>abstractMesh;
+
+            if (!mesh.isVisible || !mesh.isEnabled()) {
+                return false;
+            }
+
+            if (mesh.instances.length > 0) {
+                return false;
+            }
+
+            if (mesh.skeleton || mesh.hasLODLevels) {
+                return false;
+            }
+
+            return true;
+        }
+
+        public apply = (scene: Scene): boolean => {
+
+            var globalPool = scene.meshes.slice(0);
+            var globalLength = globalPool.length;
+
+            for (var index = 0; index < globalLength; index++) {
+                var currentPool = new Array<Mesh>();
+                var current = globalPool[index];
+
+                // Checks
+                if (!this._canBeMerged(current)) {
+                    continue;
+                }
+
+                currentPool.push(<Mesh>current);
+
+                // Find compatible meshes
+                for (var subIndex = index + 1; subIndex < globalLength; subIndex++) {
+                    var otherMesh = globalPool[subIndex];
+
+                    if (!this._canBeMerged(otherMesh)) {
+                        continue;
+                    }
+
+                    if (otherMesh.material !== current.material) {
+                        continue;
+                    }
+
+                    if (otherMesh.checkCollisions !== current.checkCollisions) {
+                        continue;
+                    }
+
+                    currentPool.push(<Mesh>otherMesh);
+                    globalLength--;
+
+                    globalPool.splice(subIndex, 1);
+
+                    subIndex--;
+                }
+
+                if (currentPool.length < 2) {
+                    continue;
+                }
+
+                // Merge meshes
+                Mesh.MergeMeshes(currentPool);
+            }
+
+            return true;
+        };
+    }
+
     // Options
     export class SceneOptimizerOptions {
         public optimizations = new Array<SceneOptimization>();
@@ -99,6 +175,7 @@
             var result = new SceneOptimizerOptions(targetFrameRate);
 
             var priority = 0;
+            result.optimizations.push(new MergeMeshesOptimization(priority));
             result.optimizations.push(new ShadowsOptimization(priority));
             result.optimizations.push(new LensFlaresOptimization(priority));
 
@@ -118,6 +195,7 @@
             var result = new SceneOptimizerOptions(targetFrameRate);
 
             var priority = 0;
+            result.optimizations.push(new MergeMeshesOptimization(priority));
             result.optimizations.push(new ShadowsOptimization(priority));
             result.optimizations.push(new LensFlaresOptimization(priority));
 
@@ -145,6 +223,7 @@
             var result = new SceneOptimizerOptions(targetFrameRate);
 
             var priority = 0;
+            result.optimizations.push(new MergeMeshesOptimization(priority));
             result.optimizations.push(new ShadowsOptimization(priority));
             result.optimizations.push(new LensFlaresOptimization(priority));
 

+ 4 - 4
Babylon/babylon.scene.js

@@ -265,16 +265,16 @@
                     if (pickResult.pickedMesh.actionManager) {
                         switch (evt.button) {
                             case 0:
-                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
                                 break;
                             case 1:
-                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
                                 break;
                             case 2:
-                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
                                 break;
                         }
-                        pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
+                        pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
                     }
                 }
 

+ 4 - 4
Babylon/babylon.scene.ts

@@ -344,16 +344,16 @@
                     if (pickResult.pickedMesh.actionManager) {
                         switch (evt.button) {
                             case 0:
-                                pickResult.pickedMesh.actionManager.processTrigger(ActionManager.OnLeftPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh));
+                                pickResult.pickedMesh.actionManager.processTrigger(ActionManager.OnLeftPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh, evt));
                                 break;
                             case 1:
-                                pickResult.pickedMesh.actionManager.processTrigger(ActionManager.OnCenterPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh));
+                                pickResult.pickedMesh.actionManager.processTrigger(ActionManager.OnCenterPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh, evt));
                                 break;
                             case 2:
-                                pickResult.pickedMesh.actionManager.processTrigger(ActionManager.OnRightPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh));
+                                pickResult.pickedMesh.actionManager.processTrigger(ActionManager.OnRightPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh,evt));
                                 break;
                         }
-                        pickResult.pickedMesh.actionManager.processTrigger(ActionManager.OnPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh));
+                        pickResult.pickedMesh.actionManager.processTrigger(ActionManager.OnPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh,evt));
                     }
                 }
 

+ 3 - 0
Exporters/3ds Max/BabylonExport.Entities/BabylonCamera.cs

@@ -18,6 +18,9 @@ namespace BabylonExport.Entities
         public string lockedTargetId { get; set; }
 
         [DataMember]
+        public string type { get; set; }
+
+        [DataMember]
         public float[] position { get; set; }
 
         [DataMember]

+ 24 - 25
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Camera.cs

@@ -8,7 +8,6 @@ namespace Max2Babylon
     {
         private void ExportCamera(IIGameNode cameraNode, BabylonScene babylonScene)
         {
-
             if (cameraNode.MaxNode.GetBoolProperty("babylonjs_noexport"))
             {
                 return;
@@ -35,8 +34,8 @@ namespace Max2Babylon
             }
             else
             {
-                 babylonCamera.minZ = 0.1f;
-                 babylonCamera.maxZ = 10000.0f;
+                babylonCamera.minZ = 0.1f;
+                babylonCamera.maxZ = 10000.0f;
             }
 
             if (babylonCamera.minZ == 0.0f)
@@ -44,6 +43,9 @@ namespace Max2Babylon
                 babylonCamera.minZ = 0.1f;
             }
 
+            // Type
+            babylonCamera.type = cameraNode.MaxNode.GetStringProperty("babylonjs_type", "FreeCamera");
+
             // Control
             babylonCamera.speed = cameraNode.MaxNode.GetFloatProperty("babylonjs_speed", 1.0f);
             babylonCamera.inertia = cameraNode.MaxNode.GetFloatProperty("babylonjs_inertia", 0.9f);
@@ -54,43 +56,40 @@ namespace Max2Babylon
             babylonCamera.ellipsoid = cameraNode.MaxNode.GetVector3Property("babylonjs_ellipsoid");
 
             // Position
-            {
-                var wm = cameraNode.GetLocalTM(0);
-                var position = wm.Translation;
-                babylonCamera.position = new float[] { position.X, position.Y, position.Z };
+            var wm = cameraNode.GetLocalTM(0);
+            var position = wm.Translation;
+            babylonCamera.position = new float[] { position.X, position.Y, position.Z };
 
             // Target
-                var target = gameCamera.CameraTarget;
+            var target = gameCamera.CameraTarget;
             if (target != null)
             {
-                    babylonCamera.lockedTargetId = target.MaxNode.GetGuid().ToString();
+                babylonCamera.lockedTargetId = target.MaxNode.GetGuid().ToString();
             }
             else
             {
-                    var dir = wm.GetRow(3);
-                    babylonCamera.target = new float[] { position.X - dir.X, position.Y - dir.Y, position.Z - dir.Z };
-                }
+                var dir = wm.GetRow(3);
+                babylonCamera.target = new float[] { position.X - dir.X, position.Y - dir.Y, position.Z - dir.Z };
             }
 
             // Animations
             var animations = new List<BabylonAnimation>();
-            //if (!ExportVector3Controller(cameraNode.TMController.PositionController, "position", animations))
-            //{
-                ExportVector3Animation("position", animations, key =>
-                {
-                    var wm = cameraNode.GetLocalTM(key);
-                    var position = wm.Translation;
-                    return  new float[] { position.X, position.Y, position.Z };
-                });
-            //}
+
+            ExportVector3Animation("position", animations, key =>
+            {
+                var tm = cameraNode.GetLocalTM(key);
+                var translation = tm.Translation;
+                return new float[] { translation.X, translation.Y, translation.Z };
+            });
+
             if (gameCamera.CameraTarget == null)
             {
                 ExportVector3Animation("target", animations, key =>
                 {
-                    var wm = cameraNode.GetLocalTM(key);
-                    var position = wm.Translation;
-                    var dir = wm.GetRow(3);
-                    return new float[] { position.X - dir.X, position.Y - dir.Y, position.Z - dir.Z };
+                    var tm = cameraNode.GetLocalTM(key);
+                    var translation = tm.Translation;
+                    var dir = tm.GetRow(3);
+                    return new float[] { translation.X - dir.X, translation.Y - dir.Y, translation.Z - dir.Z };
                 });
             }
 

+ 23 - 23
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs

@@ -206,13 +206,13 @@ namespace Max2Babylon
                     IntPtr indexer = new IntPtr(i);
                     var channelNum = mappingChannels[indexer];
                     if (channelNum == 1)
-                    {
+                {
                         hasUV = true;
-                    }
+                }
                     else if (channelNum == 2)
-                    {
+                {
                         hasUV2 = true;
-                    }
+                }
                 }
                 var hasColor = unskinnedMesh.NumberOfColorVerts > 0;
                 var hasAlpha = unskinnedMesh.GetNumberOfMapVerts(-2) > 0;
@@ -232,7 +232,7 @@ namespace Max2Babylon
                 var subMeshes = new List<BabylonSubMesh>();
                 var indexStart = 0;
 
-
+                
                 for (int i = 0; i < multiMatsCount; ++i)
                 {
                     if (meshNode.NodeMaterial == null)
@@ -269,7 +269,7 @@ namespace Max2Babylon
                             ExtractFace(skin, unskinnedMesh, vertices, indices, hasUV, hasUV2, hasColor, hasAlpha, verticesAlreadyExported, ref indexCount, ref minVertexIndex, ref maxVertexIndex, face, boneIds);
                         }
                     }
-
+                    
                     if (indexCount != 0)
                     {
 
@@ -379,7 +379,7 @@ namespace Max2Babylon
             // Animations
             var animations = new List<BabylonAnimation>();
             GenerateCoordinatesAnimations(meshNode, animations);
-
+            
 
             if (!ExportFloatController(meshNode.MaxNode.VisController, "visibility", animations))
             {
@@ -444,10 +444,10 @@ namespace Max2Babylon
         }
 
         public static void GenerateCoordinatesAnimations(IIGameNode meshNode, List<BabylonAnimation> animations)
-        {
-
-            ExportVector3Animation("position", animations, key =>
             {
+
+                ExportVector3Animation("position", animations, key =>
+                {
                 var worldMatrix = meshNode.GetObjectTM(key);
                 if (meshNode.NodeParent != null)
                 {
@@ -456,12 +456,12 @@ namespace Max2Babylon
                 }
                 var trans = worldMatrix.Translation;
                 return new float[] { trans.X, trans.Y, trans.Z };
-            });
+                });
 
 
-            ExportQuaternionAnimation("rotationQuaternion", animations, key =>
-            {
-                var worldMatrix = meshNode.GetObjectTM(key);
+                ExportQuaternionAnimation("rotationQuaternion", animations, key =>
+                {
+                    var worldMatrix = meshNode.GetObjectTM(key);
                 if (meshNode.NodeParent != null)
                 {
                     var parentWorld = meshNode.NodeParent.GetObjectTM(key);
@@ -469,23 +469,23 @@ namespace Max2Babylon
                 }
 
 
-                var rot = worldMatrix.Rotation;
-                return new float[] { rot.X, rot.Y, rot.Z, -rot.W };
-            });
+                    var rot = worldMatrix.Rotation;
+                    return new float[] { rot.X, rot.Y, rot.Z, -rot.W };
+                });
 
 
-            ExportVector3Animation("scaling", animations, key =>
-            {
-                var worldMatrix = meshNode.GetObjectTM(key);
+                ExportVector3Animation("scaling", animations, key =>
+                {
+                    var worldMatrix = meshNode.GetObjectTM(key);
                 if (meshNode.NodeParent != null)
                 {
                     var parentWorld = meshNode.NodeParent.GetObjectTM(key);
                     worldMatrix.MultiplyBy(parentWorld.Inverse);
                 }
-                var scale = worldMatrix.Scaling;
+                    var scale = worldMatrix.Scaling;
 
-                return new float[] { scale.X, scale.Y, scale.Z };
-            });
+                    return new float[] { scale.X, scale.Y, scale.Z };
+                });
 
         }
 

+ 15 - 39
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Skeleton.cs

@@ -22,58 +22,37 @@ namespace Max2Babylon
             mat3.NoScale();
             return Loader.Global.GMatrix.Create(mat3);
         }
-        private void ExportSkin( IIGameSkin skin, BabylonScene babylonScene)
+        private void ExportSkin(IIGameSkin skin, BabylonScene babylonScene)
         {
             var babylonSkeleton = new BabylonSkeleton { id = skins.IndexOf(skin) };
             babylonSkeleton.name = "skeleton #" + babylonSkeleton.id;
 
             RaiseMessage(babylonSkeleton.name, 1);
-            IGMatrix skinInitMatrix = Loader.Global.GMatrix.Create(Loader.Global.Matrix3.Create(true));
-            skin.GetInitSkinTM(skinInitMatrix);
+
             var skinIndex = skins.IndexOf(skin);
             var meshNode = skinnedNodes[skinIndex];
-            var meshInitMatrix = meshNode.GetObjectTM(0);
-            var boneIds = skinSortedBones[skin];
+            var skinInitMatrix = meshNode.GetObjectTM(0);
 
-            var bones = new BabylonBone[boneIds.Count];
-            var gameBones = new IIGameNode[boneIds.Count];
-            var bindPoseInfos = new BonePoseInfo[boneIds.Count];
-            for (var unsortedIndex = 0; unsortedIndex < skin.TotalSkinBoneCount; unsortedIndex++)
+            var bones = new List<BabylonBone>();
+            var gameBones = new List<IIGameNode>();
+            var boneIds = new List<int>();
+            var bindPoseInfos = new List<BonePoseInfo>();
+            for (var index = 0; index < skin.TotalSkinBoneCount; index++)
             {
-                var gameBone = skin.GetIGameBone(unsortedIndex, false);
-                int index = gameBone == null ? boneIds.IndexOf(-2) : boneIds.IndexOf(gameBone.NodeID);
-                if (gameBone == null)
-                {
-
-                    gameBones[index]=null;
-                    bones[index] = new BabylonBone { index = index, name = "null-bone" };
+                var gameBone = skin.GetIGameBone(index, false);
 
-                    bindPoseInfos[index] = new BonePoseInfo {  };
-                }
-                else
-                {
-                    gameBones[index] = gameBone;
-                    bones[index] = new BabylonBone { index = index, name = gameBone.Name };
-                    //IGMatrix boneInitMatrix = Loader.Global.GMatrix.Create(Loader.Global.Matrix3.Create(true));
+                gameBones.Add(gameBone);
+                boneIds.Add(gameBone.NodeID);
+                bones.Add(new BabylonBone { index = index, name = gameBone.Name });
 
                 var boneInitMatrix = gameBone.GetObjectTM(0);
-                    bindPoseInfos[index] = new BonePoseInfo { AbsoluteTransform = boneInitMatrix };
-                }
+                bindPoseInfos.Add(new BonePoseInfo { AbsoluteTransform = boneInitMatrix });
             }
 
             // fix hierarchy an generate animation keys
             for (var index = 0; index < skin.TotalSkinBoneCount; index++)
             {
                 var gameBone = gameBones[index];
-                if (gameBone == null)
-                {
-
-                    var babBone = bones[index];
-                    bindPoseInfos[index].LocalTransform = Loader.Global.GMatrix.Create(Loader.Global.Matrix3.Create(true));
-                    babBone.matrix = bindPoseInfos[index].LocalTransform.ToArray();
-                }
-                else
-                {
                 var parent = gameBone.NodeParent;
                 var babBone = bones[index];
                 if (parent != null)
@@ -82,7 +61,7 @@ namespace Max2Babylon
                 }
                 if (babBone.parentBoneIndex == -1)
                 {
-                        bindPoseInfos[index].LocalTransform = bindPoseInfos[index].AbsoluteTransform.Multiply(meshInitMatrix.Inverse);
+                    bindPoseInfos[index].LocalTransform = bindPoseInfos[index].AbsoluteTransform.Multiply(skinInitMatrix.Inverse);
                 }
                 else
                 {
@@ -134,12 +113,9 @@ namespace Max2Babylon
 
                 babylonAnimation.keys = keys.ToArray();
                 babBone.animation = babylonAnimation;
-                }
-
             }
 
-
-            babylonSkeleton.bones = bones;
+            babylonSkeleton.bones = bones.ToArray();
 
             babylonScene.SkeletonsList.Add(babylonSkeleton);
         }

+ 57 - 18
Exporters/3ds Max/Max2Babylon/Forms/CameraPropertiesForm.Designer.cs

@@ -29,7 +29,6 @@
         private void InitializeComponent()
         {
             this.groupBox1 = new System.Windows.Forms.GroupBox();
-            this.ellipsoidControl = new Max2Babylon.Vector3Control();
             this.label3 = new System.Windows.Forms.Label();
             this.chkGravity = new System.Windows.Forms.CheckBox();
             this.chkCollisions = new System.Windows.Forms.CheckBox();
@@ -50,6 +49,9 @@
             this.chkAutoAnimate = new System.Windows.Forms.CheckBox();
             this.groupBox4 = new System.Windows.Forms.GroupBox();
             this.chkNoExport = new System.Windows.Forms.CheckBox();
+            this.cbCameraType = new System.Windows.Forms.ComboBox();
+            this.label6 = new System.Windows.Forms.Label();
+            this.ellipsoidControl = new Max2Babylon.Vector3Control();
             this.groupBox1.SuspendLayout();
             this.groupBox2.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.nupInertia)).BeginInit();
@@ -68,23 +70,13 @@
             this.groupBox1.Controls.Add(this.chkGravity);
             this.groupBox1.Controls.Add(this.chkCollisions);
             this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
-            this.groupBox1.Location = new System.Drawing.Point(12, 77);
+            this.groupBox1.Location = new System.Drawing.Point(12, 119);
             this.groupBox1.Name = "groupBox1";
             this.groupBox1.Size = new System.Drawing.Size(319, 138);
             this.groupBox1.TabIndex = 0;
             this.groupBox1.TabStop = false;
             this.groupBox1.Text = "Collisions";
             // 
-            // ellipsoidControl
-            // 
-            this.ellipsoidControl.Location = new System.Drawing.Point(21, 95);
-            this.ellipsoidControl.Name = "ellipsoidControl";
-            this.ellipsoidControl.Size = new System.Drawing.Size(294, 28);
-            this.ellipsoidControl.TabIndex = 3;
-            this.ellipsoidControl.X = 0F;
-            this.ellipsoidControl.Y = 0F;
-            this.ellipsoidControl.Z = 0F;
-            // 
             // label3
             // 
             this.label3.AutoSize = true;
@@ -121,7 +113,7 @@
             this.butOK.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
             this.butOK.DialogResult = System.Windows.Forms.DialogResult.OK;
             this.butOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
-            this.butOK.Location = new System.Drawing.Point(93, 538);
+            this.butOK.Location = new System.Drawing.Point(93, 578);
             this.butOK.Name = "butOK";
             this.butOK.Size = new System.Drawing.Size(75, 23);
             this.butOK.TabIndex = 1;
@@ -134,7 +126,7 @@
             this.butCancel.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
             this.butCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
             this.butCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
-            this.butCancel.Location = new System.Drawing.Point(174, 538);
+            this.butCancel.Location = new System.Drawing.Point(174, 578);
             this.butCancel.Name = "butCancel";
             this.butCancel.Size = new System.Drawing.Size(75, 23);
             this.butCancel.TabIndex = 2;
@@ -148,7 +140,7 @@
             this.groupBox2.Controls.Add(this.label1);
             this.groupBox2.Controls.Add(this.nupSpeed);
             this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
-            this.groupBox2.Location = new System.Drawing.Point(12, 221);
+            this.groupBox2.Location = new System.Drawing.Point(12, 263);
             this.groupBox2.Name = "groupBox2";
             this.groupBox2.Size = new System.Drawing.Size(319, 140);
             this.groupBox2.TabIndex = 3;
@@ -204,7 +196,7 @@
             this.groupBox3.Controls.Add(this.grpAutoAnimate);
             this.groupBox3.Controls.Add(this.chkAutoAnimate);
             this.groupBox3.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
-            this.groupBox3.Location = new System.Drawing.Point(12, 367);
+            this.groupBox3.Location = new System.Drawing.Point(12, 409);
             this.groupBox3.Name = "groupBox3";
             this.groupBox3.Size = new System.Drawing.Size(319, 156);
             this.groupBox3.TabIndex = 5;
@@ -294,11 +286,13 @@
             // 
             // groupBox4
             // 
+            this.groupBox4.Controls.Add(this.label6);
+            this.groupBox4.Controls.Add(this.cbCameraType);
             this.groupBox4.Controls.Add(this.chkNoExport);
             this.groupBox4.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.groupBox4.Location = new System.Drawing.Point(12, 12);
             this.groupBox4.Name = "groupBox4";
-            this.groupBox4.Size = new System.Drawing.Size(319, 59);
+            this.groupBox4.Size = new System.Drawing.Size(319, 101);
             this.groupBox4.TabIndex = 6;
             this.groupBox4.TabStop = false;
             this.groupBox4.Text = "Misc.";
@@ -315,13 +309,56 @@
             this.chkNoExport.ThreeState = true;
             this.chkNoExport.UseVisualStyleBackColor = true;
             // 
+            // cbCameraType
+            // 
+            this.cbCameraType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.cbCameraType.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+            this.cbCameraType.FormattingEnabled = true;
+            this.cbCameraType.Items.AddRange(new object[] {
+            "AnaglyphArcRotateCamera",
+            "AnaglyphFreeCamera",
+            "ArcRotateCamera",
+            "DeviceOrientationCamera",
+            "FollowCamera",
+            "FreeCamera",
+            "GamepadCamera",
+            "OculusCamera",
+            "OculusGamepadCamera",
+            "TouchCamera",
+            "VirtualJoysticksCamera",
+            "WebVRCamera",
+            "VRDeviceOrientationCamera"});
+            this.cbCameraType.Location = new System.Drawing.Point(23, 74);
+            this.cbCameraType.Name = "cbCameraType";
+            this.cbCameraType.Size = new System.Drawing.Size(290, 21);
+            this.cbCameraType.TabIndex = 5;
+            // 
+            // label6
+            // 
+            this.label6.AutoSize = true;
+            this.label6.Location = new System.Drawing.Point(16, 58);
+            this.label6.Name = "label6";
+            this.label6.Size = new System.Drawing.Size(34, 13);
+            this.label6.TabIndex = 6;
+            this.label6.Text = "Type:";
+            // 
+            // ellipsoidControl
+            // 
+            this.ellipsoidControl.Location = new System.Drawing.Point(21, 95);
+            this.ellipsoidControl.Name = "ellipsoidControl";
+            this.ellipsoidControl.Size = new System.Drawing.Size(294, 28);
+            this.ellipsoidControl.TabIndex = 3;
+            this.ellipsoidControl.X = 0F;
+            this.ellipsoidControl.Y = 0F;
+            this.ellipsoidControl.Z = 0F;
+            // 
             // CameraPropertiesForm
             // 
             this.AcceptButton = this.butOK;
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.CancelButton = this.butCancel;
-            this.ClientSize = new System.Drawing.Size(343, 573);
+            this.ClientSize = new System.Drawing.Size(343, 613);
             this.Controls.Add(this.groupBox4);
             this.Controls.Add(this.groupBox3);
             this.Controls.Add(this.groupBox2);
@@ -375,5 +412,7 @@
         private System.Windows.Forms.CheckBox chkAutoAnimate;
         private System.Windows.Forms.GroupBox groupBox4;
         private System.Windows.Forms.CheckBox chkNoExport;
+        private System.Windows.Forms.Label label6;
+        private System.Windows.Forms.ComboBox cbCameraType;
     }
 }

+ 5 - 0
Exporters/3ds Max/Max2Babylon/Forms/CameraPropertiesForm.cs

@@ -35,6 +35,8 @@ namespace Max2Babylon
 
             Tools.PrepareVector3Control(ellipsoidControl, cameras[0], "babylonjs_ellipsoid", 0.5f, 1.0f, 0.5f);
 
+            Tools.PrepareComboBox(cbCameraType, cameras[0], "babylonjs_type", "FreeCamera");
+
             Tools.PrepareCheckBox(chkAutoAnimate, cameras, "babylonjs_autoanimate");
             Tools.PrepareCheckBox(chkLoop, cameras, "babylonjs_autoanimateloop");
             Tools.PrepareNumericUpDown(nupFrom, cameras, "babylonjs_autoanimate_from");
@@ -52,6 +54,8 @@ namespace Max2Babylon
 
             Tools.UpdateVector3Control(ellipsoidControl, cameras, "babylonjs_ellipsoid");
 
+            Tools.UpdateComboBox(cbCameraType, cameras, "babylonjs_type");
+
             Tools.UpdateCheckBox(chkAutoAnimate, cameras, "babylonjs_autoanimate");
             Tools.UpdateCheckBox(chkLoop, cameras, "babylonjs_autoanimateloop");
             Tools.UpdateNumericUpDown(nupFrom, cameras, "babylonjs_autoanimate_from");
@@ -62,5 +66,6 @@ namespace Max2Babylon
         {
             grpAutoAnimate.Enabled = chkAutoAnimate.Checked;
         }
+
     }
 }

+ 35 - 0
Exporters/3ds Max/Max2Babylon/Tools/Tools.cs

@@ -571,6 +571,18 @@ namespace Max2Babylon
             return state == 1;
         }
 
+        public static string GetStringProperty(this IINode node, string propertyName, string defaultState)
+        {
+            string state = defaultState;
+#if MAX2015
+            node.GetUserPropString(propertyName, ref state);
+#else
+            node.GetUserPropString(ref propertyName, ref state);
+#endif
+
+            return state;
+        }
+
         public static float GetFloatProperty(this IINode node, string propertyName, float defaultState = 0)
         {
             float state = defaultState;
@@ -654,6 +666,11 @@ namespace Max2Babylon
             }
         }
 
+        public static void PrepareComboBox(ComboBox comboBox, IINode node, string propertyName, string defaultValue)
+        {
+            comboBox.SelectedItem = node.GetStringProperty(propertyName, defaultValue);
+        }
+
         public static void UpdateCheckBox(CheckBox checkBox, IINode node, string propertyName)
         {
             if (checkBox.CheckState != CheckState.Indeterminate)
@@ -730,6 +747,24 @@ namespace Max2Babylon
             }
         }
 
+        public static void UpdateComboBox(ComboBox comboBox, IINode node, string propertyName)
+        {
+            var value = comboBox.SelectedItem.ToString();
+#if MAX2015
+            node.SetUserPropString(propertyName, value);
+#else
+            node.SetUserPropString(ref propertyName, ref value);
+#endif
+        }
+
+        public static void UpdateComboBox(ComboBox comboBox, List<IINode> nodes, string propertyName)
+        {
+            foreach (var node in nodes)
+            {
+                UpdateComboBox(comboBox, node, propertyName);
+            }
+        }
+
         public static IMatrix3 ExtractCoordinates(IINode meshNode, BabylonAbstractMesh babylonMesh, bool exportQuaternionsInsteadOfEulers)
         {
             var wm = meshNode.GetWorldMatrix(0, meshNode.HasParent());

+ 4 - 0
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/babylonJS.xml

@@ -1,5 +1,9 @@
 <?xml version="1.0" encoding="utf-8" ?>
 <files xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="babylonJS.xsd">
+  <script src="Babylon/Audio/babylon.audioengine.js"></script>
+  <script src="Babylon/Audio/babylon.sound.js"></script>
+  <script src="Babylon/Audio/babylon.soundtrack.js"></script>
+  <script src="Babylon/Debug/babylon.debugLayer.js"></script>
   <script src="Babylon/Mesh/babylon.meshLODLevel.js"></script>
   <script src="Babylon/Tools/babylon.sceneOptimizer.js"></script>
   <script src="Babylon/Cameras/babylon.vrDeviceOrientationCamera.js"></script>

+ 5 - 1
Tools/Gulp/gulpfile.js

@@ -161,7 +161,11 @@ gulp.task('scripts', ['shaders'] ,function() {
       '../../Babylon/Cameras/babylon.vrDeviceOrientationCamera.js',
       '../../Babylon/Cameras/babylon.webVRCamera.js',
       '../../Babylon/Tools/babylon.sceneOptimizer.js',
-      '../../Babylon/Mesh/babylon.meshLODLevel.js'
+      '../../Babylon/Mesh/babylon.meshLODLevel.js',
+      '../../Babylon/Audio/babylon.audioengine.js',
+      '../../Babylon/Audio/babylon.sound.js',
+      '../../Babylon/Audio/babylon.soundtrack.js',
+      '../../Babylon/Debug/babylon.debugLayer.js'
     ])
     .pipe(concat('babylon.js'))
     .pipe(gulp.dest('build/'))

+ 173 - 25
babylon.2.0-alpha.debug.js

@@ -5859,6 +5859,10 @@ var BABYLON;
             return this._shadowGenerator;
         };
 
+        Light.prototype.getAbsolutePosition = function () {
+            return BABYLON.Vector3.Zero();
+        };
+
         Light.prototype.transferToEffect = function (effect, uniformName0, uniformName1) {
         };
 
@@ -5928,6 +5932,10 @@ var BABYLON;
             _super.call(this, name, scene);
             this.position = position;
         }
+        PointLight.prototype.getAbsolutePosition = function () {
+            return this._transformedPosition ? this._transformedPosition : this.position;
+        };
+
         PointLight.prototype.transferToEffect = function (effect, positionUniformName) {
             if (this.parent && this.parent.getWorldMatrix) {
                 if (!this._transformedPosition) {
@@ -5977,6 +5985,10 @@ var BABYLON;
             this.angle = angle;
             this.exponent = exponent;
         }
+        SpotLight.prototype.getAbsolutePosition = function () {
+            return this._transformedPosition ? this._transformedPosition : this.position;
+        };
+
         SpotLight.prototype.setDirectionToTarget = function (target) {
             this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
             return this.direction;
@@ -5989,6 +6001,7 @@ var BABYLON;
                 if (!this._transformedDirection) {
                     this._transformedDirection = BABYLON.Vector3.Zero();
                 }
+
                 if (!this._transformedPosition) {
                     this._transformedPosition = BABYLON.Vector3.Zero();
                 }
@@ -6037,6 +6050,10 @@ var BABYLON;
 
             this.position = direction.scale(-1);
         }
+        DirectionalLight.prototype.getAbsolutePosition = function () {
+            return this._transformedPosition ? this._transformedPosition : this.position;
+        };
+
         DirectionalLight.prototype.setDirectionToTarget = function (target) {
             this.direction = BABYLON.Vector3.Normalize(target.subtract(this.position));
             return this.direction;
@@ -8557,16 +8574,16 @@ var BABYLON;
                     if (pickResult.pickedMesh.actionManager) {
                         switch (evt.button) {
                             case 0:
-                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
                                 break;
                             case 1:
-                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
                                 break;
                             case 2:
-                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
                                 break;
                         }
-                        pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
+                        pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh, evt));
                     }
                 }
 
@@ -12073,6 +12090,54 @@ var BABYLON;
             var minMaxVector = meshesOrMinMaxVector.min !== undefined ? meshesOrMinMaxVector : BABYLON.Mesh.MinMax(meshesOrMinMaxVector);
             return BABYLON.Vector3.Center(minMaxVector.min, minMaxVector.max);
         };
+
+        Mesh.MergeMeshes = function (meshes, disposeSource, allow32BitsIndices) {
+            if (typeof disposeSource === "undefined") { disposeSource = true; }
+            var source = meshes[0];
+            var material = source.material;
+            var scene = source.getScene();
+
+            if (!allow32BitsIndices) {
+                var totalVertices = 0;
+
+                for (var index = 0; index < meshes.length; index++) {
+                    totalVertices += meshes[index].getTotalVertices();
+
+                    if (totalVertices > 65536) {
+                        BABYLON.Tools.Warn("Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices");
+                        return null;
+                    }
+                }
+            }
+
+           
+            var vertexData = BABYLON.VertexData.ExtractFromMesh(source);
+            vertexData.transform(source.getWorldMatrix());
+
+            for (index = 1; index < meshes.length; index++) {
+                var otherVertexData = BABYLON.VertexData.ExtractFromMesh(meshes[index]);
+                otherVertexData.transform(meshes[index].getWorldMatrix());
+
+                vertexData.merge(otherVertexData);
+            }
+
+            var newMesh = new Mesh(source.name + "_merged", scene);
+
+            vertexData.applyToMesh(newMesh);
+
+           
+            newMesh.material = material;
+            newMesh.checkCollisions = source.checkCollisions;
+
+           
+            if (disposeSource) {
+                for (index = 0; index < meshes.length; index++) {
+                    meshes[index].dispose();
+                }
+            }
+
+            return newMesh;
+        };
         return Mesh;
     })(BABYLON.AbstractMesh);
     BABYLON.Mesh = Mesh;
@@ -20928,6 +20993,8 @@ var BABYLON;
                 camera = new BABYLON.GamepadCamera(parsedCamera.name, position, scene);
             } else if (parsedCamera.type === "OculusCamera") {
                 camera = new BABYLON.OculusCamera(parsedCamera.name, position, scene);
+            } else if (parsedCamera.type === "OculusGamepadCamera") {
+                camera = new BABYLON.OculusGamepadCamera(parsedCamera.name, position, scene);
             } else if (parsedCamera.type === "TouchCamera") {
                 camera = new BABYLON.TouchCamera(parsedCamera.name, position, scene);
             } else if (parsedCamera.type === "VirtualJoysticksCamera") {
@@ -24676,12 +24743,12 @@ var BABYLON;
             this._getPostProcess = getPostProcess;
 
             this._cameras = [];
-
-            this._postProcesses = [];
             this._indicesForCamera = [];
 
-            this._renderPasses = [];
-            this._renderEffectAsPasses = [];
+            this._postProcesses = {};
+
+            this._renderPasses = {};
+            this._renderEffectAsPasses = {};
         }
         PostProcessRenderEffect.prototype._update = function () {
             for (var renderPassName in this._renderPasses) {
@@ -24716,7 +24783,7 @@ var BABYLON;
         };
 
         PostProcessRenderEffect.prototype.emptyPasses = function () {
-            this._renderPasses.length = 0;
+            this._renderPasses = {};
 
             this._linkParameters();
         };
@@ -24853,8 +24920,8 @@ var BABYLON;
             this._engine = engine;
             this._name = name;
 
-            this._renderEffects = [];
-            this._renderEffectsForIsolatedPass = [];
+            this._renderEffects = {};
+            this._renderEffectsForIsolatedPass = {};
 
             this._cameras = [];
         }
@@ -24997,7 +25064,7 @@ var BABYLON;
 (function (BABYLON) {
     var PostProcessRenderPipelineManager = (function () {
         function PostProcessRenderPipelineManager() {
-            this._renderPipelines = new Array();
+            this._renderPipelines = {};
         }
         PostProcessRenderPipelineManager.prototype.addPipeline = function (renderPipeline) {
             this._renderPipelines[renderPipeline._name] = renderPipeline;
@@ -26309,9 +26376,9 @@ var BABYLON;
             this.meshUnderPointer = meshUnderPointer;
             this.sourceEvent = sourceEvent;
         }
-        ActionEvent.CreateNew = function (source) {
+        ActionEvent.CreateNew = function (source, evt) {
             var scene = source.getScene();
-            return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer);
+            return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt);
         };
 
         ActionEvent.CreateNewFromScene = function (scene, evt) {
@@ -28822,6 +28889,85 @@ var BABYLON;
     })(SceneOptimization);
     BABYLON.RenderTargetsOptimization = RenderTargetsOptimization;
 
+    var MergeMeshesOptimization = (function (_super) {
+        __extends(MergeMeshesOptimization, _super);
+        function MergeMeshesOptimization() {
+            _super.apply(this, arguments);
+            var _this = this;
+            this._canBeMerged = function (abstractMesh) {
+                if (!(abstractMesh instanceof BABYLON.Mesh)) {
+                    return false;
+                }
+
+                var mesh = abstractMesh;
+
+                if (!mesh.isVisible || !mesh.isEnabled()) {
+                    return false;
+                }
+
+                if (mesh.instances.length > 0) {
+                    return false;
+                }
+
+                if (mesh.skeleton || mesh.hasLODLevels) {
+                    return false;
+                }
+
+                return true;
+            };
+            this.apply = function (scene) {
+                var globalPool = scene.meshes.slice(0);
+                var globalLength = globalPool.length;
+
+                for (var index = 0; index < globalLength; index++) {
+                    var currentPool = new Array();
+                    var current = globalPool[index];
+
+                   
+                    if (!_this._canBeMerged(current)) {
+                        continue;
+                    }
+
+                    currentPool.push(current);
+
+                    for (var subIndex = index + 1; subIndex < globalLength; subIndex++) {
+                        var otherMesh = globalPool[subIndex];
+
+                        if (!_this._canBeMerged(otherMesh)) {
+                            continue;
+                        }
+
+                        if (otherMesh.material !== current.material) {
+                            continue;
+                        }
+
+                        if (otherMesh.checkCollisions !== current.checkCollisions) {
+                            continue;
+                        }
+
+                        currentPool.push(otherMesh);
+                        globalLength--;
+
+                        globalPool.splice(subIndex, 1);
+
+                        subIndex--;
+                    }
+
+                    if (currentPool.length < 2) {
+                        continue;
+                    }
+
+                   
+                    BABYLON.Mesh.MergeMeshes(currentPool);
+                }
+
+                return true;
+            };
+        }
+        return MergeMeshesOptimization;
+    })(SceneOptimization);
+    BABYLON.MergeMeshesOptimization = MergeMeshesOptimization;
+
    
     var SceneOptimizerOptions = (function () {
         function SceneOptimizerOptions(targetFrameRate, trackerDuration) {
@@ -28835,6 +28981,7 @@ var BABYLON;
             var result = new SceneOptimizerOptions(targetFrameRate);
 
             var priority = 0;
+            result.optimizations.push(new MergeMeshesOptimization(priority));
             result.optimizations.push(new ShadowsOptimization(priority));
             result.optimizations.push(new LensFlaresOptimization(priority));
 
@@ -28854,6 +29001,7 @@ var BABYLON;
             var result = new SceneOptimizerOptions(targetFrameRate);
 
             var priority = 0;
+            result.optimizations.push(new MergeMeshesOptimization(priority));
             result.optimizations.push(new ShadowsOptimization(priority));
             result.optimizations.push(new LensFlaresOptimization(priority));
 
@@ -28881,6 +29029,7 @@ var BABYLON;
             var result = new SceneOptimizerOptions(targetFrameRate);
 
             var priority = 0;
+            result.optimizations.push(new MergeMeshesOptimization(priority));
             result.optimizations.push(new ShadowsOptimization(priority));
             result.optimizations.push(new LensFlaresOptimization(priority));
 
@@ -29341,7 +29490,7 @@ var BABYLON;
                     _this._treeDiv.style.top = "10px";
                     _this._treeDiv.style.width = "300px";
                     _this._treeDiv.style.height = "auto";
-                    _this._treeSubsetDiv.style.maxHeight = (canvasRect.height - 420) + "px";
+                    _this._treeSubsetDiv.style.maxHeight = (canvasRect.height - 490) + "px";
                 }
 
                 _this._globalDiv.style.left = canvasRect.left + "px";
@@ -29435,7 +29584,7 @@ var BABYLON;
                             continue;
                         }
 
-                        projectedPosition = BABYLON.Vector3.Project(camera.position, _this._identityMatrix, _this._scene.getTransformMatrix(), globalViewport);
+                        projectedPosition = BABYLON.Vector3.Project(BABYLON.Vector3.Zero(), camera.getWorldMatrix(), _this._scene.getTransformMatrix(), globalViewport);
 
                         if (!_this.shouldDisplayLabel || _this.shouldDisplayLabel(camera)) {
                             _this._renderLabel(camera.name, projectedPosition, 12, function () {
@@ -29454,7 +29603,7 @@ var BABYLON;
                         var light = lights[index];
 
                         if (light.position) {
-                            projectedPosition = BABYLON.Vector3.Project(light.position, _this._identityMatrix, _this._scene.getTransformMatrix(), globalViewport);
+                            projectedPosition = BABYLON.Vector3.Project(light.getAbsolutePosition(), _this._identityMatrix, _this._scene.getTransformMatrix(), globalViewport);
 
                             if (!_this.shouldDisplayLabel || _this.shouldDisplayLabel(light)) {
                                 _this._renderLabel(light.name, projectedPosition, -20, function () {
@@ -29632,8 +29781,6 @@ var BABYLON;
 
             var engine = this._scene.getEngine();
 
-            this._scene.registerAfterRender(this._syncData);
-
             this._globalDiv = document.createElement("div");
 
             document.body.appendChild(this._globalDiv);
@@ -29644,6 +29791,7 @@ var BABYLON;
             engine.getRenderingCanvas().addEventListener("click", this._onCanvasClick);
 
             this._syncPositions();
+            this._scene.registerAfterRender(this._syncData);
         };
 
         DebugLayer.prototype._clearLabels = function () {
@@ -29698,6 +29846,7 @@ var BABYLON;
 
             leftPart.innerHTML = leftTitle;
             rightPart.innerHTML = rightTitle;
+            rightPart.style.maxWidth = "200px";
 
             container.appendChild(leftPart);
             container.appendChild(rightPart);
@@ -29747,6 +29896,11 @@ var BABYLON;
         DebugLayer.prototype._generateDOMelements = function () {
             var _this = this;
             this._globalDiv.id = "DebugLayer";
+            this._globalDiv.style.position = "absolute";
+
+            this._globalDiv.style.fontFamily = "Segoe UI, Arial";
+            this._globalDiv.style.fontSize = "14px";
+            this._globalDiv.style.color = "white";
 
            
             this._drawingCanvas = document.createElement("canvas");
@@ -29942,16 +30096,10 @@ var BABYLON;
                     _this._scene.texturesEnabled = element.checked;
                 });
 
-               
-                this._globalDiv.style.position = "absolute";
                 this._globalDiv.appendChild(this._statsDiv);
                 this._globalDiv.appendChild(this._logDiv);
                 this._globalDiv.appendChild(this._optionsDiv);
                 this._globalDiv.appendChild(this._treeDiv);
-
-                this._globalDiv.style.fontFamily = "Segoe UI, Arial";
-                this._globalDiv.style.fontSize = "14px";
-                this._globalDiv.style.color = "white";
             }
         };
 

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 13 - 13
babylon.2.0-alpha.js


+ 13 - 4
babylon.2.0.d.ts

@@ -561,7 +561,7 @@ declare module BABYLON {
         public meshUnderPointer: AbstractMesh;
         public sourceEvent: any;
         constructor(source: AbstractMesh, pointerX: number, pointerY: number, meshUnderPointer: AbstractMesh, sourceEvent?: any);
-        static CreateNew(source: AbstractMesh): ActionEvent;
+        static CreateNew(source: AbstractMesh, evt?: Event): ActionEvent;
         static CreateNewFromScene(scene: Scene, evt: Event): ActionEvent;
     }
     class ActionManager {
@@ -1611,6 +1611,7 @@ declare module BABYLON {
         public _transformedPosition: Vector3;
         private _worldMatrix;
         constructor(name: string, direction: Vector3, scene: Scene);
+        public getAbsolutePosition(): Vector3;
         public setDirectionToTarget(target: Vector3): Vector3;
         public _computeTransformedPosition(): boolean;
         public transferToEffect(effect: Effect, directionUniformName: string): void;
@@ -1643,6 +1644,7 @@ declare module BABYLON {
         public _includedOnlyMeshesIds: string[];
         constructor(name: string, scene: Scene);
         public getShadowGenerator(): ShadowGenerator;
+        public getAbsolutePosition(): Vector3;
         public transferToEffect(effect: Effect, uniformName0?: string, uniformName1?: string): void;
         public _getWorldMatrix(): Matrix;
         public canAffectMesh(mesh: AbstractMesh): boolean;
@@ -1656,6 +1658,7 @@ declare module BABYLON {
         private _worldMatrix;
         private _transformedPosition;
         constructor(name: string, position: Vector3, scene: Scene);
+        public getAbsolutePosition(): Vector3;
         public transferToEffect(effect: Effect, positionUniformName: string): void;
         public getShadowGenerator(): ShadowGenerator;
         public _getWorldMatrix(): Matrix;
@@ -1671,6 +1674,7 @@ declare module BABYLON {
         private _transformedPosition;
         private _worldMatrix;
         constructor(name: string, position: Vector3, direction: Vector3, angle: number, exponent: number, scene: Scene);
+        public getAbsolutePosition(): Vector3;
         public setDirectionToTarget(target: Vector3): Vector3;
         public transferToEffect(effect: Effect, positionUniformName: string, directionUniformName: string): void;
         public _getWorldMatrix(): Matrix;
@@ -2737,7 +2741,7 @@ declare module BABYLON {
         public isCompletelyInFrustum(camera?: Camera): boolean;
         public intersectsMesh(mesh: AbstractMesh, precise?: boolean): boolean;
         public intersectsPoint(point: Vector3): boolean;
-        public setPhysicsState(impostor?: any, options?: PhysicsBodyCreationOptions): void;
+        public setPhysicsState(impostor?: any, options?: PhysicsBodyCreationOptions): any;
         public getPhysicsImpostor(): number;
         public getPhysicsMass(): number;
         public getPhysicsFriction(): number;
@@ -3076,6 +3080,7 @@ declare module BABYLON {
             max: Vector3;
         };
         static Center(meshesOrMinMaxVector: any): Vector3;
+        static MergeMeshes(meshes: Mesh[], disposeSource?: boolean, allow32BitsIndices?: boolean): Mesh;
     }
 }
 declare module BABYLON {
@@ -3636,7 +3641,7 @@ declare module BABYLON {
         private _alphaTestSubMeshes;
         private _activeVertices;
         constructor(index: number, scene: Scene);
-        public render(customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>, beforeTransparents: () => void) => void, beforeTransparents: any): boolean;
+        public render(customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>) => void): boolean;
         public prepare(): void;
         public dispatch(subMesh: SubMesh): void;
     }
@@ -3651,7 +3656,7 @@ declare module BABYLON {
         private _renderParticles(index, activeMeshes);
         private _renderSprites(index);
         private _clearDepthBuffer();
-        public render(customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>, beforeTransparents: () => void) => void, activeMeshes: AbstractMesh[], renderParticles: boolean, renderSprites: boolean): void;
+        public render(customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>) => void, activeMeshes: AbstractMesh[], renderParticles: boolean, renderSprites: boolean): void;
         public reset(): void;
         public dispatch(subMesh: SubMesh): void;
     }
@@ -4013,6 +4018,10 @@ declare module BABYLON {
     class RenderTargetsOptimization extends SceneOptimization {
         public apply: (scene: Scene) => boolean;
     }
+    class MergeMeshesOptimization extends SceneOptimization {
+        private _canBeMerged;
+        public apply: (scene: Scene) => boolean;
+    }
     class SceneOptimizerOptions {
         public targetFrameRate: number;
         public trackerDuration: number;

+ 1 - 0
readme.md

@@ -23,6 +23,7 @@ Online [asset converter](http://www.babylonjs.com/converter.html) where you can
 - [Roadmap](https://github.com/BabylonJS/Babylon.js/wiki/Roadmap)
 - [Samples](https://github.com/BabylonJS/Samples)
 - [Video overview (1 hour) of BabylonJS features](http://www.youtube.com/watch?v=z80TYMqsdEM)
+- [Complete course (8 hours)](http://www.microsoftvirtualacademy.com/training-courses/introduction-to-webgl-3d-with-html5-and-babylon-js)
 
 ## Features
 - Complete scene graph with lights, cameras, materials and meshes