Pārlūkot izejas kodu

Fixed issue with applyToMesh

David Catuhe 8 gadi atpakaļ
vecāks
revīzija
cb05861412

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3897 - 3845
dist/preview release/babylon.d.ts


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 41 - 41
dist/preview release/babylon.js


+ 123 - 7
dist/preview release/babylon.max.js

@@ -67,16 +67,108 @@ var __extends = (this && this.__extends) || (function () {
             return Math.log(value) * Math.LOG2E;
         };
         /**
-         * Loops the value, so that it is never larger than length and never smaller than 0.
-         *
-         * This is similar to the modulo operator but it works with floating point numbers.
-         * For example, using 3.0 for t and 2.5 for length, the result would be 0.5.
-         * With t = 5 and length = 2.5, the result would be 0.0.
-         * Note, however, that the behaviour is not defined for negative numbers as it is for the modulo operator
-         */
+        * Loops the value, so that it is never larger than length and never smaller than 0.
+        *
+        * This is similar to the modulo operator but it works with floating point numbers.
+        * For example, using 3.0 for t and 2.5 for length, the result would be 0.5.
+        * With t = 5 and length = 2.5, the result would be 0.0.
+        * Note, however, that the behaviour is not defined for negative numbers as it is for the modulo operator
+        */
         MathTools.Repeat = function (value, length) {
             return value - Math.floor(value / length) * length;
         };
+        /**
+        * Normalize the value between 0.0 and 1.0 using min and max values
+        */
+        MathTools.Normalize = function (value, min, max) {
+            return (value - min) / (max - min);
+        };
+        /**
+        * Denormalize the value from 0.0 and 1.0 using min and max values
+        */
+        MathTools.Denormalize = function (normalized, min, max) {
+            return (normalized * (max - min) + min);
+        };
+        /**
+        * Clamps value between 0 and 1 and returns value.
+        */
+        MathTools.ClampValue = function (value) {
+            var result = 0;
+            if (value < 0.0) {
+                result = 0.0;
+            }
+            else if (value > 1.0) {
+                result = 1.0;
+            }
+            else {
+                result = value;
+            }
+            return result;
+        };
+        /**
+        * Calculates the shortest difference between two given angles given in degrees.
+        */
+        MathTools.DeltaAngle = function (current, target) {
+            var num = MathTools.Repeat(target - current, 360.0);
+            if (num > 180.0) {
+                num -= 360.0;
+            }
+            return num;
+        };
+        /**
+        * PingPongs the value t, so that it is never larger than length and never smaller than 0.
+        *
+        * The returned value will move back and forth between 0 and length
+        */
+        MathTools.PingPong = function (tx, length) {
+            var t = MathTools.Repeat(tx, length * 2.0);
+            return length - Math.abs(t - length);
+        };
+        /**
+        * Interpolates between min and max with smoothing at the limits.
+        *
+        * This function interpolates between min and max in a similar way to Lerp. However, the interpolation will gradually speed up
+        * from the start and slow down toward the end. This is useful for creating natural-looking animation, fading and other transitions.
+        */
+        MathTools.SmoothStep = function (from, to, tx) {
+            var t = MathTools.ClampValue(tx);
+            t = -2.0 * t * t * t + 3.0 * t * t;
+            return to * t + from * (1.0 - t);
+        };
+        /**
+        * Moves a value current towards target.
+        *
+        * This is essentially the same as Mathf.Lerp but instead the function will ensure that the speed never exceeds maxDelta.
+        * Negative values of maxDelta pushes the value away from target.
+        */
+        MathTools.MoveTowards = function (current, target, maxDelta) {
+            var result = 0;
+            if (Math.abs(target - current) <= maxDelta) {
+                result = target;
+            }
+            else {
+                result = current + MathTools.Sign(target - current) * maxDelta;
+            }
+            return result;
+        };
+        /**
+        * Same as MoveTowards but makes sure the values interpolate correctly when they wrap around 360 degrees.
+        *
+        * Variables current and target are assumed to be in degrees. For optimization reasons, negative values of maxDelta
+        *  are not supported and may cause oscillation. To push current away from a target angle, add 180 to that angle instead.
+        */
+        MathTools.MoveTowardsAngle = function (current, target, maxDelta) {
+            var num = MathTools.DeltaAngle(current, target);
+            var result = 0;
+            if (-maxDelta < num && num < maxDelta) {
+                result = target;
+            }
+            else {
+                target = current + num;
+                result = MathTools.MoveTowards(current, target, maxDelta);
+            }
+            return result;
+        };
         return MathTools;
     }());
     BABYLON.MathTools = MathTools;
