Browse Source

SIMD.js - step 2

David Catuhe 10 năm trước cách đây
mục cha
commit
5127e21c9c

+ 9 - 12
Babylon/Audio/babylon.sound.js

@@ -18,7 +18,7 @@ var BABYLON;
             this.rolloffFactor = 1;
             this.maxDistance = 100;
             this.distanceModel = "linear";
-            this._panningModel = "equalpower";
+            this.panningModel = "HRTF";
             this._playbackRate = 1;
             this._startTime = 0;
             this._startOffset = 0;
@@ -60,6 +60,7 @@ var BABYLON;
                 this.rolloffFactor = options.rolloffFactor || 1;
                 this.refDistance = options.refDistance || 1;
                 this.distanceModel = options.distanceModel || "linear";
+                this.panningModel = options.panningModel || "HRTF";
                 this._playbackRate = options.playbackRate || 1;
             }
             if (BABYLON.Engine.audioEngine.canUseWebAudio) {
@@ -159,14 +160,12 @@ var BABYLON;
                 this.rolloffFactor = options.rolloffFactor || this.rolloffFactor;
                 this.refDistance = options.refDistance || this.refDistance;
                 this.distanceModel = options.distanceModel || this.distanceModel;
+                this.panningModel = options.panningModel || this.panningModel;
                 this._playbackRate = options.playbackRate || this._playbackRate;
             }
         };
         Sound.prototype._createSpatialParameters = function () {
             if (BABYLON.Engine.audioEngine.canUseWebAudio) {
-                if (this._scene.headphone) {
-                    this._panningModel = "HRTF";
-                }
                 this._soundPanner = BABYLON.Engine.audioEngine.audioContext.createPanner();
                 if (this.useCustomAttenuation) {
                     // Tricks to disable in a way embedded Web Audio attenuation 
@@ -174,30 +173,28 @@ var BABYLON;
                     this._soundPanner.maxDistance = Number.MAX_VALUE;
                     this._soundPanner.refDistance = 1;
                     this._soundPanner.rolloffFactor = 1;
-                    this._soundPanner.panningModel = this._panningModel;
+                    this._soundPanner.panningModel = "HRTF";
                 }
                 else {
                     this._soundPanner.distanceModel = this.distanceModel;
                     this._soundPanner.maxDistance = this.maxDistance;
                     this._soundPanner.refDistance = this.refDistance;
                     this._soundPanner.rolloffFactor = this.rolloffFactor;
-                    this._soundPanner.panningModel = this._panningModel;
+                    this._soundPanner.panningModel = this.panningModel;
                 }
                 this._soundPanner.connect(this._ouputAudioNode);
                 this._inputAudioNode = this._soundPanner;
             }
         };
         Sound.prototype.switchPanningModelToHRTF = function () {
-            this._panningModel = "HRTF";
-            this._switchPanningModel();
+            this._switchPanningModel("HRTF");
         };
         Sound.prototype.switchPanningModelToEqualPower = function () {
-            this._panningModel = "equalpower";
-            this._switchPanningModel();
+            this._switchPanningModel("equalpower");
         };
