David Catuhe 11 anni fa
parent
commit
ca50f0470f
93 ha cambiato i file con 1333 aggiunte e 368 eliminazioni
  1. 3 1
      Babylon/Animations/babylon.animatable.js
  2. 3 1
      Babylon/Animations/babylon.animation.js
  3. 3 1
      Babylon/Bones/babylon.bone.js
  4. 3 1
      Babylon/Bones/babylon.skeleton.js
  5. 3 1
      Babylon/Cameras/babylon.arcRotateCamera.js
  6. 6 7
      Babylon/Cameras/babylon.camera.js
  7. 3 1
      Babylon/Cameras/babylon.deviceOrientationCamera.js
  8. 3 1
      Babylon/Cameras/babylon.freeCamera.js
  9. 3 1
      Babylon/Cameras/babylon.touchCamera.js
  10. 12 0
      Babylon/Collisions/babylon.pickingInfo.js
  11. 30 0
      Babylon/LensFlare/babylon.lensFlare.js
  12. 212 0
      Babylon/LensFlare/babylon.lensFlareSystem.js
  13. 3 0
      Babylon/Lights/babylon.light.js
  14. 8 0
      Babylon/Materials/babylon.standardMaterial.js
  15. 14 3
      Babylon/Materials/textures/babylon.dynamicTexture.js
  16. 2 14
      Babylon/Materials/textures/babylon.mirrorTexture.js
  17. 5 0
      Babylon/Materials/textures/babylon.renderTargetTexture.js
  18. 1 0
      Babylon/Materials/textures/babylon.texture.js
  19. 42 10
      Babylon/Mesh/babylon.mesh.js
  20. 25 25
      Babylon/Mesh/babylon.subMesh.js
  21. 8 1
      Babylon/Particles/babylon.particleSystem.js
  22. 3 0
      Babylon/PostProcess/babylon.postProcess.js
  23. 30 7
      Babylon/Rendering/babylon.renderingGroup.js
  24. 78 34
      Babylon/Shaders/default.fragment.fx
  25. 5 51
      Babylon/Shaders/default.vertex.fx
  26. 16 0
      Babylon/Shaders/lensFlare.fragment.fx
  27. 20 0
      Babylon/Shaders/lensFlare.vertex.fx
  28. 63 38
      Babylon/Tools/babylon.math.js
  29. 24 1
      Babylon/Tools/babylon.sceneLoader.js
  30. 4 0
      Babylon/Tools/babylon.tools.js
  31. 48 15
      Babylon/babylon.engine.js
  32. 3 1
      Babylon/babylon.node.js
  33. 127 64
      Babylon/babylon.scene.js
  34. 1 1
      Babylon/jscompaktor.bat
  35. 12 3
      Exporters/FBX - OBJ/BabylonExport.Core/BabylonExport.Core.csproj
  36. 20 0
      Exporters/FBX - OBJ/BabylonExport.Core/Entities/Export/BabylonLensFlare.cs
  37. 17 0
      Exporters/FBX - OBJ/BabylonExport.Core/Entities/Export/BabylonLensFlareSystem.cs
  38. 5 2
      Exporters/FBX - OBJ/BabylonExport.Core/Entities/Export/BabylonMesh.cs
  39. 3 0
      Exporters/FBX - OBJ/BabylonExport.Core/Entities/Export/BabylonScene.cs
  40. 1 1
      Exporters/FBX - OBJ/BabylonExport.Core/Entities/Mesh.cs
  41. 1 1
      Exporters/FBX - OBJ/BabylonExport.Core/Exporters/FBX/FBXExporter.cs
  42. 49 4
      Exporters/FBX - OBJ/BabylonExport.Core/Exporters/MXB/NovaExporter.cs
  43. BIN
      Exporters/FBX - OBJ/BabylonExport.zip
  44. 111 0
      Exporters/FBX - OBJ/BabylonExport/BabylonExport.csproj
  45. BIN
      Samples/Assets/CamDeviceOff.png
  46. BIN
      Samples/Assets/CamTouchOff.png
  47. BIN
      Samples/Assets/lens4.png
  48. BIN
      Samples/Assets/lens5.png
  49. BIN
      Samples/Scenes/Blender/MountainGrass_jpg72767116-efb0-4b79-a016-8ac4ef7561a1Larger.jpg
  50. 9 12
      Samples/Scenes/Blender/blender.babylon
  51. BIN
      Samples/Scenes/Blender/chocolat.jpg
  52. BIN
      Samples/Scenes/Blender/paper.png
  53. BIN
      Samples/Scenes/Blender/paper02.png
  54. BIN
      Samples/Scenes/Blender/paper_bump.png
  55. BIN
      Samples/Scenes/Blender/wildtextures-old-wood-original-file-1280x853.jpg
  56. 39 0
      Samples/Scenes/Customs/lensFlares.js
  57. 14 3
      Samples/Scenes/Customs/test.js
  58. BIN
      Samples/Scenes/Robot/Assets/Slides/Slide2.JPG
  59. BIN
      Samples/Scenes/Robot/DispenderDiffuseMap.jpg
  60. BIN
      Samples/Scenes/Robot/EnvAmbient Occlusion _MR.jpg
  61. BIN
      Samples/Scenes/Robot/Ref.jpg
  62. 1 1
      Samples/Scenes/Robot/Robot.babylon
  63. BIN
      Samples/Scenes/Robot/RobotCompmap.jpg
  64. BIN
      Samples/Scenes/Robot/Slide1.jpg
  65. 15 2
      Samples/Scenes/Robot/index.html
  66. 7 7
      Samples/Scenes/Robot/index.js
  67. 1 1
      Samples/Scenes/Train/Train.babylon
  68. 1 1
      Samples/Scenes/Train/Train.babylon.manifest
  69. 1 0
      Samples/Scenes/Train/debug.txt
  70. BIN
      Samples/Scenes/Train/lens2.png
  71. BIN
      Samples/Scenes/Train/lens3.png
  72. BIN
      Samples/Scenes/Train/lens4.png
  73. BIN
      Samples/Scenes/Train/lens5.png
  74. BIN
      Samples/Scenes/Train/lens6.png
  75. 25 0
      Samples/Scenes/WorldMonger/Postprocesses/compose.fragment.fx
  76. 29 0
      Samples/Scenes/WorldMonger/Postprocesses/downsample.fragment.fx
  77. 15 1
      Samples/Scenes/WorldMonger/index.html
  78. 23 0
      Samples/Scenes/WorldMonger/index.js
  79. BIN
      Samples/Screenshots/expo.jpg
  80. BIN
      Samples/Screenshots/expo.png
  81. BIN
      Samples/Screenshots/lens.jpg
  82. BIN
      Samples/Screenshots/psn.jpg
  83. BIN
      Samples/Screenshots/sokrate3D.jpg
  84. 7 5
      Samples/babylon.js
  85. 0 1
      Samples/hand.minified-1.1.1.js
  86. 1 0
      Samples/hand.minified-1.2.js
  87. 17 2
      Samples/index.css
  88. 33 11
      Samples/index.html
  89. 26 10
      Samples/index.js
  90. 0 20
      babylon.1.6.0.js
  91. 22 0
      babylon.1.7.js
  92. 2 0
      readme.md
  93. 12 0
      what's new.md

+ 3 - 1
Babylon/Animations/babylon.animatable.js

