ソースを参照

Fixing math SIMD detection

David Catuhe 10 年 前
コミット
e8a6994e87
4 ファイル変更151 行追加32 行削除
  1. 44 6
      Babylon/Math/babylon.math.js
  2. 61 18
      Babylon/Math/babylon.math.ts
  3. 44 6
      babylon.2.1-alpha.debug.js
  4. 2 2
      babylon.2.1-alpha.js

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

@@ -2340,7 +2340,7 @@ var BABYLON;
     BABYLON.PathCursor = PathCursor;
     var Path2 = (function () {
         function Path2(x, y) {
-            this._points = [];
+            this._points = new Array();
             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 = [];
-            this._distances = [];
-            this._tangents = [];
-            this._normals = [];
-            this._binormals = [];
+            this._curve = new Array();
+            this._distances = new Array();
+            this._tangents = new Array();
+            this._normals = new Array();
+            this._binormals = new Array();
             this._curve = path.slice(); // copy array         
             var l = this._curve.length;
             // first and last tangents
@@ -2507,6 +2507,44 @@ var BABYLON;
         return Path3D;
     })();
     BABYLON.Path3D = Path3D;
+    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;
     // SIMD
     if (window.SIMD !== undefined) {
         // Replace functions

+ 61 - 18
Babylon/Math/babylon.math.ts

@@ -2958,9 +2958,10 @@
     }
 
     export class Path2 {
-        private _points: Vector2[] = [];
-        private _length: number = 0;
-        closed: boolean = false;
+        private _points = new Array<Vector2>();
+        private _length = 0;
+
+        public closed = false;
 
         constructor(x: number, y: number) {
             this._points.push(new Vector2(x, y));
@@ -3062,25 +3063,25 @@
     }
 
     export class Path3D {
-        private _curve: Vector3[] = [];
-        private _distances: number[] = [];
-        private _tangents: Vector3[] = [];
-        private _normals: Vector3[] = [];
-        private _binormals: Vector3[] = [];
+        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>();
 
         constructor(public path: Vector3[]) {
             this._curve = path.slice();   // copy array         
-            var l: number = this._curve.length;
+            var l = 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: Vector3 = this._tangents[0];
-            var pp0: Vector3 = this._normalVector(this._curve[0], tg0);
+            var tg0 = this._tangents[0];
+            var pp0 = this._normalVector(this._curve[0], tg0);
             this._normals[0] = pp0;
             this._normals[0].normalize();
             this._binormals[0] = Vector3.Cross(tg0, this._normals[0]);
@@ -3094,11 +3095,11 @@
             var prevNorm: Vector3;    // previous normal
             var prevBinor: Vector3;   // previous binormal
 
-            for(var i: number = 1; i < l; i++) {
+            for (var i = 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();               
                 }
@@ -3107,8 +3108,8 @@
                 // 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]);
@@ -3156,6 +3157,48 @@
         }
     }
 
+    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;
+        }
+    }
+
     // SIMD
     if (window.SIMD !== undefined) {
         // Replace functions

+ 44 - 6
babylon.2.1-alpha.debug.js

@@ -2345,7 +2345,7 @@ var __extends = this.__extends || function (d, b) {
     BABYLON.PathCursor = PathCursor;
     var Path2 = (function () {
         function Path2(x, y) {
-            this._points = [];
+            this._points = new Array();
             this._length = 0;
             this.closed = false;
             this._points.push(new Vector2(x, y));
@@ -2431,11 +2431,11 @@ var __extends = this.__extends || function (d, b) {
     var Path3D = (function () {
         function Path3D(path) {
             this.path = path;
-            this._curve = [];
-            this._distances = [];
-            this._tangents = [];
-            this._normals = [];
-            this._binormals = [];
+            this._curve = new Array();
+            this._distances = new Array();
+            this._tangents = new Array();
+            this._normals = new Array();
+            this._binormals = new Array();
             this._curve = path.slice(); // copy array         
             var l = this._curve.length;
             // first and last tangents
@@ -2512,6 +2512,44 @@ var __extends = this.__extends || function (d, b) {
         return Path3D;
     })();
     BABYLON.Path3D = Path3D;
+    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;
     // SIMD
     if (window.SIMD !== undefined) {
         // Replace functions

ファイルの差分が大きいため隠しています
+ 2 - 2
babylon.2.1-alpha.js