babylon.skeleton.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. }
  35. else {
  36. bone.getWorldMatrix().copyFrom(bone.getLocalMatrix());
  37. }
  38. bone.getInvertedAbsoluteTransform().multiplyToArray(bone.getWorldMatrix(), this._transformMatrices, index * 16);
  39. }
  40. this._identity.copyToArray(this._transformMatrices, this.bones.length * 16);
  41. this._isDirty = false;
  42. };
  43. Skeleton.prototype.getAnimatables = function () {
  44. if (!this._animatables || this._animatables.length != this.bones.length) {
  45. this._animatables = [];
  46. for (var index = 0; index < this.bones.length; index++) {
  47. this._animatables.push(this.bones[index]);
  48. }
  49. }
  50. return this._animatables;
  51. };
  52. Skeleton.prototype.clone = function (name, id) {
  53. var result = new BABYLON.Skeleton(name, id || name, this._scene);
  54. for (var index = 0; index < this.bones.length; index++) {
  55. var source = this.bones[index];
  56. var parentBone = null;
  57. if (source.getParent()) {
  58. var parentIndex = this.bones.indexOf(source.getParent());
  59. parentBone = result.bones[parentIndex];
  60. }
  61. var bone = new BABYLON.Bone(source.name, result, parentBone, source.getBaseMatrix());
  62. BABYLON.Tools.DeepCopy(source.animations, bone.animations);
  63. }
  64. return result;
  65. };
  66. return Skeleton;
  67. })();
  68. BABYLON.Skeleton = Skeleton;
  69. })(BABYLON || (BABYLON = {}));
  70. //# sourceMappingURL=babylon.skeleton.js.map