Bläddra i källkod

Fixing computeWorldMatrix call issue

David Catuhe 10 år sedan
förälder
incheckning
78e12d5dc3

+ 30 - 0
Babylon/Actions/babylon.directActions.js

@@ -172,5 +172,35 @@ var BABYLON;
         return SetParentAction;
     })(BABYLON.Action);
     BABYLON.SetParentAction = SetParentAction;
+    var PlaySoundAction = (function (_super) {
+        __extends(PlaySoundAction, _super);
+        function PlaySoundAction(triggerOptions, sound, condition) {
+            _super.call(this, triggerOptions, condition);
+            this._sound = sound;
+        }
+        PlaySoundAction.prototype._prepare = function () {
+        };
+        PlaySoundAction.prototype.execute = function () {
+            if (this._sound !== undefined)
+                this._sound.play();
+        };
+        return PlaySoundAction;
+    })(BABYLON.Action);
+    BABYLON.PlaySoundAction = PlaySoundAction;
+    var StopSoundAction = (function (_super) {
+        __extends(StopSoundAction, _super);
+        function StopSoundAction(triggerOptions, sound, condition) {
+            _super.call(this, triggerOptions, condition);
+            this._sound = sound;
+        }
+        StopSoundAction.prototype._prepare = function () {
+        };
+        StopSoundAction.prototype.execute = function () {
+            if (this._sound !== undefined)
+                this._sound.stop();
+        };
+        return StopSoundAction;
+    })(BABYLON.Action);
+    BABYLON.StopSoundAction = StopSoundAction;
 })(BABYLON || (BABYLON = {}));
 //# sourceMappingURL=babylon.directActions.js.map

+ 34 - 0
Babylon/Actions/babylon.directActions.ts

@@ -171,4 +171,38 @@
             this._target.parent = this._parent;
         }
     }
+
+    export class PlaySoundAction extends Action {
+        private _sound: Sound;
+
+        constructor(triggerOptions: any, sound: Sound, condition?: Condition) {
+            super(triggerOptions, condition);
+            this._sound = sound;
+        }
+
+        public _prepare(): void {
+        }
+
+        public execute(): void {
+            if (this._sound !== undefined)
+                this._sound.play();
+        }
+    }
+
+    export class StopSoundAction extends Action {
+        private _sound: Sound;
+
+        constructor(triggerOptions: any, sound: Sound, condition?: Condition) {
+            super(triggerOptions, condition);
+            this._sound = sound;
+        }
+
+        public _prepare(): void {
+        }
+
+        public execute(): void {
+            if (this._sound !== undefined)
+                this._sound.stop();
+        }
+    }
 } 

+ 2 - 1
Babylon/Audio/babylon.sound.ts

@@ -343,12 +343,13 @@
                     this.play();
                 }
             }
+            this._onRegisterAfterWorldMatrixUpdate(this._connectedMesh);
             this._registerFunc = (connectedMesh: AbstractMesh) => this._onRegisterAfterWorldMatrixUpdate(connectedMesh);
             meshToConnectTo.registerAfterWorldMatrixUpdate(this._registerFunc);
         }
 
         private _onRegisterAfterWorldMatrixUpdate(connectedMesh: AbstractMesh) {
-            this.setPosition(connectedMesh.position);
+            this.setPosition(connectedMesh.getBoundingInfo().boundingSphere.centerWorld);
             if (this._isDirectional && this._isPlaying) {
                 this._updateDirection();
             }

+ 9 - 7
Babylon/Loading/Plugins/babylon.babylonFileLoader.js

@@ -704,6 +704,8 @@ var BABYLON;
                         value = target = scene.getNodeByName(value);
                     else if (name === "parent")
                         value = scene.getNodeByName(value);
+                    else if (name === "sound")
+                        value = scene.getSoundByName(value);
                     else if (name !== "propertyPath") {
                         if (parsedAction.type === 2 && name === "operator")
                             value = BABYLON.ValueCondition[value];
@@ -1162,6 +1164,13 @@ var BABYLON;
                         light._waitingParentId = undefined;
                     }
                 }
