浏览代码

AdaptToRatio = false by default

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

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


文件差异内容过多而无法显示
+ 2751 - 2749
dist/preview release/babylon.d.ts


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


+ 80 - 9
dist/preview release/babylon.max.js

@@ -5147,7 +5147,7 @@ var BABYLON;
          */
         function Engine(canvas, antialias, options, adaptToDeviceRatio) {
             var _this = this;
-            if (adaptToDeviceRatio === void 0) { adaptToDeviceRatio = true; }
+            if (adaptToDeviceRatio === void 0) { adaptToDeviceRatio = false; }
             // Public members
             this.isFullscreen = false;
             this.isPointerLock = false;
@@ -20491,17 +20491,26 @@ var BABYLON;
                     }
                 }
                 // Sounds
+                var loadedSounds = [];
+                var loadedSound;
                 if (BABYLON.AudioEngine && parsedData.sounds) {
                     for (index = 0, cache = parsedData.sounds.length; index < cache; index++) {
                         var parsedSound = parsedData.sounds[index];
                         if (BABYLON.Engine.audioEngine.canUseWebAudio) {
-                            BABYLON.Sound.Parse(parsedSound, scene, rootUrl);
+                            if (!loadedSounds[parsedSound.name]) {
+                                loadedSound = BABYLON.Sound.Parse(parsedSound, scene, rootUrl);
+                                loadedSounds[loadedSound.name] = loadedSound;
+                            }
+                            else {
+                                BABYLON.Sound.Parse(parsedSound, scene, rootUrl, loadedSounds[parsedSound.name]);
+                            }
                         }
                         else {
                             var emptySound = new BABYLON.Sound(parsedSound.name, null, scene);
                         }
                     }
                 }
+                loadedSounds = [];
                 // Connect parents & children and parse actions
                 for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     var mesh = scene.meshes[index];
@@ -28992,7 +29001,7 @@ var BABYLON;
                             //find the mesh that collided with the registered mesh
                             for (var idx = 0; idx < _this._registeredMeshes.length; idx++) {
                                 if (_this._registeredMeshes[idx].body == e.body) {
-                                    registeredMesh.mesh.onPhysicsCollide(_this._registeredMeshes[idx].mesh);
+                                    registeredMesh.mesh.onPhysicsCollide(_this._registeredMeshes[idx].mesh, e.contact);
                                 }
                             }
                         };
@@ -29611,7 +29620,7 @@ var BABYLON;
                             //get the mesh and execute the callback
                             var otherMesh = mesh.getScene().getMeshByUniqueID(otherUniqueId);
                             if (otherMesh)
-                                mesh.onPhysicsCollide(otherMesh);
+                                mesh.onPhysicsCollide(otherMesh, contact);
                         }
                         contact = contact.next;
                     }
@@ -34136,7 +34145,7 @@ var BABYLON;
         * @param name Name of your sound
         * @param urlOrArrayBuffer Url to the sound to load async or ArrayBuffer
         * @param readyToPlayCallback Provide a callback function if you'd like to load your code once the sound is ready to be played
-        * @param options Objects to provide with the current available options: autoplay, loop, volume, spatialSound, maxDistance, rolloffFactor, refDistance, distanceModel, panningModel
+        * @param options Objects to provide with the current available options: autoplay, loop, volume, spatialSound, maxDistance, rolloffFactor, refDistance, distanceModel, panningModel, streaming
         */
         function Sound(name, urlOrArrayBuffer, scene, readyToPlayCallback, options) {
             var _this = this;
@@ -34233,7 +34242,9 @@ var BABYLON;
                     }
                     else {
                         if (urlOrArrayBuffer instanceof ArrayBuffer) {
-                            this._soundLoaded(urlOrArrayBuffer);
+                            if (urlOrArrayBuffer.byteLength > 0) {
+                                this._soundLoaded(urlOrArrayBuffer);
+                            }
                         }
                         else {
                             BABYLON.Tools.Error("Parameter must be a URL to the sound or an ArrayBuffer of the sound.");
@@ -34550,6 +34561,10 @@ var BABYLON;
         };
         Sound.prototype.attachToMesh = function (meshToConnectTo) {
             var _this = this;
+            if (this._connectedMesh) {
+                this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc);
+                this._registerFunc = null;
+            }
             this._connectedMesh = meshToConnectTo;
             if (!this.spatialSound) {
                 this.spatialSound = true;
@@ -34569,7 +34584,44 @@ var BABYLON;
                 this._updateDirection();
             }
         };