@@ -90,6 +182,30 @@ var __extends = (this && this.__extends) || (function () {
             return start + ((end - start) * amount);
         };
         /**
+        * Same as Lerp but makes sure the values interpolate correctly when they wrap around 360 degrees.
+        * The parameter t is clamped to the range [0, 1]. Variables a and b are assumed to be in degrees.
+        */
+        Scalar.LerpAngle = function (start, end, amount) {
+            var num = MathTools.Repeat(end - start, 360.0);
+            if (num > 180.0) {
+                num -= 360.0;
+            }
+            return start + num * MathTools.ClampValue(amount);
+        };
+        /**
+        * Calculates the linear parameter t that produces the interpolant value within the range [a, b].
+        */
+        Scalar.InverseLerp = function (a, b, value) {
+            var result = 0;
+            if (a != b) {
+                result = MathTools.ClampValue((value - a) / (b - a));
+            }
+            else {
+                result = 0.0;
+            }
+            return result;
+        };
+        /**
          * Returns a new scalar located for "amount" (float) on the Hermite spline defined by the scalars "value1", "value3", "tangent1", "tangent2".
          */
         Scalar.Hermite = function (value1, tangent1, value2, tangent2, amount) {

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3897 - 3845
dist/preview release/babylon.module.d.ts


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 42 - 42
dist/preview release/babylon.worker.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 599 - 547
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 27 - 27
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 123 - 7
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -67,16 +67,108 @@ var __extends = (this && this.__extends) || (function () {
             return Math.log(value) * Math.LOG2E;
         };
         /**
-         * Loops the value, so that it is never larger than length and never smaller than 0.
-         *
-         * This is similar to the modulo operator but it works with floating point numbers.
-         * For example, using 3.0 for t and 2.5 for length, the result would be 0.5.
-         * With t = 5 and length = 2.5, the result would be 0.0.
-         * Note, however, that the behaviour is not defined for negative numbers as it is for the modulo operator
-         */
+        * Loops the value, so that it is never larger than length and never smaller than 0.
+        *
+        * This is similar to the modulo operator but it works with floating point numbers.
+        * For example, using 3.0 for t and 2.5 for length, the result would be 0.5.
+        * With t = 5 and length = 2.5, the result would be 0.0.
+        * Note, however, that the behaviour is not defined for negative numbers as it is for the modulo operator
+        */
         MathTools.Repeat = function (value, length) {
             return value - Math.floor(value / length) * length;
         };
+        /**
+        * Normalize the value between 0.0 and 1.0 using min and max values
+        */
+        MathTools.Normalize = function (value, min, max) {
+            return (value - min) / (max - min);
+        };
+        /**
+        * Denormalize the value from 0.0 and 1.0 using min and max values
+        */
+        MathTools.Denormalize = function (normalized, min, max) {
+            return (normalized * (max - min) + min);
+        };
+        /**
+        * Clamps value between 0 and 1 and returns value.
+        */
+        MathTools.ClampValue = function (value) {
+            var result = 0;
+            if (value < 0.0) {
+                result = 0.0;
+            }
+            else if (value > 1.0) {
+                result = 1.0;
+            }
+            else {
+                result = value;
+            }
+            return result;
+        };
+        /**
+        * Calculates the shortest difference between two given angles given in degrees.
+        */
+        MathTools.DeltaAngle = function (current, target) {
+            var num = MathTools.Repeat(target - current, 360.0);
+            if (num > 180.0) {
+                num -= 360.0;
+            }
+            return num;
+        };
+        /**
+        * PingPongs the value t, so that it is never larger than length and never smaller than 0.
+        *
+        * The returned value will move back and forth between 0 and length
+        */
+        MathTools.PingPong = function (tx, length) {
+            var t = MathTools.Repeat(tx, length * 2.0);
+            return length - Math.abs(t - length);
+        };
+        /**
+        * Interpolates between min and max with smoothing at the limits.
+        *
+        * This function interpolates between min and max in a similar way to Lerp. However, the interpolation will gradually speed up
+        * from the start and slow down toward the end. This is useful for creating natural-looking animation, fading and other transitions.
+        */
+        MathTools.SmoothStep = function (from, to, tx) {
+            var t = MathTools.ClampValue(tx);
+            t = -2.0 * t * t * t + 3.0 * t * t;
+            return to * t + from * (1.0 - t);
+        };
+        /**
+        * Moves a value current towards target.
+        *
+        * This is essentially the same as Mathf.Lerp but instead the function will ensure that the speed never exceeds maxDelta.
+        * Negative values of maxDelta pushes the value away from target.
+        */
+        MathTools.MoveTowards = function (current, target, maxDelta) {
+            var result = 0;
+            if (Math.abs(target - current) <= maxDelta) {
+                result = target;
+            }
+            else {
+                result = current + MathTools.Sign(target - current) * maxDelta;
+            }
+            return result;
+        };
+        /**
+        * Same as MoveTowards but makes sure the values interpolate correctly when they wrap around 360 degrees.
+        *
+        * Variables current and target are assumed to be in degrees. For optimization reasons, negative values of maxDelta
+        *  are not supported and may cause oscillation. To push current away from a target angle, add 180 to that angle instead.
+        */
+        MathTools.MoveTowardsAngle = function (current, target, maxDelta) {
+            var num = MathTools.DeltaAngle(current, target);
+            var result = 0;
+            if (-maxDelta < num && num < maxDelta) {
+                result = target;
+            }
+            else {
+                target = current + num;
+                result = MathTools.MoveTowards(current, target, maxDelta);
+            }
+            return result;
+        };
         return MathTools;
     }());
     BABYLON.MathTools = MathTools;
@@ -90,6 +182,30 @@ var __extends = (this && this.__extends) || (function () {
             return start + ((end - start) * amount);
         };
         /**
+        * Same as Lerp but makes sure the values interpolate correctly when they wrap around 360 degrees.
+        * The parameter t is clamped to the range [0, 1]. Variables a and b are assumed to be in degrees.
+        */
+        Scalar.LerpAngle = function (start, end, amount) {
+            var num = MathTools.Repeat(end - start, 360.0);
+            if (num > 180.0) {
+                num -= 360.0;
+            }
+            return start + num * MathTools.ClampValue(amount);
+        };
+        /**
+        * Calculates the linear parameter t that produces the interpolant value within the range [a, b].
+        */
+        Scalar.InverseLerp = function (a, b, value) {
+            var result = 0;
+            if (a != b) {
+                result = MathTools.ClampValue((value - a) / (b - a));
+            }
+            else {
+                result = 0.0;
+            }
+            return result;
+        };
+        /**
          * Returns a new scalar located for "amount" (float) on the Hermite spline defined by the scalars "value1", "value3", "tangent1", "tangent2".
          */
         Scalar.Hermite = function (value1, tangent1, value2, tangent2, amount) {

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 599 - 547
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


+ 23 - 0
dist/preview release/gui/babylon.gui.d.ts

@@ -94,6 +94,7 @@ declare module BABYLON.GUI {
         readonly isPercentage: boolean;
         readonly isPixel: boolean;
         readonly internalValue: number;
+        getValueInPixel(host: AdvancedDynamicTexture, refValue: number): number;
         getValue(host: AdvancedDynamicTexture): number;
         toString(host: AdvancedDynamicTexture): string;
         fromString(source: string | number): boolean;
@@ -577,3 +578,25 @@ declare module BABYLON.GUI {
         protected _onPointerUp(coordinates: Vector2): void;
     }
 }
+
+
+declare module BABYLON.GUI {
+    class InputText extends Control {
+        name: string;
+        private _text;
+        private _background;
+        private _thickness;
+        private _margin;
+        private _autoStretchWidth;
+        private _maxWidth;
+        maxWidth: string | number;
+        margin: string;
+        autoStretchWidth: boolean;
+        thickness: number;
+        background: string;
+        text: string;
+        constructor(name?: string, text?: string);
+        protected _getTypeName(): string;
+        _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
+    }
+}

+ 162 - 0
dist/preview release/gui/babylon.gui.js

@@ -551,6 +551,12 @@ var BABYLON;
                 enumerable: true,
                 configurable: true
             });
+            ValueAndUnit.prototype.getValueInPixel = function (host, refValue) {
+                if (this.isPixel) {
+                    return this.getValue(host);
+                }
+                return this.getValue(host) * refValue;
+            };
             ValueAndUnit.prototype.getValue = function (host) {
                 if (host && !this.ignoreAdaptiveScaling && this.unit !== ValueAndUnit.UNITMODE_PERCENTAGE) {
                     if (host.idealWidth) {
@@ -3608,3 +3614,159 @@ var BABYLON;
         GUI.ColorPicker = ColorPicker;
     })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
 })(BABYLON || (BABYLON = {}));
