babylon.skeleton.js 2.8 KB

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