babylon.bone.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. }
  19. else {
  20. this._parent = null;
  21. }
  22. this._updateDifferenceMatrix();
  23. }
  24. // Members
  25. Bone.prototype.getParent = function () {
  26. return this._parent;
  27. };
  28. Bone.prototype.getLocalMatrix = function () {
  29. return this._matrix;
  30. };
  31. Bone.prototype.getBaseMatrix = function () {
  32. return this._baseMatrix;
  33. };
  34. Bone.prototype.getWorldMatrix = function () {
  35. return this._worldTransform;
  36. };
  37. Bone.prototype.getInvertedAbsoluteTransform = function () {
  38. return this._invertedAbsoluteTransform;
  39. };
  40. Bone.prototype.getAbsoluteMatrix = function () {
  41. var matrix = this._matrix.clone();
  42. var parent = this._parent;
  43. while (parent) {
  44. matrix = matrix.multiply(parent.getLocalMatrix());
  45. parent = parent.getParent();
  46. }
  47. return matrix;
  48. };
  49. // Methods
  50. Bone.prototype.updateMatrix = function (matrix) {
  51. this._matrix = matrix;
  52. this._skeleton._markAsDirty();
  53. this._updateDifferenceMatrix();
  54. };
  55. Bone.prototype._updateDifferenceMatrix = function () {
  56. if (this._parent) {
  57. this._matrix.multiplyToRef(this._parent._absoluteTransform, this._absoluteTransform);
  58. }
  59. else {
  60. this._absoluteTransform.copyFrom(this._matrix);
  61. }
  62. this._absoluteTransform.invertToRef(this._invertedAbsoluteTransform);
  63. for (var index = 0; index < this.children.length; index++) {
  64. this.children[index]._updateDifferenceMatrix();
  65. }
  66. };
  67. Bone.prototype.markAsDirty = function () {
  68. this._skeleton._markAsDirty();
  69. };
  70. return Bone;
  71. })();
  72. BABYLON.Bone = Bone;
  73. })(BABYLON || (BABYLON = {}));
  74. //# sourceMappingURL=babylon.bone.js.map