@@ -1,4 +1,6 @@
-var BABYLON = BABYLON || {};
+"use strict";
+
+var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON._Animatable = function (target, from, to, loop, speedRatio, onAnimationEnd) {

+ 3 - 1
Babylon/Animations/babylon.animation.js

@@ -1,4 +1,6 @@
-var BABYLON = BABYLON || {};
+"use strict";
+
+var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON.Animation = function (name, targetProperty, framePerSecond, dataType, loopMode) {

+ 3 - 1
Babylon/Bones/babylon.bone.js

@@ -1,4 +1,6 @@
-var BABYLON = BABYLON || {};
+"use strict";
+
+var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON.Bone = function (name, skeleton, parentBone, matrix) {

+ 3 - 1
Babylon/Bones/babylon.skeleton.js

@@ -1,4 +1,6 @@
-var BABYLON = BABYLON || {};
+"use strict";
+
+var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON.Skeleton = function (name, id, scene) {

+ 3 - 1
Babylon/Cameras/babylon.arcRotateCamera.js

@@ -1,4 +1,6 @@
-var BABYLON = BABYLON || {};
+"use strict";
+
+var BABYLON = BABYLON || {};
 
 (function () {
     var eventPrefix = BABYLON.Tools.GetPointerPrefix();

+ 6 - 7
Babylon/Cameras/babylon.camera.js

@@ -1,4 +1,6 @@
-var BABYLON = BABYLON || {};
+"use strict";
+
+var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON.Camera = function (name, position, scene) {
@@ -17,13 +19,15 @@
         }
 
         this._computedViewMatrix = BABYLON.Matrix.Identity();
-        this._currentRenderId = -1;
 
         // Animations
         this.animations = [];
 
         // Postprocesses
         this.postProcesses = [];
+        
+        // Viewport
+        this.viewport = new BABYLON.Viewport(0, 0, 1.0, 1.0);
     };
 
     BABYLON.Camera.prototype = Object.create(BABYLON.Node.prototype);
@@ -76,12 +80,7 @@
     };
 
     BABYLON.Camera.prototype.getViewMatrix = function () {
-        if (this._currentRenderId == this._scene.getRenderId()) {
-            return this._computedViewMatrix;
-        }
-
         this._computedViewMatrix = this._getViewMatrix();
-        this._currentRenderId = this._scene.getRenderId();
 
         if (this.parent && this.parent.getWorldMatrix) {
             if (!this._worldMatrix) {

+ 3 - 1
Babylon/Cameras/babylon.deviceOrientationCamera.js

@@ -1,4 +1,6 @@
-var BABYLON = BABYLON || {};
+"use strict";
+
+var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON.DeviceOrientationCamera = function (name, position, scene) {

+ 3 - 1
Babylon/Cameras/babylon.freeCamera.js

@@ -1,4 +1,6 @@
-var BABYLON = BABYLON || {};
+"use strict";
+
+var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON.FreeCamera = function (name, position, scene) {

+ 3 - 1
Babylon/Cameras/babylon.touchCamera.js

@@ -1,4 +1,6 @@
-var BABYLON = BABYLON || {};
+"use strict";
+
+var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON.TouchCamera = function (name, position, scene) {

+ 12 - 0
Babylon/Collisions/babylon.pickingInfo.js

@@ -0,0 +1,12 @@
+var BABYLON = BABYLON || {};
+
+(function () {
+    BABYLON.PickingInfo = function () {
+    };
+
+    // Properties
+    BABYLON.PickingInfo.prototype.hit = false;
+    BABYLON.PickingInfo.prototype.distance = 0;
+    BABYLON.PickingInfo.prototype.pickedPoint = null;
+    BABYLON.PickingInfo.prototype.pickedMesh = null;
+})();

+ 30 - 0
Babylon/LensFlare/babylon.lensFlare.js

@@ -0,0 +1,30 @@
+var BABYLON = BABYLON || {};
+
+(function () {
+    BABYLON.LensFlare = function (size, position, color, imgUrl, system) {
+        this.color = color || new BABYLON.Color3(1, 1, 1);
+        this.position = position;
+        this.size = size;
+        this.texture = imgUrl ? new BABYLON.Texture(imgUrl, system.getScene(), true) : null;
+        this._system = system;
+        
+        system.lensFlares.push(this);
+    };
+    
+    // Properties
+    BABYLON.LensFlare.prototype.position = 0;
+    BABYLON.LensFlare.prototype.size = 1.0;
+    BABYLON.LensFlare.prototype.texture = null;
+    
+    // Methods
+    BABYLON.LensFlare.prototype.dispose = function() {
+        if (this.texture) {
+            this.texture.dispose();
+        }
+        
+        // Remove from scene
+        var index = this._system.lensFlares.indexOf(this);
+        this._system.lensFlares.splice(index, 1);
+    };
+    
+})();

+ 212 - 0
Babylon/LensFlare/babylon.lensFlareSystem.js

@@ -0,0 +1,212 @@
+var BABYLON = BABYLON || {};
+
+(function () {
+    BABYLON.LensFlareSystem = function (name, emitter, scene) {
+        this.lensFlares = [];
+        this._scene = scene;
+        this._emitter = emitter;
+        this.name = name;
+
+        scene.lensFlareSystems.push(this);
+
+        this.meshesSelectionPredicate = function(m) {
+            return m.material && m.isVisible && m.isEnabled() && m.checkCollisions;
+        };
+        
+        // VBO
+        var vertices = [];
+        vertices.push(1, 1);
+        vertices.push(-1, 1);
+        vertices.push(-1, -1);
+        vertices.push(1, -1);
+        this._vertexDeclaration = [2];
+        this._vertexStrideSize = 2 * 4;
+        this._vertexBuffer = scene.getEngine().createVertexBuffer(vertices);
+
+        // Indices
+        var indices = [];
+        indices.push(0);
+        indices.push(1);
+        indices.push(2);
+
+        indices.push(0);
+        indices.push(2);
+        indices.push(3);
+
+        this._indexBuffer = scene.getEngine().createIndexBuffer(indices);       
+
+        // Effects
+        this._effect = this._scene.getEngine().createEffect("lensFlare",
+                    ["position"],
+                    ["color", "viewportMatrix"],
+                    ["textureSampler"], "");
+    };
+
+    // Members
+    BABYLON.LensFlareSystem.prototype.borderLimit = 300;
+    
+    // Properties
+    BABYLON.LensFlareSystem.prototype.getScene = function() {
+        return this._scene;
+    };
+    
+    BABYLON.LensFlareSystem.prototype.getEmitterPosition = function() {
+        return this._emitter.getAbsolutePosition ? this._emitter.getAbsolutePosition() : this._emitter.position;
+    };
+
+    // Methods
+    BABYLON.LensFlareSystem.prototype.computeEffectivePosition = function (globalViewport) {
+        var position = this.getEmitterPosition();
+
+        position = BABYLON.Vector3.Project(position, BABYLON.Matrix.Identity(), this._scene.getTransformMatrix(), globalViewport);
+
+        this._positionX = position.x;
+        this._positionY = position.y;
+
+        position = BABYLON.Vector3.TransformCoordinates(this.getEmitterPosition(), this._scene.getViewMatrix());
+
+        if (position.z > 0) {
+            if ((this._positionX > globalViewport.x) && (this._positionX < globalViewport.x + globalViewport.width)) {
+                if ((this._positionY > globalViewport.y) && (this._positionY < globalViewport.y + globalViewport.height))
+                    return true;
+            }
+        }
+
+        return false;
+    };
+
+    BABYLON.LensFlareSystem.prototype._isVisible = function () {
+        var emitterPosition = this.getEmitterPosition();
+        var direction = emitterPosition.subtract(this._scene.activeCamera.position);
+        var distance = direction.length();
+        direction.normalize();
+        
+        var ray = new BABYLON.Ray(this._scene.activeCamera.position, direction);
+        var pickInfo = this._scene.pickWithRay(ray, this.meshesSelectionPredicate, true);
+
+        return !pickInfo.hit || pickInfo.distance > distance;
+    };
+
+    BABYLON.LensFlareSystem.prototype.render = function () {
+        if (!this._effect.isReady())
+            return false;
+
+        var engine = this._scene.getEngine();
+        var viewport = this._scene.activeCamera.viewport;
+        var globalViewport = viewport.toGlobal(engine);
+        
+        // Position
+        if (!this.computeEffectivePosition(globalViewport)) {
+            return false;
+        }
+        
+        // Visibility
+        if (!this._isVisible()) {
+            return false;
+        }
+
+        // Intensity
+        var awayX;
+        var awayY;
+
+        if (this._positionX < this.borderLimit + globalViewport.x) {
+            awayX = this.borderLimit + globalViewport.x - this._positionX;
+        } else if (this._positionX > globalViewport.x + globalViewport.width - this.borderLimit) {
+            awayX = this._positionX - globalViewport.x - globalViewport.width + this.borderLimit;
+        } else {
+            awayX = 0;
+        }
+
+        if (this._positionY < this.borderLimit + globalViewport.y) {
+            awayY = this.borderLimit + globalViewport.y - this._positionY;
+        } else if (this._positionY > globalViewport.y + globalViewport.height - this.borderLimit) {
+            awayY = this._positionY - globalViewport.y - globalViewport.height + this.borderLimit;
+        } else {
+            awayY = 0;
+        }
+
+        var away = (awayX > awayY) ? awayX : awayY;
+        if (away > this.borderLimit) {
+            away = this.borderLimit;
+        }
+
+        var intensity = 1.0 - (away / this.borderLimit);
+        if (intensity < 0) {
+            return false;
+        }
+        
+        if (intensity > 1.0) {
+            intensity = 1.0;
+        }
+
+        // Position
+        var centerX = globalViewport.x + globalViewport.width / 2;
+        var centerY = globalViewport.y + globalViewport.height / 2;
+        var distX = centerX - this._positionX;
+        var distY = centerY - this._positionY;
+
+        // Effects
+        engine.enableEffect(this._effect);
+        engine.setState(false);
+        engine.setDepthBuffer(false);
+        engine.setAlphaMode(BABYLON.Engine.ALPHA_ADD);
+        
+        // VBOs
+        engine.bindBuffers(this._vertexBuffer, this._indexBuffer, this._vertexDeclaration, this._vertexStrideSize, this._effect);
+
+        // Flares
+        for (var index = 0; index < this.lensFlares.length; index++) {
+            var flare = this.lensFlares[index];
+
+            var x = centerX - (distX * flare.position);
+            var y = centerY - (distY * flare.position);
+            
+            var cw = flare.size;
+            var ch = flare.size * engine.getAspectRatio();
+            var cx = 2 * (x / globalViewport.width) - 1.0;
+            var cy = 1.0 - 2 * (y / globalViewport.height);
+            
+            var viewportMatrix = BABYLON.Matrix.FromValues(
+                                    cw / 2, 0, 0, 0,
+                                    0, ch / 2, 0, 0,
+                                    0, 0, 1, 0,
+                                    cx, cy, 0, 1);
+
+            this._effect.setMatrix("viewportMatrix", viewportMatrix);
+            
+            // Texture
+            this._effect.setTexture("textureSampler", flare.texture);
+
+            // Color
+            this._effect.setFloat4("color", flare.color.r * intensity, flare.color.g * intensity, flare.color.b * intensity, 1.0);
+
+            // Draw order
+            engine.draw(true, 0, 6);
+        }
+        
+        engine.setDepthBuffer(true);
+        engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
+        return true;
+    };
+
+    BABYLON.LensFlareSystem.prototype.dispose = function () {
+        if (this._vertexBuffer) {
+            this._scene.getEngine()._releaseBuffer(this._vertexBuffer);
+            this._vertexBuffer = null;
+        }
+
+        if (this._indexBuffer) {
+            this._scene.getEngine()._releaseBuffer(this._indexBuffer);
+            this._indexBuffer = null;
+        }
+
+        while (this.lensFlares.length) {
+            this.lensFlares[0].dispose();
+        }
+
+        // Remove from scene
+        var index = this._scene.lensFlareSystems.indexOf(this);
+        this._scene.lensFlareSystems.splice(index, 1);
+    };
+
+})();

+ 3 - 0
Babylon/Lights/babylon.light.js

@@ -12,6 +12,9 @@
         
         // Animations
         this.animations = [];
+        
+        // Exclusions
+        this.excludedMeshes = [];
     };
     
     BABYLON.Light.prototype = Object.create(BABYLON.Node.prototype);

+ 8 - 0
Babylon/Materials/babylon.standardMaterial.js

@@ -137,6 +137,10 @@
                 continue;
             }
 
+            if (mesh && light.excludedMeshes.indexOf(mesh) !== -1) {
+                continue;
+            }
+
             defines.push("#define LIGHT" + lightIndex);
             
             if (lightIndex > 0) {
@@ -347,6 +351,10 @@
             if (!light.isEnabled()) {
                 continue;
             }
+            
+            if (mesh && light.excludedMeshes.indexOf(mesh) !== -1) {
+                continue;
+            }
 
             if (light instanceof BABYLON.PointLight) {
                 // Point Light

+ 14 - 3
Babylon/Materials/textures/babylon.dynamicTexture.js

@@ -1,7 +1,7 @@
 var BABYLON = BABYLON || {};
 
 (function () {
-    BABYLON.DynamicTexture = function (name, size, scene, generateMipMaps) {
+    BABYLON.DynamicTexture = function (name, options, scene, generateMipMaps) {
         this._scene = scene;
         this._scene.textures.push(this);
 
@@ -12,10 +12,21 @@
 
         this._generateMipMaps = generateMipMaps;
 
-        this._texture = scene.getEngine().createDynamicTexture(size, generateMipMaps);
+        if (options.getContext) {
+            this._canvas = options;
+            this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps);
+        } else {
+            this._canvas = document.createElement("canvas");
+
+            if (options.width) {
+                this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps);
+            } else {
+                this._texture = scene.getEngine().createDynamicTexture(options, options, generateMipMaps);
+            }
+        }
+        
         var textureSize = this.getSize();
 
-        this._canvas = document.createElement("canvas");
         this._canvas.width = textureSize.width;
         this._canvas.height = textureSize.height;
         this._context = this._canvas.getContext("2d");

+ 2 - 14
Babylon/Materials/textures/babylon.mirrorTexture.js

@@ -2,19 +2,7 @@
 
 (function () {
     BABYLON.MirrorTexture = function (name, size, scene, generateMipMaps) {
-        this._scene = scene;
-        this._scene.textures.push(this);
-
-        this.name = name;
-        this._generateMipMaps = generateMipMaps;
-
-        this._texture = scene.getEngine().createRenderTargetTexture(size, generateMipMaps);
-        
-        // Render list
-        this.renderList = [];
-
-        // Rendering groups
-        this._renderingManager = new BABYLON.RenderingManager(scene);
+        BABYLON.RenderTargetTexture.call(this, name, size, scene, generateMipMaps);
         
         // Internals
         this._transformMatrix = BABYLON.Matrix.Zero();
@@ -53,7 +41,7 @@
     
     BABYLON.MirrorTexture.prototype.clone = function () {
         var textureSize = this.getSize();
-        var newTexture = new BABYLON.DynamicTexture(this.name, textureSize.width, this._scene, this._generateMipMaps);
+        var newTexture = new BABYLON.MirrorTexture(this.name, textureSize.width, this._scene, this._generateMipMaps);
 
         // Base texture
         newTexture.hasAlpha = this.hasAlpha;

+ 5 - 0
Babylon/Materials/textures/babylon.renderTargetTexture.js

@@ -6,6 +6,7 @@
         this._scene.textures.push(this);
 
         this.name = name;
+        this._generateMipMaps = generateMipMaps;
 
         this._texture = scene.getEngine().createRenderTargetTexture(size, generateMipMaps);
 
@@ -34,6 +35,7 @@
     };
 
     BABYLON.RenderTargetTexture.prototype.render = function () {
+
         if (this.onBeforeRender) {
             this.onBeforeRender();
         }
@@ -52,6 +54,9 @@
         }
 
         if (!this.renderList || this.renderList.length == 0) {
+            if (this.onAfterRender) {
+                this.onAfterRender();
+            }
             return;
         }
 

+ 1 - 0
Babylon/Materials/textures/babylon.texture.js

@@ -54,6 +54,7 @@
     BABYLON.Texture.prototype.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
     BABYLON.Texture.prototype.coordinatesIndex = 0;
     BABYLON.Texture.prototype.coordinatesMode = BABYLON.Texture.EXPLICIT_MODE;
+    BABYLON.Texture.prototype.anisotropicFilteringLevel = 4;
 
     // Methods    
     BABYLON.Texture.prototype.delayLoad = function () {

+ 42 - 10
Babylon/Mesh/babylon.mesh.js

@@ -32,6 +32,7 @@
         this._positions = null;
         this._cache = {
             localMatrixUpdated: false,
+            infiniteDistance: true,
             position: BABYLON.Vector3.Zero(),
             scaling: BABYLON.Vector3.Zero(),
             rotation: BABYLON.Vector3.Zero(),
@@ -51,6 +52,8 @@
 
         this._collisionsTransformMatrix = BABYLON.Matrix.Zero();
         this._collisionsScalingMatrix = BABYLON.Matrix.Zero();
+
+        this._absolutePosition = BABYLON.Vector3.Zero();
     };
     
     BABYLON.Mesh.prototype = Object.create(BABYLON.Node.prototype);
@@ -78,6 +81,8 @@
     BABYLON.Mesh.prototype.skeleton = null;
     
     BABYLON.Mesh.prototype.renderingGroupId = 0;
+    
+    BABYLON.Mesh.prototype.infiniteDistance = false;
 
     // Properties
 
@@ -90,9 +95,16 @@
     };
 
     BABYLON.Mesh.prototype.getWorldMatrix = function () {
+        if (this._currentRenderId !== this._scene.getRenderId()) {
+            this.computeWorldMatrix();
+        }
         return this._worldMatrix;
     };
-
+    
+    BABYLON.Mesh.prototype.getAbsolutePosition = function () {
+        return this._absolutePosition;
+    };
+        
     BABYLON.Mesh.prototype.getTotalVertices = function () {
         return this._totalVertices;
     };
@@ -137,6 +149,10 @@
         if (this._cache.pivotMatrixUpdated) {
             return false;
         }
+        
+        if (this._cache.infiniteDistance !== this.infiniteDistance) {
+            return false;
+        }
 
         if (!this._cache.position.equals(this.position))
             return false;
@@ -175,6 +191,7 @@
         if (property === "rotation") {
             this.rotationQuaternion = null;
         }
+        this._childrenFlag = true;
     };
     
     BABYLON.Mesh.prototype.refreshBoundingInfo = function () {
@@ -219,6 +236,7 @@
         }
 
         this._childrenFlag = true;
+        this._cache.infiniteDistance = this.infiniteDistance;
         this._cache.position.copyFrom(this.position);
         this._cache.scaling.copyFrom(this.scaling);
         this._cache.pivotMatrixUpdated = false;
@@ -237,7 +255,12 @@
         }
 
         // Translation
-        BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._localTranslation);
+        if (this.infiniteDistance) {
+            var camera = this._scene.activeCamera;
+            BABYLON.Matrix.TranslationToRef(this.position.x + camera.position.x, this.position.y + camera.position.y, this.position.z + camera.position.z, this._localTranslation);
+        } else {
+            BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._localTranslation);
+        }
 
         // Composing transformations
         this._pivotMatrix.multiplyToRef(this._localScaling, this._localPivotScaling);
@@ -286,6 +309,9 @@
         // Bounding info
         this._updateBoundingInfo();
 
+        // Absolute position
+        this._absolutePosition.copyFromFloats(this._worldMatrix.m[12], this._worldMatrix.m[13], this._worldMatrix.m[14]);
+
         return this._worldMatrix;
     };
 
@@ -629,8 +655,10 @@
 
     // Picking
     BABYLON.Mesh.prototype.intersects = function (ray, fastCheck) {
+        var pickingInfo = new BABYLON.PickingInfo();
+
         if (!this._boundingInfo || !ray.intersectsSphere(this._boundingInfo.boundingSphere) || !ray.intersectsBox(this._boundingInfo.boundingBox)) {
-            return { hit: false, distance: 0 };
+            return pickingInfo;
         }
 
         this._generatePointsArray();
@@ -644,11 +672,11 @@
             if (this.subMeshes.length > 1 && !subMesh.canIntersects(ray))
                 continue;
 
-            var result = subMesh.intersects(ray, this._positions, this._indices, fastCheck);
+            var currentDistance = subMesh.intersects(ray, this._positions, this._indices, fastCheck);
 
-            if (result.hit) {
-                if ((fastCheck || result.distance < distance) && result.distance >= 0) {
-                    distance = result.distance;
+            if (currentDistance > 0) {
+                if (fastCheck || currentDistance < distance) {
+                    distance = currentDistance;
 
                     if (fastCheck) {
                         break;
@@ -657,7 +685,7 @@
             }
         }
 
-        if (distance >= 0) {
+        if (distance >= 0 && distance < Number.MAX_VALUE) {
             // Get picked point
             var world = this.getWorldMatrix();
             var worldOrigin = BABYLON.Vector3.TransformCoordinates(ray.origin, world);
@@ -669,10 +697,14 @@
             var pickedPoint = worldOrigin.add(worldDirection);
 
             // Return result
-            return { hit: true, distance: BABYLON.Vector3.Distance(worldOrigin, pickedPoint), pickedPoint: pickedPoint };
+            pickingInfo.hit = true;
+            pickingInfo.distance = BABYLON.Vector3.Distance(worldOrigin, pickedPoint);
+            pickingInfo.pickedPoint = pickedPoint;
+            pickingInfo.pickedMesh = this;
+            return pickingInfo;
         }
 
-        return { hit: false, distance: 0 };
+        return pickingInfo;
     };
 
     // Clone

+ 25 - 25
Babylon/Mesh/babylon.subMesh.js

@@ -12,23 +12,23 @@
 
         this.refreshBoundingInfo();
     };
-    
+
     //Properties
-    BABYLON.SubMesh.prototype.getBoundingInfo = function() {
+    BABYLON.SubMesh.prototype.getBoundingInfo = function () {
         return this._boundingInfo;
     };
-    
+
     BABYLON.SubMesh.prototype.getMesh = function () {
         return this._mesh;
     };
 
     BABYLON.SubMesh.prototype.getMaterial = function () {
         var rootMaterial = this._mesh.material;
-        
+
         if (rootMaterial && rootMaterial.getSubMaterial) {
             return rootMaterial.getSubMaterial(this.materialIndex);
         }
-        
+
         if (!rootMaterial) {
             return this._mesh._scene.defaultMaterial;
         }
@@ -51,25 +51,25 @@
     BABYLON.SubMesh.prototype._checkCollision = function (collider) {
         return this._boundingInfo._checkCollision(collider);
     };
-    
-    BABYLON.SubMesh.prototype.updateBoundingInfo = function(world, scale) {
+
+    BABYLON.SubMesh.prototype.updateBoundingInfo = function (world, scale) {
         this._boundingInfo._update(world, scale);
     };
-    
+
     BABYLON.SubMesh.prototype.isInFrustrum = function (frustumPlanes) {
         return this._boundingInfo.isInFrustrum(frustumPlanes);
     };
-    
-    BABYLON.SubMesh.prototype.render = function() {
+
+    BABYLON.SubMesh.prototype.render = function () {
         this._mesh.render(this);
     };
 
-    BABYLON.SubMesh.prototype.getLinesIndexBuffer = function(indices, engine) {
+    BABYLON.SubMesh.prototype.getLinesIndexBuffer = function (indices, engine) {
         if (!this._linesIndexBuffer) {
             var linesIndices = [];
 
             for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += 3) {
-                linesIndices.push(  indices[index], indices[index + 1],
+                linesIndices.push(indices[index], indices[index + 1],
                                     indices[index + 1], indices[index + 2],
                                     indices[index + 2], indices[index]);
             }
@@ -80,24 +80,24 @@
         return this._linesIndexBuffer;
     };
 
-    BABYLON.SubMesh.prototype.canIntersects = function(ray) {
+    BABYLON.SubMesh.prototype.canIntersects = function (ray) {
         return ray.intersectsBox(this._boundingInfo.boundingBox);
     };
 
     BABYLON.SubMesh.prototype.intersects = function (ray, positions, indices, fastCheck) {
         var distance = Number.MAX_VALUE;
-        
+
         // Triangles test
         for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += 3) {
             var p0 = positions[indices[index]];
             var p1 = positions[indices[index + 1]];
             var p2 = positions[indices[index + 2]];
 
-            var result = ray.intersectsTriangle(p0, p1, p2);
+            var currentDistance = ray.intersectsTriangle(p0, p1, p2);
 
-            if (result.hit) {
-                if ((fastCheck || result.distance < distance) && result.distance >= 0) {
-                    distance = result.distance;
+            if (currentDistance > 0) {
+                if (fastCheck || currentDistance < distance) {
+                    distance = currentDistance;
 
                     if (fastCheck) {
                         break;
@@ -105,20 +105,20 @@
                 }
             }
         }
-        
-        if (distance >= 0)
-            return { hit: true, distance: distance };
 
-        return { hit: false, distance: 0 };
+        if (distance > 0 && distance < Number.MAX_VALUE)
+            return distance;
+
+        return 0;
     };
 
     // Clone    
-    BABYLON.SubMesh.prototype.clone = function(newMesh) {
+    BABYLON.SubMesh.prototype.clone = function (newMesh) {
         return new BABYLON.SubMesh(this.materialIndex, this.verticesStart, this.verticesCount, this.indexStart, this.indexCount, newMesh);
     };
-    
+
     // Statics
-    BABYLON.SubMesh.CreateFromIndices = function(materialIndex, startIndex, indexCount, mesh) {
+    BABYLON.SubMesh.CreateFromIndices = function (materialIndex, startIndex, indexCount, mesh) {
         var minVertexIndex = Number.MAX_VALUE;
         var maxVertexIndex = -Number.MAX_VALUE;
 

+ 8 - 1
Babylon/Particles/babylon.particleSystem.js

@@ -38,7 +38,7 @@
 
         // VBO
         this._vertexDeclaration = [3, 4, 4];
-        this._vertexStrideSize = 11 * 4; // 10 floats per particle (x, y, z, r, g, b, a, angle, size, offsetX, offsetY)
+        this._vertexStrideSize = 11 * 4; // 11 floats per particle (x, y, z, r, g, b, a, angle, size, offsetX, offsetY)
         this._vertexBuffer = scene.getEngine().createDynamicVertexBuffer(capacity * this._vertexStrideSize * 4);
 
         var indices = [];
@@ -62,6 +62,7 @@
         this._colorDiff = new BABYLON.Color4(0, 0, 0, 0);
         this._scaledDirection = BABYLON.Vector3.Zero();
         this._scaledGravity = BABYLON.Vector3.Zero();
+        this._currentRenderId = -1;
     };
 
     // Members
@@ -228,6 +229,12 @@
         // Check
         if (!this.emitter || !effect.isReady() || !this.particleTexture || !this.particleTexture.isReady())
             return;
+        
+        if (this._currentRenderId === this._scene.getRenderId()) {
+            return;
+        }
+
+        this._currentRenderId = this._scene.getRenderId();
 
         this._scaledUpdateSpeed = this.updateSpeed * this._scene.getAnimationRatio();
 

+ 3 - 0
Babylon/PostProcess/babylon.postProcess.js

@@ -41,6 +41,9 @@
             }
         }
         this._engine.bindFramebuffer(this._texture);
+        
+        // Clear
+        this._engine.clear(this._scene.clearColor, this._scene.autoClear || this._scene.forceWireframe, true);
     };
 
     BABYLON.PostProcess.prototype.apply = function () {

+ 30 - 7
Babylon/Rendering/babylon.renderingGroup.js

@@ -46,15 +46,38 @@
         }
 
         // Transparent
-        engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE);
-        for (subIndex = 0; subIndex < this._transparentSubMeshes.length; subIndex++) {
-            submesh = this._transparentSubMeshes.data[subIndex];
-            this._activeVertices += submesh.verticesCount;
+        if (this._transparentSubMeshes.length) {
+            // Sorting
+            for (subIndex = 0; subIndex < this._transparentSubMeshes.length; subIndex++) {
+                submesh = this._transparentSubMeshes.data[subIndex];
+                submesh._distanceToCamera = submesh.getBoundingInfo().boundingSphere.centerWorld.subtract(this._scene.activeCamera.position).length();
+            }
 
-            submesh.render();
-        }
-        engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
+            var sortedArray = this._transparentSubMeshes.data.slice(0, this._transparentSubMeshes.length);
+
+            sortedArray.sort(function (a, b) {
+                if (a._distanceToCamera < b._distanceToCamera) {
+                    return 1;
+                }
+                if (a._distanceToCamera > b._distanceToCamera) {
+                    return -1;
+                }
 
+                return 0;
+            });
+
+            // Rendering
+            engine.setDepthWrite(false);
+            engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE);
+            for (subIndex = 0; subIndex < sortedArray.length; subIndex++) {
+                submesh = sortedArray[subIndex];
+                this._activeVertices += submesh.verticesCount;
+
+                submesh.render();
+            }
+            engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
+            engine.setDepthWrite(true);
+        }
         return true;
     };
 

+ 78 - 34
Babylon/Shaders/default.fragment.fx

@@ -2,7 +2,12 @@
 precision mediump float;
 #endif
 
+#define MAP_EXPLICIT	0.
+#define MAP_SPHERICAL	1.
+#define MAP_PLANAR		2.
+#define MAP_CUBIC		3.
 #define MAP_PROJECTION	4.
+#define MAP_SKYBOX		5.
 
 // Constants
 uniform vec3 vEyePosition;
@@ -103,13 +108,6 @@ uniform sampler2D opacitySampler;
 uniform vec2 vOpacityInfos;
 #endif
 
-#ifdef REFLECTION
-varying vec3 vReflectionUVW;
-uniform samplerCube reflectionCubeSampler;
-uniform sampler2D reflection2DSampler;
-uniform vec3 vReflectionInfos;
-#endif
-
 #ifdef EMISSIVE
 varying vec2 vEmissiveUV;
 uniform vec2 vEmissiveInfos;
@@ -122,6 +120,50 @@ uniform vec2 vSpecularInfos;
 uniform sampler2D specularSampler;
 #endif
 
+// Reflection
+#ifdef REFLECTION
+varying vec3 vPositionUVW;
+uniform samplerCube reflectionCubeSampler;
+uniform sampler2D reflection2DSampler;
+uniform vec3 vReflectionInfos;
+uniform mat4 reflectionMatrix;
+uniform mat4 view;
+
+vec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)
+{
+	if (mode == MAP_SPHERICAL)
+	{
+		vec3 coords = vec3(view * vec4(worldNormal, 0.0));
+
+		return vec3(reflectionMatrix * vec4(coords, 1.0));
+	}
+	else if (mode == MAP_PLANAR)
+	{
+		vec3 viewDir = worldPos.xyz - vEyePosition;
+		vec3 coords = normalize(reflect(viewDir, worldNormal));
+
+		return vec3(reflectionMatrix * vec4(coords, 1));
+	}
+	else if (mode == MAP_CUBIC)
+	{
+		vec3 viewDir = worldPos.xyz - vEyePosition;
+		vec3 coords = reflect(viewDir, worldNormal);
+
+		return vec3(reflectionMatrix * vec4(coords, 0));
+	}
+	else if (mode == MAP_PROJECTION)
+	{
+		return vec3(reflectionMatrix * (view * worldPos));
+	}
+	else if (mode == MAP_SKYBOX)
+	{
+		return vPositionUVW;
+	}
+
+	return vec3(0, 0, 0);
+}
+#endif
+
 // Shadows
 #ifdef SHADOWS
 
@@ -131,8 +173,8 @@ float unpack(vec4 color)
 	return dot(color, bitShift);
 }
 
-float unpackHalf(vec2 color) 
-{ 
+float unpackHalf(vec2 color)
+{
 	return color.x + (color.y / 255.0);
 }
 
@@ -156,18 +198,18 @@ float computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler)
 }
 
 // Thanks to http://devmaster.net/
-float ChebychevInequality(vec2 moments, float t) 
+float ChebychevInequality(vec2 moments, float t)
 {
 	if (t <= moments.x)
 	{
 		return 1.0;
 	}
-	
-	float variance = moments.y - (moments.x * moments.x); 
+
+	float variance = moments.y - (moments.x * moments.x);
 	variance = max(variance, 0.);
 
-	float d = t - moments.x; 	
-	return variance / (variance + d * d); 
+	float d = t - moments.x;
+	return variance / (variance + d * d);
 }
 
 float computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler)
@@ -407,11 +449,11 @@ void main(void) {
 	lightingInfo info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0);
 #endif
 #ifdef SHADOW0
-	#ifdef SHADOWVSM0
-		shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0);
-	#else
-		shadow = computeShadow(vPositionFromLight0, shadowSampler0);
-	#endif
+#ifdef SHADOWVSM0
+	shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0);
+#else
+	shadow = computeShadow(vPositionFromLight0, shadowSampler0);
+#endif
 #else
 	shadow = 1.;
 #endif
@@ -430,11 +472,11 @@ void main(void) {
 	info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1);
 #endif
 #ifdef SHADOW1
-	#ifdef SHADOWVSM1
-		shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1);
-	#else
-		shadow = computeShadow(vPositionFromLight1, shadowSampler1);
-	#endif
+#ifdef SHADOWVSM1
+	shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1);
+#else
+	shadow = computeShadow(vPositionFromLight1, shadowSampler1);
+#endif
 #else
 	shadow = 1.;
 #endif
@@ -453,11 +495,11 @@ void main(void) {
 	info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2);
 #endif
 #ifdef SHADOW2
-	#ifdef SHADOWVSM2
-		shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2);
-	#else
-		shadow = computeShadow(vPositionFromLight2, shadowSampler2);
-	#endif	
+#ifdef SHADOWVSM2
+	shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2);
+#else
+	shadow = computeShadow(vPositionFromLight2, shadowSampler2);
+#endif	
 #else
 	shadow = 1.;
 #endif
@@ -476,11 +518,11 @@ void main(void) {
 	info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3);
 #endif
 #ifdef SHADOW3
-	#ifdef SHADOWVSM3
-		shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3);
-	#else
-		shadow = computeShadow(vPositionFromLight3, shadowSampler3);
-	#endif	
+#ifdef SHADOWVSM3
+	shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3);
+#else
+	shadow = computeShadow(vPositionFromLight3, shadowSampler3);
+#endif	
 #else
 	shadow = 1.;
 #endif
@@ -492,6 +534,8 @@ void main(void) {
 	vec3 reflectionColor = vec3(0., 0., 0.);
 
 #ifdef REFLECTION
+	vec3 vReflectionUVW = computeReflectionCoords(vReflectionInfos.x, vec4(vPositionW, 1.0), normalW);
+
 	if (vReflectionInfos.z != 0.0)
 	{
 		reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.y;

+ 5 - 51
Babylon/Shaders/default.vertex.fx

@@ -2,13 +2,6 @@
 precision mediump float;
 #endif
 
-#define MAP_EXPLICIT	0.
-#define MAP_SPHERICAL	1.
-#define MAP_PLANAR		2.
-#define MAP_CUBIC		3.
-#define MAP_PROJECTION	4.
-#define MAP_SKYBOX		5.
-
 // Attributes
 attribute vec3 position;
 attribute vec3 normal;
@@ -48,13 +41,6 @@ uniform mat4 opacityMatrix;
 uniform vec2 vOpacityInfos;
 #endif
 
-#ifdef REFLECTION
-uniform vec3 vEyePosition;
-varying vec3 vReflectionUVW;
-uniform vec3 vReflectionInfos;
-uniform mat4 reflectionMatrix;
-#endif
-
 #ifdef EMISSIVE
 varying vec2 vEmissiveUV;
 uniform vec2 vEmissiveInfos;
@@ -117,44 +103,16 @@ varying vec4 vPositionFromLight3;
 #endif
 
 #ifdef REFLECTION
-vec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)
-{
-	if (mode == MAP_SPHERICAL)
-	{
-		vec3 coords = vec3(view * vec4(worldNormal, 0.0));
-
-		return vec3(reflectionMatrix * vec4(coords, 1.0));
-	}
-	else if (mode == MAP_PLANAR)
-	{
-		vec3 viewDir = worldPos.xyz - vEyePosition;
-		vec3 coords = normalize(reflect(viewDir, worldNormal));
-
-		return vec3(reflectionMatrix * vec4(coords, 1));
-	}
-	else if (mode == MAP_CUBIC)
-	{
-		vec3 viewDir = worldPos.xyz - vEyePosition;
-		vec3 coords = reflect(viewDir, worldNormal);
-
-		return vec3(reflectionMatrix * vec4(coords, 0));
-	}
-	else if (mode == MAP_PROJECTION)
-	{
-		return vec3(reflectionMatrix * (view * worldPos));
-	}
-	else if (mode == MAP_SKYBOX)
-	{
-		return position;
-	}
-
-	return vec3(0, 0, 0);
-}
+varying vec3 vPositionUVW;
 #endif
 
 void main(void) {
 	mat4 finalWorld;
 
+#ifdef REFLECTION
+	vPositionUVW = position;
+#endif 
+
 #ifdef BONES
 	mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;
 	mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;
@@ -218,10 +176,6 @@ void main(void) {
 	}
 #endif
 
-#ifdef REFLECTION
-	vReflectionUVW = computeReflectionCoords(vReflectionInfos.x, vec4(vPositionW, 1.0), vNormalW);
-#endif
-
 #ifdef EMISSIVE
 	if (vEmissiveInfos.x == 0.)
 	{

+ 16 - 0
Babylon/Shaders/lensFlare.fragment.fx

@@ -0,0 +1,16 @@
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+// Samplers
+varying vec2 vUV;
+uniform sampler2D textureSampler;
+
+// Color
+uniform vec4 color;
+
+void main(void) {
+	vec4 baseColor = texture2D(textureSampler, vUV);
+
+	gl_FragColor = baseColor * color;
+}

+ 20 - 0
Babylon/Shaders/lensFlare.vertex.fx

@@ -0,0 +1,20 @@
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+// Attributes
+attribute vec2 position;
+
+// Uniforms
+uniform mat4 viewportMatrix;
+
+// Output
+varying vec2 vUV;
+
+const vec2 madd = vec2(0.5, 0.5);
+
+void main(void) {	
+
+	vUV = position * madd + madd;
+	gl_Position = viewportMatrix * vec4(position, 0.0, 1.0);
+}

+ 63 - 38
Babylon/Tools/babylon.math.js

@@ -109,56 +109,42 @@
     };
 
     BABYLON.Ray.prototype.intersectsTriangle = function (vertex0, vertex1, vertex2) {
-        var edge1 = vertex1.subtract(vertex0);
-        var edge2 = vertex2.subtract(vertex0);
-        var pvec = BABYLON.Vector3.Cross(this.direction, edge2);
-        var det = BABYLON.Vector3.Dot(edge1, pvec);
+        if (!this._edge1) {
+            this._edge1 = BABYLON.Vector3.Zero();
+            this._edge2 = BABYLON.Vector3.Zero();
+            this._pvec = BABYLON.Vector3.Zero();
+            this._tvec = BABYLON.Vector3.Zero();
+            this._qvec = BABYLON.Vector3.Zero();
+        }
+
+        vertex1.subtractToRef(vertex0, this._edge1);
+        vertex2.subtractToRef(vertex0, this._edge2);
+        BABYLON.Vector3.CrossToRef(this.direction, this._edge2, this._pvec);
+        var det = BABYLON.Vector3.Dot(this._edge1, this._pvec);
 
         if (det === 0) {
-            return {
-                hit: false,
-                distance: 0,
-                bu: 0,
-                bv: 0
-            };
+            return 0;
         }
 
         var invdet = 1 / det;
 
-        var tvec = this.origin.subtract(vertex0);
+        this.origin.subtractToRef(vertex0, this._tvec);
 
-        var bu = BABYLON.Vector3.Dot(tvec, pvec) * invdet;
+        var bu = BABYLON.Vector3.Dot(this._tvec, this._pvec) * invdet;
 
         if (bu < 0 || bu > 1.0) {
-            return {
-                hit: false,
-                distance: 0,
-                bu: bu,
-                bv: 0
-            };
+            return 0;
         }
 
-        var qvec = BABYLON.Vector3.Cross(tvec, edge1);
+        BABYLON.Vector3.CrossToRef(this._tvec, this._edge1, this._qvec);
 
-        bv = BABYLON.Vector3.Dot(this.direction, qvec) * invdet;
+        var bv = BABYLON.Vector3.Dot(this.direction, this._qvec) * invdet;
 
         if (bv < 0 || bu + bv > 1.0) {
-            return {
-                hit: false,
-                distance: 0,
-                bu: bu,
-                bv: bv
-            };
+            return 0;
         }
 
-        distance = BABYLON.Vector3.Dot(edge2, qvec) * invdet;
-
-        return {
-            hit: true,
-            distance: distance,
-            bu: bu,
-            bv: bv
-        };
+        return BABYLON.Vector3.Dot(this._edge2, this._qvec) * invdet;
     };
 
     // Statics
@@ -171,6 +157,13 @@
 
         return new BABYLON.Ray(start, direction);
     };
+    
+    BABYLON.Ray.Transform = function (ray, matrix) {
+        var newOrigin = BABYLON.Vector3.TransformCoordinates(ray.origin, matrix);
+        var newDirection = BABYLON.Vector3.TransformNormal(ray.direction, matrix);
+        
+        return new BABYLON.Ray(newOrigin, newDirection);
+    };
 
     ////////////////////////////////// Color3 //////////////////////////////////
 
@@ -790,6 +783,23 @@
         result.copyFrom(vector);
         result.normalize();
     };
+    
+    BABYLON.Vector3.Project = function (vector, world, transform, viewport) {
+        var cw = viewport.width;
+        var ch = viewport.height;
+        var cx = viewport.x;
+        var cy = viewport.y;
+
+        var viewportMatrix = BABYLON.Matrix.FromValues(
+                                            cw / 2.0, 0, 0, 0,
+                                            0, -ch / 2.0, 0, 0,
+                                            0, 0, 1, 0,
+                                            cx + cw / 2.0, ch / 2.0 + cy, 0, 1);
+        
+        var finalMatrix = world.multiply(transform).multiply(viewportMatrix);
+
+        return BABYLON.Vector3.TransformCoordinates(vector, finalMatrix);
+    };
 
     BABYLON.Vector3.Unproject = function (source, viewportWidth, viewportHeight, world, view, projection) {
         var matrix = world.multiply(view).multiply(projection);
@@ -1457,7 +1467,6 @@
 
     };
 
-
     var xAxis = BABYLON.Vector3.Zero();
     var yAxis = BABYLON.Vector3.Zero();
     var zAxis = BABYLON.Vector3.Zero();
@@ -1561,13 +1570,11 @@
             BABYLON.Matrix.RotationQuaternion(rotation) * BABYLON.Matrix.Translation(rotationCenter) * BABYLON.Matrix.Translation(translation);
     };
 
-    BABYLON.Matrix.GetFinalMatrix = function (viewport, world, view, projection) {
+    BABYLON.Matrix.GetFinalMatrix = function (viewport, world, view, projection, zmin, zmax) {
         var cw = viewport.width;
         var ch = viewport.height;
         var cx = viewport.x;
         var cy = viewport.y;
-        var zmin = viewport.minZ;
-        var zmax = viewport.maxZ;
 
         var viewportMatrix = new BABYLON.Matrix(cw / 2.0, 0, 0, 0,
             0, -ch / 2.0, 0, 0,
@@ -1741,6 +1748,7 @@
 
         return BABYLON.Vector3.Dot(point, normal) + d;
     };
+    
     ////////////////////////////////// Frustum //////////////////////////////////
     BABYLON.Frustum = {};
 
@@ -1800,4 +1808,21 @@
         frustumPlanes[5].d = transform.m[15] + transform.m[13];
         frustumPlanes[5].normalize();
     };
+    
+    ////////////////////////////////// Viewport //////////////////////////////////
+    BABYLON.Viewport = {};
+    
+    BABYLON.Viewport = function (x, y, width, height) {
+        this.width = width;
+        this.height = height;
+        this.x = x;
+        this.y = y;
+    };
+    
+
+    BABYLON.Viewport.prototype.toGlobal = function (engine) {
+        var width = engine.getRenderWidth() * engine.getHardwareScalingLevel();
+        var height = engine.getRenderHeight() * engine.getHardwareScalingLevel();
+        return new BABYLON.Viewport(this.x * width, this.y * height, this.width * width, this.height * height);
+    };
 })();

+ 24 - 1
Babylon/Tools/babylon.sceneLoader.js

@@ -158,6 +158,20 @@
 
         return multiMaterial;
     };
+    
+    var parseLensFlareSystem = function (parsedLensFlareSystem, scene, rootUrl) {
+        var emitter = scene.getLastEntryByID(parsedLensFlareSystem.emitterId);
+
+        var lensFlareSystem = new BABYLON.LensFlareSystem("lensFlareSystem#" + parsedLensFlareSystem.emitterId, emitter, scene);
+        lensFlareSystem.borderLimit = parsedLensFlareSystem.borderLimit;
+        
+        for (var index = 0; index < parsedLensFlareSystem.flares.length; index++) {
+            var parsedFlare = parsedLensFlareSystem.flares[index];
+            var flare = new BABYLON.LensFlare(parsedFlare.size, parsedFlare.position, BABYLON.Color3.FromArray(parsedFlare.color), rootUrl + parsedFlare.textureName, lensFlareSystem);
+        }
+
+        return lensFlareSystem;
+    };
 
     var parseParticleSystem = function (parsedParticleSystem, scene, rootUrl) {
         var emitter = scene.getLastMeshByID(parsedParticleSystem.emitterId);
@@ -340,7 +354,8 @@
 
         mesh.setEnabled(parsedMesh.isEnabled);
         mesh.isVisible = parsedMesh.isVisible;
-
+        mesh.infiniteDistance = parsedMesh.infiniteDistance;
+        
         mesh.receiveShadows = parsedMesh.receiveShadows;
 
         mesh.billboardMode = parsedMesh.billboardMode;
@@ -662,6 +677,14 @@
                         parseParticleSystem(parsedParticleSystem, scene, rootUrl);
                     }
                 }
+                
+                // Lens flares
+                if (parsedData.lensFlareSystems) {
+                    for (var index = 0; index < parsedData.lensFlareSystems.length; index++) {
+                        var parsedLensFlareSystem = parsedData.lensFlareSystems[index];
+                        parseLensFlareSystem(parsedLensFlareSystem, scene, rootUrl);
+                    }
+                }
 
                 // Shadows
                 if (parsedData.shadowGenerators) {

+ 4 - 0
Babylon/Tools/babylon.tools.js

@@ -40,6 +40,10 @@
         }
         this.push(value);
     };
+    
+    BABYLON.Tools.SmartArray.prototype.sort = function (compareFn) {
+        this.data.sort(compareFn);
+    };
 
     BABYLON.Tools.SmartArray.prototype.reset = function() {
         this.length = 0;

+ 48 - 15
Babylon/babylon.engine.js

@@ -1,4 +1,6 @@
-var BABYLON = BABYLON || {};
+"use strict";
+
+var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON.Engine = function (canvas, antialias) {
@@ -38,8 +40,10 @@
         this._caps.maxRenderTextureSize = this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE);
 
         // Extensions
-        var derivatives = this._gl.getExtension('OES_standard_derivatives');
-        this._caps.standardDerivatives = (derivatives !== null);
+        this._caps.standardDerivatives = (this._gl.getExtension('OES_standard_derivatives') !== null);
+        this._caps.textureFloat = (this._gl.getExtension('OES_texture_float') !== null);        
+        this._caps.textureAnisotropicFilterExtension = this._gl.getExtension('EXT_texture_filter_anisotropic') || this._gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic') || this._gl.getExtension('MOZ_EXT_texture_filter_anisotropic');
+        this._caps.maxAnisotropy = this._caps.textureAnisotropicFilterExtension ? this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 0;
 
         // Cache
         this._loadedTexturesCache = [];
@@ -197,11 +201,28 @@
 
         this._gl.clear(mode);
     };
+    
+    BABYLON.Engine.prototype.setViewport = function (viewport, requiredWidth, requiredHeight) {
+        var width = requiredWidth || this._renderingCanvas.width;
+        var height = requiredHeight || this._renderingCanvas.height;
+        var x = viewport.x || 0;
+        var y = viewport.y || 0;
+        
+        this._cachedViewport = viewport;
+        
+        this._gl.viewport(x * width, y * height, width * viewport.width, height * viewport.height);
+        this._aspectRatio = (width * viewport.width) / (height * viewport.height);
+    };
+    
+    BABYLON.Engine.prototype.setDirectViewport = function (x, y, width, height) {
+        this._cachedViewport = null;
+
+        this._gl.viewport(x, y, width, height);
+        this._aspectRatio = width / height;
+    };
 
     BABYLON.Engine.prototype.beginFrame = function () {
         BABYLON.Tools._MeasureFps();
-
-        this._gl.viewport(0, 0, this._renderingCanvas.width, this._renderingCanvas.height);
     };
 
     BABYLON.Engine.prototype.endFrame = function () {
@@ -210,14 +231,14 @@
 
     BABYLON.Engine.prototype.resize = function () {
         this._renderingCanvas.width = this._renderingCanvas.clientWidth / this._hardwareScalingLevel;
-        this._renderingCanvas.height = this._renderingCanvas.clientHeight / this._hardwareScalingLevel;
-        this._aspectRatio = this._renderingCanvas.width / this._renderingCanvas.height;
+        this._renderingCanvas.height = this._renderingCanvas.clientHeight / this._hardwareScalingLevel;        
     };
 
     BABYLON.Engine.prototype.bindFramebuffer = function (texture) {
         var gl = this._gl;
         gl.bindFramebuffer(gl.FRAMEBUFFER, texture._framebuffer);
-        gl.viewport(0.0, 0.0, texture._width, texture._height);
+        this._gl.viewport(0, 0, texture._width, texture._height);
+        this._aspectRatio = texture._width / texture._height;
 
         this.wipeCaches();
     };
@@ -237,7 +258,8 @@
 
     BABYLON.Engine.prototype.restoreDefaultFramebuffer = function () {
         this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, null);
-        this._gl.viewport(0, 0, this._renderingCanvas.width, this._renderingCanvas.height);
+
+        this.setViewport(this._cachedViewport);
 
         this.wipeCaches();
     };
@@ -636,11 +658,11 @@
         return texture;
     };
 
