Sfoglia il codice sorgente

Removing unnecessary files

David Catuhe 10 anni fa
parent
commit
fdfa7c829b

+ 25 - 3
Babylon/Audio/babylon.sound.js

@@ -13,8 +13,11 @@
             this.maxDistance = 10;
             this.autoplay = false;
             this.loop = false;
+            this.useBabylonJSAttenuation = false;
             this._position = BABYLON.Vector3.Zero();
             this._localDirection = new BABYLON.Vector3(1, 0, 0);
+            this._volume = 1;
+            this._distanceFromCamera = 1;
             this._isLoaded = false;
             this._isReadyToPlay = false;
             this._isPlaying = false;
@@ -38,21 +41,32 @@
                 if (options.loop) {
                     this.loop = options.loop;
                 }
+                if (options.volume) {
+                    this._volume = options.volume;
+                }
+                if (options.useBabylonJSAttenuation) {
+                    this.useBabylonJSAttenuation = options.useBabylonJSAttenuation;
+                }
             }
 
             if (this._audioEngine.canUseWebAudio) {
                 this._soundGain = this._audioEngine.audioContext.createGain();
-                this._soundGain.connect(this._audioEngine.masterGain);
+                this._soundGain.gain.value = this._volume;
+
+                //this._soundGain.connect(this._audioEngine.masterGain);
                 this._soundPanner = this._audioEngine.audioContext.createPanner();
                 this._soundPanner.connect(this._soundGain);
+                this._scene.mainSoundTrack.AddSound(this);
                 BABYLON.Tools.LoadFile(url, function (data) {
                     _this._soundLoaded(data);
                 }, null, null, true);
             }
         }
         Sound.prototype.connectToSoundTrackAudioNode = function (soundTrackAudioNode) {
-            this._soundGain.disconnect();
-            this._soundGain.connect(soundTrackAudioNode);
+            if (this._audioEngine.canUseWebAudio) {
+                this._soundGain.disconnect();
+                this._soundGain.connect(soundTrackAudioNode);
+            }
         };
 
         /**
@@ -141,6 +155,14 @@
             //this._soundSource.p
         };
 
+        Sound.prototype.setVolume = function (newVolume) {
+            this._volume = newVolume;
+        };
+
+        Sound.prototype.getVolume = function () {
+            return this._volume;
+        };
+
         Sound.prototype.attachToMesh = function (meshToConnectTo) {
             var _this = this;
             this._connectedMesh = meshToConnectTo;

+ 21 - 5
Babylon/Audio/babylon.sound.ts

@@ -3,10 +3,12 @@
         public maxDistance: number = 10;
         public autoplay: boolean = false;
         public loop: boolean = false;
+        public useBabylonJSAttenuation: boolean = false;
+        public soundTrackId: number;
         private _position: Vector3 = Vector3.Zero();
         private _localDirection: Vector3 = new Vector3(1,0,0);
-        private _volume: number;
-        private _currentVolume: number;
+        private _volume: number = 1;
+        private _distanceFromCamera: number = 1; 
         private _isLoaded: boolean = false;
         private _isReadyToPlay: boolean = false;
         private _isPlaying: boolean = false;
@@ -42,20 +44,26 @@
                 if (options.distanceMax) { this.maxDistance = options.distanceMax; }
                 if (options.autoplay) { this.autoplay = options.autoplay; }
                 if (options.loop) { this.loop = options.loop; }
+                if (options.volume) { this._volume = options.volume; }
+                if (options.useBabylonJSAttenuation) { this.useBabylonJSAttenuation = options.useBabylonJSAttenuation; }
             }
 
             if (this._audioEngine.canUseWebAudio) {
                 this._soundGain = this._audioEngine.audioContext.createGain();
-                this._soundGain.connect(this._audioEngine.masterGain);
+                this._soundGain.gain.value = this._volume;
+                //this._soundGain.connect(this._audioEngine.masterGain);
                 this._soundPanner = this._audioEngine.audioContext.createPanner();
                 this._soundPanner.connect(this._soundGain);
+                this._scene.mainSoundTrack.AddSound(this);
                 BABYLON.Tools.LoadFile(url, (data) => { this._soundLoaded(data); }, null, null, true);
             }
         }
 
         public connectToSoundTrackAudioNode(soundTrackAudioNode: AudioNode) {
-            this._soundGain.disconnect();
-            this._soundGain.connect(soundTrackAudioNode);
+            if (this._audioEngine.canUseWebAudio) {
+                this._soundGain.disconnect();
+                this._soundGain.connect(soundTrackAudioNode);
+            }
         }
 
         /**
@@ -145,6 +153,14 @@
             //this._soundSource.p
         }
 
+        public setVolume(newVolume: number) {
+            this._volume = newVolume;
+        }
+
+        public getVolume(): number {
+            return this._volume;
+        }
+
         public attachToMesh(meshToConnectTo: BABYLON.AbstractMesh) {
             this._connectedMesh = meshToConnectTo;
             meshToConnectTo.registerAfterWorldMatrixUpdate((connectedMesh: BABYLON.AbstractMesh) => this._onRegisterAfterWorldMatrixUpdate(connectedMesh));

+ 37 - 8
Babylon/Audio/babylon.soundtrack.js

@@ -2,21 +2,50 @@
 (function (BABYLON) {
     var SoundTrack = (function () {
         function SoundTrack(scene, options) {
+            this.id = -1;
+            this._isMainTrack = false;
             this._scene = scene;
             this._audioEngine = scene.getEngine().getAudioEngine();
-            this._trackGain = this._audioEngine.audioContext.createGain();
-            this._trackConvolver = this._audioEngine.audioContext.createConvolver();
-            this._trackConvolver.connect(this._trackGain);
-            this._trackGain.connect(this._audioEngine.masterGain);
             this._soundCollection = new Array();
-            this._scene._soundTracks.push(this);
+            if (this._audioEngine.canUseWebAudio) {
+                this._trackGain = this._audioEngine.audioContext.createGain();
+
+                //this._trackConvolver = this._audioEngine.audioContext.createConvolver();
+                //this._trackConvolver.connect(this._trackGain);
+                this._trackGain.connect(this._audioEngine.masterGain);
+
+                if (options) {
+                    if (options.volume) {
+                        this._trackGain.gain.value = options.volume;
+                    }
+                    if (options.mainTrack) {
+                        this._isMainTrack = options.mainTrack;
+                    }
+                }
+            }
+            if (!this._isMainTrack) {
+                this._scene.soundTracks.push(this);
+                this.id = this._scene.soundTracks.length - 1;
+            }
         }
-        SoundTrack.prototype.AddSound = function (newSound) {
-            newSound.connectToSoundTrackAudioNode(this._trackConvolver);
-            this._soundCollection.push(newSound);
+        SoundTrack.prototype.AddSound = function (sound) {
+            sound.connectToSoundTrackAudioNode(this._trackGain);
+            if (sound.soundTrackId) {
+                if (sound.soundTrackId === -1) {
+                    this._scene.mainSoundTrack.RemoveSound(sound);
+                } else {
+                    this._scene.soundTracks[sound.soundTrackId].RemoveSound(sound);
+                }
+            }
+            this._soundCollection.push(sound);
+            sound.soundTrackId = this.id;
         };
 
         SoundTrack.prototype.RemoveSound = function (sound) {
+            var index = this._soundCollection.indexOf(sound);
+            if (index !== -1) {
+                this._soundCollection.splice(index, 1);
+            }
         };
 
         SoundTrack.prototype.setVolume = function (newVolume) {

+ 34 - 12
Babylon/Audio/babylon.soundtrack.ts

@@ -4,27 +4,50 @@
         private _trackGain: GainNode;
         private _trackConvolver: ConvolverNode;
         private _scene: BABYLON.Scene;
-        private _id: number;
+        public id: number = -1;
         private _soundCollection: Array<BABYLON.Sound>;
+        private _isMainTrack: boolean = false;
 
-        constructor(scene: BABYLON.Scene, options?) {
+        constructor(scene: BABYLON.Scene, options?: any) {
             this._scene = scene;
             this._audioEngine = scene.getEngine().getAudioEngine();
-            this._trackGain = this._audioEngine.audioContext.createGain();
-            this._trackConvolver = this._audioEngine.audioContext.createConvolver();
-            this._trackConvolver.connect(this._trackGain);
-            this._trackGain.connect(this._audioEngine.masterGain);
             this._soundCollection = new Array();
-            this._scene._soundTracks.push(this);
+            if (this._audioEngine.canUseWebAudio) {
+                this._trackGain = this._audioEngine.audioContext.createGain();
+                //this._trackConvolver = this._audioEngine.audioContext.createConvolver();
+                //this._trackConvolver.connect(this._trackGain);
+                this._trackGain.connect(this._audioEngine.masterGain);
+
+                if (options) {
+                    if (options.volume) { this._trackGain.gain.value = options.volume; }
+                    if (options.mainTrack) { this._isMainTrack = options.mainTrack; }
+                }
+            }
+            if (!this._isMainTrack) {
+                this._scene.soundTracks.push(this);
+                this.id = this._scene.soundTracks.length - 1;
+            }
         }
 
-        public AddSound(newSound: BABYLON.Sound) {
-            newSound.connectToSoundTrackAudioNode(this._trackConvolver);
-            this._soundCollection.push(newSound);
+        public AddSound(sound: BABYLON.Sound) {
+            sound.connectToSoundTrackAudioNode(this._trackGain);
+            if (sound.soundTrackId) {
+                if (sound.soundTrackId === -1) {
+                    this._scene.mainSoundTrack.RemoveSound(sound);
+                }
+                else {
+                    this._scene.soundTracks[sound.soundTrackId].RemoveSound(sound);
+                }
+            }
+            this._soundCollection.push(sound);
+            sound.soundTrackId = this.id;
         }
 
         public RemoveSound(sound: BABYLON.Sound) {
-            
+            var index = this._soundCollection.indexOf(sound);
+            if (index !== -1) {
+                this._soundCollection.splice(index, 1);
+            }
         }
 
         public setVolume(newVolume: number) {
@@ -32,6 +55,5 @@
                 this._trackGain.gain.value = newVolume;
             }
         }
-     
     }
 }

+ 6 - 6
Babylon/Loading/babylon.sceneLoader.ts

@@ -92,13 +92,13 @@
                     return;
                 }
 
-                BABYLON.Tools.LoadFile(rootUrl + sceneFilename, data => {
+                Tools.LoadFile(rootUrl + sceneFilename, data => {
                     importMeshFromData(data);
                 }, progressCallBack, database);
             };
 
             // Checking if a manifest file has been set for this scene and if offline mode has been requested
-            var database = new BABYLON.Database(rootUrl + sceneFilename, manifestChecked);
+            var database = new Database(rootUrl + sceneFilename, manifestChecked);
         }
 
         /**
@@ -108,7 +108,7 @@
         * @param engine is the instance of BABYLON.Engine to use to create the scene
         */
         public static Load(rootUrl: string, sceneFilename: any, engine: Engine, onsuccess?: (scene: Scene) => void, progressCallBack?: any, onerror?: (scene: Scene) => void): void {
-            SceneLoader.Append(rootUrl, sceneFilename, new BABYLON.Scene(engine), onsuccess, progressCallBack, onerror);
+            SceneLoader.Append(rootUrl, sceneFilename, new Scene(engine), onsuccess, progressCallBack, onerror);
         }
 
         /**
@@ -150,7 +150,7 @@
             };
 
             var manifestChecked = success => {
-                BABYLON.Tools.LoadFile(rootUrl + sceneFilename, loadSceneFromData, progressCallBack, database);
+                Tools.LoadFile(rootUrl + sceneFilename, loadSceneFromData, progressCallBack, database);
             };
 
             if (sceneFilename.substr && sceneFilename.substr(0, 5) === "data:") {
@@ -161,11 +161,11 @@
 
             if (rootUrl.indexOf("file:") === -1) {
                 // Checking if a manifest file has been set for this scene and if offline mode has been requested
-                database = new BABYLON.Database(rootUrl + sceneFilename, manifestChecked);
+                database = new Database(rootUrl + sceneFilename, manifestChecked);
             }
             // Loading file from disk via input file or drag'n'drop
             else {
-                BABYLON.Tools.ReadFile(sceneFilename, loadSceneFromData, progressCallBack);
+                Tools.ReadFile(sceneFilename, loadSceneFromData, progressCallBack);
             }
         }
     };

+ 0 - 226
Babylon/Materials/textures/babylon.proceduralTexture.js

@@ -1,226 +0,0 @@
-var __extends = this.__extends || function (d, b) {
-    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
-    function __() { this.constructor = d; }
-    __.prototype = b.prototype;
-    d.prototype = new __();
-};
-var BABYLON;
-(function (BABYLON) {
-    var ProceduralTexture = (function (_super) {
-        __extends(ProceduralTexture, _super);
-        function ProceduralTexture(name, size, fragment, scene, generateMipMaps) {
-            _super.call(this, null, scene, !generateMipMaps);
-            this._currentRefreshId = -1;
-            this._refreshRate = 1;
-            this._vertexDeclaration = [2];
-            this._vertexStrideSize = 2 * 4;
-            this._uniforms = new Array();
-            this._samplers = new Array();
-            this._textures = new Array();
-            this._floats = new Array();
-            this._floatsArrays = {};
-            this._colors3 = new Array();
-            this._colors4 = new Array();
-            this._vectors2 = new Array();
-            this._vectors3 = new Array();
-            this._matrices = new Array();
-
-            scene._proceduralTextures.push(this);
-
-            this.name = name;
-            this.isRenderTarget = true;
-            this._size = size;
-            this._generateMipMaps = generateMipMaps;
-
-            this._fragment = fragment;
-
-            this._texture = scene.getEngine().createRenderTargetTexture(size, generateMipMaps);
-
-            // VBO
-            var vertices = [];
-            vertices.push(1, 1);
-            vertices.push(-1, 1);
-            vertices.push(-1, -1);
-            vertices.push(1, -1);
-
-            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);
-        }
-        ProceduralTexture.prototype.isReady = function () {
-            var engine = this.getScene().getEngine();
-
-            this._effect = engine.createEffect({ vertex: "procedural", fragment: this._fragment }, ["position"], this._uniforms, this._samplers, "");
-
-            return this._effect.isReady();
-        };
-
-        ProceduralTexture.prototype.resetRefreshCounter = function () {
-            this._currentRefreshId = -1;
-        };
-
-        Object.defineProperty(ProceduralTexture.prototype, "refreshRate", {
-            get: function () {
-                return this._refreshRate;
-            },
-            // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
-            set: function (value) {
-                this._refreshRate = value;
-                this.resetRefreshCounter();
-            },
-            enumerable: true,
-            configurable: true
-        });
-
-
-        ProceduralTexture.prototype._shouldRender = function () {
-            if (this._currentRefreshId === -1) {
-                this._currentRefreshId = 1;
-                return true;
-            }
-
-            if (this.refreshRate == this._currentRefreshId) {
-                this._currentRefreshId = 1;
-                return true;
-            }
-
-            this._currentRefreshId++;
-            return false;
-        };
-
-        ProceduralTexture.prototype.getRenderSize = function () {
-            return this._size;
-        };
-
-        ProceduralTexture.prototype.resize = function (size, generateMipMaps) {
-            this.releaseInternalTexture();
-            this._texture = this.getScene().getEngine().createRenderTargetTexture(size, generateMipMaps);
-        };
-
-        ProceduralTexture.prototype._checkUniform = function (uniformName) {
-            if (this._uniforms.indexOf(uniformName) === -1) {
-                this._uniforms.push(uniformName);
-            }
-        };
-
-        ProceduralTexture.prototype.setTexture = function (name, texture) {
-            if (this._samplers.indexOf(name) === -1) {
-                this._samplers.push(name);
-            }
-            this._textures[name] = texture;
-
-            return this;
-        };
-
-        ProceduralTexture.prototype.setFloat = function (name, value) {
-            this._checkUniform(name);
-            this._floats[name] = value;
-
-            return this;
-        };
-
-        ProceduralTexture.prototype.setFloats = function (name, value) {
-            this._checkUniform(name);
-            this._floatsArrays[name] = value;
-
-            return this;
-        };
-
-        ProceduralTexture.prototype.setColor3 = function (name, value) {
-            this._checkUniform(name);
-            this._colors3[name] = value;
-
-            return this;
-        };
-
-        ProceduralTexture.prototype.setColor4 = function (name, value) {
-            this._checkUniform(name);
-            this._colors4[name] = value;
-
-            return this;
-        };
-
-        ProceduralTexture.prototype.setVector2 = function (name, value) {
-            this._checkUniform(name);
-            this._vectors2[name] = value;
-
-            return this;
-        };
-
-        ProceduralTexture.prototype.setVector3 = function (name, value) {
-            this._checkUniform(name);
-            this._vectors3[name] = value;
-
-            return this;
-        };
-
-        ProceduralTexture.prototype.setMatrix = function (name, value) {
-            this._checkUniform(name);
-            this._matrices[name] = value;
-
-            return this;
-        };
-
-        ProceduralTexture.prototype.render = function (useCameraPostProcess) {
-            if (!this.isReady() || !this._texture)
-                return;
-
-            var scene = this.getScene();
-            var engine = scene.getEngine();
-
-            engine.bindFramebuffer(this._texture);
-
-            // Clear
-            engine.clear(scene.clearColor, true, true);
-
-            // Render
-            engine.enableEffect(this._effect);
-            engine.setState(false);
-
-            // VBOs
-            engine.bindBuffers(this._vertexBuffer, this._indexBuffer, this._vertexDeclaration, this._vertexStrideSize, this._effect);
-
-            // Draw order
-            engine.draw(true, 0, 6);
-
-            // Unbind
-            engine.unBindFramebuffer(this._texture);
-        };
-
-        ProceduralTexture.prototype.clone = function () {
-            var textureSize = this.getSize();
-            var newTexture = new BABYLON.ProceduralTexture(this.name, textureSize.width, this._fragment, this.getScene(), this._generateMipMaps);
-
-            // Base texture
-            newTexture.hasAlpha = this.hasAlpha;
-            newTexture.level = this.level;
-
-            // RenderTarget Texture
-            newTexture.coordinatesMode = this.coordinatesMode;
-
-            return newTexture;
-        };
-
-        ProceduralTexture.prototype.dispose = function () {
-            var index = this.getScene()._proceduralTextures.indexOf(this);
-
-            if (index >= 0) {
-                this.getScene()._proceduralTextures.splice(index, 1);
-            }
-            _super.prototype.dispose.call(this);
-        };
-        return ProceduralTexture;
-    })(BABYLON.Texture);
-    BABYLON.ProceduralTexture = ProceduralTexture;
-})(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.proceduralTexture.js.map

+ 7 - 2
Babylon/babylon.scene.js

@@ -10,6 +10,7 @@
             this.forceWireframe = false;
             this.forcePointsCloud = false;
             this.forceShowBoundingBoxes = false;
+            this.animationsEnabled = true;
             this.cameraToUseForPointers = null;
             // Fog
             this.fogMode = Scene.FOGMODE_NONE;
@@ -62,8 +63,7 @@
             // Procedural textures
             this.proceduralTexturesEnabled = true;
             this._proceduralTextures = new Array();
-            // Sound Tracks
-            this._soundTracks = new Array();
+            this.soundTracks = new Array();
             this._totalVertices = 0;
             this._activeVertices = 0;
             this._activeParticles = 0;
@@ -107,6 +107,7 @@
             this.attachControl();
 
             this._debugLayer = new BABYLON.DebugLayer(this);
+            this.mainSoundTrack = new BABYLON.SoundTrack(this, { mainTrack: true });
         }
         Object.defineProperty(Scene.prototype, "debugLayer", {
             // Properties
@@ -473,6 +474,10 @@
         };
 
         Scene.prototype._animate = function () {
+            if (!this.animationsEnabled) {
+                return;
+            }
+
             if (!this._animationStartDate) {
                 this._animationStartDate = BABYLON.Tools.Now;
             }

+ 8 - 1
Babylon/babylon.scene.ts

@@ -26,6 +26,7 @@
         public forcePointsCloud = false;
         public forceShowBoundingBoxes = false;
         public clipPlane: Plane;
+        public animationsEnabled = true;
 
         // Pointers
         private _onPointerMove: (evt: PointerEvent) => void;
@@ -121,7 +122,8 @@
         public _proceduralTextures = new Array<ProceduralTexture>();
 
         // Sound Tracks
-        public _soundTracks = new Array<SoundTrack>();
+        public mainSoundTrack: SoundTrack;
+        public soundTracks = new Array<SoundTrack>();
 
         // Private
         private _engine: Engine;
@@ -198,6 +200,7 @@
             this.attachControl();
 
             this._debugLayer = new DebugLayer(this);
+            this.mainSoundTrack = new SoundTrack(this, { mainTrack: true });
         }
 
         // Properties 
@@ -550,6 +553,10 @@
         }
 
         private _animate(): void {
+            if (!this.animationsEnabled) {
+                return;
+            }
+
             if (!this._animationStartDate) {
                 this._animationStartDate = Tools.Now;
             }

+ 78 - 19
babylon.2.0-alpha.debug.js

@@ -8302,6 +8302,7 @@ var BABYLON;
             this.forceWireframe = false;
             this.forcePointsCloud = false;
             this.forceShowBoundingBoxes = false;
+            this.animationsEnabled = true;
             this.cameraToUseForPointers = null;
            
             this.fogMode = Scene.FOGMODE_NONE;
@@ -8354,8 +8355,7 @@ var BABYLON;
            
             this.proceduralTexturesEnabled = true;
             this._proceduralTextures = new Array();
-           
-            this._soundTracks = new Array();
+            this.soundTracks = new Array();
             this._totalVertices = 0;
             this._activeVertices = 0;
             this._activeParticles = 0;
@@ -8399,6 +8399,7 @@ var BABYLON;
             this.attachControl();
 
             this._debugLayer = new BABYLON.DebugLayer(this);
+            this.mainSoundTrack = new BABYLON.SoundTrack(this, { mainTrack: true });
         }
         Object.defineProperty(Scene.prototype, "debugLayer", {
            
@@ -8765,6 +8766,10 @@ var BABYLON;
         };
 
         Scene.prototype._animate = function () {
+            if (!this.animationsEnabled) {
+                return;
+            }
+
             if (!this._animationStartDate) {
                 this._animationStartDate = BABYLON.Tools.Now;
             }
@@ -29025,8 +29030,11 @@ var BABYLON;
             this.maxDistance = 10;
             this.autoplay = false;
             this.loop = false;
+            this.useBabylonJSAttenuation = false;
             this._position = BABYLON.Vector3.Zero();
             this._localDirection = new BABYLON.Vector3(1, 0, 0);
+            this._volume = 1;
+            this._distanceFromCamera = 1;
             this._isLoaded = false;
             this._isReadyToPlay = false;
             this._isPlaying = false;
@@ -29050,21 +29058,32 @@ var BABYLON;
                 if (options.loop) {
                     this.loop = options.loop;
                 }
+                if (options.volume) {
+                    this._volume = options.volume;
+                }
+                if (options.useBabylonJSAttenuation) {
+                    this.useBabylonJSAttenuation = options.useBabylonJSAttenuation;
+                }
             }
 
             if (this._audioEngine.canUseWebAudio) {
                 this._soundGain = this._audioEngine.audioContext.createGain();
-                this._soundGain.connect(this._audioEngine.masterGain);
+                this._soundGain.gain.value = this._volume;
+
+               
                 this._soundPanner = this._audioEngine.audioContext.createPanner();
                 this._soundPanner.connect(this._soundGain);
+                this._scene.mainSoundTrack.AddSound(this);
                 BABYLON.Tools.LoadFile(url, function (data) {
                     _this._soundLoaded(data);
                 }, null, null, true);
             }
         }
         Sound.prototype.connectToSoundTrackAudioNode = function (soundTrackAudioNode) {
-            this._soundGain.disconnect();
-            this._soundGain.connect(soundTrackAudioNode);
+            if (this._audioEngine.canUseWebAudio) {
+                this._soundGain.disconnect();
+                this._soundGain.connect(soundTrackAudioNode);
+            }
         };
 
         /**
@@ -29153,6 +29172,14 @@ var BABYLON;
            
         };
 
+        Sound.prototype.setVolume = function (newVolume) {
+            this._volume = newVolume;
+        };
+
+        Sound.prototype.getVolume = function () {
+            return this._volume;
+        };
+
         Sound.prototype.attachToMesh = function (meshToConnectTo) {
             var _this = this;
             this._connectedMesh = meshToConnectTo;
@@ -29192,21 +29219,50 @@ var BABYLON;
 (function (BABYLON) {
     var SoundTrack = (function () {
         function SoundTrack(scene, options) {
+            this.id = -1;
+            this._isMainTrack = false;
             this._scene = scene;
             this._audioEngine = scene.getEngine().getAudioEngine();
-            this._trackGain = this._audioEngine.audioContext.createGain();
-            this._trackConvolver = this._audioEngine.audioContext.createConvolver();
-            this._trackConvolver.connect(this._trackGain);
-            this._trackGain.connect(this._audioEngine.masterGain);
             this._soundCollection = new Array();
-            this._scene._soundTracks.push(this);
+            if (this._audioEngine.canUseWebAudio) {
+                this._trackGain = this._audioEngine.audioContext.createGain();
+
+               
+               
+                this._trackGain.connect(this._audioEngine.masterGain);
+
+                if (options) {
+                    if (options.volume) {
+                        this._trackGain.gain.value = options.volume;
+                    }
+                    if (options.mainTrack) {
+                        this._isMainTrack = options.mainTrack;
+                    }
+                }
+            }
+            if (!this._isMainTrack) {
+                this._scene.soundTracks.push(this);
+                this.id = this._scene.soundTracks.length - 1;
+            }
         }
-        SoundTrack.prototype.AddSound = function (newSound) {
-            newSound.connectToSoundTrackAudioNode(this._trackConvolver);
-            this._soundCollection.push(newSound);
+        SoundTrack.prototype.AddSound = function (sound) {
+            sound.connectToSoundTrackAudioNode(this._trackGain);
+            if (sound.soundTrackId) {
+                if (sound.soundTrackId === -1) {
+                    this._scene.mainSoundTrack.RemoveSound(sound);
+                } else {
+                    this._scene.soundTracks[sound.soundTrackId].RemoveSound(sound);
+                }
+            }
+            this._soundCollection.push(sound);
+            sound.soundTrackId = this.id;
         };
 
         SoundTrack.prototype.RemoveSound = function (sound) {
+            var index = this._soundCollection.indexOf(sound);
+            if (index !== -1) {
+                this._soundCollection.splice(index, 1);
+            }
         };
 
         SoundTrack.prototype.setVolume = function (newVolume) {
@@ -29630,11 +29686,11 @@ var BABYLON;
 
         DebugLayer.prototype._generateDOMelements = function () {
             var _this = this;
-            this._globalDiv.id = "Debug Layer";
+            this._globalDiv.id = "DebugLayer";
 
            
             this._drawingCanvas = document.createElement("canvas");
-            this._drawingCanvas.id = "Debug Layer - Drawing canvas";
+            this._drawingCanvas.id = "DebugLayerDrawingCanvas";
             this._drawingCanvas.style.position = "absolute";
             this._drawingCanvas.style.pointerEvents = "none";
             this._drawingContext = this._drawingCanvas.getContext("2d");
@@ -29646,7 +29702,7 @@ var BABYLON;
 
                
                 this._statsDiv = document.createElement("div");
-                this._statsDiv.id = "Debug Layer - Stats";
+                this._statsDiv.id = "DebugLayerStats";
                 this._statsDiv.style.border = border;
                 this._statsDiv.style.position = "absolute";
                 this._statsDiv.style.background = background;
@@ -29661,7 +29717,7 @@ var BABYLON;
 
                
                 this._treeDiv = document.createElement("div");
-                this._treeDiv.id = "Debug Layer - Tree";
+                this._treeDiv.id = "DebugLayerTree";
                 this._treeDiv.style.border = border;
                 this._treeDiv.style.position = "absolute";
                 this._treeDiv.style.background = background;
@@ -29700,7 +29756,7 @@ var BABYLON;
                
                 this._logDiv = document.createElement("div");
                 this._logDiv.style.border = border;
-                this._logDiv.id = "Debug Layer - Logs";
+                this._logDiv.id = "DebugLayerLogs";
                 this._logDiv.style.position = "absolute";
                 this._logDiv.style.background = background;
                 this._logDiv.style.padding = "0px 0px 0px 5px";
@@ -29720,7 +29776,7 @@ var BABYLON;
 
                
                 this._optionsDiv = document.createElement("div");
-                this._optionsDiv.id = "Debug Layer - Options";
+                this._optionsDiv.id = "DebugLayerOptions";
                 this._optionsDiv.style.border = border;
                 this._optionsDiv.style.position = "absolute";
                 this._optionsDiv.style.background = background;
@@ -29806,6 +29862,9 @@ var BABYLON;
                 });
                 this._optionsSubsetDiv.appendChild(document.createElement("br"));
                 this._generateTexBox(this._optionsSubsetDiv, "<b>Options:</b>");
+                this._generateCheckBox(this._optionsSubsetDiv, "Animations", this._scene.animationsEnabled, function (element) {
+                    _this._scene.animationsEnabled = element.checked;
+                });
                 this._generateCheckBox(this._optionsSubsetDiv, "Collisions", this._scene.collisionsEnabled, function (element) {
                     _this._scene.collisionsEnabled = element.checked;
                 });

File diff suppressed because it is too large
+ 4 - 4
babylon.2.0-alpha.js


+ 11 - 48
babylon.2.0.d.ts

@@ -342,6 +342,7 @@ declare module BABYLON {
         public forcePointsCloud: boolean;
         public forceShowBoundingBoxes: boolean;
         public clipPlane: Plane;
+        public animationsEnabled: boolean;
         private _onPointerMove;
         private _onPointerDown;
         public onPointerDown: (evt: PointerEvent, pickInfo: PickingInfo) => void;
@@ -392,7 +393,8 @@ declare module BABYLON {
         private _meshesForIntersections;
         public proceduralTexturesEnabled: boolean;
         public _proceduralTextures: ProceduralTexture[];
-        public _soundTracks: SoundTrack[];
+        public mainSoundTrack: SoundTrack;
+        public soundTracks: SoundTrack[];
         private _engine;
         private _totalVertices;
         public _activeVertices: number;
@@ -885,10 +887,12 @@ declare module BABYLON {
         public maxDistance: number;
         public autoplay: boolean;
         public loop: boolean;
+        public useBabylonJSAttenuation: boolean;
+        public soundTrackId: number;
         private _position;
         private _localDirection;
         private _volume;
-        private _currentVolume;
+        private _distanceFromCamera;
         private _isLoaded;
         private _isReadyToPlay;
         private _isPlaying;
@@ -935,6 +939,8 @@ declare module BABYLON {
         */
         public stop(time?: number): void;
         public pause(): void;