-        Sound.Parse = function (parsedSound, scene, rootUrl) {
+        Sound.prototype.clone = function () {
+            var _this = this;
+            if (!this._streaming) {
+                var setBufferAndRun = function () {
+                    if (_this._isReadyToPlay) {
+                        clonedSound._audioBuffer = _this.getAudioBuffer();
+                        clonedSound._isReadyToPlay = true;
+                        if (clonedSound.autoplay) {
+                            clonedSound.play();
+                        }
+                    }
+                    else {
+                        window.setTimeout(setBufferAndRun, 300);
+                    }
+                };
+                var currentOptions = {
+                    autoplay: this.autoplay, loop: this.loop,
+                    volume: this._volume, spatialSound: this.spatialSound, maxDistance: this.maxDistance,
+                    useCustomAttenuation: this.useCustomAttenuation, rolloffFactor: this.rolloffFactor,
+                    refDistance: this.refDistance, distanceModel: this.distanceModel
+                };
+                var clonedSound = new Sound(this.name + "_cloned", new ArrayBuffer(0), this._scene, null, currentOptions);
+                if (this.useCustomAttenuation) {
+                    clonedSound.setAttenuationFunction(this._customAttenuationFunction);
+                }
+                clonedSound.setPosition(this._position);
+                clonedSound.setPlaybackRate(this._playbackRate);
+                setBufferAndRun();
+                return clonedSound;
+            }
+            else {
+                return null;
+            }
+        };
+        Sound.prototype.getAudioBuffer = function () {
+            return this._audioBuffer;
+        };
+        Sound.Parse = function (parsedSound, scene, rootUrl, sourceSound) {
             var soundName = parsedSound.name;
             var soundUrl = rootUrl + soundName;
             var options = {
@@ -34580,8 +34632,27 @@ var BABYLON;
                 distanceModel: parsedSound.distanceModel,
                 playbackRate: parsedSound.playbackRate
             };
-            var newSound = new Sound(soundName, soundUrl, scene, function () { scene._removePendingData(newSound); }, options);
-            scene._addPendingData(newSound);
+            var newSound;
+            if (!sourceSound) {
+                newSound = new Sound(soundName, soundUrl, scene, function () { scene._removePendingData(newSound); }, options);
+                scene._addPendingData(newSound);
+            }
+            else {
+                var setBufferAndRun = function () {
+                    if (sourceSound._isReadyToPlay) {
+                        newSound._audioBuffer = sourceSound.getAudioBuffer();
+                        newSound._isReadyToPlay = true;
+                        if (newSound.autoplay) {
+                            newSound.play();
+                        }
+                    }
+                    else {
+                        window.setTimeout(setBufferAndRun, 300);
+                    }
+                };
+                newSound = new Sound(soundName, new ArrayBuffer(0), scene, null, options);
+                setBufferAndRun();
+            }
             if (parsedSound.position) {
                 var soundPosition = BABYLON.Vector3.FromArray(parsedSound.position);
                 newSound.setPosition(soundPosition);

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


+ 67 - 5
src/Audio/babylon.sound.js

@@ -6,7 +6,7 @@ var BABYLON;
         * @param name Name of your sound
         * @param urlOrArrayBuffer Url to the sound to load async or ArrayBuffer
         * @param readyToPlayCallback Provide a callback function if you'd like to load your code once the sound is ready to be played
-        * @param options Objects to provide with the current available options: autoplay, loop, volume, spatialSound, maxDistance, rolloffFactor, refDistance, distanceModel, panningModel
+        * @param options Objects to provide with the current available options: autoplay, loop, volume, spatialSound, maxDistance, rolloffFactor, refDistance, distanceModel, panningModel, streaming
         */
         function Sound(name, urlOrArrayBuffer, scene, readyToPlayCallback, options) {
             var _this = this;
@@ -103,7 +103,9 @@ var BABYLON;
                     }
                     else {
                         if (urlOrArrayBuffer instanceof ArrayBuffer) {
-                            this._soundLoaded(urlOrArrayBuffer);
+                            if (urlOrArrayBuffer.byteLength > 0) {
+                                this._soundLoaded(urlOrArrayBuffer);
+                            }
                         }
                         else {
                             BABYLON.Tools.Error("Parameter must be a URL to the sound or an ArrayBuffer of the sound.");
@@ -420,6 +422,10 @@ var BABYLON;
         };
         Sound.prototype.attachToMesh = function (meshToConnectTo) {
             var _this = this;
+            if (this._connectedMesh) {
+                this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc);
+                this._registerFunc = null;
+            }
             this._connectedMesh = meshToConnectTo;
             if (!this.spatialSound) {
                 this.spatialSound = true;
@@ -439,7 +445,44 @@ var BABYLON;
                 this._updateDirection();
             }
         };
-        Sound.Parse = function (parsedSound, scene, rootUrl) {
+        Sound.prototype.clone = function () {
+            var _this = this;
+            if (!this._streaming) {
+                var setBufferAndRun = function () {
+                    if (_this._isReadyToPlay) {
+                        clonedSound._audioBuffer = _this.getAudioBuffer();
+                        clonedSound._isReadyToPlay = true;
+                        if (clonedSound.autoplay) {
+                            clonedSound.play();
+                        }
+                    }
+                    else {
+                        window.setTimeout(setBufferAndRun, 300);
+                    }
+                };
+                var currentOptions = {
+                    autoplay: this.autoplay, loop: this.loop,
+                    volume: this._volume, spatialSound: this.spatialSound, maxDistance: this.maxDistance,
+                    useCustomAttenuation: this.useCustomAttenuation, rolloffFactor: this.rolloffFactor,
+                    refDistance: this.refDistance, distanceModel: this.distanceModel
+                };
+                var clonedSound = new Sound(this.name + "_cloned", new ArrayBuffer(0), this._scene, null, currentOptions);
+                if (this.useCustomAttenuation) {
+                    clonedSound.setAttenuationFunction(this._customAttenuationFunction);
+                }
+                clonedSound.setPosition(this._position);
+                clonedSound.setPlaybackRate(this._playbackRate);
+                setBufferAndRun();
+                return clonedSound;
+            }
+            else {
+                return null;
+            }
+        };
+        Sound.prototype.getAudioBuffer = function () {
+            return this._audioBuffer;
+        };
+        Sound.Parse = function (parsedSound, scene, rootUrl, sourceSound) {
             var soundName = parsedSound.name;
             var soundUrl = rootUrl + soundName;
             var options = {
@@ -450,8 +493,27 @@ var BABYLON;
                 distanceModel: parsedSound.distanceModel,
                 playbackRate: parsedSound.playbackRate
             };
-            var newSound = new Sound(soundName, soundUrl, scene, function () { scene._removePendingData(newSound); }, options);
-            scene._addPendingData(newSound);
+            var newSound;
+            if (!sourceSound) {
+                newSound = new Sound(soundName, soundUrl, scene, function () { scene._removePendingData(newSound); }, options);
+                scene._addPendingData(newSound);
+            }
+            else {
+                var setBufferAndRun = function () {
+                    if (sourceSound._isReadyToPlay) {
+                        newSound._audioBuffer = sourceSound.getAudioBuffer();
+                        newSound._isReadyToPlay = true;
+                        if (newSound.autoplay) {
+                            newSound.play();
+                        }
+                    }
+                    else {
+                        window.setTimeout(setBufferAndRun, 300);
+                    }
+                };
+                newSound = new Sound(soundName, new ArrayBuffer(0), scene, null, options);
+                setBufferAndRun();
+            }
             if (parsedSound.position) {
                 var soundPosition = BABYLON.Vector3.FromArray(parsedSound.position);
                 newSound.setPosition(soundPosition);

+ 71 - 6
src/Audio/babylon.sound.ts

@@ -49,7 +49,7 @@
         * @param name Name of your sound 
         * @param urlOrArrayBuffer Url to the sound to load async or ArrayBuffer 
         * @param readyToPlayCallback Provide a callback function if you'd like to load your code once the sound is ready to be played
-        * @param options Objects to provide with the current available options: autoplay, loop, volume, spatialSound, maxDistance, rolloffFactor, refDistance, distanceModel, panningModel
+        * @param options Objects to provide with the current available options: autoplay, loop, volume, spatialSound, maxDistance, rolloffFactor, refDistance, distanceModel, panningModel, streaming
         */
         constructor(name: string, urlOrArrayBuffer: any, scene: Scene, readyToPlayCallback?: () => void, options?) {
             this.name = name;
@@ -118,7 +118,9 @@
                     }
                     else {
                         if (urlOrArrayBuffer instanceof ArrayBuffer) {
-                            this._soundLoaded(urlOrArrayBuffer);
+                            if ((<ArrayBuffer>urlOrArrayBuffer).byteLength > 0) {
+                                this._soundLoaded(urlOrArrayBuffer);
+                            }
                         }
                         else {
                             Tools.Error("Parameter must be a URL to the sound or an ArrayBuffer of the sound.");
@@ -457,6 +459,10 @@
         }
 
         public attachToMesh(meshToConnectTo: AbstractMesh) {
+            if (this._connectedMesh) {
+                this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc);
+                this._registerFunc = null;
+            }
             this._connectedMesh = meshToConnectTo;
             if (!this.spatialSound) {
                 this.spatialSound = true;
@@ -478,7 +484,47 @@
             }
         }
 
-        public static Parse(parsedSound: any, scene: Scene, rootUrl: string): Sound {
+        public clone(): Sound {
+            if (!this._streaming) {
+                var setBufferAndRun = () => {
+                    if (this._isReadyToPlay) {
+                        clonedSound._audioBuffer = this.getAudioBuffer();
+                        clonedSound._isReadyToPlay = true;
+                        if (clonedSound.autoplay) { clonedSound.play(); }
+                    }
+                    else {
+                        window.setTimeout(setBufferAndRun, 300);
+                    }
+                };
+
+                var currentOptions = {
+                    autoplay: this.autoplay, loop: this.loop,
+                    volume: this._volume, spatialSound: this.spatialSound, maxDistance: this.maxDistance,
+                    useCustomAttenuation: this.useCustomAttenuation, rolloffFactor: this.rolloffFactor,
+                    refDistance: this.refDistance, distanceModel: this.distanceModel
+                };
+
+                var clonedSound = new Sound(this.name + "_cloned", new ArrayBuffer(0), this._scene, null, currentOptions);
+                if (this.useCustomAttenuation) {
+                    clonedSound.setAttenuationFunction(this._customAttenuationFunction);
+                }
+                clonedSound.setPosition(this._position);
+                clonedSound.setPlaybackRate(this._playbackRate);
+                setBufferAndRun();
+
+                return clonedSound;
+            }
+            // Can't clone a streaming sound
+            else {
+                return null;
+            } 
+        }
+
+        public getAudioBuffer() {
+            return this._audioBuffer;
+        }
+
+        public static Parse(parsedSound: any, scene: Scene, rootUrl: string, sourceSound?: Sound): Sound {
             var soundName = parsedSound.name;
             var soundUrl = rootUrl + soundName;
 
@@ -491,8 +537,27 @@
                 playbackRate: parsedSound.playbackRate
             };
 
-            var newSound = new Sound(soundName, soundUrl, scene, () => { scene._removePendingData(newSound); }, options);
-            scene._addPendingData(newSound);
+            var newSound: Sound;
+
+            if (!sourceSound) {
+                newSound = new Sound(soundName, soundUrl, scene, () => { scene._removePendingData(newSound); }, options);
+                scene._addPendingData(newSound);
+            }
+            else {
+                var setBufferAndRun = () => {
+                    if (sourceSound._isReadyToPlay) {
+                        newSound._audioBuffer = sourceSound.getAudioBuffer();
+                        newSound._isReadyToPlay = true;
+                        if (newSound.autoplay) { newSound.play(); }
+                    }
+                    else {
+                        window.setTimeout(setBufferAndRun, 300);
+                    }
+                }
+
+                newSound = new Sound(soundName, new ArrayBuffer(0), scene, null, options);
+                setBufferAndRun();
+            }
 
             if (parsedSound.position) {
                 var soundPosition = Vector3.FromArray(parsedSound.position);
@@ -515,4 +580,4 @@
             return newSound;
         }
     }
-}
+}

+ 10 - 1
src/Loading/Plugins/babylon.babylonFileLoader.js

@@ -321,17 +321,26 @@ var BABYLON;
                     }
                 }
                 // Sounds
+                var loadedSounds = [];
+                var loadedSound;
                 if (BABYLON.AudioEngine && parsedData.sounds) {
                     for (index = 0, cache = parsedData.sounds.length; index < cache; index++) {
                         var parsedSound = parsedData.sounds[index];
                         if (BABYLON.Engine.audioEngine.canUseWebAudio) {
-                            BABYLON.Sound.Parse(parsedSound, scene, rootUrl);
+                            if (!loadedSounds[parsedSound.name]) {
+                                loadedSound = BABYLON.Sound.Parse(parsedSound, scene, rootUrl);
+                                loadedSounds[loadedSound.name] = loadedSound;
+                            }
+                            else {
+                                BABYLON.Sound.Parse(parsedSound, scene, rootUrl, loadedSounds[parsedSound.name]);
+                            }
                         }
                         else {
                             var emptySound = new BABYLON.Sound(parsedSound.name, null, scene);
                         }
                     }
                 }
+                loadedSounds = [];
                 // Connect parents & children and parse actions
                 for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     var mesh = scene.meshes[index];

+ 11 - 1
src/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -352,17 +352,27 @@
             }
 
             // Sounds
+            var loadedSounds: Sound[] = [];
+            var loadedSound: Sound;
             if (AudioEngine && parsedData.sounds) {
                 for (index = 0, cache = parsedData.sounds.length; index < cache; index++) {
                     var parsedSound = parsedData.sounds[index];
                     if (Engine.audioEngine.canUseWebAudio) {
-                        Sound.Parse(parsedSound, scene, rootUrl);
+                        if (!loadedSounds[parsedSound.name]) {
+                            loadedSound = Sound.Parse(parsedSound, scene, rootUrl);
+                            loadedSounds[loadedSound.name] = loadedSound;
+                        }
+                        else {
+                            Sound.Parse(parsedSound, scene, rootUrl, loadedSounds[parsedSound.name]);
+                        }
                     } else {
                         var emptySound = new Sound(parsedSound.name, null, scene);
                     }
                 }
             }
 
+            loadedSounds = [];
+
             // Connect parents & children and parse actions
             for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                 var mesh = scene.meshes[index];

+ 1 - 1
src/Physics/Plugins/babylon.cannonJSPlugin.js

@@ -74,7 +74,7 @@ var BABYLON;
                             //find the mesh that collided with the registered mesh
                             for (var idx = 0; idx < _this._registeredMeshes.length; idx++) {
                                 if (_this._registeredMeshes[idx].body == e.body) {
-                                    registeredMesh.mesh.onPhysicsCollide(_this._registeredMeshes[idx].mesh);
+                                    registeredMesh.mesh.onPhysicsCollide(_this._registeredMeshes[idx].mesh, e.contact);
                                 }
                             }
                         };