-        Sound.prototype._switchPanningModel = function () {
+        Sound.prototype._switchPanningModel = function (newModel) {
             if (BABYLON.Engine.audioEngine.canUseWebAudio && this.spatialSound) {
-                this._soundPanner.panningModel = this._panningModel;
+                this._soundPanner.panningModel = newModel;
             }
         };
         Sound.prototype.connectToSoundTrackAudioNode = function (soundTrackAudioNode) {

+ 9 - 12
Babylon/Audio/babylon.sound.ts

@@ -10,7 +10,7 @@
         public rolloffFactor: number = 1;
         public maxDistance: number = 100;
         public distanceModel: string = "linear";
-        private _panningModel: string = "equalpower";
+        public panningModel: string = "HRTF";
         public onended: () => any;
         private _playbackRate: number = 1;
         private _startTime: number = 0;
@@ -73,6 +73,7 @@
                 this.rolloffFactor = options.rolloffFactor || 1;
                 this.refDistance = options.refDistance || 1;
                 this.distanceModel = options.distanceModel || "linear";
+                this.panningModel = options.panningModel || "HRTF";
                 this._playbackRate = options.playbackRate || 1;
             }
 
@@ -169,15 +170,13 @@
                 this.rolloffFactor = options.rolloffFactor || this.rolloffFactor;
                 this.refDistance = options.refDistance || this.refDistance;
                 this.distanceModel = options.distanceModel || this.distanceModel;
+                this.panningModel = options.panningModel || this.panningModel;
                 this._playbackRate = options.playbackRate || this._playbackRate;
             }
         }
 
         private _createSpatialParameters() {
             if (Engine.audioEngine.canUseWebAudio) {
-                if (this._scene.headphone) {
-                    this._panningModel = "HRTF";
-                }
                 this._soundPanner = Engine.audioEngine.audioContext.createPanner();
 
                 if (this.useCustomAttenuation) {
@@ -186,14 +185,14 @@
                     this._soundPanner.maxDistance = Number.MAX_VALUE;
                     this._soundPanner.refDistance = 1;
                     this._soundPanner.rolloffFactor = 1;
-                    this._soundPanner.panningModel = this._panningModel;
+                    this._soundPanner.panningModel = "HRTF";
                 }
                 else {
                     this._soundPanner.distanceModel = this.distanceModel;
                     this._soundPanner.maxDistance = this.maxDistance;
                     this._soundPanner.refDistance = this.refDistance;
                     this._soundPanner.rolloffFactor = this.rolloffFactor;
-                    this._soundPanner.panningModel = this._panningModel;
+                    this._soundPanner.panningModel = this.panningModel;
                 }
                 this._soundPanner.connect(this._ouputAudioNode);
                 this._inputAudioNode = this._soundPanner;
@@ -201,18 +200,16 @@
         }
 
         public switchPanningModelToHRTF() {
-            this._panningModel = "HRTF";
-            this._switchPanningModel();    
+            this._switchPanningModel("HRTF");    
         }
 
         public switchPanningModelToEqualPower() {
-            this._panningModel = "equalpower";
-            this._switchPanningModel();
+            this._switchPanningModel("equalpower");
         }
 
-        private _switchPanningModel() {
+        private _switchPanningModel(newModel: string) {
             if (Engine.audioEngine.canUseWebAudio && this.spatialSound) {
-                this._soundPanner.panningModel = this._panningModel;
+                this._soundPanner.panningModel = newModel;
             }
         }
 

+ 4 - 4
Babylon/Debug/babylon.debugLayer.js

@@ -582,14 +582,14 @@ var BABYLON;
                 if (BABYLON.Engine.audioEngine.canUseWebAudio) {
                     this._optionsSubsetDiv.appendChild(document.createElement("br"));
                     this._generateTexBox(this._optionsSubsetDiv, "<b>Audio:</b>", this.accentColor);
-                    this._generateRadio(this._optionsSubsetDiv, "Headphones", "panningModel", this._scene.headphone, function (element) {
+                    this._generateRadio(this._optionsSubsetDiv, "Headphones", "panningModel", true, function (element) {
                         if (element.checked) {
-                            _this._scene.headphone = true;
+                            _this._scene.switchAudioModeForHeadphones();
                         }
                     });
-                    this._generateRadio(this._optionsSubsetDiv, "Normal Speakers", "panningModel", !this._scene.headphone, function (element) {
+                    this._generateRadio(this._optionsSubsetDiv, "Normal Speakers", "panningModel", false, function (element) {
                         if (element.checked) {
-                            _this._scene.headphone = false;
+                            _this._scene.switchAudioModeForNormalSpeakers();
                         }
                     });
                     this._generateCheckBox(this._optionsSubsetDiv, "Disable audio", !this._scene.audioEnabled, function (element) {

+ 4 - 4
Babylon/Debug/babylon.debugLayer.ts

@@ -674,14 +674,14 @@
                 if (Engine.audioEngine.canUseWebAudio) {
                     this._optionsSubsetDiv.appendChild(document.createElement("br"));
                     this._generateTexBox(this._optionsSubsetDiv, "<b>Audio:</b>", this.accentColor);
-                    this._generateRadio(this._optionsSubsetDiv, "Headphones", "panningModel", this._scene.headphone, (element) => {
+                    this._generateRadio(this._optionsSubsetDiv, "Headphones", "panningModel", true, (element) => {
                         if (element.checked) {
-                            this._scene.headphone = true;
+                            this._scene.switchAudioModeForHeadphones();
                         }
                     });
-                    this._generateRadio(this._optionsSubsetDiv, "Normal Speakers", "panningModel", !this._scene.headphone, (element) => {
+                    this._generateRadio(this._optionsSubsetDiv, "Normal Speakers", "panningModel", false, (element) => {
                         if (element.checked) {
-                            this._scene.headphone = false;
+                            this._scene.switchAudioModeForNormalSpeakers();
                         }
                     });
                     this._generateCheckBox(this._optionsSubsetDiv, "Disable audio", !this._scene.audioEnabled, (element) => {

+ 1 - 0
Babylon/Loading/Plugins/babylon.babylonFileLoader.js

@@ -788,6 +788,7 @@ var BABYLON;
                 rolloffFactor: parsedSound.rolloffFactor,
                 refDistance: parsedSound.refDistance,
                 distanceModel: parsedSound.distanceModel,
+                panningModel: parsedSound.panningModel,
                 playbackRate: parsedSound.playbackRate
             };
             var newSound = new BABYLON.Sound(soundName, soundUrl, scene, function () {

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

@@ -979,6 +979,7 @@
             rolloffFactor: parsedSound.rolloffFactor,
             refDistance: parsedSound.refDistance,
             distanceModel: parsedSound.distanceModel,
+            panningModel: parsedSound.panningModel,
             playbackRate: parsedSound.playbackRate
         };
 

+ 6 - 47
Babylon/Math/babylon.math.js

@@ -2340,7 +2340,7 @@ var BABYLON;
     BABYLON.PathCursor = PathCursor;
     var Path2 = (function () {
         function Path2(x, y) {
-            this._points = new Array();
+            this._points = [];
             this._length = 0;
             this.closed = false;
             this._points.push(new Vector2(x, y));
@@ -2426,11 +2426,11 @@ var BABYLON;
     var Path3D = (function () {
         function Path3D(path) {
             this.path = path;
-            this._curve = new Array();
-            this._distances = new Array();
-            this._tangents = new Array();
-            this._normals = new Array();
-            this._binormals = new Array();
+            this._curve = [];
+            this._distances = [];
+            this._tangents = [];
+            this._normals = [];
+            this._binormals = [];
             this._curve = path.slice(); // copy array         
             var l = this._curve.length;
             // first and last tangents
@@ -2507,51 +2507,10 @@ var BABYLON;
         return Path3D;
     })();
     BABYLON.Path3D = Path3D;
-<<<<<<< HEAD
     // SIMD
     if (window.SIMD !== undefined) {
         // Replace functions
         Matrix.prototype.multiplyToArray = Matrix.prototype.multiplyToArraySIMD;
     }
-=======
-    var Curve3 = (function () {
-        function Curve3(points) {
-            this._points = points;
-        }
-        // QuadraticBezier(origin_V3, control_V3, destination_V3 )
-        Curve3.QuadraticBezier = function (v0, v1, v2, nbPoints) {
-            nbPoints = nbPoints > 2 ? nbPoints : 3;
-            var bez = new Array();
-            var step = 1 / nbPoints;
-            var equation = function (t, val0, val1, val2) {
-                var res = (1 - t) * (1 - t) * val0 + 2 * t * (1 - t) * val1 + t * t * val2;
-                return res;
-            };
-            for (var i = 0; i <= 1; i += step) {
-                bez.push(new Vector3(equation(i, v0.x, v1.x, v2.x), equation(i, v0.y, v1.y, v2.y), equation(i, v0.z, v1.z, v2.z)));
-            }
-            return new Curve3(bez);
-        };
-        // CubicBezier(origin_V3, control1_V3, control2_V3, destination_V3)
-        Curve3.CubicBezier = function (v0, v1, v2, v3, nbPoints) {
-            nbPoints = nbPoints > 3 ? nbPoints : 4;
-            var bez = new Array();
-            var step = 1 / nbPoints;
-            var equation = function (t, val0, val1, val2, val3) {
-                var res = (1 - t) * (1 - t) * (1 - t) * val0 + 3 * t * (1 - t) * (1 - t) * val1 + 3 * t * t * (1 - t) * val2 + t * t * t * val3;
-                return res;
-            };
-            for (var i = 0; i <= 1; i += step) {
-                bez.push(new Vector3(equation(i, v0.x, v1.x, v2.x, v3.x), equation(i, v0.y, v1.y, v2.y, v3.y), equation(i, v0.z, v1.z, v2.z, v3.z)));
-            }
-            return new Curve3(bez);
-        };
-        Curve3.prototype.getPoints = function () {
-            return this._points;
-        };
-        return Curve3;
-    })();
-    BABYLON.Curve3 = Curve3;
->>>>>>> a2f7b504bf990ef8502cd0b9faa3102e21a0d510
 })(BABYLON || (BABYLON = {}));
 //# sourceMappingURL=babylon.math.js.map

+ 28 - 75
Babylon/Math/babylon.math.ts

@@ -2958,10 +2958,9 @@
     }
 
     export class Path2 {
-        private _points = new Array<Vector2>();
-        private _length = 0;
-
-        public closed = false;
+        private _points: Vector2[] = [];
+        private _length: number = 0;
+        closed: boolean = false;
 
         constructor(x: number, y: number) {
             this._points.push(new Vector2(x, y));
@@ -3063,25 +3062,25 @@
     }
 
     export class Path3D {
-        private _curve = new Array<Vector3>();
-        private _distances = new Array<number>();
-        private _tangents = new Array<Vector3>();
-        private _normals = new Array<Vector3>();
-        private _binormals = new Array<Vector3>();
+        private _curve: Vector3[] = [];
+        private _distances: number[] = [];
+        private _tangents: Vector3[] = [];
+        private _normals: Vector3[] = [];
+        private _binormals: Vector3[] = [];
 
         constructor(public path: Vector3[]) {
             this._curve = path.slice();   // copy array         
-            var l = this._curve.length;
+            var l: number = this._curve.length;
 
             // first and last tangents
             this._tangents[0] = this._curve[1].subtract(this._curve[0]);
             this._tangents[0].normalize();
-            this._tangents[l - 1] = this._curve[l - 1].subtract(this._curve[l - 2]);
+            this._tangents[l-1] = this._curve[l-1].subtract(this._curve[l-2]);
             this._tangents[l - 1].normalize();
-
+            
             // normals and binormals at first point : arbitrary vector with _normalVector()
-            var tg0 = this._tangents[0];
-            var pp0 = this._normalVector(this._curve[0], tg0);
+            var tg0: Vector3 = this._tangents[0];
+            var pp0: Vector3 = this._normalVector(this._curve[0], tg0);
             this._normals[0] = pp0;
             this._normals[0].normalize();
             this._binormals[0] = Vector3.Cross(tg0, this._normals[0]);
@@ -3095,21 +3094,21 @@
             var prevNorm: Vector3;    // previous normal
             var prevBinor: Vector3;   // previous binormal
 
-            for (var i = 1; i < l; i++) {
+            for(var i: number = 1; i < l; i++) {
                 // tangents
-                prev = this._curve[i].subtract(this._curve[i - 1]);
-                if (i < l - 1) {
-                    cur = this._curve[i + 1].subtract(this._curve[i]);
+                prev = this._curve[i].subtract(this._curve[i-1]);
+                if (i < l-1) {
+                    cur = this._curve[i+1].subtract(this._curve[i]);
                     this._tangents[i] = prev.add(cur);
-                    this._tangents[i].normalize();
+                    this._tangents[i].normalize();               
                 }
-                this._distances[i] = this._distances[i - 1] + prev.length();
-
+                this._distances[i] = this._distances[i - 1] + prev.length();   
+                      
                 // normals and binormals
                 // http://www.cs.cmu.edu/afs/andrew/scs/cs/15-462/web/old/asst2camera.html
                 curTang = this._tangents[i];
-                prevNorm = this._normals[i - 1];
-                prevBinor = this._binormals[i - 1];
+                prevNorm = this._normals[i-1];
+                prevBinor = this._binormals[i-1];
                 this._normals[i] = Vector3.Cross(prevBinor, curTang);
                 this._normals[i].normalize();
                 this._binormals[i] = Vector3.Cross(curTang, this._normals[i]);
@@ -3140,72 +3139,26 @@
         // private function normalVector(v0, vt) :
         // returns an arbitrary point in the plane defined by the point v0 and the vector vt orthogonal to this plane
         private _normalVector(v0: Vector3, vt: Vector3): Vector3 {
-            var point: Vector3;
+            var point: Vector3; 
 
             if (vt.x !== 1) {     // search for a point in the plane
-                point = new Vector3(1, 0, 0);
+                point = new Vector3(1, 0, 0);   
             }
             else if (vt.y !== 1) {
-                point = new Vector3(0, 1, 0);
+                point = new Vector3(0, 1, 0);  
             }
             else if (vt.z !== 1) {
-                point = new Vector3(0, 0, 1);
+                point = new Vector3(0, 0, 1);  
             }
             var normal0: Vector3 = Vector3.Cross(vt, point);
             normal0.normalize();
-            return normal0;
-        }
-    }
-
-    export class Curve3 {
-        private _points: Vector3[];
-
-        // QuadraticBezier(origin_V3, control_V3, destination_V3 )
-        public static QuadraticBezier(v0: Vector3, v1: Vector3, v2: Vector3, nbPoints: number): Curve3 {
-            nbPoints = nbPoints > 2 ? nbPoints : 3;
-            var bez = new Array<Vector3>();
-            var step = 1 / nbPoints;
-            var equation = (t: number, val0: number, val1: number, val2: number) => {
-                var res = (1 - t) * (1 - t) * val0 + 2 * t * (1 - t) * val1 + t * t * val2;
-                return res;
-            }
-            for (var i = 0; i <= 1; i += step) {
-                bez.push(new Vector3(equation(i, v0.x, v1.x, v2.x), equation(i, v0.y, v1.y, v2.y), equation(i, v0.z, v1.z, v2.z)));
-            }
-            return new Curve3(bez);
-        }
-
-        // CubicBezier(origin_V3, control1_V3, control2_V3, destination_V3)
-        public static CubicBezier(v0: Vector3, v1: Vector3, v2: Vector3, v3: Vector3, nbPoints: number): Curve3 {
-            nbPoints = nbPoints > 3 ? nbPoints : 4;
-            var bez = new Array<Vector3>();
-            var step = 1 / nbPoints;
-            var equation = (t: number, val0: number, val1: number, val2: number, val3: number) => {
-                var res = (1 - t) * (1 - t) * (1 - t) * val0 + 3 * t * (1 - t) * (1 - t) * val1 + 3 * t * t * (1 - t) * val2 + t * t * t * val3;
-                return res;
-            }
-            for (var i = 0; i <= 1; i += step) {
-                bez.push(new Vector3(equation(i, v0.x, v1.x, v2.x, v3.x), equation(i, v0.y, v1.y, v2.y, v3.y), equation(i, v0.z, v1.z, v2.z, v3.z)));
-            }
-            return new Curve3(bez);
-        }
-
-        constructor(points: Vector3[]) {
-            this._points = points;
-        }
-
-        public getPoints() {
-            return this._points;
+            return normal0;        
         }
     }
-<<<<<<< HEAD
 
     // SIMD
     if (window.SIMD !== undefined) {
         // Replace functions
         Matrix.prototype.multiplyToArray = <any>Matrix.prototype.multiplyToArraySIMD;
     }
-}
-=======
-}
->>>>>>> a2f7b504bf990ef8502cd0b9faa3102e21a0d510
+}

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

@@ -306,8 +306,7 @@ var BABYLON;
             var updatable = false;
             var stopChecking = false;
             for (var kind in this._vertexBuffers) {
-                // using slice() to make a copy of the array and not just reference it
-                vertexData.set(this.getVerticesData(kind).slice(0), kind);
+                vertexData.set(this.getVerticesData(kind), kind);
                 if (!stopChecking) {
                     updatable = this.getVertexBuffer(kind).isUpdatable();
                     stopChecking = !updatable;

+ 2 - 4
Babylon/Mesh/babylon.geometry.ts

@@ -394,8 +394,7 @@
             var stopChecking = false;
 
             for (var kind in this._vertexBuffers) {
-                // using slice() to make a copy of the array and not just reference it
-                vertexData.set(this.getVerticesData(kind).slice(0), kind);
+                vertexData.set(this.getVerticesData(kind), kind);
 
                 if (!stopChecking) {
                     updatable = this.getVertexBuffer(kind).isUpdatable();
@@ -730,5 +729,4 @@
             }
         }
     }
-} 
-
+} 

+ 2 - 13
Babylon/Mesh/babylon.mesh.js

@@ -959,7 +959,6 @@ var BABYLON;
             var extruded = Mesh._ExtrudeShapeGeneric(name, shape, path, scale, rotation, null, null, false, false, false, scene, updatable, sideOrientation);
             return extruded;
         };
-<<<<<<< HEAD
         Mesh.ExtrudeShapeCustom = function (name, shape, path, scaleFunction, rotateFunction, ribbonCloseArray, ribbonClosePath, scene, updatable, sideOrientation) {
             if (sideOrientation === void 0) { sideOrientation = Mesh.DEFAULTSIDE; }
             ribbonCloseArray = ribbonCloseArray || false;
@@ -996,16 +995,6 @@ var BABYLON;
                 shapePaths.push(shapePath);
                 angle += angleStep;
             }
-=======
-        Mesh.ExtrudeShapeCustom = function (name, shape, path, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, scene, updatable, sideOrientation) {
-            if (sideOrientation === void 0) { sideOrientation = Mesh.DEFAULTSIDE; }
-            var extrudedCustom = Mesh._ExtrudeShapeGeneric(name, shape, path, null, null, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, true, scene, updatable, sideOrientation);
-            return extrudedCustom;
-        };
-        Mesh._ExtrudeShapeGeneric = function (name, shape, curve, scale, rotation, scaleFunction, rotationFunction, rbCA, rbCP, custom, scene, updtbl, side) {
-            var path3D = new BABYLON.Path3D(curve);
-            var shapePaths = [];
->>>>>>> a2f7b504bf990ef8502cd0b9faa3102e21a0d510
             var extrudedGeneric = Mesh.CreateRibbon(name, shapePaths, rbCA, rbCP, 0, scene, updtbl, side);
             return extrudedGeneric;
         };
@@ -1070,7 +1059,7 @@ var BABYLON;
             var step = pi2 / tesselation;
             var returnRadius = function (i, distance) { return radius; };
             var radiusFunctionFinal = radiusFunction || returnRadius;
-            var circlePaths = new Array();
+            var circlePaths = [];
             var circlePath;
             var rad;
             var normal;
@@ -1078,7 +1067,7 @@ var BABYLON;
             var rotationMatrix;
             for (var i = 0; i < path.length; i++) {
                 rad = radiusFunctionFinal(i, distances[i]); // current radius
-                circlePath = Array(); // current circle array
+                circlePath = []; // current circle array
                 normal = normals[i]; // current normal  
                 for (var ang = 0; ang < pi2; ang += step) {
                     rotationMatrix = BABYLON.Matrix.RotationAxis(tangents[i], ang);

+ 12 - 27
Babylon/Mesh/babylon.mesh.ts

@@ -1175,7 +1175,6 @@
             return extruded;
         }
 
-<<<<<<< HEAD
         public static ExtrudeShapeCustom(name: string, shape: Vector3[], path: Vector3[], scaleFunction, rotateFunction, ribbonCloseArray: boolean, ribbonClosePath: boolean, scene: Scene, updatable?: boolean, sideOrientation: number = Mesh.DEFAULTSIDE): Mesh {
             ribbonCloseArray = ribbonCloseArray || false;
             ribbonClosePath = ribbonClosePath || false;
@@ -1212,20 +1211,6 @@
 
             var extrudedGeneric = Mesh.CreateRibbon(name, shapePaths, rbCA, rbCP, 0, scene, updtbl, side);
             return extrudedGeneric;
-=======
-        public static ExtrudeShapeCustom(name: string, shape: Vector3[], path: Vector3[], scaleFunction, rotationFunction, ribbonCloseArray: boolean, ribbonClosePath: boolean, scene: Scene, updatable?: boolean, sideOrientation: number = Mesh.DEFAULTSIDE): Mesh {
-            var extrudedCustom = Mesh._ExtrudeShapeGeneric(name, shape, path, null, null, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, true, scene, updatable, sideOrientation);
-            return extrudedCustom;
-        }
-
-        private static _ExtrudeShapeGeneric(name: string, shape: Vector3[], curve: Vector3[], scale: number, rotation: number, scaleFunction, rotationFunction, rbCA: boolean, rbCP: boolean, custom: boolean, scene: Scene, updtbl: boolean, side: number): Mesh {
-            var path3D = new Path3D(curve);
-
-            var shapePaths: Vector3[][] = [];
-            var extrudedGeneric = Mesh.CreateRibbon(name, shapePaths, rbCA, rbCP, 0, scene, updtbl, side);
-            return extrudedGeneric;
-
->>>>>>> a2f7b504bf990ef8502cd0b9faa3102e21a0d510
         }
 
         // Plane & ground
@@ -1300,26 +1285,26 @@
         }
 
         public static CreateTube(name: string, path: Vector3[], radius: number, tesselation: number, radiusFunction: { (i: number, distance: number): number; }, scene: Scene, updatable?: boolean, sideOrientation: number = Mesh.DEFAULTSIDE): Mesh {
-            var path3D = new Path3D(path);
-            var tangents = path3D.getTangents();
-            var normals = path3D.getNormals();
-            var distances = path3D.getDistances();
-            var pi2 = Math.PI * 2;
-            var step = pi2 / tesselation;
+            var path3D: Path3D = new Path3D(path);
+            var tangents: Vector3[] = path3D.getTangents();
+            var normals: Vector3[] = path3D.getNormals();
+            var distances: number[] = path3D.getDistances();
+            var pi2: number = Math.PI * 2;
+            var step: number = pi2 / tesselation;
             var returnRadius: { (i: number, distance: number): number; } = (i, distance) => radius;
             var radiusFunctionFinal: { (i: number, distance: number): number; } = radiusFunction || returnRadius;
 
-            var circlePaths = new Array<Array<Vector3>>();
+            var circlePaths: Vector3[][] = [];
             var circlePath: Vector3[];
             var rad: number;
             var normal: Vector3;
             var rotated: Vector3;
             var rotationMatrix: Matrix;
-            for (var i = 0; i < path.length; i++) {
-                rad = radiusFunctionFinal(i, distances[i]); // current radius
-                circlePath = Array<Vector3>();              // current circle array
+            for (var i: number = 0; i < path.length; i++) {
+                rad = radiusFunctionFinal(i, distances[i]);      // current radius
+                circlePath = [];                            // current circle array
                 normal = normals[i];                        // current normal  
-                for (var ang = 0; ang < pi2; ang += step) {
+                for (var ang: number = 0; ang < pi2; ang += step) {
                     rotationMatrix = Matrix.RotationAxis(tangents[i], ang);
                     rotated = Vector3.TransformCoordinates(normal, rotationMatrix).scaleInPlace(rad).add(path[i]);
                     circlePath.push(rotated);
@@ -1405,4 +1390,4 @@
             return newMesh;
         }
     }
-} 
+} 

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

@@ -73,7 +73,7 @@ var BABYLON;
             if (material) {
                 if (material.needAlphaTesting() || mesh === this.mesh)
                     defines.push("#define ALPHATEST");
-                if (material.opacityTexture !== undefined && mesh === this.mesh)
+                if (material.opacityTexture !== undefined)
                     defines.push("#define OPACITY");
                 if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
                     attribs.push(BABYLON.VertexBuffer.UVKind);
@@ -103,7 +103,7 @@ var BABYLON;
             var join = defines.join("\n");
             if (this._cachedDefines !== join) {
                 this._cachedDefines = join;
-                this._volumetricLightScatteringPass = mesh.getScene().getEngine().createEffect({ vertexElement: "depth", fragmentElement: "volumetricLightScatteringPass" }, attribs, ["world", "mBones", "viewProjection", "diffuseMatrix"], ["diffuseSampler", "opacitySampler"], join);
+                this._volumetricLightScatteringPass = mesh.getScene().getEngine().createEffect({ vertexElement: "depth", fragmentElement: "volumetricLightScatteringPass" }, attribs, ["world", "mBones", "viewProjection", "diffuseMatrix", "far"], ["diffuseSampler", "opacitySampler"], join);
             }
             return this._volumetricLightScatteringPass.isReady();
         };
@@ -180,9 +180,8 @@ var BABYLON;
                     if (material && (mesh === _this.mesh || material.needAlphaTesting() || material.opacityTexture !== undefined)) {
                         var alphaTexture = material.getAlphaTestTexture();
                         _this._volumetricLightScatteringPass.setTexture("diffuseSampler", alphaTexture);
-                        if (alphaTexture) {
+                        if (_this.mesh.material && alphaTexture)
                             _this._volumetricLightScatteringPass.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
-                        }
                         if (material.opacityTexture !== undefined)
                             _this._volumetricLightScatteringPass.setTexture("opacitySampler", material.opacityTexture);
                     }

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

@@ -87,7 +87,7 @@
                 if (material.needAlphaTesting() || mesh === this.mesh)
                     defines.push("#define ALPHATEST");
 
-                if (material.opacityTexture !== undefined && mesh === this.mesh)
+                if (material.opacityTexture !== undefined)
                     defines.push("#define OPACITY");
 
                 if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
@@ -124,7 +124,7 @@
                 this._volumetricLightScatteringPass = mesh.getScene().getEngine().createEffect(
                     { vertexElement: "depth", fragmentElement: "volumetricLightScatteringPass" },
                     attribs,
-                    ["world", "mBones", "viewProjection", "diffuseMatrix"],
+                    ["world", "mBones", "viewProjection", "diffuseMatrix", "far"],
                     ["diffuseSampler", "opacitySampler"], join);
             }
 
@@ -220,10 +220,8 @@
                     if (material && (mesh === this.mesh || material.needAlphaTesting() || material.opacityTexture !== undefined)) {
                         var alphaTexture = material.getAlphaTestTexture();
                         this._volumetricLightScatteringPass.setTexture("diffuseSampler", alphaTexture);
-
-                        if (alphaTexture) {
+                        if (this.mesh.material && alphaTexture)
                             this._volumetricLightScatteringPass.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
-                        }
 
                         if (material.opacityTexture !== undefined)
                             this._volumetricLightScatteringPass.setTexture("opacitySampler", material.opacityTexture);

+ 2 - 2
Babylon/Shaders/depth.vertex.fx

@@ -24,7 +24,7 @@ uniform mat4 viewProjection;
 uniform mat4 mBones[BonesPerMesh];
 #endif
 
-#if defined(ALPHATEST) || defined(BASIC_RENDER)
+#ifdef ALPHATEST
 varying vec2 vUV;
 uniform mat4 diffuseMatrix;
 #ifdef UV1
@@ -54,7 +54,7 @@ void main(void)
 	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
 #endif
 
-#if defined(ALPHATEST) || defined(BASIC_RENDER)
+#ifdef ALPHATEST
 #ifdef UV1
 	vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
 #endif

+ 5 - 5
Babylon/Shaders/volumetricLightScatteringPass.fragment.fx

@@ -26,11 +26,11 @@ void main(void)
 #endif
 
 #ifdef BASIC_RENDER
-	#ifdef OPACITY
-		gl_FragColor = diffuseColor * texture2D(opacitySampler, vUV);
-	#else
-		gl_FragColor = diffuseColor;
-	#endif
+#ifdef OPACITY
+	gl_FragColor = diffuseColor * texture2D(opacitySampler, vUV);
+#else
+	gl_FragColor = diffuseColor;
+#endif
 #else
 	gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
 #endif

+ 6 - 7
Babylon/Sprites/babylon.spriteManager.js

@@ -1,8 +1,7 @@
 var BABYLON;
 (function (BABYLON) {
     var SpriteManager = (function () {
-        function SpriteManager(name, imgUrl, capacity, cellSize, scene, epsilon, samplingMode) {
-            if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
+        function SpriteManager(name, imgUrl, capacity, cellSize, scene, epsilon) {
             this.name = name;
             this.cellSize = cellSize;
             this.sprites = new Array();
@@ -11,7 +10,7 @@ var BABYLON;
             this._vertexDeclaration = [3, 4, 4, 4];
             this._vertexStrideSize = 15 * 4; // 15 floats per sprite (x, y, z, angle, size, offsetX, offsetY, invertU, invertV, cellIndexX, cellIndexY, color)
             this._capacity = capacity;
-            this._spriteTexture = new BABYLON.Texture(imgUrl, scene, true, false, samplingMode);
+            this._spriteTexture = new BABYLON.Texture(imgUrl, scene, true, false);
             this._spriteTexture.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._spriteTexture.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._epsilon = epsilon === undefined ? 0.01 : epsilon;
@@ -40,13 +39,13 @@ var BABYLON;
         }
         SpriteManager.prototype._appendSpriteVertex = function (index, sprite, offsetX, offsetY, rowSize) {
             var arrayOffset = index * 15;
-            if (offsetX === 0)
+            if (offsetX == 0)
                 offsetX = this._epsilon;
-            else if (offsetX === 1)
+            else if (offsetX == 1)
                 offsetX = 1 - this._epsilon;
-            if (offsetY === 0)
+            if (offsetY == 0)
                 offsetY = this._epsilon;
-            else if (offsetY === 1)
+            else if (offsetY == 1)
                 offsetY = 1 - this._epsilon;
             this._vertices[arrayOffset] = sprite.position.x;
             this._vertices[arrayOffset + 1] = sprite.position.y;

+ 11 - 12
Babylon/Sprites/babylon.spriteManager.ts

@@ -13,18 +13,17 @@
 
         private _vertexDeclaration = [3, 4, 4, 4];
         private _vertexStrideSize = 15 * 4; // 15 floats per sprite (x, y, z, angle, size, offsetX, offsetY, invertU, invertV, cellIndexX, cellIndexY, color)
-        private _vertexBuffer: WebGLBuffer;
+        private _vertexBuffer: WebGLBuffer
         private _indexBuffer: WebGLBuffer;
         private _vertices: Float32Array;
         private _effectBase: Effect;
         private _effectFog: Effect;
 
-        constructor(public name: string, imgUrl: string, capacity: number, public cellSize: number, scene: Scene, epsilon?: number, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) {
+        constructor(public name: string, imgUrl: string, capacity: number, public cellSize: number, scene: Scene, epsilon?: number) {
             this._capacity = capacity;
-            this._spriteTexture = new Texture(imgUrl, scene, true, false, samplingMode);
-            this._spriteTexture.wrapU = Texture.CLAMP_ADDRESSMODE;
-            this._spriteTexture.wrapV = Texture.CLAMP_ADDRESSMODE;
-
+            this._spriteTexture = new BABYLON.Texture(imgUrl, scene, true, false);
+            this._spriteTexture.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
+            this._spriteTexture.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._epsilon = epsilon === undefined ? 0.01 : epsilon;
 
             this._scene = scene;
@@ -65,14 +64,14 @@
         private _appendSpriteVertex(index: number, sprite: Sprite, offsetX: number, offsetY: number, rowSize: number): void {
             var arrayOffset = index * 15;
 
-            if (offsetX === 0)
+            if (offsetX == 0)
                 offsetX = this._epsilon;
-            else if (offsetX === 1)
+            else if (offsetX == 1)
                 offsetX = 1 - this._epsilon;
 
-            if (offsetY === 0)
+            if (offsetY == 0)
                 offsetY = this._epsilon;
-            else if (offsetY === 1)
+            else if (offsetY == 1)
                 offsetY = 1 - this._epsilon;
 
             this._vertices[arrayOffset] = sprite.position.x;
@@ -155,9 +154,9 @@
             engine.setColorWrite(true);
             effect.setBool("alphaTest", false);
 
-            engine.setAlphaMode(Engine.ALPHA_COMBINE);
+            engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE);
             engine.draw(true, 0, max * 6);
-            engine.setAlphaMode(Engine.ALPHA_DISABLE);
+            engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
         }
 
         public dispose(): void {

+ 3 - 7
Babylon/babylon.engine.js

@@ -1636,13 +1636,9 @@ var BABYLON;
         };
         Engine.prototype._setAnisotropicLevel = function (key, texture) {
             var anisotropicFilterExtension = this._caps.textureAnisotropicFilterExtension;
-            var value = texture.anisotropicFilteringLevel;
-            if (texture.getInternalTexture().samplingMode === BABYLON.Texture.NEAREST_SAMPLINGMODE) {
-                value = 1;
-            }
-            if (anisotropicFilterExtension && texture._cachedAnisotropicFilteringLevel !== value) {
-                this._gl.texParameterf(key, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._caps.maxAnisotropy));
-                texture._cachedAnisotropicFilteringLevel = value;
+            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;
             }
         };
         Engine.prototype.readPixels = function (x, y, width, height) {

+ 3 - 8
Babylon/babylon.engine.ts

@@ -1976,15 +1976,10 @@
 
         public _setAnisotropicLevel(key: number, texture: BaseTexture) {
             var anisotropicFilterExtension = this._caps.textureAnisotropicFilterExtension;
-            var value = texture.anisotropicFilteringLevel;
 
-            if (texture.getInternalTexture().samplingMode === Texture.NEAREST_SAMPLINGMODE) {
-                value = 1;
-            }
-
-            if (anisotropicFilterExtension && texture._cachedAnisotropicFilteringLevel !== value) {
-                this._gl.texParameterf(key, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._caps.maxAnisotropy));
-                texture._cachedAnisotropicFilteringLevel = value;
+            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;
             }
         }
 

+ 13 - 30
Babylon/babylon.scene.js

@@ -102,7 +102,6 @@ var BABYLON;
             this._proceduralTextures = new Array();
             this.soundTracks = new Array();
             this._audioEnabled = true;
-            this._headphone = false;
             this._totalVertices = 0;
             this._activeVertices = 0;
             this._activeParticles = 0;
@@ -1196,7 +1195,6 @@ var BABYLON;
             }
         };
         Object.defineProperty(Scene.prototype, "audioEnabled", {
-            // Audio
             get: function () {
                 return this._audioEnabled;
             },
@@ -1236,34 +1234,6 @@ var BABYLON;
                 }
             }
         };
-        Object.defineProperty(Scene.prototype, "headphone", {
-            get: function () {
-                return this._headphone;
-            },
-            set: function (value) {
-                this._headphone = value;
-                if (this._headphone) {
-                    this._switchAudioModeForHeadphones();
-                }
-                else {
-                    this._switchAudioModeForNormalSpeakers();
-                }
-            },
-            enumerable: true,
-            configurable: true
-        });
-        Scene.prototype._switchAudioModeForHeadphones = function () {
-            this.mainSoundTrack.switchPanningModelToHRTF();
-            for (var i = 0; i < this.soundTracks.length; i++) {
-                this.soundTracks[i].switchPanningModelToHRTF();
-            }
-        };
-        Scene.prototype._switchAudioModeForNormalSpeakers = function () {
-            this.mainSoundTrack.switchPanningModelToEqualPower();
-            for (var i = 0; i < this.soundTracks.length; i++) {
-                this.soundTracks[i].switchPanningModelToEqualPower();
-            }
-        };
         Scene.prototype.enableDepthRenderer = function () {
             if (this._depthRenderer) {
                 return this._depthRenderer;
@@ -1595,6 +1565,19 @@ var BABYLON;
         Scene.prototype.getMaterialByTags = function (tagsQuery, forEach) {
             return this._getByTags(this.materials, tagsQuery, forEach).concat(this._getByTags(this.multiMaterials, tagsQuery, forEach));
         };
+        // Audio
+        Scene.prototype.switchAudioModeForHeadphones = function () {
+            this.mainSoundTrack.switchPanningModelToHRTF();
+            for (var i = 0; i < this.soundTracks.length; i++) {
+                this.soundTracks[i].switchPanningModelToHRTF();
+            }
+        };
+        Scene.prototype.switchAudioModeForNormalSpeakers = function () {
+            this.mainSoundTrack.switchPanningModelToEqualPower();
+            for (var i = 0; i < this.soundTracks.length; i++) {
+                this.soundTracks[i].switchPanningModelToEqualPower();
+            }
+        };
         // Statics
         Scene._FOGMODE_NONE = 0;
         Scene._FOGMODE_EXP = 1;

+ 17 - 32
Babylon/babylon.scene.ts

@@ -191,7 +191,6 @@
         public mainSoundTrack: SoundTrack;
         public soundTracks = new Array<SoundTrack>();
         private _audioEnabled = true;
-        private _headphone = false;
 
         //Simplification Queue
         public simplificationQueue: SimplificationQueue;
@@ -1529,7 +1528,6 @@
             }
         }
 
-        // Audio
         public get audioEnabled(): boolean {
             return this._audioEnabled;
         }
@@ -1570,36 +1568,6 @@
             }
         }
 
-        public get headphone(): boolean {
-            return this._headphone;
-        }
-
-        public set headphone(value: boolean) {
-            this._headphone = value;
-            if (this._headphone) {
-                this._switchAudioModeForHeadphones();
-            }
-            else {
-                this._switchAudioModeForNormalSpeakers();
-            }
-        }
-
-        private _switchAudioModeForHeadphones() {
-            this.mainSoundTrack.switchPanningModelToHRTF();
-
-            for (var i = 0; i < this.soundTracks.length; i++) {
-                this.soundTracks[i].switchPanningModelToHRTF();
-            }
-        }
-
-        private _switchAudioModeForNormalSpeakers() {
-            this.mainSoundTrack.switchPanningModelToEqualPower();
-
-            for (var i = 0; i < this.soundTracks.length; i++) {
-                this.soundTracks[i].switchPanningModelToEqualPower();
-            }
-        }
-
         public enableDepthRenderer(): DepthRenderer {
             if (this._depthRenderer) {
                 return this._depthRenderer;
@@ -2030,5 +1998,22 @@
         public getMaterialByTags(tagsQuery: string, forEach?: (material: Material) => void): Material[] {
             return this._getByTags(this.materials, tagsQuery, forEach).concat(this._getByTags(this.multiMaterials, tagsQuery, forEach));
         }
+
+        // Audio
+        public switchAudioModeForHeadphones() {
+            this.mainSoundTrack.switchPanningModelToHRTF();
+
+            for (var i = 0; i < this.soundTracks.length; i++) {
+                this.soundTracks[i].switchPanningModelToHRTF();
+            }
+        }
+
+        public switchAudioModeForNormalSpeakers() {
+            this.mainSoundTrack.switchPanningModelToEqualPower();
+
+            for (var i = 0; i < this.soundTracks.length; i++) {
+                this.soundTracks[i].switchPanningModelToEqualPower();
+            }
+        }
     }
 } 

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 51 - 163
babylon.2.1-alpha.debug.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 23
babylon.2.1-alpha.js