-    BABYLON.Engine.prototype.createDynamicTexture = function (size, generateMipMaps) {
+    BABYLON.Engine.prototype.createDynamicTexture = function (width, height, generateMipMaps) {
         var texture = this._gl.createTexture();
 
-        var width = getExponantOfTwo(size, this._caps.maxTextureSize);
-        var height = width;
+        width = getExponantOfTwo(width, this._caps.maxTextureSize);
+        height = getExponantOfTwo(height, this._caps.maxTextureSize);
 
         this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
         this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, this._gl.LINEAR);
@@ -722,9 +744,7 @@
             }
         }
         var gl = this._gl;
-
-        
-
+       
         var texture = gl.createTexture();
         gl.bindTexture(gl.TEXTURE_2D, texture);
 
@@ -952,6 +972,8 @@
                 this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_S, texture.coordinatesMode !== BABYLON.CubeTexture.CUBIC_MODE ? this._gl.REPEAT : this._gl.CLAMP_TO_EDGE);
                 this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_T, texture.coordinatesMode !== BABYLON.CubeTexture.CUBIC_MODE ? this._gl.REPEAT : this._gl.CLAMP_TO_EDGE);
             }
+
+            this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP, texture);
         } else {
             this._gl.bindTexture(this._gl.TEXTURE_2D, internalTexture);
 
@@ -985,6 +1007,17 @@
                         break;
                 }
             }
