David Catuhe преди 7 години
родител
ревизия
bd03cbc7a3

Файловите разлики са ограничени, защото са твърде много
+ 8847 - 8843
dist/preview release/babylon.d.ts


Файловите разлики са ограничени, защото са твърде много
+ 31 - 31
dist/preview release/babylon.js


+ 71 - 0
dist/preview release/babylon.max.js

@@ -32322,6 +32322,77 @@ var BABYLON;
             }
             return results;
         };
+        /**
+         * Normalize matrix weights so that all vertices have a total weight set to 1
+         */
+        Mesh.prototype.cleanMatrixWeights = function () {
+            var epsilon = 1e-3;
+            var noInfluenceBoneIndex = 0.0;
+            if (this.skeleton) {
+                noInfluenceBoneIndex = this.skeleton.bones.length;
+            }
+            else {
+                return;
+            }
+            var matricesIndices = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
+            var matricesIndicesExtra = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
+            var matricesWeights = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind);
+            var matricesWeightsExtra = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
+            var influencers = this.numBoneInfluencers;
+            var size = matricesWeights.length;
+            for (var i = 0; i < size; i += 4) {
+                var weight = 0.0;
+                var firstZeroWeight = -1;
+                for (var j = 0; j < 4; j++) {
+                    var w = matricesWeights[i + j];
+                    weight += w;
+                    if (w < epsilon && firstZeroWeight < 0) {
+                        firstZeroWeight = j;
+                    }
+                }
+                if (matricesWeightsExtra) {
+                    for (var j = 0; j < 4; j++) {
+                        var w = matricesWeightsExtra[i + j];
+                        weight += w;
+                        if (w < epsilon && firstZeroWeight < 0) {
+                            firstZeroWeight = j + 4;
+                        }
+                    }
+                }
+                if (firstZeroWeight < 0 || firstZeroWeight > (influencers - 1)) {
+                    firstZeroWeight = influencers - 1;
+                }
+                if (weight > epsilon) {
+                    var mweight = 1.0 / weight;
+                    for (var j = 0; j < 4; j++) {
+                        matricesWeights[i + j] *= mweight;
+                    }
+                    if (matricesWeightsExtra) {
+                        for (var j = 0; j < 4; j++) {
+                            matricesWeightsExtra[i + j] *= mweight;
+                        }
+                    }
+                }
+                else {
+                    if (firstZeroWeight >= 4) {
+                        matricesWeightsExtra[i + firstZeroWeight - 4] = 1.0 - weight;
+                        matricesIndicesExtra[i + firstZeroWeight - 4] = noInfluenceBoneIndex;
+                    }
+                    else {
+                        matricesWeights[i + firstZeroWeight] = 1.0 - weight;
+                        matricesIndices[i + firstZeroWeight] = noInfluenceBoneIndex;
+                    }
+                }
+            }
+            this.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, matricesIndices);
+            if (matricesIndicesExtra) {
+                this.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, matricesIndicesExtra);
+            }
+            this.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, matricesWeights);
+            if (matricesWeightsExtra) {
+                this.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, matricesWeightsExtra);
+            }
+        };
         Mesh.prototype._checkDelayState = function () {
             var scene = this.getScene();
             if (this._geometry) {

+ 71 - 0
dist/preview release/babylon.no-module.max.js

@@ -32289,6 +32289,77 @@ var BABYLON;
             }
             return results;
         };
+        /**
+         * Normalize matrix weights so that all vertices have a total weight set to 1
+         */
+        Mesh.prototype.cleanMatrixWeights = function () {
+            var epsilon = 1e-3;
+            var noInfluenceBoneIndex = 0.0;
+            if (this.skeleton) {
+                noInfluenceBoneIndex = this.skeleton.bones.length;
+            }
+            else {
+                return;
+            }
+            var matricesIndices = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
+            var matricesIndicesExtra = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
+            var matricesWeights = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind);
+            var matricesWeightsExtra = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
+            var influencers = this.numBoneInfluencers;
+            var size = matricesWeights.length;
+            for (var i = 0; i < size; i += 4) {
+                var weight = 0.0;
+                var firstZeroWeight = -1;
+                for (var j = 0; j < 4; j++) {
+                    var w = matricesWeights[i + j];
+                    weight += w;
+                    if (w < epsilon && firstZeroWeight < 0) {
+                        firstZeroWeight = j;
+                    }
+                }
+                if (matricesWeightsExtra) {
+                    for (var j = 0; j < 4; j++) {
+                        var w = matricesWeightsExtra[i + j];
+                        weight += w;
+                        if (w < epsilon && firstZeroWeight < 0) {
+                            firstZeroWeight = j + 4;
+                        }
+                    }
+                }
+                if (firstZeroWeight < 0 || firstZeroWeight > (influencers - 1)) {
+                    firstZeroWeight = influencers - 1;
+                }
+                if (weight > epsilon) {
+                    var mweight = 1.0 / weight;
+                    for (var j = 0; j < 4; j++) {
+                        matricesWeights[i + j] *= mweight;
+                    }
+                    if (matricesWeightsExtra) {
+                        for (var j = 0; j < 4; j++) {
+                            matricesWeightsExtra[i + j] *= mweight;
+                        }
+                    }
+                }
+                else {
+                    if (firstZeroWeight >= 4) {
+                        matricesWeightsExtra[i + firstZeroWeight - 4] = 1.0 - weight;
+                        matricesIndicesExtra[i + firstZeroWeight - 4] = noInfluenceBoneIndex;
+                    }
+                    else {
+                        matricesWeights[i + firstZeroWeight] = 1.0 - weight;
+                        matricesIndices[i + firstZeroWeight] = noInfluenceBoneIndex;
+                    }
+                }
+            }
+            this.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, matricesIndices);
+            if (matricesIndicesExtra) {
+                this.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, matricesIndicesExtra);
+            }
+            this.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, matricesWeights);
+            if (matricesWeightsExtra) {
+                this.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, matricesWeightsExtra);
+            }
+        };
         Mesh.prototype._checkDelayState = function () {
             var scene = this.getScene();
             if (this._geometry) {

Файловите разлики са ограничени, защото са твърде много
+ 31 - 31
dist/preview release/babylon.worker.js


+ 71 - 0
dist/preview release/es6.js

@@ -32289,6 +32289,77 @@ var BABYLON;
             }
             return results;
         };