+                // Sounds
+                if (parsedData.sounds && BABYLON.Engine.audioEngine.canUseWebAudio) {
+                    for (index = 0; index < parsedData.sounds.length; index++) {
+                        var parsedSound = parsedData.sounds[index];
+                        parseSound(parsedSound, scene, rootUrl);
+                    }
+                }
                 for (index = 0; index < scene.meshes.length; index++) {
                     var mesh = scene.meshes[index];
                     if (mesh._waitingParentId) {
@@ -1194,13 +1203,6 @@ var BABYLON;
                         parseShadowGenerator(parsedShadowGenerator, scene);
                     }
                 }
-                // Sounds
-                if (parsedData.sounds && BABYLON.Engine.audioEngine.canUseWebAudio) {
-                    for (index = 0; index < parsedData.sounds.length; index++) {
-                        var parsedSound = parsedData.sounds[index];
-                        parseSound(parsedSound, scene, rootUrl);
-                    }
-                }
                 // Actions (scene)
                 if (parsedData.actions) {
                     parseActions(parsedData.actions, null, scene);

+ 11 - 8
Babylon/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -889,6 +889,8 @@
                     value = target = scene.getNodeByName(value);
                 else if (name === "parent")
                     value = scene.getNodeByName(value);
+                else if (name === "sound")
+                    value = scene.getSoundByName(value);
                 else if (name !== "propertyPath") {
                     if (parsedAction.type === 2 && name === "operator")
                         value = BABYLON.ValueCondition[value];
@@ -1431,6 +1433,15 @@
                 }
             }
 
+            // Sounds
+            if (parsedData.sounds && Engine.audioEngine.canUseWebAudio) {
+                for (index = 0; index < parsedData.sounds.length; index++) {
+                    var parsedSound = parsedData.sounds[index];
+                    parseSound(parsedSound, scene, rootUrl);
+                }
+            }
+
+            // Connect parents & children and parse actions
             for (index = 0; index < scene.meshes.length; index++) {
                 var mesh = scene.meshes[index];
                 if (mesh._waitingParentId) {
@@ -1468,14 +1479,6 @@
                 }
             }
 
-            // Sounds
-            if (parsedData.sounds && Engine.audioEngine.canUseWebAudio) {
-                for (index = 0; index < parsedData.sounds.length; index++) {
-                    var parsedSound = parsedData.sounds[index];
-                    parseSound(parsedSound, scene, rootUrl);
-                }
-            }
-
             // Actions (scene)
             if (parsedData.actions) {
                 parseActions(parsedData.actions, null, scene);

+ 1 - 0
Babylon/Mesh/babylon.geometry.js

@@ -26,6 +26,7 @@ var BABYLON;
             // applyToMesh
             if (mesh) {
                 this.applyToMesh(mesh);
+                mesh.computeWorldMatrix(true);
             }
         }
         Geometry.prototype.getScene = function () {

+ 1 - 0
Babylon/Mesh/babylon.geometry.ts

@@ -35,6 +35,7 @@
             // applyToMesh
             if (mesh) {
                 this.applyToMesh(mesh);
+                mesh.computeWorldMatrix(true);
             }
         }
 

+ 6 - 5
Babylon/PostProcess/babylon.ssaoRenderingPipeline.js