+
+            this._setAnisotropicLevel(this._gl.TEXTURE_2D, texture);
+        }
+    };
+
+    BABYLON.Engine.prototype._setAnisotropicLevel = function (key, texture) {
+        var anisotropicFilterExtension = this._caps.textureAnisotropicFilterExtension;
+
+        if (anisotropicFilterExtension && texture._cachedAnisotropicFilteringLevel !== texture.anisotropicFilteringLevel) {
+            this._gl.texParameterf(key, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropicFilteringLevel, this._caps.maxAnisotropy));
+            texture._cachedAnisotropicFilteringLevel = texture.anisotropicFilteringLevel;
         }
     };
 

+ 3 - 1
Babylon/babylon.node.js

@@ -1,4 +1,6 @@
-var BABYLON = BABYLON || {};
+"use strict";
+
+var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON.Node = function () {

+ 127 - 64
Babylon/babylon.scene.js

@@ -1,4 +1,6 @@
-var BABYLON = BABYLON || {};
+"use strict";
+
+var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON.Scene = function (engine) {
@@ -50,7 +52,7 @@
         this._renderTargets = new BABYLON.Tools.SmartArray(256);
         this._activeParticleSystems = new BABYLON.Tools.SmartArray(256);
         this._activeSkeletons = new BABYLON.Tools.SmartArray(32);
-        
+
         // Rendering groups
         this._renderingManager = new BABYLON.RenderingManager(this);
 
@@ -74,6 +76,9 @@
 
         // Skeletons
         this.skeletons = [];
+        
+        // Lens flares
+        this.lensFlareSystems = [];
 
         // Collisions
         this.collisionsEnabled = true;
@@ -92,6 +97,12 @@
         // Postprocesses
         this.postProcessesEnabled = true;
         this.postProcessManager = new BABYLON.PostProcessManager(this);
+
+        // Customs render targets
+        this.customRenderTargets = [];
+
+        // Multi-cameras
+        this.activeCameras = [];
     };
 
     // Properties   
@@ -195,7 +206,7 @@
             this._pendingData.splice(index, 1);
         }
     };
-    
+
     BABYLON.Scene.prototype.getWaitingItemsCount = function () {
         return this._pendingData.length;
     };
@@ -206,7 +217,7 @@
         if (this._executeWhenReadyTimeoutId !== -1) {
             return;
         }