+        /**
+         * Normalize matrix weights so that all vertices have a total weight set to 1
+         */
+        Mesh.prototype.cleanMatrixWeights = function () {
+            var epsilon = 1e-3;
+            var noInfluenceBoneIndex = 0.0;
+            if (this.skeleton) {
+                noInfluenceBoneIndex = this.skeleton.bones.length;
+            }
+            else {
+                return;
+            }
+            var matricesIndices = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
+            var matricesIndicesExtra = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
+            var matricesWeights = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind);
+            var matricesWeightsExtra = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
+            var influencers = this.numBoneInfluencers;
+            var size = matricesWeights.length;
+            for (var i = 0; i < size; i += 4) {
+                var weight = 0.0;
+                var firstZeroWeight = -1;
+                for (var j = 0; j < 4; j++) {
+                    var w = matricesWeights[i + j];
+                    weight += w;
+                    if (w < epsilon && firstZeroWeight < 0) {
+                        firstZeroWeight = j;
+                    }
+                }
+                if (matricesWeightsExtra) {
+                    for (var j = 0; j < 4; j++) {
+                        var w = matricesWeightsExtra[i + j];
+                        weight += w;
+                        if (w < epsilon && firstZeroWeight < 0) {
+                            firstZeroWeight = j + 4;
+                        }
+                    }
+                }
+                if (firstZeroWeight < 0 || firstZeroWeight > (influencers - 1)) {
+                    firstZeroWeight = influencers - 1;
+                }
+                if (weight > epsilon) {
+                    var mweight = 1.0 / weight;
+                    for (var j = 0; j < 4; j++) {
+                        matricesWeights[i + j] *= mweight;
+                    }
+                    if (matricesWeightsExtra) {
+                        for (var j = 0; j < 4; j++) {
+                            matricesWeightsExtra[i + j] *= mweight;
+                        }
+                    }
+                }
+                else {
+                    if (firstZeroWeight >= 4) {
+                        matricesWeightsExtra[i + firstZeroWeight - 4] = 1.0 - weight;
+                        matricesIndicesExtra[i + firstZeroWeight - 4] = noInfluenceBoneIndex;
+                    }
+                    else {
+                        matricesWeights[i + firstZeroWeight] = 1.0 - weight;
+                        matricesIndices[i + firstZeroWeight] = noInfluenceBoneIndex;
+                    }
+                }
+            }
+            this.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, matricesIndices);
+            if (matricesIndicesExtra) {
+                this.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, matricesIndicesExtra);
+            }
+            this.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, matricesWeights);
+            if (matricesWeightsExtra) {
+                this.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, matricesWeightsExtra);
+            }
+        };
         Mesh.prototype._checkDelayState = function () {
             var scene = this.getScene();
             if (this._geometry) {

Файловите разлики са ограничени, защото са твърде много
+ 2 - 2
dist/preview release/inspector/babylon.inspector.bundle.js


Файловите разлики са ограничени, защото са твърде много
+ 31 - 31
dist/preview release/viewer/babylon.viewer.js


+ 71 - 0
dist/preview release/viewer/babylon.viewer.max.js

@@ -32410,6 +32410,77 @@ var BABYLON;
             }
             return results;
         };
