|
@@ -32322,6 +32322,77 @@ var BABYLON;
|
|
}
|
|
}
|
|
return results;
|
|
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 () {
|
|
Mesh.prototype._checkDelayState = function () {
|
|
var scene = this.getScene();
|
|
var scene = this.getScene();
|
|
if (this._geometry) {
|
|
if (this._geometry) {
|