-        
+
         var that = this;
         this._executeWhenReadyTimeoutId = setTimeout(function () {
             that._checkIsReady();
@@ -223,7 +234,7 @@
             this._executeWhenReadyTimeoutId = -1;
             return;
         }
-        
+
         var that = this;
         this._executeWhenReadyTimeoutId = setTimeout(function () {
             that._checkIsReady();
@@ -318,7 +329,7 @@
 
         return null;
     };
-    
+
     BABYLON.Scene.prototype.getMaterialByName = function (name) {
         for (var index = 0; index < this.materials.length; index++) {
             if (this.materials[index].name === name) {
@@ -328,7 +339,7 @@
 
         return null;
     };
-    
+
     BABYLON.Scene.prototype.getCameraByName = function (name) {
         for (var index = 0; index < this.cameras.length; index++) {
             if (this.cameras[index].name === name) {
@@ -368,19 +379,25 @@
 
         return null;
     };
-    
+
     BABYLON.Scene.prototype.getLastEntryByID = function (id) {
         for (var index = this.meshes.length - 1; index >= 0 ; index--) {
             if (this.meshes[index].id === id) {
                 return this.meshes[index];
             }
         }
-        
+
         for (var index = this.cameras.length - 1; index >= 0 ; index--) {
             if (this.cameras[index].id === id) {
                 return this.cameras[index];
             }
         }
+        
+        for (var index = this.lights.length - 1; index >= 0 ; index--) {
+            if (this.lights[index].id === id) {
+                return this.lights[index];
+            }
+        }
 
         return null;
     };
@@ -454,7 +471,6 @@
         this._activeMeshes.reset();
         this._renderingManager.reset();
         this._processedMaterials.reset();
-        this._renderTargets.reset();
         this._activeParticleSystems.reset();
         this._activeSkeletons.reset();
 
@@ -464,9 +480,6 @@
             BABYLON.Frustum.GetPlanesToRef(this._transformMatrix, this._frustumPlanes);
         }
 
-        this._totalVertices = 0;
-        this._activeVertices = 0;
-
         // Meshes
         if (this._selectionOctree) { // Octree
             var selection = this._selectionOctree.select(this._frustumPlanes);
@@ -557,37 +570,25 @@
         this._particlesDuration += new Date() - beforeParticlesDate;
     };
 
-    BABYLON.Scene.prototype.render = function () {
-        var startDate = new Date();
-        this._particlesDuration = 0;
-        this._spritesDuration = 0;
-        this._activeParticles = 0;
+    BABYLON.Scene.prototype._renderForCamera = function (camera) {
         var engine = this._engine;
 
-        // Before render
-        if (this.beforeRender) {
-            this.beforeRender();
-        }
-
-        for (var callbackIndex = 0; callbackIndex < this._onBeforeRenderCallbacks.length; callbackIndex++) {
-            this._onBeforeRenderCallbacks[callbackIndex]();
-        }
+        this.activeCamera = camera;
 
         if (!this.activeCamera)
             throw new Error("Active camera not set");
 
-        // Animations
-        this._animationRatio = BABYLON.Tools.GetDeltaTime() * (60.0 / 1000.0);
-        this._animate();
+        // Viewport
+        engine.setViewport(this.activeCamera.viewport);
+
+        // Camera
+        this._renderId++;
+        this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix());
 
         // Meshes
         var beforeEvaluateActiveMeshesDate = new Date();
         this._evaluateActiveMeshes();
-        this._evaluateActiveMeshesDuration = new Date() - beforeEvaluateActiveMeshesDate;
-        this._renderId++;
-
-        // Camera
-        this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix());
+        this._evaluateActiveMeshesDuration += new Date() - beforeEvaluateActiveMeshesDate;
 
         // Skeletons
         for (var skeletonIndex = 0; skeletonIndex < this._activeSkeletons.length; skeletonIndex++) {
@@ -596,14 +597,9 @@
             skeleton.prepare();
         }
 
-        // Shadows
-        for (var lightIndex = 0; lightIndex < this.lights.length; lightIndex++) {
-            var light = this.lights[lightIndex];
-            var shadowGenerator = light.getShadowGenerator();
-
-            if (light.isEnabled() && shadowGenerator) {
-                this._renderTargets.push(shadowGenerator.getShadowMap());
-            }
+        // Customs render targets registration
+        for (var customIndex = 0; customIndex < this.customRenderTargets.length; customIndex++) {
+            this._renderTargets.push(this.customRenderTargets[customIndex]);
         }
 
         // Render targets
@@ -622,10 +618,7 @@
         // Prepare Frame
         this.postProcessManager._prepareFrame();
 
-        // Clear
-        var beforeRenderDate = new Date();
-        engine.clear(this.clearColor, this.autoClear || this.forceWireframe, true);
-
+        var beforeRenderDate = new Date();        
         // Backgrounds
         if (this.layers.length) {
             engine.setDepthBuffer(false);
@@ -642,6 +635,11 @@
 
         // Render
         this._renderingManager.render(null, null, true, true);
+        
+        // Lens flares
+        for (var lensFlareSystemIndex = 0; lensFlareSystemIndex < this.lensFlareSystems.length; lensFlareSystemIndex++) {
+            this.lensFlareSystems[lensFlareSystemIndex].render();
+        }
 
         // Foregrounds
         if (this.layers.length) {
@@ -655,13 +653,64 @@
             engine.setDepthBuffer(true);
         }
 
-        this._renderDuration = new Date() - beforeRenderDate;
+        this._renderDuration += new Date() - beforeRenderDate;
 
         // Finalize frame
         this.postProcessManager._finalizeFrame();
 
         // Update camera
         this.activeCamera._update();
+        
+        // Reset some special arrays
+        this._renderTargets.reset();
+    };
+
+    BABYLON.Scene.prototype.render = function () {
+        var startDate = new Date();
+        this._particlesDuration = 0;
+        this._spritesDuration = 0;
+        this._activeParticles = 0;
+        this._renderDuration = 0;
+        this._evaluateActiveMeshesDuration = 0;
+        this._totalVertices = 0;
+        this._activeVertices = 0;
+
+        // Before render
+        if (this.beforeRender) {
+            this.beforeRender();
+        }
+
+        for (var callbackIndex = 0; callbackIndex < this._onBeforeRenderCallbacks.length; callbackIndex++) {
+            this._onBeforeRenderCallbacks[callbackIndex]();
+        }
+        
+        // Animations
+        this._animationRatio = BABYLON.Tools.GetDeltaTime() * (60.0 / 1000.0);
+        this._animate();
+        
+        // Clear
+        this._engine.clear(this.clearColor, this.autoClear || this.forceWireframe, true);
+        
+        // Shadows
+        for (var lightIndex = 0; lightIndex < this.lights.length; lightIndex++) {
+            var light = this.lights[lightIndex];
+            var shadowGenerator = light.getShadowGenerator();
+
+            if (light.isEnabled() && shadowGenerator) {
+                this._renderTargets.push(shadowGenerator.getShadowMap());
+            }
+        }
+
+        // Multi-cameras?
+        if (this.activeCameras.length > 0) {
+            var currentRenderId = this._renderId;
+            for (var cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {
+                this._renderId = currentRenderId;
+                this._renderForCamera(this.activeCameras[cameraIndex]);
+            }
+        } else {
+            this._renderForCamera(this.activeCamera);
+        }
 
         // After render
         if (this.afterRender) {
@@ -701,7 +750,7 @@
         while (this.meshes.length) {
             this.meshes[0].dispose(true);
         }
-        
+
         // Release cameras
         while (this.cameras.length) {
             this.cameras[0].dispose();
@@ -731,7 +780,7 @@
         while (this.textures.length) {
             this.textures[0].dispose();
         }
-        
+
         // Post-processes
         this.postProcessManager.dispose();
 
@@ -841,14 +890,13 @@
 
             this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix());
         }
+        var viewport = this.activeCamera.viewport.toGlobal(engine);
 
-        return BABYLON.Ray.CreateNew(x, y, engine.getRenderWidth() * engine.getHardwareScalingLevel(), engine.getRenderHeight() * engine.getHardwareScalingLevel(), world ? world : BABYLON.Matrix.Identity(), this._viewMatrix, this._projectionMatrix);
+        return BABYLON.Ray.CreateNew(x, y, viewport.width, viewport.height, world ? world : BABYLON.Matrix.Identity(), this._viewMatrix, this._projectionMatrix);
     };
 
-    BABYLON.Scene.prototype.pick = function (x, y, predicate, fastCheck) {
-        var distance = Number.MAX_VALUE;
-        var pickedPoint = null;
-        var pickedMesh = null;
+    BABYLON.Scene.prototype._internalPick = function (rayFunction, predicate, fastCheck) {
+        var pickingInfo = null;
 
         for (var meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {
             var mesh = this.meshes[meshIndex];
@@ -857,31 +905,46 @@
                 if (!predicate(mesh)) {
                     continue;
                 }
-            }
-            else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {
+            } else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {
                 continue;
-            }                        
+            }
 
             var world = mesh.getWorldMatrix();
-            var ray = this.createPickingRay(x, y, world);
+            var ray = rayFunction(world);
 
             var result = mesh.intersects(ray, fastCheck);
             if (!result.hit)
                 continue;
 
-            if (!fastCheck && result.distance >= distance)
+            if (!fastCheck && pickingInfo != null && result.distance >= pickingInfo.distance)
                 continue;
 
-            distance = result.distance;
-            pickedMesh = mesh;
-            pickedPoint = result.pickedPoint;
-            
+            pickingInfo = result;
+
             if (fastCheck) {
                 break;
             }
         }
+        
+        return pickingInfo || new BABYLON.PickingInfo();
+    };
 
-        return { hit: distance != Number.MAX_VALUE, distance: distance, pickedMesh: pickedMesh, pickedPoint: pickedPoint };
+    BABYLON.Scene.prototype.pick = function (x, y, predicate, fastCheck) {
+        var that = this;
+        return this._internalPick(function(world) {
+            return that.createPickingRay(x, y, world);
+        }, predicate, fastCheck);
+    };
+    
+    BABYLON.Scene.prototype.pickWithRay = function (ray, predicate, fastCheck) {
+        var that = this;
+        return this._internalPick(function (world) {
+            if (!that._pickWithRayInverseMatrix) {
+                that._pickWithRayInverseMatrix = BABYLON.Matrix.Identity();
+            }
+            world.invertToRef(that._pickWithRayInverseMatrix);
+            return BABYLON.Ray.Transform(ray, that._pickWithRayInverseMatrix);
+        }, predicate, fastCheck);
     };
 
     // Statics

File diff suppressed because it is too large
+ 1 - 1
Babylon/jscompaktor.bat


+ 12 - 3
Exporters/FBX - OBJ/BabylonExport.Core/BabylonExport.Core.csproj

@@ -35,13 +35,20 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="Microsoft.Build" />
-    <Reference Include="Microsoft.Build.Engine" />
-    <Reference Include="Microsoft.Build.Framework" />
+    <Reference Include="Microsoft.Build">
+      <Private>False</Private>
+    </Reference>
+    <Reference Include="Microsoft.Build.Engine">
+      <Private>False</Private>
+    </Reference>
+    <Reference Include="Microsoft.Build.Framework">
+      <Private>False</Private>
+    </Reference>
     <Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
     <Reference Include="Microsoft.Xna.Framework.Content.Pipeline, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\BabylonExport\Refs\Microsoft.Xna.Framework.Content.Pipeline.dll</HintPath>
+      <Private>True</Private>
     </Reference>
     <Reference Include="Microsoft.Xna.Framework.Content.Pipeline.AudioImporters, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
       <SpecificVersion>False</SpecificVersion>
@@ -123,10 +130,12 @@
     <Compile Include="Entities\Export\BabylonAnimationKey.cs" />
     <Compile Include="Entities\Export\BabylonBone.cs" />
     <Compile Include="Entities\Export\BabylonCamera.cs" />
+    <Compile Include="Entities\Export\BabylonLensFlare.cs" />
     <Compile Include="Entities\Export\BabylonLight.cs" />
     <Compile Include="Entities\Export\BabylonMaterial.cs" />
     <Compile Include="Entities\Export\BabylonMesh.cs" />
     <Compile Include="Entities\Export\BabylonMultiMaterial.cs" />
+    <Compile Include="Entities\Export\BabylonLensFlareSystem.cs" />
     <Compile Include="Entities\Export\BabylonParticleSystem.cs" />
     <Compile Include="Entities\Export\BabylonScene.cs" />
     <Compile Include="Entities\Export\BabylonShadowGenerator.cs" />

+ 20 - 0
Exporters/FBX - OBJ/BabylonExport.Core/Entities/Export/BabylonLensFlare.cs

@@ -0,0 +1,20 @@
+using System.Runtime.Serialization;
+
+namespace BabylonExport.Core
+{
+    [DataContract]
+    public class BabylonLensFlare
+    {
+        [DataMember]
+        public float position { get; set; }
+
+        [DataMember]
+        public float size { get; set; }
+
+        [DataMember]
+        public float[] color { get; set; }
+
+        [DataMember]
+        public string textureName { get; set; }
+    }
+}

+ 17 - 0
Exporters/FBX - OBJ/BabylonExport.Core/Entities/Export/BabylonLensFlareSystem.cs

@@ -0,0 +1,17 @@
+using System.Runtime.Serialization;
+
+namespace BabylonExport.Core
+{
+    [DataContract]
+    public class BabylonLensFlareSystem
+    {
+        [DataMember]
+        public string emitterId { get; set; }
+
+        [DataMember]
+        public int borderLimit { get; set; }
+
+        [DataMember]
+        public BabylonLensFlare[] flares { get; set; }
+    }
+}

+ 5 - 2
Exporters/FBX - OBJ/BabylonExport.Core/Entities/Export/BabylonMesh.cs

@@ -63,8 +63,11 @@ namespace BabylonExport.Core
         public bool checkCollisions { get; set; }
 
         [DataMember]
-        public bool receiveShadows { get; set; }        
-
+        public bool receiveShadows { get; set; }    
+    
+        [DataMember]
+        public bool infiniteDistance { get; set; }
+        
         [DataMember]
         public int billboardMode { get; set; }
 

+ 3 - 0
Exporters/FBX - OBJ/BabylonExport.Core/Entities/Export/BabylonScene.cs

@@ -58,6 +58,9 @@ namespace BabylonExport.Core
         public BabylonParticleSystem[] particleSystems { get; set; }
 
         [DataMember]
+        public BabylonLensFlareSystem[] lensFlareSystems { get; set; }
+
+        [DataMember]
         public BabylonShadowGenerator[] shadowGenerators { get; set; }
 
         [DataMember]

+ 1 - 1
Exporters/FBX - OBJ/BabylonExport.Core/Entities/Mesh.cs

@@ -28,7 +28,7 @@ namespace BabylonExport.Core
         public void AddPart(string name, List<T> addedVertices, List<int> addedIndices)
         {
             if (concatenatedName == "")
-                concatenatedName += " / ";
+                concatenatedName += " # ";
 
             concatenatedName += name;
 

+ 1 - 1
Exporters/FBX - OBJ/BabylonExport.Core/Exporters/FBX/FBXExporter.cs

@@ -42,7 +42,7 @@ namespace BabylonExport.Core.Exporters
             // Create a graphics device
             var form = new Form();
             
-            services.AddService<IGraphicsDeviceService>(BabylonExport.Core.Exporters.FBX.GraphicsDeviceService.AddRef(form.Handle, 1, 1));
+            services.AddService<IGraphicsDeviceService>(GraphicsDeviceService.AddRef(form.Handle, 1, 1));
 
             var contentBuilder = new ContentBuilder();
             var contentManager = new ContentManager(services, contentBuilder.OutputDirectory);

+ 49 - 4
Exporters/FBX - OBJ/BabylonExport.Core/Exporters/MXB/NovaExporter.cs

@@ -18,6 +18,7 @@ namespace BabylonExport.Core.Exporters
         readonly List<string> alreadyExportedTextures = new List<string>();
         readonly List<NovaMaterial> materialsToExport = new List<NovaMaterial>();
         readonly List<NovaParticleSystem> particleSystemsToExport = new List<NovaParticleSystem>();
+        readonly List<NovaLensFlares> lensFlareSystemToExport = new List<NovaLensFlares>();
         readonly Dictionary<NovaMaterial, NovaObject> mirrorsMaterials = new Dictionary<NovaMaterial, NovaObject>();
 
         public event Action<int> OnImportProgressChanged;
@@ -100,6 +101,9 @@ namespace BabylonExport.Core.Exporters
             // Particles
             DumpParticles(babylonScene);
 
+            // Lens flares
+            DumpLensFlares(babylonScene);
+
             // Output
             babylonScene.Prepare(false);
             using (var outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write))
@@ -110,6 +114,40 @@ namespace BabylonExport.Core.Exporters
             ReportProgressChanged(100);
         }
 
+
+        void DumpLensFlares(BabylonScene babylonScene)
+        {
+            if (lensFlareSystemToExport.Count == 0)
+                return;
+
+            babylonScene.lensFlareSystems = new BabylonLensFlareSystem[lensFlareSystemToExport.Count];
+
+            var index = 0;
+            foreach (var lensFlareSystem in lensFlareSystemToExport)
+            {
+                var flares = new List<BabylonLensFlare>();
+                foreach (var flare in lensFlareSystem.Flares)
+                {
+                    flares.Add(new BabylonLensFlare
+                    {
+                        color = flare.Color.ToArray(),
+                        position = flare.Position,
+                        size = flare.Size / 1000.0f,
+                        textureName = CopyTexture(flare.Texture, babylonScene)
+                    });
+                }
+
+                babylonScene.lensFlareSystems[index] = new BabylonLensFlareSystem
+                {
+                    emitterId = (lensFlareSystem.Tag as NovaLight).ID.ToString(),
+                    borderLimit = lensFlareSystem.BorderLimit,
+                    flares = flares.ToArray()
+                };
+
+                index++;
+            }
+        }
+
         private void DumpParticles(BabylonScene babylonScene)
         {
             if (particleSystemsToExport.Count == 0)
@@ -293,6 +331,7 @@ namespace BabylonExport.Core.Exporters
             babylonMesh.visibility = novaObject.Visibility;
             babylonMesh.checkCollisions = novaObject.CheckCollisions;
             babylonMesh.receiveShadows = novaObject.ReceiveShadows;
+            babylonMesh.infiniteDistance = novaObject.InfiniteDistance;
 
             if (novaObject.Billboard)
             {
@@ -361,7 +400,7 @@ namespace BabylonExport.Core.Exporters
 
             babylonMesh.animations = animations.ToArray();
             babylonMesh.autoAnimate = novaObject.AutoAnimate;
-            
+
             if (novaObject.AutoAnimate)
             {
                 babylonMesh.autoAnimateFrom = novaObject.AnimationStartKey;
@@ -405,7 +444,7 @@ namespace BabylonExport.Core.Exporters
                     subMesh.indexCount = subObject.AttributeRange.FaceCount * 3;
 
                     subMeshes.Add(subMesh);
-                }                
+                }
             }
             babylonMesh.subMeshes = subMeshes.ToArray();
 
@@ -446,7 +485,7 @@ namespace BabylonExport.Core.Exporters
 
             if (novaObject.VertexPaint)
             {
-                var color = RGBAColor.FromArgb((int) vertex.Color);
+                var color = RGBAColor.FromArgb((int)vertex.Color);
                 colors.Add(color.Red); colors.Add(color.Green); colors.Add(color.Blue);
             }
         }
@@ -613,7 +652,7 @@ namespace BabylonExport.Core.Exporters
             }
         }
 
-        static void DumpLights(NovaScene scene, BabylonScene babylonScene)
+        void DumpLights(NovaScene scene, BabylonScene babylonScene)
         {
             foreach (NovaLight light in scene.Lights)
             {
@@ -652,6 +691,12 @@ namespace BabylonExport.Core.Exporters
                         };
                         babylonScene.ShadowGeneratorsList.Add(shadowGenerator);
                     }
+
+                    if (light.LensFlares != null)
+                    {
+                        light.LensFlares.Tag = light;
+                        lensFlareSystemToExport.Add(light.LensFlares);
+                    }
                 }
             }
         }

BIN
Exporters/FBX - OBJ/BabylonExport.zip


+ 111 - 0
Exporters/FBX - OBJ/BabylonExport/BabylonExport.csproj

@@ -101,6 +101,7 @@
   <ItemGroup>
     <Reference Include="Microsoft.Xna.Framework.Content.Pipeline">
       <HintPath>..\BabylonExport.Core\Refs\Microsoft.Xna.Framework.Content.Pipeline.dll</HintPath>
+      <Private>True</Private>
     </Reference>
     <Reference Include="Microsoft.Xna.Framework.Content.Pipeline.AudioImporters">
       <HintPath>..\BabylonExport.Core\Refs\Microsoft.Xna.Framework.Content.Pipeline.AudioImporters.dll</HintPath>
