babylon.bone.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var Bone = (function () {
  4. function Bone(name, skeleton, parentBone, matrix) {
  5. this.name = name;
  6. this.children = new Array();
  7. this.animations = new Array();
  8. this._worldTransform = new BABYLON.Matrix();
  9. this._absoluteTransform = new BABYLON.Matrix();
  10. this._invertedAbsoluteTransform = new BABYLON.Matrix();
  11. this._skeleton = skeleton;
  12. this._matrix = matrix;
  13. this._baseMatrix = matrix;
  14. skeleton.bones.push(this);
  15. if (parentBone) {
  16. this._parent = parentBone;
  17. parentBone.children.push(this);
  18. } else {
  19. this._parent = null;
  20. }
  21. this._updateDifferenceMatrix();
  22. }
  23. // Members
  24. Bone.prototype.getParent = function () {
  25. return this._parent;
  26. };
  27. Bone.prototype.getLocalMatrix = function () {
  28. return this._matrix;
  29. };
  30. Bone.prototype.getBaseMatrix = function () {
  31. return this._baseMatrix;
  32. };
  33. Bone.prototype.getWorldMatrix = function () {
  34. return this._worldTransform;
  35. };
  36. Bone.prototype.getInvertedAbsoluteTransform = function () {
  37. return this._invertedAbsoluteTransform;
  38. };
  39. Bone.prototype.getAbsoluteMatrix = function () {
  40. var matrix = this._matrix.clone();
  41. var parent = this._parent;
  42. while (parent) {
  43. matrix = matrix.multiply(parent.getLocalMatrix());
  44. parent = parent.getParent();
  45. }
  46. return matrix;
  47. };
  48. // Methods
  49. Bone.prototype.updateMatrix = function (matrix) {
  50. this._matrix = matrix;
  51. this._skeleton._markAsDirty();
  52. this._updateDifferenceMatrix();
  53. };
  54. Bone.prototype._updateDifferenceMatrix = function () {
  55. if (this._parent) {
  56. this._matrix.multiplyToRef(this._parent._absoluteTransform, this._absoluteTransform);
  57. } else {
  58. this._absoluteTransform.copyFrom(this._matrix);
  59. }
  60. this._absoluteTransform.invertToRef(this._invertedAbsoluteTransform);
  61. for (var index = 0; index < this.children.length; index++) {
  62. this.children[index]._updateDifferenceMatrix();
  63. }
  64. };
  65. Bone.prototype.markAsDirty = function () {
  66. this._skeleton._markAsDirty();
  67. };
  68. return Bone;
  69. })();
  70. BABYLON.Bone = Bone;
  71. })(BABYLON || (BABYLON = {}));
  72. //# sourceMappingURL=babylon.bone.js.map