+
+/// <reference path="../../../dist/preview release/babylon.d.ts"/>
+var __extends = (this && this.__extends) || (function () {
+    var extendStatics = Object.setPrototypeOf ||
+        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
+    return function (d, b) {
+        extendStatics(d, b);
+        function __() { this.constructor = d; }
+        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+    };
+})();
+var BABYLON;
+(function (BABYLON) {
+    var GUI;
+    (function (GUI) {
+        var InputText = (function (_super) {
+            __extends(InputText, _super);
+            function InputText(name, text) {
+                if (text === void 0) { text = ""; }
+                var _this = _super.call(this, name) || this;
+                _this.name = name;
+                _this._text = "";
+                _this._background = "black";
+                _this._thickness = 1;
+                _this._margin = new GUI.ValueAndUnit(10, GUI.ValueAndUnit.UNITMODE_PIXEL);
+                _this._autoStretchWidth = true;
+                _this._maxWidth = new GUI.ValueAndUnit(1, GUI.ValueAndUnit.UNITMODE_PERCENTAGE, false);
+                _this.text = text;
+                return _this;
+            }
+            Object.defineProperty(InputText.prototype, "maxWidth", {
+                get: function () {
+                    return this._maxWidth.toString(this._host);
+                },
+                set: function (value) {
+                    if (this._maxWidth.toString(this._host) === value) {
+                        return;
+                    }
+                    if (this._maxWidth.fromString(value)) {
+                        this._markAsDirty();
+                    }
+                },
+                enumerable: true,
+                configurable: true
+            });
+            Object.defineProperty(InputText.prototype, "margin", {
+                get: function () {
+                    return this._margin.toString(this._host);
+                },
+                set: function (value) {
+                    if (this._margin.toString(this._host) === value) {
+                        return;
+                    }
+                    if (this._margin.fromString(value)) {
+                        this._markAsDirty();
+                    }
+                },
+                enumerable: true,
+                configurable: true
+            });
+            Object.defineProperty(InputText.prototype, "autoStretchWidth", {
+                get: function () {
+                    return this._autoStretchWidth;
+                },
+                set: function (value) {
+                    if (this._autoStretchWidth === value) {
+                        return;
+                    }
+                    this._autoStretchWidth = value;
+                    this._markAsDirty();
+                },
+                enumerable: true,
+                configurable: true
+            });
+            Object.defineProperty(InputText.prototype, "thickness", {
+                get: function () {
+                    return this._thickness;
+                },
+                set: function (value) {
+                    if (this._thickness === value) {
+                        return;
+                    }
+                    this._thickness = value;
+                    this._markAsDirty();
+                },
+                enumerable: true,
+                configurable: true
+            });
+            Object.defineProperty(InputText.prototype, "background", {
+                get: function () {
+                    return this._background;
+                },
+                set: function (value) {
+                    if (this._background === value) {
+                        return;
+                    }
+                    this._background = value;
+                    this._markAsDirty();
+                },
+                enumerable: true,
+                configurable: true
+            });
+            Object.defineProperty(InputText.prototype, "text", {
+                get: function () {
+                    return this._text;
+                },
+                set: function (value) {
+                    if (this._text === value) {
+                        return;
+                    }
+                    this._text = value;
+                    this._markAsDirty();
+                },
+                enumerable: true,
+                configurable: true
+            });
+            InputText.prototype._getTypeName = function () {
+                return "InputText";
+            };
+            InputText.prototype._draw = function (parentMeasure, context) {
+                context.save();
+                this._applyStates(context);
+                if (this._processMeasures(parentMeasure, context)) {
+                    // Background
+                    if (this._background) {
+                        context.fillStyle = this._background;
+                        context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
+                    }
+                    // Text
+                    if (this._text) {
+                        if (this.color) {
+                            context.fillStyle = this.color;
+                        }
+                        var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
+                        context.fillText(this._text, this._currentMeasure.left + this._margin.getValueInPixel(this._host, parentMeasure.width), this._currentMeasure.top + rootY);
+                        if (this._autoStretchWidth) {
+                            this.width = Math.min(this._maxWidth.getValueInPixel(this._host, parentMeasure.width), context.measureText(this._text).width + this._margin.getValueInPixel(this._host, parentMeasure.width) * 2) + "px";
+                        }
+                    }
+                    // Border
+                    if (this._thickness) {
+                        if (this.color) {
+                            context.strokeStyle = this.color;
+                        }
+                        context.lineWidth = this._thickness;
+                        context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
+                    }
+                }
+                context.restore();
+            };
+            return InputText;
+        }(GUI.Control));
+        GUI.InputText = InputText;
+    })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
+})(BABYLON || (BABYLON = {}));

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 3
dist/preview release/gui/babylon.gui.min.js


