babylon.skeleton.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var Skeleton = (function () {
  4. function Skeleton(name, id, scene) {
  5. this.name = name;
  6. this.id = id;
  7. this.bones = new Array();
  8. this._isDirty = true;
  9. this._identity = BABYLON.Matrix.Identity();
  10. this.bones = [];
  11. this._scene = scene;
  12. scene.skeletons.push(this);
  13. }
  14. // Members
  15. Skeleton.prototype.getTransformMatrices = function () {
  16. return this._transformMatrices;
  17. };
  18. // Methods
  19. Skeleton.prototype._markAsDirty = function () {
  20. this._isDirty = true;
  21. };
  22. Skeleton.prototype.prepare = function () {
  23. if (!this._isDirty) {
  24. return;
  25. }
  26. if (!this._transformMatrices || this._transformMatrices.length !== 16 * (this.bones.length + 1)) {
  27. this._transformMatrices = new Float32Array(16 * (this.bones.length + 1));
  28. }
  29. for (var index = 0; index < this.bones.length; index++) {
  30. var bone = this.bones[index];
  31. var parentBone = bone.getParent();
  32. if (parentBone) {
  33. bone.getLocalMatrix().multiplyToRef(parentBone.getWorldMatrix(), bone.getWorldMatrix());
  34. } else {
  35. bone.getWorldMatrix().copyFrom(bone.getLocalMatrix());
  36. }
  37. bone.getInvertedAbsoluteTransform().multiplyToArray(bone.getWorldMatrix(), this._transformMatrices, index * 16);
  38. }
  39. this._identity.copyToArray(this._transformMatrices, this.bones.length * 16);
  40. this._isDirty = false;
  41. };
  42. Skeleton.prototype.getAnimatables = function () {
  43. if (!this._animatables || this._animatables.length != this.bones.length) {
  44. this._animatables = [];
  45. for (var index = 0; index < this.bones.length; index++) {
  46. this._animatables.push(this.bones[index]);
  47. }
  48. }
  49. return this._animatables;
  50. };
  51. Skeleton.prototype.clone = function (name, id) {
  52. var result = new BABYLON.Skeleton(name, id || name, this._scene);
  53. for (var index = 0; index < this.bones.length; index++) {
  54. var source = this.bones[index];
  55. var parentBone = null;
  56. if (source.getParent()) {
  57. var parentIndex = this.bones.indexOf(source.getParent());
  58. parentBone = result.bones[parentIndex];
  59. }
  60. var bone = new BABYLON.Bone(source.name, result, parentBone, source.getBaseMatrix());
  61. BABYLON.Tools.DeepCopy(source.animations, bone.animations);
  62. }
  63. return result;
  64. };
  65. return Skeleton;
  66. })();
  67. BABYLON.Skeleton = Skeleton;
  68. })(BABYLON || (BABYLON = {}));
  69. //# sourceMappingURL=babylon.skeleton.js.map