Source: extern/armature.js

  1. import register from "../util/register.js";
  2. import * as m_armat from "../intern/armature.js";
  3. import m_obj_util_fact from "../intern/obj_util.js";
  4. import m_trans_fact from "../intern/transform.js";
  5. import m_print_fact from "../intern/print.js";
  6. /**
  7. * API methods to control armature objects.
  8. * @module armature
  9. */
  10. function Armature(ns, exports) {
  11. var m_obj_util = m_obj_util_fact(ns);
  12. var m_trans = m_trans_fact(ns);
  13. var m_print = m_print_fact(ns);
  14. /**
  15. * Get translation, scale and rotation quaternion of the armature's bone,
  16. * defined in armature space.
  17. * @method module:armature.get_bone_tsr
  18. * @param {Object3D} armobj Armature object
  19. * @param {string} bone_name Bone name
  20. * @param {TSR} [dest] Destination vector
  21. * @returns {?TSR} Destination vector
  22. */
  23. exports.get_bone_tsr = function(armobj, bone_name, dest) {
  24. if (!m_obj_util.is_armature(armobj))
  25. return null;
  26. if (!m_armat.check_bone(armobj, bone_name)) {
  27. m_print.error("There is no bone: \"", bone_name, "\" in \"", armobj.name, "\".");
  28. return null;
  29. }
  30. if (!dest)
  31. dest = new Float32Array(8);
  32. m_armat.get_bone_tsr(armobj, bone_name, false, false, dest);
  33. return dest;
  34. }
  35. /**
  36. * Get translation, scale and rotation quaternion of the armature's bone,
  37. * defined in parent bone space.
  38. * @method module:armature.get_bone_tsr_rel
  39. * @param {Object3D} armobj Armature object
  40. * @param {string} bone_name Bone name
  41. * @param {TSR} [dest] Destination vector
  42. * @returns {?TSR} Destination vector
  43. */
  44. exports.get_bone_tsr_rel = function(armobj, bone_name, dest) {
  45. if (!m_obj_util.is_armature(armobj))
  46. return null;
  47. if (!m_armat.check_bone(armobj, bone_name)) {
  48. m_print.error("There is no bone: \"", bone_name, "\" in \"", armobj.name, "\".");
  49. return null;
  50. }
  51. if (!dest)
  52. dest = new Float32Array(8);
  53. m_armat.get_bone_tsr(armobj, bone_name, false, true, dest);
  54. return dest;
  55. }
  56. /**
  57. * Set translation, scale and rotation quaternion of the armature's bone,
  58. * defined in armature space.
  59. * @method module:armature.set_bone_tsr
  60. * @param {Object3D} armobj Armature object
  61. * @param {string} bone_name Bone name
  62. * @param {TSR} tsr Translation, scale and rotation quaternion
  63. */
  64. exports.set_bone_tsr = function(armobj, bone_name, tsr) {
  65. if (!m_obj_util.is_armature(armobj))
  66. return;
  67. if (!m_armat.check_bone(armobj, bone_name)) {
  68. m_print.error("There is no bone: \"", bone_name, "\" in \"", armobj.name, "\".");
  69. return;
  70. }
  71. m_armat.set_bone_tsr(armobj, bone_name, tsr, false);
  72. m_trans.update_transform(armobj);
  73. }
  74. /**
  75. * Set translation, scale and rotation quaternion of the armature's bone,
  76. * defined in parent bone space.
  77. * @method module:armature.set_bone_tsr_rel
  78. * @param {Object3D} armobj Armature object
  79. * @param {string} bone_name Bone name
  80. * @param {TSR} tsr Translation, scale and rotation quaternion
  81. */
  82. exports.set_bone_tsr_rel = function(armobj, bone_name, tsr) {
  83. if (!m_obj_util.is_armature(armobj))
  84. return;
  85. if (!m_armat.check_bone(armobj, bone_name)) {
  86. m_print.error("There is no bone: \"", bone_name, "\" in \"", armobj.name, "\".");
  87. return;
  88. }
  89. m_armat.set_bone_tsr(armobj, bone_name, tsr, true);
  90. m_trans.update_transform(armobj);
  91. }
  92. }
  93. var armature_factory = register("armature", Armature);
  94. export default armature_factory;