@@ -502,6 +503,7 @@
     <None Include="Test scenes\TheCar\volant.dds" />
     <None Include="Test scenes\TheCar\wood.dds" />
     <None Include="Test scenes\TheCar\WOODlm.dds" />
+    <None Include="Test scenes\Train\Train.babylon" />
     <None Include="Test scenes\Train\train.mxb" />
     <None Include="Test scenes\Viper\Viper.mtl" />
     <None Include="Test scenes\Viper\Viper.obj" />
@@ -627,52 +629,105 @@
     <Content Include="Test scenes\SpaceDeK\VaisseauSpecularMap.jpg" />
     <Content Include="Test scenes\Spaceship\wedge_p2_diff_v1.tga" />
     <Content Include="Test scenes\Train\barrieres_bois.dds" />
+    <Content Include="Test scenes\Train\barrieres_bois.jpg" />
     <Content Include="Test scenes\Train\barrieres_bois_n.dds" />
+    <Content Include="Test scenes\Train\barrieres_bois_n.jpg" />
     <Content Include="Test scenes\Train\bat_console_murs_ext_lm.dds" />
+    <Content Include="Test scenes\Train\bat_console_murs_ext_lm.jpg" />
     <Content Include="Test scenes\Train\bat_console_murs_lm.dds" />
+    <Content Include="Test scenes\Train\bat_console_murs_lm.jpg" />
     <Content Include="Test scenes\Train\bat_lm.dds" />
+    <Content Include="Test scenes\Train\bat_lm.jpg" />
     <Content Include="Test scenes\Train\bg.dds" />
     <Content Include="Test scenes\Train\bg_credits.dds" />
     <Content Include="Test scenes\Train\bg_help.dds" />
     <Content Include="Test scenes\Train\bosquet_grass.dds" />
+    <Content Include="Test scenes\Train\bosquet_grass.png" />
     <Content Include="Test scenes\Train\bottes_paille.dds" />
+    <Content Include="Test scenes\Train\bottes_paille.jpg" />
     <Content Include="Test scenes\Train\bottes_paille_face.dds" />
+    <Content Include="Test scenes\Train\bottes_paille_face.jpg" />
     <Content Include="Test scenes\Train\champ_ble.dds" />
+    <Content Include="Test scenes\Train\champ_ble.png" />
     <Content Include="Test scenes\Train\chariot_planche.dds" />
+    <Content Include="Test scenes\Train\chariot_planche.jpg" />
     <Content Include="Test scenes\Train\chariot_planche_n.dds" />
+    <Content Include="Test scenes\Train\chariot_planche_n.jpg" />
     <Content Include="Test scenes\Train\chariot_roue.dds" />
+    <Content Include="Test scenes\Train\chariot_roue.jpg" />
     <Content Include="Test scenes\Train\chariot_roue_n.dds" />
+    <Content Include="Test scenes\Train\chariot_roue_n.jpg" />
     <Content Include="Test scenes\Train\console.dds" />
+    <Content Include="Test scenes\Train\console.jpg" />
     <Content Include="Test scenes\Train\console_n.dds" />
+    <Content Include="Test scenes\Train\console_n.jpg" />
     <Content Include="Test scenes\Train\cubemap.dds" />
     <Content Include="Test scenes\Train\cubemap5.dds" />
+    <Content Include="Test scenes\Train\cubemap5_nx.jpg" />
+    <Content Include="Test scenes\Train\cubemap5_ny.jpg" />
+    <Content Include="Test scenes\Train\cubemap5_nz.jpg" />
+    <Content Include="Test scenes\Train\cubemap5_px.jpg" />
+    <Content Include="Test scenes\Train\cubemap5_py.jpg" />
+    <Content Include="Test scenes\Train\cubemap5_pz.jpg" />
+    <Content Include="Test scenes\Train\cubemap_nx.jpg" />
+    <Content Include="Test scenes\Train\cubemap_ny.jpg" />
+    <Content Include="Test scenes\Train\cubemap_nz.jpg" />
+    <Content Include="Test scenes\Train\cubemap_px.jpg" />
+    <Content Include="Test scenes\Train\cubemap_py.jpg" />
+    <Content Include="Test scenes\Train\cubemap_pz.jpg" />
     <Content Include="Test scenes\Train\cubemap_vitres.dds" />
+    <Content Include="Test scenes\Train\cubemap_vitres_nx.jpg" />
+    <Content Include="Test scenes\Train\cubemap_vitres_ny.jpg" />
+    <Content Include="Test scenes\Train\cubemap_vitres_nz.jpg" />
+    <Content Include="Test scenes\Train\cubemap_vitres_px.jpg" />
+    <Content Include="Test scenes\Train\cubemap_vitres_py.jpg" />
+    <Content Include="Test scenes\Train\cubemap_vitres_pz.jpg" />
     <Content Include="Test scenes\Train\cuir.dds" />
+    <Content Include="Test scenes\Train\cuir.jpg" />
     <Content Include="Test scenes\Train\cuir_n.dds" />
+    <Content Include="Test scenes\Train\cuir_n.jpg" />
     <Content Include="Test scenes\Train\cur_default.cur" />
     <Content Include="Test scenes\Train\cur_link.cur" />
+    <Content Include="Test scenes\Train\debug.txt" />
     <Content Include="Test scenes\Train\disneyland_paris.dds" />
+    <Content Include="Test scenes\Train\disneyland_paris.jpg" />
     <Content Include="Test scenes\Train\flechage.dds" />
+    <Content Include="Test scenes\Train\flechage.png" />
     <Content Include="Test scenes\Train\flechage2.dds" />
+    <Content Include="Test scenes\Train\flechage2.png" />
     <Content Include="Test scenes\Train\grass.dds" />
+    <Content Include="Test scenes\Train\grass.png" />
     <Content Include="Test scenes\Train\grillage.dds" />
+    <Content Include="Test scenes\Train\grillage.png" />
     <Content Include="Test scenes\Train\lens2.dds" />
+    <Content Include="Test scenes\Train\lens2.png" />
     <Content Include="Test scenes\Train\lens3.dds" />
+    <Content Include="Test scenes\Train\lens3.png" />
     <Content Include="Test scenes\Train\lens4.dds" />
+    <Content Include="Test scenes\Train\lens4.png" />
     <Content Include="Test scenes\Train\lens5.dds" />
+    <Content Include="Test scenes\Train\lens5.png" />
     <Content Include="Test scenes\Train\lens6.dds" />
+    <Content Include="Test scenes\Train\lens6.png" />
     <Content Include="Test scenes\Train\lens_sun.dds" />
     <Content Include="Test scenes\Train\light_blanche.dds" />
     <Content Include="Test scenes\Train\light_jaune.dds" />
     <Content Include="Test scenes\Train\light_rouge.dds" />
     <Content Include="Test scenes\Train\light_verte.dds" />
     <Content Include="Test scenes\Train\metal_rouille.dds" />
+    <Content Include="Test scenes\Train\metal_rouille.jpg" />
     <Content Include="Test scenes\Train\metal_rouille_n.dds" />
+    <Content Include="Test scenes\Train\metal_rouille_n.jpg" />
     <Content Include="Test scenes\Train\metal_tache.dds" />
+    <Content Include="Test scenes\Train\metal_tache.jpg" />
     <Content Include="Test scenes\Train\metal_tache_n.dds" />
+    <Content Include="Test scenes\Train\metal_tache_n.jpg" />
     <Content Include="Test scenes\Train\murs_wood.dds" />
+    <Content Include="Test scenes\Train\murs_wood.jpg" />
     <Content Include="Test scenes\Train\murs_wood_n.dds" />
+    <Content Include="Test scenes\Train\murs_wood_n.jpg" />
     <Content Include="Test scenes\Train\no_signal.dds" />
+    <Content Include="Test scenes\Train\no_signal.jpg" />
     <Content Include="Test scenes\Train\OSVCenter.dds" />
     <Content Include="Test scenes\Train\OSVCenterb.dds" />
     <Content Include="Test scenes\Train\OSVFps.dds" />
@@ -690,25 +745,45 @@
     <Content Include="Test scenes\Train\OSVZoom.dds" />
     <Content Include="Test scenes\Train\OSVZoomb.dds" />
     <Content Include="Test scenes\Train\paille_alpha.dds" />
+    <Content Include="Test scenes\Train\paille_alpha.png" />
     <Content Include="Test scenes\Train\pile_bois.dds" />
+    <Content Include="Test scenes\Train\pile_bois.jpg" />
     <Content Include="Test scenes\Train\pile_bois_n.dds" />
+    <Content Include="Test scenes\Train\pile_bois_n.jpg" />
     <Content Include="Test scenes\Train\planches.dds" />
+    <Content Include="Test scenes\Train\planches.jpg" />
     <Content Include="Test scenes\Train\planches_n.dds" />
+    <Content Include="Test scenes\Train\planches_n.jpg" />
     <Content Include="Test scenes\Train\poteaux.dds" />
+    <Content Include="Test scenes\Train\poteaux.jpg" />
     <Content Include="Test scenes\Train\poteaux_n.dds" />
+    <Content Include="Test scenes\Train\poteaux_n.jpg" />
     <Content Include="Test scenes\Train\poubelle.dds" />
+    <Content Include="Test scenes\Train\poubelle.jpg" />
     <Content Include="Test scenes\Train\poubelle_n.dds" />
+    <Content Include="Test scenes\Train\poubelle_n.jpg" />
     <Content Include="Test scenes\Train\rochers_big.dds" />
+    <Content Include="Test scenes\Train\rochers_big.jpg" />
     <Content Include="Test scenes\Train\rochers_big_n.dds" />
+    <Content Include="Test scenes\Train\rochers_big_n.jpg" />
     <Content Include="Test scenes\Train\rock_tunnel.dds" />
+    <Content Include="Test scenes\Train\rock_tunnel.jpg" />
     <Content Include="Test scenes\Train\rock_tunnel_n.dds" />
+    <Content Include="Test scenes\Train\rock_tunnel_n.jpg" />
     <Content Include="Test scenes\Train\sacs_sable.dds" />
+    <Content Include="Test scenes\Train\sacs_sable.jpg" />
     <Content Include="Test scenes\Train\sacs_sable_n.dds" />
+    <Content Include="Test scenes\Train\sacs_sable_n.jpg" />
     <Content Include="Test scenes\Train\sapin_leaves.dds" />
+    <Content Include="Test scenes\Train\sapin_leaves.png" />
     <Content Include="Test scenes\Train\sapin_trunk_up.dds" />
+    <Content Include="Test scenes\Train\sapin_trunk_up.jpg" />
     <Content Include="Test scenes\Train\sapin_trunk_up_n.dds" />
+    <Content Include="Test scenes\Train\sapin_trunk_up_n.jpg" />
     <Content Include="Test scenes\Train\skydome.dds" />
+    <Content Include="Test scenes\Train\skydome.jpg" />
     <Content Include="Test scenes\Train\smoke.dds" />
+    <Content Include="Test scenes\Train\smoke.png" />
     <Content Include="Test scenes\Train\snd_bg.mp3" />
     <Content Include="Test scenes\Train\snd_bt_clic.mp3" />
     <Content Include="Test scenes\Train\snd_bt_clic_ui.wma" />
@@ -718,41 +793,77 @@
     <Content Include="Test scenes\Train\snd_roller_coaster_loop.mp3" />
     <Content Include="Test scenes\Train\snd_siren.mp3" />
     <Content Include="Test scenes\Train\sol_metal.dds" />
+    <Content Include="Test scenes\Train\sol_metal.jpg" />
     <Content Include="Test scenes\Train\sol_metal_n.dds" />
+    <Content Include="Test scenes\Train\sol_metal_n.jpg" />
     <Content Include="Test scenes\Train\terrain1.dds" />
+    <Content Include="Test scenes\Train\terrain1.jpg" />
     <Content Include="Test scenes\Train\terrain1_lm.dds" />
+    <Content Include="Test scenes\Train\terrain1_lm.jpg" />
     <Content Include="Test scenes\Train\terrain1_n.dds" />
+    <Content Include="Test scenes\Train\terrain1_n.jpg" />
     <Content Include="Test scenes\Train\terrain2.dds" />
+    <Content Include="Test scenes\Train\terrain2.jpg" />
     <Content Include="Test scenes\Train\terrain2_lm.dds" />
+    <Content Include="Test scenes\Train\terrain2_lm.jpg" />
     <Content Include="Test scenes\Train\terrain2_n.dds" />
+    <Content Include="Test scenes\Train\terrain2_n.jpg" />
     <Content Include="Test scenes\Train\terrain3.dds" />
+    <Content Include="Test scenes\Train\terrain3.jpg" />
     <Content Include="Test scenes\Train\terrain3_lm.dds" />
+    <Content Include="Test scenes\Train\terrain3_lm.jpg" />
     <Content Include="Test scenes\Train\terrain3_n.dds" />
+    <Content Include="Test scenes\Train\terrain3_n.jpg" />
     <Content Include="Test scenes\Train\terrain4.dds" />
+    <Content Include="Test scenes\Train\terrain4.jpg" />
     <Content Include="Test scenes\Train\terrain4_lm.dds" />
+    <Content Include="Test scenes\Train\terrain4_lm.jpg" />
     <Content Include="Test scenes\Train\terrain4_n.dds" />
+    <Content Include="Test scenes\Train\terrain4_n.jpg" />
     <Content Include="Test scenes\Train\terrain_clotures_lm.dds" />
+    <Content Include="Test scenes\Train\terrain_clotures_lm.jpg" />
     <Content Include="Test scenes\Train\terrain_escalier_lm.dds" />
+    <Content Include="Test scenes\Train\terrain_escalier_lm.jpg" />
     <Content Include="Test scenes\Train\terrain_tunnel_lm.dds" />
+    <Content Include="Test scenes\Train\terrain_tunnel_lm.jpg" />
     <Content Include="Test scenes\Train\toit_bois.dds" />
+    <Content Include="Test scenes\Train\toit_bois.jpg" />
     <Content Include="Test scenes\Train\toit_bois_n.dds" />
+    <Content Include="Test scenes\Train\toit_bois_n.jpg" />
     <Content Include="Test scenes\Train\tole.dds" />
+    <Content Include="Test scenes\Train\tole.jpg" />
     <Content Include="Test scenes\Train\tole_n.dds" />
+    <Content Include="Test scenes\Train\tole_n.jpg" />
     <Content Include="Test scenes\Train\tonneau.dds" />
+    <Content Include="Test scenes\Train\tonneau.jpg" />
     <Content Include="Test scenes\Train\tonneau_n.dds" />
+    <Content Include="Test scenes\Train\tonneau_n.jpg" />
     <Content Include="Test scenes\Train\tracteur.dds" />
+    <Content Include="Test scenes\Train\tracteur.jpg" />
     <Content Include="Test scenes\Train\tracteur_n.dds" />
+    <Content Include="Test scenes\Train\tracteur_n.jpg" />
     <Content Include="Test scenes\Train\train_4.dds" />
+    <Content Include="Test scenes\Train\train_4.jpg" />
     <Content Include="Test scenes\Train\train_4_n.dds" />
+    <Content Include="Test scenes\Train\train_4_n.jpg" />
     <Content Include="Test scenes\Train\train_cote.dds" />
+    <Content Include="Test scenes\Train\train_cote.jpg" />
     <Content Include="Test scenes\Train\train_cote_n.dds" />
+    <Content Include="Test scenes\Train\train_cote_n.jpg" />
     <Content Include="Test scenes\Train\train_loco_lm.dds" />
+    <Content Include="Test scenes\Train\train_loco_lm.jpg" />
     <Content Include="Test scenes\Train\train_wagon_lm.dds" />
+    <Content Include="Test scenes\Train\train_wagon_lm.jpg" />
     <Content Include="Test scenes\Train\tronc.dds" />
+    <Content Include="Test scenes\Train\tronc.jpg" />
     <Content Include="Test scenes\Train\tronc_face.dds" />
+    <Content Include="Test scenes\Train\tronc_face.jpg" />
     <Content Include="Test scenes\Train\tronc_face_n.dds" />
+    <Content Include="Test scenes\Train\tronc_face_n.jpg" />
     <Content Include="Test scenes\Train\tronc_n.dds" />
+    <Content Include="Test scenes\Train\tronc_n.jpg" />
     <Content Include="Test scenes\Train\verre_lampes.dds" />
+    <Content Include="Test scenes\Train\verre_lampes.jpg" />
     <Content Include="Test scenes\Train\water_n.jpg" />
     <Content Include="Test scenes\Viper\aripa-buna.jpg" />
     <Content Include="Test scenes\Viper\carlinga-specular.jpg" />