+        public setVolume(newVolume: number): void;
+        public getVolume(): number;
         public attachToMesh(meshToConnectTo: AbstractMesh): void;
         private _onRegisterAfterWorldMatrixUpdate(connectedMesh);
         private _soundLoaded(audioData);
@@ -946,10 +952,11 @@ declare module BABYLON {
         private _trackGain;
         private _trackConvolver;
         private _scene;
-        private _id;
+        public id: number;
         private _soundCollection;
+        private _isMainTrack;
         constructor(scene: Scene, options?: any);
-        public AddSound(newSound: Sound): void;
+        public AddSound(sound: Sound): void;
         public RemoveSound(sound: Sound): void;
         public setVolume(newVolume: number): void;
     }
@@ -2009,50 +2016,6 @@ declare module BABYLON {
     }
 }
 declare module BABYLON {
-    class ProceduralTexture extends Texture {
-        private _size;
-        public _generateMipMaps: boolean;
-        private _doNotChangeAspectRatio;
-        private _currentRefreshId;
-        private _refreshRate;
-        private _vertexBuffer;
-        private _indexBuffer;
-        private _effect;
-        private _vertexDeclaration;
-        private _vertexStrideSize;
-        private _uniforms;
-        private _samplers;
-        private _fragment;
-        private _textures;
-        private _floats;
-        private _floatsArrays;
-        private _colors3;
-        private _colors4;
-        private _vectors2;
-        private _vectors3;
-        private _matrices;
-        constructor(name: string, size: any, fragment: any, scene: Scene, generateMipMaps?: boolean);
-        public isReady(): boolean;
-        public resetRefreshCounter(): void;
-        public refreshRate : number;
-        public _shouldRender(): boolean;
-        public getRenderSize(): number;
-        public resize(size: any, generateMipMaps: any): void;
-        private _checkUniform(uniformName);
-        public setTexture(name: string, texture: Texture): ProceduralTexture;
-        public setFloat(name: string, value: number): ProceduralTexture;
-        public setFloats(name: string, value: number[]): ProceduralTexture;
-        public setColor3(name: string, value: Color3): ProceduralTexture;
-        public setColor4(name: string, value: Color4): ProceduralTexture;
-        public setVector2(name: string, value: Vector2): ProceduralTexture;
-        public setVector3(name: string, value: Vector3): ProceduralTexture;
-        public setMatrix(name: string, value: Matrix): ProceduralTexture;
-        public render(useCameraPostProcess?: boolean): void;
-        public clone(): ProceduralTexture;
-        public dispose(): void;
-    }
-}
-declare module BABYLON {
     class RenderTargetTexture extends Texture {
         public renderList: AbstractMesh[];
         public renderParticles: boolean;