+ 1 - 1
src/Physics/Plugins/babylon.oimoJSPlugin.js

@@ -318,7 +318,7 @@ var BABYLON;
                             //get the mesh and execute the callback
                             var otherMesh = mesh.getScene().getMeshByUniqueID(otherUniqueId);
                             if (otherMesh)
-                                mesh.onPhysicsCollide(otherMesh);
+                                mesh.onPhysicsCollide(otherMesh, contact);
                         }
                         contact = contact.next;
                     }

+ 1 - 1
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -402,7 +402,7 @@ module BABYLON {
                             //get the mesh and execute the callback
                             var otherMesh = mesh.getScene().getMeshByUniqueID(otherUniqueId);
                             if (otherMesh)
-                                mesh.onPhysicsCollide(otherMesh, contact);
+                                mesh.onPhysicsCollide(otherMesh, contact); 
                         }
                         contact = contact.next;
                     }

+ 1 - 1
src/babylon.engine.js

@@ -355,7 +355,7 @@ var BABYLON;
          */
         function Engine(canvas, antialias, options, adaptToDeviceRatio) {
             var _this = this;
-            if (adaptToDeviceRatio === void 0) { adaptToDeviceRatio = true; }
+            if (adaptToDeviceRatio === void 0) { adaptToDeviceRatio = false; }
             // Public members
             this.isFullscreen = false;
             this.isPointerLock = false;

+ 1 - 1
src/babylon.engine.ts

@@ -568,7 +568,7 @@
          * @param {boolean} [antialias] - enable antialias
          * @param options - further options to be sent to the getContext function
          */
-        constructor(canvas: HTMLCanvasElement, antialias?: boolean, options?: { antialias?: boolean, preserveDrawingBuffer?: boolean }, adaptToDeviceRatio = true) {
+        constructor(canvas: HTMLCanvasElement, antialias?: boolean, options?: { antialias?: boolean, preserveDrawingBuffer?: boolean }, adaptToDeviceRatio = false) {
             this._renderingCanvas = canvas;
 
             options = options || {};