BIN
Samples/Assets/CamDeviceOff.png


BIN
Samples/Assets/CamTouchOff.png


BIN
Samples/Assets/lens4.png


BIN
Samples/Assets/lens5.png


BIN
Samples/Scenes/Blender/MountainGrass_jpg72767116-efb0-4b79-a016-8ac4ef7561a1Larger.jpg


File diff suppressed because it is too large
+ 9 - 12
Samples/Scenes/Blender/blender.babylon


BIN
Samples/Scenes/Blender/chocolat.jpg


BIN
Samples/Scenes/Blender/paper.png


BIN
Samples/Scenes/Blender/paper02.png


BIN
Samples/Scenes/Blender/paper_bump.png


BIN
Samples/Scenes/Blender/wildtextures-old-wood-original-file-1280x853.jpg


+ 39 - 0
Samples/Scenes/Customs/lensFlares.js

@@ -0,0 +1,39 @@
+var CreateLensFlaresTestScene = function (engine) {
+    var scene = new BABYLON.Scene(engine);
+    var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene);
+    var light0 = new BABYLON.PointLight("Omni0", new BABYLON.Vector3(21.84, 50, -28.26), scene);
+
+    camera.alpha = 2.8;
+    camera.beta = 2.25;
+    
+    // Creating light sphere
+    var lightSphere0 = BABYLON.Mesh.CreateSphere("Sphere0", 16, 0.5, scene);
+    
+    lightSphere0.material = new BABYLON.StandardMaterial("white", scene);
+    lightSphere0.material.diffuseColor = new BABYLON.Color3(0, 0, 0);
+    lightSphere0.material.specularColor = new BABYLON.Color3(0, 0, 0);
+    lightSphere0.material.emissiveColor = new BABYLON.Color3(1, 1, 1);
+
+    lightSphere0.position = light0.position;
+    
+    var lensFlareSystem = new BABYLON.LensFlareSystem("lensFlareSystem", light0, scene);
+    var flare00 = new BABYLON.LensFlare(0.2, 0, new BABYLON.Color3(1, 1, 1), "Assets/lens5.png", lensFlareSystem);
+    var flare01 = new BABYLON.LensFlare(0.5, 0.2, new BABYLON.Color3(0.5, 0.5, 1), "Assets/lens4.png", lensFlareSystem);
+    var flare02 = new BABYLON.LensFlare(0.2, 1.0, new BABYLON.Color3(1, 1, 1), "Assets/lens4.png", lensFlareSystem);
+    var flare03 = new BABYLON.LensFlare(0.4, 0.4, new BABYLON.Color3(1, 0.5, 1), "Assets/Flare.png", lensFlareSystem);
+    var flare04 = new BABYLON.LensFlare(0.1, 0.6, new BABYLON.Color3(1, 1, 1), "Assets/lens5.png", lensFlareSystem);
+    var flare05 = new BABYLON.LensFlare(0.3, 0.8, new BABYLON.Color3(1, 1, 1), "Assets/lens4.png", lensFlareSystem);
+
+
+    // Skybox
+    var skybox = BABYLON.Mesh.CreateBox("skyBox", 100.0, scene);
+    var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
+    skyboxMaterial.backFaceCulling = false;
+    skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("Scenes/Customs/skybox/skybox", scene);
+    skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
+    skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
+    skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
+    skybox.material = skyboxMaterial;
+
+    return scene;
+};

+ 14 - 3
Samples/Scenes/Customs/test.js

@@ -1,8 +1,9 @@
 var CreateTestScene = function (engine) {
     var scene = new BABYLON.Scene(engine);
     //var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 10, BABYLON.Vector3.Zero(), scene);
+    var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 0, -10), scene);
     var camera2 = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 0, -10), scene);
-    var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 100, 2), scene);
+    var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 100, 50), scene);
     var material = new BABYLON.StandardMaterial("leaves", scene);
     var material2 = new BABYLON.StandardMaterial("kosh transparent", scene);
     var material3 = new BABYLON.StandardMaterial("kosh", scene);
@@ -13,6 +14,12 @@
     var sphere = BABYLON.Mesh.CreateSphere("Sphere", 16, 3, scene);
     var plane = BABYLON.Mesh.CreatePlane("plane", 3, scene);
 
+    camera.viewport = new BABYLON.Viewport(0.5, 0, 0.5, 1.0);
+    camera2.viewport = new BABYLON.Viewport(0, 0, 0.5, 1.0);
+
+    scene.activeCameras.push(camera);
+    scene.activeCameras.push(camera2);
+
     //material.diffuseColor = new BABYLON.Color3(0, 0, 1);
     material.diffuseTexture = new BABYLON.Texture("Assets/Tree.png", scene);
     material.diffuseTexture.hasAlpha = true;
@@ -32,13 +39,15 @@
     torus.material = material2;
     sphere.material = material;
     plane.material = planeMaterial;
-    cylinder.position.x += 13;
+    cylinder.position.z += 13;
     cylinder.renderingGroupId = 1;
     torus.position.x -= 3;
     torus.parent = sphere;
     sphere.position.z = 3;
     plane.position = new BABYLON.Vector3(0, 7, 0);
 
+    cylinder.parent = camera2;
+
     // Particles
     var particleSystem = new BABYLON.ParticleSystem("particles", 4000, scene);
     particleSystem.particleTexture = new BABYLON.Texture("Assets/Flare.png", scene);
@@ -125,6 +134,8 @@
         
         spaceDek3.material.emissiveColor = new BABYLON.Color3(1.0, 0, 0);
 
+        spaceDek3.infiniteDistance = true;
+
         scene.beginAnimation(spaceDek3, 0, 100, true, 1.0);
     });
 