+ 3 - 3
src/Mesh/babylon.geometry.ts

@@ -145,7 +145,7 @@
                 for (var index = 0; index < numOfMeshes; index++) {
                     var mesh = meshes[index];
                     mesh._boundingInfo = new BoundingInfo(this._extend.minimum, this._extend.maximum);
-                    mesh._createGlobalSubMesh();
+                    mesh._createGlobalSubMesh(false);
                     mesh.computeWorldMatrix(true);
                 }
             }
@@ -315,7 +315,7 @@
             var numOfMeshes = meshes.length;
 
             for (var index = 0; index < numOfMeshes; index++) {
-                meshes[index]._createGlobalSubMesh();
+                meshes[index]._createGlobalSubMesh(true);
             }
             this.notifyUpdate();
         }
@@ -432,7 +432,7 @@
                     }
                     mesh._boundingInfo = new BoundingInfo(this._extend.minimum, this._extend.maximum);
 
-                    mesh._createGlobalSubMesh();
+                    mesh._createGlobalSubMesh(false);
 
                     //bounding info was just created again, world matrix should be applied again.
                     mesh._updateBoundingInfo();

+ 13 - 9
src/Mesh/babylon.mesh.ts

@@ -638,7 +638,7 @@
             return this;
         }
 
-        public _createGlobalSubMesh(): SubMesh {
+        public _createGlobalSubMesh(force: boolean): SubMesh {
             var totalVertices = this.getTotalVertices();
             if (!totalVertices || !this.getIndices()) {
                 return null;
@@ -649,15 +649,19 @@
                 var totalIndices = this.getIndices().length;
                 let needToRecreate = false;
     
-                for (var submesh of this.subMeshes) {
-                    if (submesh.indexStart + submesh.indexCount >= totalIndices) {
-                        needToRecreate = true;
-                        break;
-                    }
+                if (force) {
+                    needToRecreate = true;
+                } else {
+                    for (var submesh of this.subMeshes) {
+                        if (submesh.indexStart + submesh.indexCount >= totalIndices) {
+                            needToRecreate = true;
+                            break;
+                        }
 
-                    if (submesh.verticesStart + submesh.verticesCount >= totalVertices) {
-                        needToRecreate = true;
-                        break;
+                        if (submesh.verticesStart + submesh.verticesCount >= totalVertices) {
+                            needToRecreate = true;
+                            break;
+                        }
                     }
                 }
 

+ 4 - 4
src/Mesh/babylon.mesh.vertexData.ts

@@ -1646,15 +1646,15 @@
             var face: number = 0;
             for (var index = 0; index < normals.length; index += 3) { 
                 //Edge Face  no. 1
-                if(Math.abs(normals[index + 1]) == 0) {
+                if(Math.abs(normals[index + 1]) < 0.001) {
                    face = 1; 
                 }
                 //Top Face  no. 0
-                if(normals[index + 1] == 1) {
+                if(Math.abs(normals[index + 1] - 1) < 0.001 ) {
                    face = 0; 
                 }
                 //Bottom Face  no. 2
-                if(normals[index + 1] == -1) {
+                if(Math.abs(normals[index + 1] + 1) < 0.001 ) {
                    face = 2; 
                 }
                 idx = index / 3;
@@ -2526,4 +2526,4 @@
             geometry.setAllVerticesData(vertexData, parsedVertexData.updatable);
         }
     }
-}
+}