+        /**
+         * Normalize matrix weights so that all vertices have a total weight set to 1
+         */
+        Mesh.prototype.cleanMatrixWeights = function () {
+            var epsilon = 1e-3;
+            var noInfluenceBoneIndex = 0.0;
+            if (this.skeleton) {
+                noInfluenceBoneIndex = this.skeleton.bones.length;
+            }
+            else {
+                return;
+            }
+            var matricesIndices = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
+            var matricesIndicesExtra = this.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
+            var matricesWeights = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind);
+            var matricesWeightsExtra = this.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
+            var influencers = this.numBoneInfluencers;
+            var size = matricesWeights.length;
+            for (var i = 0; i < size; i += 4) {
+                var weight = 0.0;
+                var firstZeroWeight = -1;
+                for (var j = 0; j < 4; j++) {
+                    var w = matricesWeights[i + j];
+                    weight += w;
+                    if (w < epsilon && firstZeroWeight < 0) {
+                        firstZeroWeight = j;
+                    }
+                }
+                if (matricesWeightsExtra) {
+                    for (var j = 0; j < 4; j++) {
+                        var w = matricesWeightsExtra[i + j];
+                        weight += w;
+                        if (w < epsilon && firstZeroWeight < 0) {
+                            firstZeroWeight = j + 4;
+                        }
+                    }
+                }
+                if (firstZeroWeight < 0 || firstZeroWeight > (influencers - 1)) {
+                    firstZeroWeight = influencers - 1;
+                }
+                if (weight > epsilon) {
+                    var mweight = 1.0 / weight;
+                    for (var j = 0; j < 4; j++) {
+                        matricesWeights[i + j] *= mweight;
+                    }
+                    if (matricesWeightsExtra) {
+                        for (var j = 0; j < 4; j++) {
+                            matricesWeightsExtra[i + j] *= mweight;
+                        }
+                    }
+                }
+                else {
+                    if (firstZeroWeight >= 4) {
+                        matricesWeightsExtra[i + firstZeroWeight - 4] = 1.0 - weight;
+                        matricesIndicesExtra[i + firstZeroWeight - 4] = noInfluenceBoneIndex;
+                    }
+                    else {
+                        matricesWeights[i + firstZeroWeight] = 1.0 - weight;
+                        matricesIndices[i + firstZeroWeight] = noInfluenceBoneIndex;
+                    }
+                }
+            }
+            this.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, matricesIndices);
+            if (matricesIndicesExtra) {
+                this.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesExtraKind, matricesIndicesExtra);
+            }
+            this.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, matricesWeights);
+            if (matricesWeightsExtra) {
+                this.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsExtraKind, matricesWeightsExtra);
+            }
+        };
         Mesh.prototype._checkDelayState = function () {
             var scene = this.getScene();
             if (this._geometry) {

+ 75 - 0
src/Mesh/babylon.mesh.ts

@@ -1454,6 +1454,81 @@
 
             return results;
         }
+        
+        /**
+         * Normalize matrix weights so that all vertices have a total weight set to 1
+         */
+        public cleanMatrixWeights(): void {
+            const epsilon: number = 1e-3;
+
+            let noInfluenceBoneIndex = 0.0;
+            if (this.skeleton) {
+                noInfluenceBoneIndex = this.skeleton.bones.length;
+            } else {
+                return;
+            }            
+
+            let matricesIndices = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesIndicesKind));
+            let matricesIndicesExtra = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesIndicesExtraKind));
+            let matricesWeights = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesWeightsKind));
+            let matricesWeightsExtra = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind));
+            let influencers = this.numBoneInfluencers;
+            let size = matricesWeights.length;
+
+            for (var i = 0; i < size; i += 4) {
+                let weight = 0.0;
+                let firstZeroWeight = -1;
+                for (var j = 0; j < 4; j++) {
+                    let w = matricesWeights[i + j];
+                    weight += w;
+                    if (w < epsilon && firstZeroWeight < 0) {
+                        firstZeroWeight = j;
+                    }
+                }
+                if (matricesWeightsExtra) {
+                    for (var j = 0; j < 4; j++) {
+                        let w = matricesWeightsExtra[i + j];
+                        weight += w;
+                        if (w < epsilon && firstZeroWeight < 0) {
+                            firstZeroWeight = j + 4;
+                        }
+                    }
+                }
+                if (firstZeroWeight < 0 || firstZeroWeight > (influencers - 1)) {
+                    firstZeroWeight = influencers - 1;
+                }
+                if (weight > epsilon) {
+                    let mweight = 1.0 / weight;
+                    for (var j = 0; j < 4; j++) {
+                        matricesWeights[i + j] *= mweight;
+                    }
+                    if (matricesWeightsExtra) {
+                        for (var j = 0; j < 4; j++) {
+                            matricesWeightsExtra[i + j] *= mweight;
+                        }
+                    }
+                } else {
+                    if (firstZeroWeight >= 4) {
+                        matricesWeightsExtra[i + firstZeroWeight - 4] = 1.0 - weight;
+                        matricesIndicesExtra[i + firstZeroWeight - 4] = noInfluenceBoneIndex;
+                    } else {
+                        matricesWeights[i + firstZeroWeight] = 1.0 - weight;
+                        matricesIndices[i + firstZeroWeight] = noInfluenceBoneIndex;
+                    }
+                }
+            }
+
+            this.setVerticesData(VertexBuffer.MatricesIndicesKind, matricesIndices);
+            if (matricesIndicesExtra) {
+                this.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, matricesIndicesExtra);
+            }
+
+            this.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeights);
+            if (matricesWeightsExtra) {
+                this.setVerticesData(VertexBuffer.MatricesWeightsExtraKind, matricesWeightsExtra);
+            }            
+        }
+
 
         public _checkDelayState(): Mesh {
             var scene = this.getScene();