babylon.bone.js 3.0 KB

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