|
@@ -23434,6 +23434,12 @@ var BABYLON;
|
|
|
if (parsedTexture.base64String) {
|
|
|
texture = Texture.CreateFromBase64String(parsedTexture.base64String, parsedTexture.name, scene);
|
|
|
}
|
|
|
+ else if (parsedTexture.name instanceof Array) {
|
|
|
+ for (var i = 0, len = parsedTexture.name.length; i < len; i++) {
|
|
|
+ parsedTexture.name[i] = rootUrl + parsedTexture.name[i];
|
|
|
+ }
|
|
|
+ texture = new Texture(parsedTexture.name, scene);
|
|
|
+ }
|
|
|
else {
|
|
|
texture = new Texture(rootUrl + parsedTexture.name, scene);
|
|
|
}
|
|
@@ -29774,6 +29780,7 @@ var BABYLON;
|
|
|
this._scaleMatrix = BABYLON.Matrix.Identity();
|
|
|
this._scaleVector = new BABYLON.Vector3(1, 1, 1);
|
|
|
this._negateScaleChildren = new BABYLON.Vector3(1, 1, 1);
|
|
|
+ this._scalingDeterminant = 1;
|
|
|
this._syncScaleVector = function () {
|
|
|
var lm = this.getLocalMatrix();
|
|
|
var xsq = (lm.m[0] * lm.m[0] + lm.m[1] * lm.m[1] + lm.m[2] * lm.m[2]);
|
|
@@ -29790,6 +29797,7 @@ var BABYLON;
|
|
|
this._scaleVector.y /= this._parent._negateScaleChildren.y;
|
|
|
this._scaleVector.z /= this._parent._negateScaleChildren.z;
|
|
|
}
|
|
|
+ BABYLON.Matrix.FromValuesToRef(this._scaleVector.x, 0, 0, 0, 0, this._scaleVector.y, 0, 0, 0, 0, this._scaleVector.z, 0, 0, 0, 0, 1, this._scaleMatrix);
|
|
|
};
|
|
|
this._skeleton = skeleton;
|
|
|
this._matrix = matrix;
|
|
@@ -29804,6 +29812,9 @@ var BABYLON;
|
|
|
this._parent = null;
|
|
|
}
|
|
|
this._updateDifferenceMatrix();
|
|
|
+ if (this.getAbsoluteTransform().determinant() < 0) {
|
|
|
+ this._scalingDeterminant *= -1;
|
|
|
+ }
|
|
|
}
|
|
|
// Members
|
|
|
Bone.prototype.getParent = function () {
|
|
@@ -30036,10 +30047,12 @@ var BABYLON;
|
|
|
Bone.prototype.setRotationMatrix = function (rotMat, space, mesh) {
|
|
|
if (space === void 0) { space = BABYLON.Space.LOCAL; }
|
|
|
if (mesh === void 0) { mesh = null; }
|
|
|
- var rotMatInv = BABYLON.Tmp.Matrix[1];
|
|
|
+ var rotMatInv = BABYLON.Tmp.Matrix[0];
|
|
|
this._getNegativeRotationToRef(rotMatInv, space, mesh);
|
|
|
- rotMatInv.multiplyToRef(rotMat, rotMat);
|
|
|
- this._rotateWithMatrix(rotMat, space, mesh);
|
|
|
+ var rotMat2 = BABYLON.Tmp.Matrix[1];
|
|
|
+ rotMat2.copyFrom(rotMat);
|
|
|
+ rotMatInv.multiplyToRef(rotMat, rotMat2);
|
|
|
+ this._rotateWithMatrix(rotMat2, space, mesh);
|
|
|
};
|
|
|
Bone.prototype._rotateWithMatrix = function (rmat, space, mesh) {
|
|
|
if (space === void 0) { space = BABYLON.Space.LOCAL; }
|
|
@@ -30103,7 +30116,7 @@ var BABYLON;
|
|
|
scaleMatrix.multiplyToRef(meshScale, scaleMatrix);
|
|
|
}
|
|
|
rotMatInv.invert();
|
|
|
- scaleMatrix.m[0] *= -1;
|
|
|
+ scaleMatrix.m[0] *= this._scalingDeterminant;
|
|
|
rotMatInv.multiplyToRef(scaleMatrix, rotMatInv);
|
|
|
}
|
|
|
else {
|
|
@@ -30118,7 +30131,7 @@ var BABYLON;
|
|
|
pscaleMatrix.multiplyToRef(rotMatInv, rotMatInv);
|
|
|
}
|
|
|
else {
|
|
|
- scaleMatrix.m[0] *= -1;
|
|
|
+ scaleMatrix.m[0] *= this._scalingDeterminant;
|
|
|
}
|
|
|
rotMatInv.multiplyToRef(scaleMatrix, rotMatInv);
|
|
|
}
|
|
@@ -30180,9 +30193,14 @@ var BABYLON;
|
|
|
mat.multiplyToRef(mesh.getWorldMatrix(), mat);
|
|
|
}
|
|
|
BABYLON.Vector3.TransformNormalToRef(localAxis, mat, result);
|
|
|
- if (this._scaleVector.x != 1 || this._scaleVector.y != 1 || this._scaleVector.z != 1) {
|
|
|
- result.normalize();
|
|
|
+ if (mesh) {
|
|
|
+ result.x /= mesh.scaling.x;
|
|
|
+ result.y /= mesh.scaling.y;
|
|
|
+ result.z /= mesh.scaling.z;
|
|
|
}
|
|
|
+ result.x /= this._scaleVector.x;
|
|
|
+ result.y /= this._scaleVector.y;
|
|
|
+ result.z /= this._scaleVector.z;
|
|
|
};
|
|
|
Bone.prototype.getRotation = function (mesh) {
|
|
|
var result = BABYLON.Quaternion.Identity();
|
|
@@ -30203,6 +30221,199 @@ var BABYLON;
|
|
|
|
|
|
var BABYLON;
|
|
|
(function (BABYLON) {
|
|
|
+ var BoneIKController = (function () {
|
|
|
+ function BoneIKController(mesh, bone, target, poleTarget, poleAngle) {
|
|
|
+ if (poleAngle === void 0) { poleAngle = 0; }
|
|
|
+ this.poleAngle = 0;
|
|
|
+ this._maxAngle = Math.PI;
|
|
|
+ this._tmpVec1 = BABYLON.Vector3.Zero();
|
|
|
+ this._tmpVec2 = BABYLON.Vector3.Zero();
|
|
|
+ this._tmpVec3 = BABYLON.Vector3.Zero();
|
|
|
+ this._tmpVec4 = BABYLON.Vector3.Zero();
|
|
|
+ this._tmpVec5 = BABYLON.Vector3.Zero();
|
|
|
+ this._tmpMat1 = BABYLON.Matrix.Identity();
|
|
|
+ this._tmpMat2 = BABYLON.Matrix.Identity();
|
|
|
+ this._rightHandedSystem = false;
|
|
|
+ target.computeWorldMatrix(true);
|
|
|
+ poleTarget.computeWorldMatrix(true);
|
|
|
+ this._bone2 = bone;
|
|
|
+ this._bone1 = bone.getParent();
|
|
|
+ this.target = target;
|
|
|
+ this.poleTarget = poleTarget;
|
|
|
+ this.poleAngle = poleAngle;
|
|
|
+ this.mesh = mesh;
|
|
|
+ if (bone.getAbsoluteTransform().determinant() > 0) {
|
|
|
+ this._rightHandedSystem = true;
|
|
|
+ }
|
|
|
+ if (this._bone1.length) {
|
|
|
+ var boneScale1 = this._bone1.getScale();
|
|
|
+ var boneScale2 = this._bone2.getScale();
|
|
|
+ this._bone1Length = this._bone1.length * boneScale1.y;
|
|
|
+ this._bone2Length = this._bone2.length * boneScale2.y;
|
|
|
+ }
|
|
|
+ else if (this._bone1.children[0]) {
|
|
|
+ mesh.computeWorldMatrix(true);
|
|
|
+ var pos1 = this._bone2.children[0].getAbsolutePosition(mesh);
|
|
|
+ var pos2 = this._bone2.getAbsolutePosition(mesh);
|
|
|
+ var pos3 = this._bone1.getAbsolutePosition(mesh);
|
|
|
+ this._bone1Length = BABYLON.Vector3.Distance(pos1, pos2);
|
|
|
+ this._bone2Length = BABYLON.Vector3.Distance(pos2, pos3);
|
|
|
+ }
|
|
|
+ this.maxAngle = Math.PI;
|
|
|
+ }
|
|
|
+ Object.defineProperty(BoneIKController.prototype, "maxAngle", {
|
|
|
+ get: function () {
|
|
|
+ return this._maxAngle;
|
|
|
+ },
|
|
|
+ set: function (value) {
|
|
|
+ this._setMaxAngle(value);
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
+ BoneIKController.prototype._setMaxAngle = function (ang) {
|
|
|
+ if (ang < 0) {
|
|
|
+ ang = 0;
|
|
|
+ }
|
|
|
+ if (ang > Math.PI || ang == undefined) {
|
|
|
+ ang = Math.PI;
|
|
|
+ }
|
|
|
+ this._maxAngle = ang;
|
|
|
+ var a = this._bone1Length;
|
|
|
+ var b = this._bone2Length;
|
|
|
+ this._maxReach = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(ang));
|
|
|
+ };
|
|
|
+ BoneIKController.prototype.update = function () {
|
|
|
+ var bone1 = this._bone1;
|
|
|
+ var target = this.target.getAbsolutePosition();
|
|
|
+ var poleTarget = this.poleTarget.getAbsolutePosition();
|
|
|
+ var bonePos = this._tmpVec1;
|
|
|
+ var zaxis = this._tmpVec2;
|
|
|
+ var xaxis = this._tmpVec3;
|
|
|
+ var yaxis = this._tmpVec4;
|
|
|
+ var upAxis = this._tmpVec5;
|
|
|
+ var mat1 = this._tmpMat1;
|
|
|
+ var mat2 = this._tmpMat2;
|
|
|
+ bone1.getAbsolutePositionToRef(this.mesh, bonePos);
|
|
|
+ poleTarget.subtractToRef(bonePos, upAxis);
|
|
|
+ if (upAxis.x == 0 && upAxis.y == 0 && upAxis.z == 0) {
|
|
|
+ upAxis.y = 1;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ upAxis.normalize();
|
|
|
+ }
|
|
|
+ target.subtractToRef(bonePos, yaxis);
|
|
|
+ yaxis.normalize();
|
|
|
+ BABYLON.Vector3.CrossToRef(yaxis, upAxis, zaxis);
|
|
|
+ zaxis.normalize();
|
|
|
+ BABYLON.Vector3.CrossToRef(yaxis, zaxis, xaxis);
|
|
|
+ xaxis.normalize();
|
|
|
+ BABYLON.Matrix.FromXYZAxesToRef(xaxis, yaxis, zaxis, mat1);
|
|
|
+ var a = this._bone1Length;
|
|
|
+ var b = this._bone2Length;
|
|
|
+ var c = BABYLON.Vector3.Distance(bonePos, target);
|
|
|
+ if (this._maxReach > 0) {
|
|
|
+ c = Math.min(this._maxReach, c);
|
|
|
+ }
|
|
|
+ var acosa = (b * b + c * c - a * a) / (2 * b * c);
|
|
|
+ var acosb = (c * c + a * a - b * b) / (2 * c * a);
|
|
|
+ if (acosa > 1) {
|
|
|
+ acosa = 1;
|
|
|
+ }
|
|
|
+ if (acosb > 1) {
|
|
|
+ acosb = 1;
|
|
|
+ }
|
|
|
+ if (acosa < -1) {
|
|
|
+ acosa = -1;
|
|
|
+ }
|
|
|
+ if (acosb < -1) {
|
|
|
+ acosb = -1;
|
|
|
+ }
|
|
|
+ var angA = Math.acos(acosa);
|
|
|
+ var angB = Math.acos(acosb);
|
|
|
+ var angC = -angA - angB;
|
|
|
+ var bendAxis = this._tmpVec1;
|
|
|
+ bendAxis.x = 0;
|
|
|
+ bendAxis.y = 0;
|
|
|
+ bendAxis.z = 0;
|
|
|
+ if (this._rightHandedSystem) {
|
|
|
+ bendAxis.z = 1;
|
|
|
+ BABYLON.Matrix.RotationYawPitchRollToRef(0, 0, angB + Math.PI * .5, mat2);
|
|
|
+ mat2.multiplyToRef(mat1, mat1);
|
|
|
+ BABYLON.Matrix.RotationAxisToRef(yaxis, this.poleAngle + Math.PI, mat2);
|
|
|
+ mat1.multiplyToRef(mat2, mat1);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ bendAxis.x = 1;
|
|
|
+ BABYLON.Matrix.RotationYawPitchRollToRef(0, angB, 0, mat2);
|
|
|
+ mat2.multiplyToRef(mat1, mat1);
|
|
|
+ if (this.poleAngle) {
|
|
|
+ BABYLON.Matrix.RotationAxisToRef(yaxis, this.poleAngle, mat2);
|
|
|
+ mat1.multiplyToRef(mat2, mat1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this._bone1.setRotationMatrix(mat1, BABYLON.Space.WORLD, this.mesh);
|
|
|
+ this._bone2.setAxisAngle(bendAxis, angC, BABYLON.Space.LOCAL);
|
|
|
+ };
|
|
|
+ return BoneIKController;
|
|
|
+ }());
|
|
|
+ BABYLON.BoneIKController = BoneIKController;
|
|
|
+})(BABYLON || (BABYLON = {}));
|
|
|
+
|
|
|
+var BABYLON;
|
|
|
+(function (BABYLON) {
|
|
|
+ var BoneLookController = (function () {
|
|
|
+ function BoneLookController(mesh, bone, target, adjustYaw, adjustPitch, adjustRoll) {
|
|
|
+ if (adjustYaw === void 0) { adjustYaw = 0; }
|
|
|
+ if (adjustPitch === void 0) { adjustPitch = 0; }
|
|
|
+ if (adjustRoll === void 0) { adjustRoll = 0; }
|
|
|
+ this.upAxis = BABYLON.Vector3.Up();
|
|
|
+ this.adjustYaw = 0;
|
|
|
+ this.adjustPitch = 0;
|
|
|
+ this.adjustRoll = 0;
|
|
|
+ this._tmpVec1 = BABYLON.Vector3.Zero();
|
|
|
+ this._tmpVec2 = BABYLON.Vector3.Zero();
|
|
|
+ this._tmpVec3 = BABYLON.Vector3.Zero();
|
|
|
+ this._tmpVec4 = BABYLON.Vector3.Zero();
|
|
|
+ this._tmpMat1 = BABYLON.Matrix.Identity();
|
|
|
+ this._tmpMat2 = BABYLON.Matrix.Identity();
|
|
|
+ this.mesh = mesh;
|
|
|
+ this.bone = bone;
|
|
|
+ this.target = target;
|
|
|
+ this.adjustYaw = adjustYaw;
|
|
|
+ this.adjustPitch = adjustPitch;
|
|
|
+ this.adjustRoll = adjustRoll;
|
|
|
+ }
|
|
|
+ BoneLookController.prototype.update = function () {
|
|
|
+ var bone = this.bone;
|
|
|
+ var target = this.target;
|
|
|
+ var bonePos = this._tmpVec1;
|
|
|
+ var zaxis = this._tmpVec2;
|
|
|
+ var xaxis = this._tmpVec3;
|
|
|
+ var yaxis = this._tmpVec4;
|
|
|
+ var mat1 = this._tmpMat1;
|
|
|
+ var mat2 = this._tmpMat2;
|
|
|
+ bone.getAbsolutePositionToRef(this.mesh, bonePos);
|
|
|
+ target.subtractToRef(bonePos, zaxis);
|
|
|
+ zaxis.normalize();
|
|
|
+ BABYLON.Vector3.CrossToRef(this.upAxis, zaxis, xaxis);
|
|
|
+ xaxis.normalize();
|
|
|
+ BABYLON.Vector3.CrossToRef(zaxis, xaxis, yaxis);
|
|
|
+ yaxis.normalize();
|
|
|
+ BABYLON.Matrix.FromXYZAxesToRef(xaxis, yaxis, zaxis, mat1);
|
|
|
+ if (this.adjustYaw || this.adjustPitch || this.adjustRoll) {
|
|
|
+ BABYLON.Matrix.RotationYawPitchRollToRef(this.adjustYaw, this.adjustPitch, this.adjustRoll, mat2);
|
|
|
+ mat2.multiplyToRef(mat1, mat1);
|
|
|
+ }
|
|
|
+ this.bone.setRotationMatrix(mat1, BABYLON.Space.WORLD, this.mesh);
|
|
|
+ };
|
|
|
+ return BoneLookController;
|
|
|
+ }());
|
|
|
+ BABYLON.BoneLookController = BoneLookController;
|
|
|
+})(BABYLON || (BABYLON = {}));
|
|
|
+
|
|
|
+var BABYLON;
|
|
|
+(function (BABYLON) {
|
|
|
var Skeleton = (function () {
|
|
|
function Skeleton(name, id, scene) {
|
|
|
this.name = name;
|