@@ -136,7 +147,7 @@
     var count = 0;
     scene.registerBeforeRender(function () {
         box.rotation.y += 0.01;
-        cylinder.rotation.x += 0.01;
+       // cylinder.rotation.x += 0.01;
         sphere.rotation.y += 0.02;
         //  box3.scaling.y = 1 + Math.cos(alpha);
         torus.rotation.z += 0.01;

BIN
Samples/Scenes/Robot/Assets/Slides/Slide2.JPG


BIN
Samples/Scenes/Robot/DispenderDiffuseMap.jpg


BIN
Samples/Scenes/Robot/EnvAmbient Occlusion _MR.jpg


BIN
Samples/Scenes/Robot/Ref.jpg


File diff suppressed because it is too large
+ 1 - 1
Samples/Scenes/Robot/Robot.babylon


BIN
Samples/Scenes/Robot/RobotCompmap.jpg


BIN
Samples/Scenes/Robot/Slide1.jpg


+ 15 - 2
Samples/Scenes/Robot/index.html

@@ -2,13 +2,26 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
     <title>Babylonjs Presentation</title>
+    <script>
+        function writeViewPort() {
+            var ua = navigator.userAgent;
+            if (ua.indexOf("Android") >= 0 && ua.indexOf("AppleWebKit") >= 0) {
+                var webkitVersion = parseFloat(ua.slice(ua.indexOf("AppleWebKit") + 12));
+                // targets android browser, not chrome browser (http://jimbergman.net/webkit-version-in-android-version/)
+                if (webkitVersion < 535) {
+                    document.write('<meta name="viewport" content="initial-scale=1" />');
+                }
+            }
+        }
+
+        writeViewPort();
+    </script>
     <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
     <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
     <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
     <link href="index.css" rel="stylesheet" />
     <script src="../../babylon.js"></script>
-    <script src="hand.minified-1.1.1.js"></script>
-
+    <script src="../../hand.minified-1.2.js"></script>
     <script src="index.js"></script>
 </head>
 <body onload="onload();">

+ 7 - 7
Samples/Scenes/Robot/index.js

@@ -32,7 +32,7 @@
 
     
 
-    var slideid = 2;
+    var slideid = 1;
 
     var canvas = document.getElementById("renderCanvas");
     var divFps = document.getElementById("fps");
@@ -74,9 +74,9 @@
 
                     slide.material.diffuseTexture = new BABYLON.Texture(demos[slideid].image, scene);
 
-                    scene.beginAnimation(scene.meshes[0], 301, 354, false, 1.0, function () {
-                        
-                    })
+                    scene.beginAnimation(scene.meshes[0], 301, 354, false, 1.0, function() {
+
+                    });
 
                 });
                 for (var index = 1; index < scene.meshes.length; index++) {
@@ -102,8 +102,6 @@
 
     camera.attachControl(canvas);
 
-    
-
     // Loading
     var importScene = function () {
         loadingBack.removeEventListener("transitionend", importScene);
@@ -112,8 +110,10 @@
         BABYLON.SceneLoader.ImportMesh("", "/Scenes/Robot/Assets/", "Robot.babylon", scene, function () {
            
         for (var index = 0; index < scene.meshes.length; index++) {
-            if (scene.meshes[index].name == "Slide")
+            if (scene.meshes[index].name == "Slide") {
                 slide = scene.meshes[index];
+                slide.material.diffuseTexture = new BABYLON.Texture(demos[slideid].image, scene);
+            }
             scene.stopAnimation(scene.meshes[index]);
             scene.beginAnimation(scene.meshes[index], 0, 265, false, 1.0);
 

File diff suppressed because it is too large
+ 1 - 1
Samples/Scenes/Train/Train.babylon


+ 1 - 1
Samples/Scenes/Train/Train.babylon.manifest

@@ -1,5 +1,5 @@
 {
-	"version" : 2,
+	"version" : 3,
 	"enableSceneOffline" : true,
 	"enableTexturesOffline" : true
 }

+ 1 - 0
Samples/Scenes/Train/debug.txt

@@ -0,0 +1 @@
+Generation of c:\Export\Train\Train.babylon successfullGeneration of c:\Export\Train\Train.babylon successfullGeneration of c:\Export\Train\Train.babylon successfullGeneration of c:\Export\Train\Train.babylon successfullGeneration of c:\Export\Train\Train.babylon successfull

BIN
Samples/Scenes/Train/lens2.png


BIN
Samples/Scenes/Train/lens3.png


BIN
Samples/Scenes/Train/lens4.png


BIN
Samples/Scenes/Train/lens5.png


BIN
Samples/Scenes/Train/lens6.png


+ 25 - 0
Samples/Scenes/WorldMonger/Postprocesses/compose.fragment.fx

@@ -0,0 +1,25 @@
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+// Samplers
+varying vec2 vUV;
+uniform sampler2D textureSampler;
+uniform sampler2D sceneSampler;
+
+// Parameters
+uniform vec2 screenSize;
+uniform float sceneIntensity;
+uniform float glowIntensity;
+uniform float highlightIntensity;
+
+void main(void) 
+{
+	vec4 orig = texture2D(sceneSampler, vUV);
+	vec4 blur = texture2D(textureSampler, vUV);
+
+	vec4 final = sceneIntensity * orig + glowIntensity * blur + highlightIntensity * blur.a;
+	final.a = 1.0;
+
+	gl_FragColor = final;
+}

+ 29 - 0
Samples/Scenes/WorldMonger/Postprocesses/downsample.fragment.fx

@@ -0,0 +1,29 @@
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+// Samplers
+varying vec2 vUV;
+uniform sampler2D textureSampler;
+
+// Parameters
+uniform vec2 screenSize;
+uniform float highlightThreshold;
+
+float highlights(vec3 color)
+{
+	return smoothstep(highlightThreshold, 1.0, dot(color, vec3(0.3, 0.59, 0.11)));
+}
+
+void main(void) 
+{
+	vec2 texelSize = vec2(1.0 / screenSize.x, 1.0 / screenSize.y);
+	vec4 baseColor = texture2D(textureSampler, vUV + vec2(-1.0, -1.0) * texelSize) * 0.25;
+	baseColor += texture2D(textureSampler, vUV + vec2(1.0, -1.0) * texelSize) * 0.25;
+	baseColor += texture2D(textureSampler, vUV + vec2(1.0, 1.0) * texelSize) * 0.25;
+	baseColor += texture2D(textureSampler, vUV + vec2(-1.0, 1.0) * texelSize) * 0.25;
+	
+	baseColor.a = highlights(baseColor.rgb);
+
+	gl_FragColor = baseColor;
+}

+ 15 - 1
Samples/Scenes/WorldMonger/index.html

@@ -2,11 +2,25 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
     <title>Babylon Engine for HTML5</title>
+    <script>
+        function writeViewPort() {
+            var ua = navigator.userAgent;
+            if (ua.indexOf("Android") >= 0 && ua.indexOf("AppleWebKit") >= 0) {
+                var webkitVersion = parseFloat(ua.slice(ua.indexOf("AppleWebKit") + 12));
+                // targets android browser, not chrome browser (http://jimbergman.net/webkit-version-in-android-version/)
+                if (webkitVersion < 535) {
+                    document.write('<meta name="viewport" content="initial-scale=1" />');
+                }
+            }
+        }
+
+        writeViewPort();
+    </script>
     <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
     <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
     <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
     <link href="index.css" rel="stylesheet" />
-    <script src="hand.minified-1.1.1.js"></script>
+    <script src="../../hand.minified-1.2.js"></script>
     <script src="../../babylon.js"></script>
     <!--<script src="../../Babylon/Tools/babylon.math.js"></script>
     <script src="../../Babylon/Tools/babylon.database.js"></script>

+ 23 - 0
Samples/Scenes/WorldMonger/index.js

@@ -56,6 +56,25 @@
     
     // Elevation
     var elevationControl = new WORLDMONGER.ElevationControl(ground);
+    
+    // Bloom
+    var blurWidth = 2.0;
+
+    var postProcess0 = new BABYLON.PassPostProcess("Scene copy", 1.0, camera);
+    var postProcess1 = new BABYLON.PostProcess("Down sample", "./postprocesses/downsample", ["screenSize", "highlightThreshold"], null, 0.5, camera, BABYLON.Texture.DEFAULT_SAMPLINGMODE);
+    postProcess1.onApply = function (effect) {
+        effect.setFloat2("screenSize", postProcess1.width, postProcess1.height);
+        effect.setFloat("highlightThreshold", 0.85);
+    };
+    var postProcess2 = new BABYLON.BlurPostProcess("Horizontal blur", new BABYLON.Vector2(1.0, 0), blurWidth, 0.5, camera, BABYLON.Texture.DEFAULT_SAMPLINGMODE);
+    var postProcess3 = new BABYLON.BlurPostProcess("Vertical blur", new BABYLON.Vector2(0, 1.0), blurWidth, 0.5, camera, BABYLON.Texture.DEFAULT_SAMPLINGMODE);
+    var postProcess4 = new BABYLON.PostProcess("Final compose", "./postprocesses/compose", ["sceneIntensity", "glowIntensity", "highlightIntensity"], ["sceneSampler"], 1, camera);
+    postProcess4.onApply = function (effect) {
+        effect.setTextureFromPostProcess("sceneSampler", postProcess0);
+        effect.setFloat("sceneIntensity", 0.8);
+        effect.setFloat("glowIntensity", 0.6);
+        effect.setFloat("highlightIntensity", 1.5);
+    };
 
     // Render loop
     var renderFunction = function () {
@@ -195,24 +214,28 @@
                     waterMaterial.reflectionTexture.resize(512, true);
                     scene.getEngine().setHardwareScalingLevel(1);
                     scene.particlesEnabled = true;
+                    scene.postProcessesEnabled = true;
                     break;
                 case 2:
                     waterMaterial.refractionTexture.resize(256, true);
                     waterMaterial.reflectionTexture.resize(256, true);
                     scene.getEngine().setHardwareScalingLevel(1);
                     scene.particlesEnabled = false;
+                    scene.postProcessesEnabled = false;
                     break;
                 case 1:
                     waterMaterial.refractionTexture.resize(256, true);
                     waterMaterial.reflectionTexture.resize(256, true);
                     scene.getEngine().setHardwareScalingLevel(2);
                     scene.particlesEnabled = false;
+                    scene.postProcessesEnabled = false;
                     break;
                 case 0:
                     waterMaterial.refractionTexture.resize(256, true);
                     waterMaterial.reflectionTexture.resize(256, true);
                     scene.getEngine().setHardwareScalingLevel(3);
                     scene.particlesEnabled = false;
+                    scene.postProcessesEnabled = false;
                     break;
             }
         }

BIN
Samples/Screenshots/expo.jpg


BIN
Samples/Screenshots/expo.png


BIN
Samples/Screenshots/lens.jpg


BIN
Samples/Screenshots/psn.jpg


BIN
Samples/Screenshots/sokrate3D.jpg


File diff suppressed because it is too large
+ 7 - 5
Samples/babylon.js


File diff suppressed because it is too large
+ 0 - 1
Samples/hand.minified-1.1.1.js


File diff suppressed because it is too large
+ 1 - 0
Samples/hand.minified-1.2.js


+ 17 - 2
Samples/index.css

@@ -29,7 +29,23 @@ a {
 .buttonControlPanel {
     height: 40px;
     width: 200px;
-    margin: 10px 0px 10px 0px;
+    margin: 5px 0px 5px 0px;
+}
+
+.smallButtonControlPanel {
+    height: 30px;
+    width: 200px;
+    margin: 2px 0px 2px 0px;
+}
+
+    .smallButtonControlPanel.pushed {
+        border: 2px solid #00008b;
+    }
+
+.buttonImg {
+    height: 32px;
+    width: 32px;
+    float: left;
 }
 
 button {
@@ -400,7 +416,6 @@ button {
 
 #cameraPanel {
     position: absolute;
-    height: 480px;
     right: 0px;
     width: 300px;
     top: 350px;

+ 33 - 11
Samples/index.html

@@ -2,7 +2,20 @@
 <html>
 <head>
     <title>Babylon.js</title>
-    <meta name="viewport" content="initial-scale=1">
+    <script>
+        function writeViewPort() {
+            var ua = navigator.userAgent;
+            if (ua.indexOf("Android") >= 0 && ua.indexOf("AppleWebKit") >= 0) {
+                var webkitVersion = parseFloat(ua.slice(ua.indexOf("AppleWebKit") + 12));
+                // targets android browser, not chrome browser (http://jimbergman.net/webkit-version-in-android-version/)
+                if (webkitVersion < 535) {
+                    document.write('<meta name="viewport" content="initial-scale=1" />');
+                }
+            }
+        }
+
+        writeViewPort();
+    </script>
     <script>
         (function (i, s, o, g, r, a, m) {
             i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
@@ -16,12 +29,13 @@
 
     </script>
     <link href="index.css" rel="stylesheet" />
-    <script src="hand.minified-1.1.1.js"></script>
-    <script src="Babylon/Tools/babylon.math.js"></script>
+    <script src="hand.minified-1.2.js"></script>
+    <!--<script src="Babylon/Tools/babylon.math.js"></script>
     <script src="Babylon/Tools/babylon.database.js"></script>
     <script src="Babylon/Tools/babylon.tools.js"></script>
     <script src="Babylon/babylon.engine.js"></script>
     <script src="Babylon/babylon.node.js"></script>
+    <script src="Babylon/Collisions/babylon.pickingInfo.js"></script>
     <script src="Babylon/Culling/babylon.boundingSphere.js"></script>
     <script src="Babylon/Culling/babylon.boundingBox.js"></script>
     <script src="Babylon/Culling/babylon.boundingInfo.js"></script>
@@ -76,7 +90,9 @@
     <script src="Babylon/PostProcess/babylon.blackAndWhitePostProcess.js"></script>
     <script src="Babylon/PostProcess/babylon.convolutionPostProcess.js"></script>
     <script src="Babylon/PostProcess/babylon.fxaaPostProcess.js"></script>
-    <!--<script src="babylon.js"></script>-->
+    <script src="Babylon/LensFlare/babylon.lensFlare.js"></script>
+    <script src="Babylon/LensFlare/babylon.lensFlareSystem.js"></script>-->
+    <script src="babylon.js"></script>
     <script src="Scenes/Customs/test.js"></script>
     <script src="Scenes/Customs/lights_test.js"></script>
     <script src="Scenes/Customs/bump_test.js"></script>
@@ -89,6 +105,7 @@
     <script src="Scenes/Customs/bones.js"></script>
     <script src="Scenes/Customs/postprocessBloom.js"></script>
     <script src="Scenes/Customs/postprocessRefraction.js"></script>
+    <script src="Scenes/Customs/lensFlares.js"></script>
     <script src="index.js"></script>
 </head>
 <body>
@@ -196,7 +213,8 @@
                                     <li>Fullscreen mode</li>
                                     <li>Shadow Maps and Variance Shadow Maps</li>
                                     <li>Rendering layers</li>
-                                    <li><b>Post-processes (blur, refraction, black'n'white, fxaa, customs...) </b></li>
+                                    <li><b>Post-processes (blur, refraction, black'n'white, fxaa, customs...)</b></li>
+                                    <li><b>Lens flares</b></li>
                                 </ul>
                             </li>
                             <li>
@@ -283,15 +301,19 @@
                     <select id="camerasList"></select>
                     <p>
                         Change control method:
-                        <button class="buttonControlPanel" id="touchCamera">Switch to touch camera</button>
-                        <button class="buttonControlPanel" id="deviceOrientationCamera">Switch to device orientation camera</button>
+                        <button class="buttonControlPanel" id="touchCamera">
+                            <img src="Assets/CamTouchOff.png" class="buttonImg"/><div style="margin-top: 8px">Touch camera</div>
+                        </button>
+                        <button class="buttonControlPanel" id="deviceOrientationCamera">
+                            <img src="Assets/CamDeviceOff.png" class="buttonImg" />Device orientation camera
+                        </button>
                     </p>
                     <p>
                         Post-processes:
-                        <button class="buttonControlPanel" id="toggleFxaa">Toggle FXAA (antialiasing)</button>
-                        <button class="buttonControlPanel" id="toggleFsaa4">Toggle FSAA 4X (antialiasing)</button>
-                        <button class="buttonControlPanel" id="toggleBandW">Toggle Black and white</button>
-                        <button class="buttonControlPanel" id="toggleSepia">Toggle Sepia</button>
+                        <button class="smallButtonControlPanel" id="toggleFxaa">Toggle FXAA (antialiasing)</button>
+                        <button class="smallButtonControlPanel" id="toggleFsaa4">Toggle FSAA 4X (antialiasing)</button>
+                        <button class="smallButtonControlPanel" id="toggleBandW">Toggle Black and white</button>
+                        <button class="smallButtonControlPanel" id="toggleSepia">Toggle Sepia</button>
                     </p>
                 </div>
                 <div class="cameraTag"><img src="Assets/camera.png" /></div>

+ 26 - 10
Samples/index.js

@@ -48,7 +48,7 @@ var onload = function () {
                 var postProcess = new BABYLON.RefractionPostProcess("Refraction", "/scenes/customs/refMap.jpg", new BABYLON.Color3(1.0, 1.0, 1.0), 0.5, 0.5, 1.0, scene.cameras[1]);
             }
         },
-        { title: "WINDOWS CAFE", scene: "WCafe", screenshot: "wcafe.jpg", size: "28 MB" },
+        { title: "WINDOWS CAFE", scene: "WCafe", screenshot: "wcafe.jpg", size: "28 MB", anchor:"WCAFE" },
         {
             title: "FLAT 2009",
             scene: "Flat2009",
@@ -60,19 +60,20 @@ var onload = function () {
                 scene.createOrUpdateSelectionOctree();
             }
         },
-        { title: "THE CAR", scene: "TheCar", screenshot: "thecar.jpg", size: "100 MB", incremental: true },
+        { title: "THE CAR", scene: "TheCar", screenshot: "thecar.jpg", size: "100 MB", incremental: true, anchor:"THECAR" },
         { title: "VIPER", scene: "Viper", screenshot: "viper.jpg", size: "18 MB" },
         { title: "SPACESHIP", scene: "Spaceship", screenshot: "spaceship.jpg", size: "1 MB" },
         {
-            title: "OMEGA CRUSHER", scene: "SpaceDek", screenshot: "omegacrusher.jpg", size: "10 MB", onload: function () {
+            title: "OMEGA CRUSHER", scene: "SpaceDek", screenshot: "omegacrusher.jpg", size: "10 MB", anchor:"OMEGA", onload: function () {
                 scene.collisionsEnabled = false;
             }
         }];
 
     var tests = [
-        { title: "POSTPROCESS - REFRACTION", id: 11, screenshot: "postprocessRefraction.jpg", size: "1.0 MB" },
-        { title: "POSTPROCESS - BLOOM", id: 10, screenshot: "postprocessBloom.jpg", size: "1.0 MB" },
-        { title: "OCTREE - 8000 spheres", id: 8, screenshot: "octree.jpg", size: "0.1 MB" },
+        { title: "LENS FLARES", id: 12, screenshot: "lens.jpg", size: "1.0 MB", anchor: "LENS" },
+        { title: "POSTPROCESS - REFRACTION", id: 11, screenshot: "postprocessRefraction.jpg", size: "1.0 MB", anchor:"PPREF" },
+        { title: "POSTPROCESS - BLOOM", id: 10, screenshot: "postprocessBloom.jpg", size: "1.0 MB", anchor: "PPBLOOM" },
+        { title: "OCTREE - 8000 spheres", id: 8, screenshot: "octree.jpg", size: "0.1 MB", anchor:"OCTREE" },
         { title: "BONES", id: 9, screenshot: "bones.jpg", size: "10 MB" },
         { title: "CHARTING", id: 7, screenshot: "charting.jpg", size: "0.1 MB" },
         { title: "SHADOWS", id: 6, screenshot: "shadows.jpg", size: "1.0 MB" },
@@ -88,7 +89,10 @@ var onload = function () {
     var thirdParties = [
     { title: "CAR GAME", url: "http://babylon.azurewebsites.net", screenshot: "car.jpg", size: "by G. Carlander" },
     { title: "CYCLE GAME", url: "http://tronbabylon.azurewebsites.net/", screenshot: "tron.jpg", size: "by G. Carlander" },
-    { title: "GALLERY", url: "http://guillaume.carlander.fr/Babylon/Gallery/", screenshot: "gallery.png", size: "by G. Carlander" }
+    { title: "GALLERY", url: "http://guillaume.carlander.fr/Babylon/Gallery/", screenshot: "gallery.png", size: "by G. Carlander" },
+    { title: "Catalog3D", url: "http://apps.microsoft.com/windows/en-gb/app/catalog-3d-by-sokrate/43771ce3-02f0-4365-98c3-557cd8acdad2", screenshot: "sokrate3D.jpg", size: "by SOKRATE" },
+    { title: "PSN TELECENTRES", url: "http://psntelecentres.com/visite_virtuelle.html", screenshot: "psn.jpg", size: "by SOKRATE" },
+    { title: "VIRTUAL EXPO", url: "http://www.sokrate.fr/expovirtuelle/index.htm", screenshot: "expo.jpg", size: "by SOKRATE" }
     ];
 
     // UI
@@ -316,6 +320,10 @@ var onload = function () {
                         break;
                     case 11:
                         newScene = CreatePostProcessRefractionTestScene(engine);
+                        break;
+                    case 12:
+                        newScene = CreateLensFlaresTestScene(engine);
+                        break;
                 }
                 scene = newScene;
 
@@ -515,7 +523,7 @@ var onload = function () {
             var pickResult = scene.pick(evt.clientX, evt.clientY);
 
             if (pickResult.hit) {
-                status.innerHTML = "Selected object: " + pickResult.pickedMesh.name;
+                status.innerHTML = "Selected object: " + pickResult.pickedMesh.name + "(" + pickResult.pickedPoint.x + "," + pickResult.pickedPoint.y  + "," + pickResult.pickedPoint.z  + ")";
 
                 // Animations
                 scene.beginAnimation(pickResult.pickedMesh, 0, 100, true, 1.0);
@@ -638,8 +646,10 @@ var onload = function () {
             if (scene.activeCamera.__bandw_cookie) {
                 scene.activeCamera.__bandw_cookie.dispose(),
                 scene.activeCamera.__bandw_cookie = null;
+                toggleBandW.className = "smallButtonControlPanel";
             } else {
                 scene.activeCamera.__bandw_cookie = new BABYLON.BlackAndWhitePostProcess("bandw", 1.0, scene.activeCamera);
+                toggleBandW.className = "smallButtonControlPanel pushed";
             }
         }
     });
@@ -649,8 +659,10 @@ var onload = function () {
             if (scene.activeCamera.__fxaa_cookie) {
                 scene.activeCamera.__fxaa_cookie.dispose(),
                 scene.activeCamera.__fxaa_cookie = null;
+                toggleFxaa.className = "smallButtonControlPanel";
             } else {
                 scene.activeCamera.__fxaa_cookie = new BABYLON.FxaaPostProcess("fxaa", 1.0, scene.activeCamera);
+                toggleFxaa.className = "smallButtonControlPanel pushed";
             }
         }
     });
@@ -660,10 +672,12 @@ var onload = function () {
             if (scene.activeCamera.__fsaa_cookie) {
                 scene.activeCamera.__fsaa_cookie.dispose(),
                 scene.activeCamera.__fsaa_cookie = null;
+                toggleFsaa4.className = "smallButtonControlPanel";
             } else {
                 var fx = new BABYLON.PassPostProcess("fsaa", 2.0, scene.activeCamera);
                 fx.renderTargetSamplingMode = BABYLON.Texture.BILINEAR_SAMPLINGMODE;
                 scene.activeCamera.__fsaa_cookie = fx;
+                toggleFsaa4.className = "smallButtonControlPanel pushed";
             }
         }
     });
@@ -673,6 +687,7 @@ var onload = function () {
             if (scene.activeCamera.__sepia_cookie) {
                 scene.activeCamera.__sepia_cookie.dispose(),
                 scene.activeCamera.__sepia_cookie = null;
+                toggleSepia.className = "smallButtonControlPanel";
             } else {
                 var sepiaKernelMatrix = BABYLON.Matrix.FromValues(
                     0.393, 0.349, 0.272, 0,
@@ -681,6 +696,7 @@ var onload = function () {
                     0, 0, 0, 0
                 );
                 scene.activeCamera.__sepia_cookie = new BABYLON.ConvolutionPostProcess("Sepia", sepiaKernelMatrix, 1.0, scene.activeCamera);
+                toggleSepia.className = "smallButtonControlPanel pushed";
             }
         }
     });
@@ -708,13 +724,13 @@ var onload = function () {
             }
         } else {
             for (index = 0; index < demos.length; index++) {
-                if (demos[index].title === query) {
+                if (demos[index].anchor && demos[index].anchor === query || demos[index].title === query) {
                     itemClick(demos[index])();
                     return;
                 }
             }
             for (index = 0; index < tests.length; index++) {
-                if (tests[index].title === query) {
+                if (tests[index].anchor && tests[index].anchor === query || tests[index].title === query) {
                     itemClick(tests[index])();
                     return;
                 }

File diff suppressed because it is too large
+ 0 - 20
babylon.1.6.0.js


File diff suppressed because it is too large
+ 22 - 0
babylon.1.7.js


+ 2 - 0
readme.md

@@ -52,6 +52,8 @@ Online [assets converter](http://www.babylonjs.com/converter.html) for .FBX, .OB
  - Shadow Maps and Variance Shadow Maps
  - Rendering layers
  - Post-processes (blur, refraction, black'n'white, fxaa, customs...)
+ - Lens flares
+ - Multi-views
 -  Textures:
  - Render target textures
  - Dynamic textures (canvas)

+ 12 - 0
what's new.md

@@ -1,5 +1,17 @@
 Changes list
 ============
+- 1.7.0:
+ - **Major updates**
+ - Support for [lens flares](https://github.com/BabylonJS/Babylon.js/wiki/How-to-use-lens-flares) ([deltakosh](http://www.github.com/deltakosh))
+ - Support for [multi-views](https://github.com/BabylonJS/Babylon.js/wiki/How-to-use-multi-views) ([deltakosh](http://www.github.com/deltakosh))
+ - **Updates**
+ - New ```light.excludedMeshes``` property to exclude specific meshes from light coputation ([deltakosh](http://www.github.com/deltakosh))
+ - New ```texture.anisotropicFilteringLevel``` property to define the anisotropic level of a texture ([deltakosh](http://www.github.com/deltakosh))
+ - New ```mesh.infiniteDistance``` property to make a mesh static from the point of view of the camera ([deltakosh](http://www.github.com/deltakosh))
+ - New ```scene.customRenderTargets``` property to add our own renderTargetTexture ([deltakosh](http://www.github.com/deltakosh))
+ - Transparent meshes are sorted back to front ([deltakosh](http://www.github.com/deltakosh))
+ - **Bugfixes**
+ - Fixing a bug when cloning mirrorTexture ([deltakosh](http://www.github.com/deltakosh))
 - 1.6.0:
  - **Major updates**
  - Support for [postprocesses](https://github.com/BabylonJS/Babylon.js/wiki/How-to-use-postprocesses) ([deltakosh](http://www.github.com/deltakosh))