@@ -25,8 +25,8 @@ var BABYLON;
             this._depthTexture = scene.enableDepthRenderer().getDepthMap(); // Force depth renderer "on"
             this._originalColorPostProcess = new BABYLON.PassPostProcess("SSAOOriginalSceneColor", 1.0, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             this._createSSAOPostProcess(ratio);
-            this._blurHPostProcess = new BABYLON.BlurPostProcess("SSAOBlurH", new BABYLON.Vector2(1.0, 0.0), 1.0, ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
-            this._blurVPostProcess = new BABYLON.BlurPostProcess("SSAOBlurV", new BABYLON.Vector2(0.0, 1.0), 1.0, ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
+            this._blurHPostProcess = new BABYLON.BlurPostProcess("SSAOBlurH", new BABYLON.Vector2(2.0, 0.0), 2.0, ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
+            this._blurVPostProcess = new BABYLON.BlurPostProcess("SSAOBlurV", new BABYLON.Vector2(0.0, 2.0), 2.0, ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             this._createSSAOCombinePostProcess();
             // Set up pipeline
             this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), this.SSAOOriginalSceneColorEffect, function () {
@@ -46,6 +46,8 @@ var BABYLON;
             }, true));
             // Finish
             scene.postProcessRenderPipelineManager.addPipeline(this);
+            if (cameras)
+                scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(name, cameras);
         }
         // Public Methods
         SSAORenderingPipeline.prototype.getBlurHPostProcess = function () {
@@ -118,17 +120,17 @@ var BABYLON;
                 -0.0271
             ];
             var samplesFactor = 1.0 / 16.0;
-            this._ssaoPostProcess = new BABYLON.PostProcess("ssao", "ssao", ["sampleSphere", "samplesFactor"], ["randomSampler"], ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false);
+            this._ssaoPostProcess = new BABYLON.PostProcess("ssao", "ssao", ["sampleSphere", "samplesFactor", "randTextureTiles"], ["randomSampler"], ratio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false);
             this._ssaoPostProcess.onApply = function (effect) {
                 if (_this._firstUpdate) {
                     effect.setArray3("sampleSphere", sampleSphere);
                     effect.setFloat("samplesFactor", samplesFactor);
+                    effect.setFloat("randTextureTiles", 4.0 / ratio);
                     _this._firstUpdate = false;
                 }
                 effect.setTexture("textureSampler", _this._depthTexture);
                 effect.setTexture("randomSampler", _this._randomTexture);
             };
-            return this._ssaoPostProcess;
         };
         SSAORenderingPipeline.prototype._createSSAOCombinePostProcess = function () {
             var _this = this;
@@ -136,7 +138,6 @@ var BABYLON;
             this._ssaoCombinePostProcess.onApply = function (effect) {
                 effect.setTextureFromPostProcess("originalColor", _this._originalColorPostProcess);
             };
-            return this._ssaoCombinePostProcess;
         };
         SSAORenderingPipeline.prototype._createRandomTexture = function () {
             var size = 512;

+ 10 - 10
Babylon/PostProcess/babylon.ssaoRenderingPipeline.ts

@@ -30,8 +30,8 @@
 
             this._originalColorPostProcess = new PassPostProcess("SSAOOriginalSceneColor", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             this._createSSAOPostProcess(ratio);
-            this._blurHPostProcess = new BlurPostProcess("SSAOBlurH", new Vector2(1.0, 0.0), 1.0, ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
-            this._blurVPostProcess = new BlurPostProcess("SSAOBlurV", new Vector2(0.0, 1.0), 1.0, ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
+            this._blurHPostProcess = new BlurPostProcess("SSAOBlurH", new Vector2(2.0, 0.0), 2.0, ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
+            this._blurVPostProcess = new BlurPostProcess("SSAOBlurV", new Vector2(0.0, 2.0), 2.0, ratio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             this._createSSAOCombinePostProcess();
 
             // Set up pipeline
@@ -40,9 +40,11 @@
             this.addEffect(new PostProcessRenderEffect(scene.getEngine(), this.SSAOBlurHRenderEffect, () => { return this._blurHPostProcess; }, true));
             this.addEffect(new PostProcessRenderEffect(scene.getEngine(), this.SSAOBlurVRenderEffect, () => { return this._blurVPostProcess; }, true));
             this.addEffect(new PostProcessRenderEffect(scene.getEngine(), this.SSAOCombineRenderEffect, () => { return this._ssaoCombinePostProcess; }, true));
-            
+
             // Finish
             scene.postProcessRenderPipelineManager.addPipeline(this);
+            if (cameras)
+                scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(name, cameras);
         }
 
         // Public Methods
@@ -68,7 +70,7 @@
         }
 
         // Private Methods
-        private _createSSAOPostProcess(ratio: number): PostProcess {
+        private _createSSAOPostProcess(ratio: number): void {
             var sampleSphere = [
                 0.5381, 0.1856, -0.4319,
                 0.1379, 0.2486, 0.4430,
@@ -89,7 +91,8 @@
             ];
             var samplesFactor = 1.0 / 16.0;
 
-            this._ssaoPostProcess = new PostProcess("ssao", "ssao", ["sampleSphere", "samplesFactor"], ["randomSampler"],
+            this._ssaoPostProcess = new PostProcess("ssao", "ssao", ["sampleSphere", "samplesFactor", "randTextureTiles"],
+                                                    ["randomSampler"],
                                                     ratio, null, Texture.BILINEAR_SAMPLINGMODE,
                                                     this._scene.getEngine(), false);
 
@@ -97,17 +100,16 @@
                 if (this._firstUpdate) {
                     effect.setArray3("sampleSphere", sampleSphere);
                     effect.setFloat("samplesFactor", samplesFactor);
+                    effect.setFloat("randTextureTiles", 4.0 / ratio);
                     this._firstUpdate = false;
                 }
 
                 effect.setTexture("textureSampler", this._depthTexture);
                 effect.setTexture("randomSampler", this._randomTexture);
             };
-
-            return this._ssaoPostProcess;
         }
 
-        private _createSSAOCombinePostProcess(): PostProcess {
+        private _createSSAOCombinePostProcess(): void {
             this._ssaoCombinePostProcess = new PostProcess("ssaoCombine", "ssaoCombine", [], ["originalColor"],
                                                            1.0, null, Texture.BILINEAR_SAMPLINGMODE,
                                                            this._scene.getEngine(), false);
@@ -115,8 +117,6 @@
             this._ssaoCombinePostProcess.onApply = (effect: Effect) => {
                 effect.setTextureFromPostProcess("originalColor", this._originalColorPostProcess);
             };
-
-            return this._ssaoCombinePostProcess;
         }
 
         private _createRandomTexture(): void {

+ 3 - 2
Babylon/PostProcess/babylon.volumetricLightScatteringPostProcess.js

@@ -87,6 +87,7 @@ var BABYLON;
             this._godRaysRTT.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._godRaysRTT.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._godRaysRTT.renderList = null;
+            this._godRaysRTT.renderParticles = false;
             scene.customRenderTargets.push(this._godRaysRTT);
             // Custom render function for submeshes
             var renderSubMesh = function (subMesh) {
@@ -121,8 +122,8 @@ var BABYLON;
                 }
             };
             // Render target texture callbacks
-            var savedSceneClearColor = null;
-            var sceneClearColor = new BABYLON.Color4(0.0, 0.0, 0.0, 1.0);
+            var savedSceneClearColor;
+            var sceneClearColor = new BABYLON.Color3(0.0, 0.0, 0.0);
             this._godRaysRTT.onBeforeRender = function () {
                 savedSceneClearColor = scene.clearColor;
                 scene.clearColor = sceneClearColor;

+ 3 - 2
Babylon/PostProcess/babylon.volumetricLightScatteringPostProcess.ts

@@ -107,6 +107,7 @@
             this._godRaysRTT.wrapU = Texture.CLAMP_ADDRESSMODE;
             this._godRaysRTT.wrapV = Texture.CLAMP_ADDRESSMODE;
             this._godRaysRTT.renderList = null;
+            this._godRaysRTT.renderParticles = false;
             scene.customRenderTargets.push(this._godRaysRTT);
 
             // Custom render function for submeshes
@@ -153,8 +154,8 @@
             };
 
             // Render target texture callbacks
-            var savedSceneClearColor: Color4 = null;
-            var sceneClearColor = new Color4(0.0, 0.0, 0.0, 1.0);
+            var savedSceneClearColor: Color3;
+            var sceneClearColor = new Color3(0.0, 0.0, 0.0);
 
             this._godRaysRTT.onBeforeRender = (): void => {
                 savedSceneClearColor = scene.clearColor;

+ 1 - 1
Babylon/Shaders/depth.fragment.fx

@@ -16,6 +16,6 @@ void main(void)
 		discard;
 #endif
 
-	float depth = gl_FragCoord.z / far;
+	float depth = (gl_FragCoord.z / gl_FragCoord.w) / far;
 	gl_FragColor = vec4(depth, depth * depth, 0.0, 1.0);
 }

+ 7 - 7
Babylon/Shaders/ssao.fragment.fx

@@ -7,6 +7,7 @@ precision highp float;
 uniform sampler2D textureSampler;
 uniform sampler2D randomSampler;
 
+uniform float randTextureTiles;
 uniform float samplesFactor;
 uniform vec3 sampleSphere[16];
 
@@ -16,8 +17,8 @@ const vec2 offset1 = vec2(0.0, 0.001);
 const vec2 offset2 = vec2(0.001, 0.0);
 
 vec3 normalFromDepth(const float depth, const vec2 coords) {
-    float depth1 = texture2D(textureSampler, coords + offset1).r;
-    float depth2 = texture2D(textureSampler, coords + offset2).r;
+	float depth1 = texture2D(textureSampler, coords + offset1).r;
+	float depth2 = texture2D(textureSampler, coords + offset2).r;
 
     vec3 p1 = vec3(offset1, depth1 - depth);
     vec3 p2 = vec3(offset2, depth2 - depth);
@@ -33,10 +34,10 @@ void main(void)
 	const float totalStrength = 1.0;
 	const float base = 0.2;
 	const float area = 0.0075;
-	const float fallOff = 0.00001;
-	const float radius = 0.002;
+	const float fallOff = 0.000001;
+	const float radius = 0.0002;
 
-	vec3 random = texture2D(randomSampler, vUV * 4.0).rgb;
+	vec3 random = texture2D(randomSampler, vUV * randTextureTiles).rgb;
 	float depth = texture2D(textureSampler, vUV).r;
 	vec3 position = vec3(vUV, depth);
 	vec3 normal = normalFromDepth(depth, vUV);
@@ -65,6 +66,5 @@ void main(void)
 	gl_FragColor.r = result;
 	gl_FragColor.g = result;
 	gl_FragColor.b = result;
-	gl_FragColor.a = 1.0;
-
+	gl_FragColor.a = result;
 }

+ 2 - 2
Babylon/Shaders/ssaoCombine.fragment.fx

@@ -1,5 +1,5 @@
 #ifdef GL_ES
-precision mediump float;
+precision highp float;
 #endif
 
 uniform sampler2D textureSampler;
@@ -8,5 +8,5 @@ uniform sampler2D originalColor;
 varying vec2 vUV;
 
 void main(void) {
-	gl_FragColor = texture2D(textureSampler, vUV) * texture2D(originalColor, vUV);
+	gl_FragColor = texture2D(originalColor, vUV) * texture2D(textureSampler, vUV);
 }

+ 0 - 1
Babylon/Shaders/volumetricLightScattering.fragment.fx

@@ -39,5 +39,4 @@ void main(void) {
 
     vec4 realColor = texture2D(textureSampler, vUV);
     gl_FragColor = ((vec4((vec3(color.r, color.g, color.b) * exposure), 1)) + (realColor * (1.5 - 0.4)));
-
 }

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 53 - 18
babylon.2.0-beta.debug.js


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