import register from "../util/register.js";
import * as m_armat from "../intern/armature.js";
import m_obj_util_fact from "../intern/obj_util.js";
import m_trans_fact from "../intern/transform.js";
import m_print_fact from "../intern/print.js";
/**
* API methods to control armature objects.
* @module armature
*/
function Armature(ns, exports) {
var m_obj_util = m_obj_util_fact(ns);
var m_trans = m_trans_fact(ns);
var m_print = m_print_fact(ns);
/**
* Get translation, scale and rotation quaternion of the armature's bone,
* defined in armature space.
* @method module:armature.get_bone_tsr
* @param {Object3D} armobj Armature object
* @param {string} bone_name Bone name
* @param {TSR} [dest] Destination vector
* @returns {?TSR} Destination vector
*/
exports.get_bone_tsr = function(armobj, bone_name, dest) {
if (!m_obj_util.is_armature(armobj))
return null;
if (!m_armat.check_bone(armobj, bone_name)) {
m_print.error("There is no bone: \"", bone_name, "\" in \"", armobj.name, "\".");
return null;
}
if (!dest)
dest = new Float32Array(8);
m_armat.get_bone_tsr(armobj, bone_name, false, false, dest);
return dest;
}
/**
* Get translation, scale and rotation quaternion of the armature's bone,
* defined in parent bone space.
* @method module:armature.get_bone_tsr_rel
* @param {Object3D} armobj Armature object
* @param {string} bone_name Bone name
* @param {TSR} [dest] Destination vector
* @returns {?TSR} Destination vector
*/
exports.get_bone_tsr_rel = function(armobj, bone_name, dest) {
if (!m_obj_util.is_armature(armobj))
return null;
if (!m_armat.check_bone(armobj, bone_name)) {
m_print.error("There is no bone: \"", bone_name, "\" in \"", armobj.name, "\".");
return null;
}
if (!dest)
dest = new Float32Array(8);
m_armat.get_bone_tsr(armobj, bone_name, false, true, dest);
return dest;
}
/**
* Set translation, scale and rotation quaternion of the armature's bone,
* defined in armature space.
* @method module:armature.set_bone_tsr
* @param {Object3D} armobj Armature object
* @param {string} bone_name Bone name
* @param {TSR} tsr Translation, scale and rotation quaternion
*/
exports.set_bone_tsr = function(armobj, bone_name, tsr) {
if (!m_obj_util.is_armature(armobj))
return;
if (!m_armat.check_bone(armobj, bone_name)) {
m_print.error("There is no bone: \"", bone_name, "\" in \"", armobj.name, "\".");
return;
}
m_armat.set_bone_tsr(armobj, bone_name, tsr, false);
m_trans.update_transform(armobj);
}
/**
* Set translation, scale and rotation quaternion of the armature's bone,
* defined in parent bone space.
* @method module:armature.set_bone_tsr_rel
* @param {Object3D} armobj Armature object
* @param {string} bone_name Bone name
* @param {TSR} tsr Translation, scale and rotation quaternion
*/
exports.set_bone_tsr_rel = function(armobj, bone_name, tsr) {
if (!m_obj_util.is_armature(armobj))
return;
if (!m_armat.check_bone(armobj, bone_name)) {
m_print.error("There is no bone: \"", bone_name, "\" in \"", armobj.name, "\".");
return;
}
m_armat.set_bone_tsr(armobj, bone_name, tsr, true);
m_trans.update_transform(armobj);
}
}
var armature_factory = register("armature", Armature);
export default armature_factory;