44 #include "SkeletonEditingPlugin.hh" 47 #include <ObjectTypes/Skeleton/Helper/SkeletonTransform.hh> 48 #include <ACG/Geometry/Algorithms.hh> 57 emit setSlotDescription(
"splitBone(int,int)",
58 tr(
"insert a joint in the middle of a bone."),
59 QString(tr(
"objectId,jointId")).split(
","),
60 QString(tr(
"ID of an object,ID of tail joint")).split(
","));
64 "addJoint(int,int,Vector)",
65 tr(
"add a joint to the skeleton."),
66 QString(tr(
"objectId,jointId,Vector")).split(
","),
69 "ID of an object,ID of parent joint,Position for the new joint")).split(
72 emit setSlotDescription(
"deleteJoint(int,int)",
73 tr(
"delete a joint from the skeleton."),
74 QString(tr(
"objectId,jointId")).split(
","),
75 QString(tr(
"ID of an object,ID of a joint")).split(
","));
77 emit setSlotDescription(
78 "transformJoint(int,int,Matrix4x4)",
79 tr(
"transform a joint with a matrix."),
80 QString(tr(
"objectId,jointId,Matrix")).split(
","),
81 QString(tr(
"ID of an object,ID of a joint,transformation matrix")).split(
84 emit setSlotDescription(
"globalMatrix(int,int)",
85 tr(
"get the global matrix of a joint in the active pose."),
86 QString(tr(
"objectId,jointId")).split(
","),
87 QString(tr(
"ID of an object,ID of a joint")).split(
","));
89 emit setSlotDescription(
"localMatrix(int,int)",
90 tr(
"get the local matrix of a joint in the active pose."),
91 QString(tr(
"objectId,jointId")).split(
","),
92 QString(tr(
"ID of an object,ID of a joint")).split(
","));
94 emit setSlotDescription(
"globalTranslation(int,int)",
95 tr(
"get the global translation of a joint in the active pose."),
96 QString(tr(
"objectId,jointId")).split(
","),
97 QString(tr(
"ID of an object,ID of a joint")).split(
","));
99 emit setSlotDescription(
"localTranslation(int,int)",
100 tr(
"get the local translation of a joint in the active pose."),
101 QString(tr(
"objectId,jointId")).split(
","),
102 QString(tr(
"ID of an object,ID of a joint")).split(
","));
104 emit setSlotDescription(
"animationCount(int)",
105 tr(
"get the number of animations the skeleton has."),
106 QString(tr(
"objectId")).split(
","),
107 QString(tr(
"ID of an object")).split(
","));
109 emit setSlotDescription(
"frameCount(int,int)",
110 tr(
"get the number of frames a given animation has."),
111 QString(tr(
"objectId,animationIndex")).split(
","),
112 QString(tr(
"ID of an object,Index of an animation")).split(
","));
114 emit setSlotDescription(
"activeAnimation(int)",
115 tr(
"get the animation which is currently active."),
116 QString(tr(
"objectId")).split(
","),
117 QString(tr(
"ID of an object")).split(
","));
119 emit setSlotDescription(
"activeFrame(int)",
120 tr(
"get the frame which is currently active"),
121 QString(tr(
"objectId")).split(
","),
122 QString(tr(
"ID of an object")).split(
","));
126 "setActivePose(int,int,int)",
127 tr(
"set the active pose of the skeleton."),
128 QString(tr(
"objectId,animationIndex,frame")).split(
","),
129 QString(tr(
"ID of an object,Index of an animation,Index of a frame")).split(
134 "addAnimation(int,QString,int)",
135 tr(
"add an animation to the skeleton."),
136 QString(tr(
"objectId,AnimationName,frameCount")).split(
","),
139 "ID of an object,name for the animation,number of frames the animation should have")).split(
161 if (tailJoint == 0) {
164 tr(
"Cannot split bone. Unable to find joint with id ")
165 + QString::number(_tailJoint));
173 skeleton->
addJoint(headJoint, jointNew);
174 tailJoint->
setParent(jointNew, *skeleton);
190 if (animation != 0) {
193 for (
int iFrame = 0; iFrame < (int) animation->frameCount(); iFrame++) {
209 emit scriptInfo(
"splitBone( ObjectId, " + QString::number(_tailJoint) +
" )");
237 tr(
"Cannot add joint. Unable to find joint with id ")
238 + QString::number(_parent));
244 skeleton->
addJoint(parent, jointNew);
253 "addJoint( ObjectId, " + QString::number(_parent) +
", Vector(" 254 + QString::number(_position[0]) +
"," + QString::number(_position[1])
255 +
"," + QString::number(_position[2]) +
") )");
264 void SkeletonEditingPlugin::deleteJoint(
int _objectId,
int _jointId) {
282 tr(
"Cannot Remove joint. Unable to find joint with id ")
283 + QString::number(_jointId));
289 emit scriptInfo(
"deleteJoint( ObjectId, " + QString::number(_jointId) +
" )");
308 emit log(
LOGERR, tr(
"Unable to get object"));
314 if (skeletonObj == 0) {
315 emit log(
LOGERR, tr(
"Unable to get skeletonObject"));
322 emit log(
LOGERR, tr(
"Unable to get skeleton"));
329 emit log(
LOGERR, tr(
"Unable to get joint"));
333 bool recursiveJointTransformation = transformChildJoints_;
347 recursiveJointTransformation =
true;
364 transformer.
rotateJoint(joint, activePose, _matrix, transformAllFrames_);
377 if (_matrix(0, 0) != 1 || _matrix(1, 1) != 1 || _matrix(2, 2) != 1
378 || _matrix(0, 1) != 0 || _matrix(0, 2) != 0 || _matrix(1, 0) != 0
379 || _matrix(1, 2) != 0 || _matrix(2, 0) != 0 || _matrix(2, 1) != 0) {
381 transformer.
transformJoint(joint, _matrix, !recursiveJointTransformation);
385 if (_matrix(0, 3) == 0 && _matrix(1, 3) == 0 && _matrix(2, 3) == 0)
388 if (joint->isRoot()) {
419 bool parentIsNotBranch = (joint->
parent()->
size() == 1);
420 bool hasOneChild = (joint->
size() == 1);
427 double parentRotAngle = 0.0;
428 double jointRotAngle = 0.0;
438 std::vector<ACG::Vec3d> oldAnimJoint, oldAnimParent;
440 for (
unsigned int iFrame = 0; iFrame < skeleton->
animation(a)->frameCount(); iFrame++) {
464 if (!ACG::Geometry::rotationOfTwoVectors<double>(oldParentAxis, transParentAxis, parentRotAxis, parentRotAngle))
469 if (!ACG::Geometry::rotationOfTwoVectors<double>(oldJointAxis, transJointAxis, jointRotAxis, jointRotAngle))
473 if (parentIsNotBranch) {
477 parentRotMatrix.
rotate(parentRotAngle, parentRotAxis);
481 localParent *= parentRotMatrix;
489 jointRotMatrix.
rotate(jointRotAngle, jointRotAxis);
493 localJoint *= jointRotMatrix;
498 std::vector<ACG::Vec3d>::iterator jointIt, parentIt;
499 jointIt = oldAnimJoint.begin();
500 parentIt = oldAnimParent.begin();
502 for (
unsigned int iFrame = 0; iFrame < skeleton->
animation(a)->frameCount(); iFrame++) {
506 if (parentIsNotBranch) {
511 double parentRotAngle = 0.0;
512 if (!ACG::Geometry::rotationOfTwoVectors<double>(*parentIt, translatedParent, parentRotAxis,
519 parentRotMatrix.
rotate(parentRotAngle, parentRotAxis);
523 parentMat *= parentRotMatrix;
533 double jointRotAngle = 0.0;
535 if (!ACG::Geometry::rotationOfTwoVectors<double>(*jointIt, translatedAxis, jointRotAxis, jointRotAngle))
541 jointRotMatrix.
rotate(jointRotAngle, jointRotAxis);
545 localMat *= jointRotMatrix;
559 for (
int i = 0; i < 4; i++)
560 for (
int j = 0; j < 4; j++)
561 matString +=
" , " + QString::number(_matrix(i, j));
563 matString = matString.right(matString.length() - 3);
566 "transformJoint( ObjectId, " + QString::number(_jointId) +
", Matrix4x4(" 567 + matString +
" ) )");
585 emit log(
LOGERR, tr(
"Unable to get object"));
591 if (skeletonObj == 0) {
592 emit log(
LOGERR, tr(
"Unable to get skeletonObject"));
600 emit log(
LOGERR, tr(
"Unable to get joint"));
615 scriptInfo(
"globalMatrix( ObjectId, " + QString::number(_jointId) +
" )");
629 emit log(
LOGERR, tr(
"Unable to get object"));
635 if (skeletonObj == 0) {
636 emit log(
LOGERR, tr(
"Unable to get skeletonObject"));
644 emit log(
LOGERR, tr(
"Unable to get joint"));
658 emit scriptInfo(
"localMatrix( ObjectId, " + QString::number(_jointId) +
" )");
672 emit log(
LOGERR, tr(
"Unable to get object"));
678 if (skeletonObj == 0) {
679 emit log(
LOGERR, tr(
"Unable to get skeletonObject"));
687 emit log(
LOGERR, tr(
"Unable to get joint"));
702 "globalTranslation( ObjectId, " + QString::number(_jointId) +
" )");
716 emit log(
LOGERR, tr(
"Unable to get object"));
722 if (skeletonObj == 0) {
723 emit log(
LOGERR, tr(
"Unable to get skeletonObject"));
731 emit log(
LOGERR, tr(
"Unable to get joint"));
746 "localTranslation( ObjectId, " + QString::number(_jointId) +
" )");
760 emit log(
LOGERR, tr(
"Unable to get object"));
766 if (skeletonObj == 0) {
767 emit log(
LOGERR, tr(
"Unable to get skeletonObject"));
773 emit scriptInfo(
"animationCount( ObjectId )");
787 emit log(
LOGERR, tr(
"Unable to get object"));
793 if (skeletonObj == 0) {
794 emit log(
LOGERR, tr(
"Unable to get skeletonObject"));
800 if ((_animationIndex < 0) || (_animationIndex
802 emit log(
LOGERR, tr(
"Invalid animationIndex"));
807 "frameCount( ObjectId, " + QString::number(_animationIndex) +
" )");
808 return skeleton->
animation(_animationIndex)->frameCount();
821 emit log(
LOGERR, tr(
"Unable to get object"));
827 if (skeletonObj == 0) {
828 emit log(
LOGERR, tr(
"Unable to get skeletonObject"));
834 emit scriptInfo(
"activeAnimation( ObjectId )");
847 emit log(
LOGERR, tr(
"Unable to get object"));
853 if (skeletonObj == 0) {
854 emit log(
LOGERR, tr(
"Unable to get skeletonObject"));
860 emit scriptInfo(
"activeFrame( ObjectId )");
861 return handle.
frame();
874 emit log(
LOGERR, tr(
"Unable to get object"));
880 if (skeletonObj == 0) {
881 emit log(
LOGERR, tr(
"Unable to get skeletonObject"));
887 if ((_animationIndex < 0) || (_animationIndex
889 emit log(
LOGERR, tr(
"Invalid animationIndex"));
893 if ((_frame < 0) || (_frame
894 > (
int) skeleton->
animation(_animationIndex)->frameCount())) {
895 emit log(
LOGERR, tr(
"Invalid frame"));
904 "setActivePose( ObjectId, " + QString::number(_animationIndex) +
", " 905 + QString::number(_frame) +
")");
918 emit log(
LOGERR, tr(
"Unable to get object"));
924 if (skeletonObj == 0) {
925 emit log(
LOGERR, tr(
"Unable to get skeletonObject"));
932 emit log(
LOGERR, tr(
"Invalid frame count"));
936 std::string stdName = _name.toStdString();
939 emit log(
LOGERR, tr(
"Animation with this name already exists"));
948 for (
unsigned int i = 0; i < skeleton->animation(handle)->
frameCount(); i++) {
952 for (
unsigned int j = 0; j < skeleton->jointCount(); j++)
958 "addAnimation( ObjectId, " + _name +
", " + QString::number(_frames)
962 emit createBackup(_objectId,
"Add Animation",
UPDATE_ALL);
void setDescriptions()
Set Descriptions for Scripting Slots.
void rotate(Scalar angle, Scalar x, Scalar y, Scalar z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(8))
Topology updated.
unsigned int frameCount()
Returns the number of frames stored in this pose.
size_t animationIndex() const
Returns the animation index (zero based)
SkeletonObject * skeletonObject(BaseObjectData *_object)
Cast an BaseObject to a SkeletonObject if possible.
void setGlobalMatrix(unsigned int _joint, const Matrix &_global, bool _keepGlobalChildPositions=true)
Sets the global coordinate system.
size_t id() const
returns the joint id
size_t size() const
Returns the number of children.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void setGlobalTranslation(unsigned int _joint, const Vector &_position, bool _keepGlobalChildPositions=true)
Sets the global translation vector.
void setActivePose(int _objectId, int _animationIndex, int _frame)
set active pose
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
ACG::SceneGraph::SkeletonNodeT< Skeleton > * skeletonNode()
Returns the skeleton scenegraph node.
bool is_identity() const
check if the matrix is the identity ( up to an epsilon )
void transformJoint(int _objectId, int _jointId, Matrix4x4 _matrix)
transform joint with given matrix
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Joint * joint(const size_t &_index)
Returns the joint with the given index.
void removeJoint(typename SkeletonT< PointT >::Joint *_pJoint)
Remove the given joint from the tree.
Vector globalTranslation(int _objectId, int _jointId)
get global translation of a joint in the active pose
void identity()
setup an identity matrix
A general pose, used to store the frames of the animation.
Pose * pose(unsigned int _iFrame)
Returns a pointer to the pose stored in the given frame.
size_t frame() const
Returns the selected frame (zero based)
void addAnimation(int _objectId, QString _name, int _frames)
add animation
bool isValid() const
Returns true if the handle is valid.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(4))
Geometry updated.
void setParent(Joint *_newParent, SkeletonT< PointT > &_skeleton)
access parent of the joint
int activeFrame(int _objectId)
get active frame
void addJoint(int _objectId, int _parent, Vector _position)
add joint to the skeleton
ACG::Vec3d Vector
Standard Type for 3d Vector used for scripting.
Represents a single joint in the skeleton.
Pose * referencePose()
Returns a pointer to the reference pose.
void addJoint(typename SkeletonT< PointT >::Joint *_pParent, typename SkeletonT< PointT >::Joint *_pJoint)
Adds a joint as child of a given parent joint.
const Matrix & localMatrix(unsigned int _joint) const
Returns the local matrix for the given joint.
Matrix4x4 globalMatrix(int _objectId, int _jointId)
get global matrix of a joint in the active pose
int animationCount(int _objectId)
get the number of animations
Skeleton * skeleton(BaseObjectData *_object)
Get a skeleton from an object.
Vector localTranslation(int _objectId, int _jointId)
get local translation of a joint in the active pose
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
Joint * child(size_t _index)
Returns the child joint with the given index.
void splitBone(int _objectId, int _tailJoint)
insert a joint in the middle of a bone given by its (unique) tailJoint
Matrix4x4 localMatrix(int _objectId, int _jointId)
get local matrix of a joint in the active pose
int frameCount(int _objectId, int _animationIndex)
get the number of frames
ACG::Matrix4x4d Matrix4x4
Standard Type for a 4x4 Matrix used for scripting.
virtual void functionExists(QString _pluginName, QString _functionName, bool &_exists)
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
Joint * parent()
Returns the parent joint.
size_t animationCount()
Returns the number of animations stored in this skeleton.
int activeAnimation(int _objectId)
get active animation
Vector localTranslation(unsigned int _joint)
Returns the local translation vector.
const Matrix & globalMatrix(unsigned int _joint) const
Returns the global matrix for the given joint.
void setLocalMatrix(unsigned int _joint, const Matrix &_local, bool _keepLocalChildPositions=true)
Sets the local coordinate system.
A handle used to refer to an animation or to a specific frame in an animation.
Vector globalTranslation(unsigned int _joint)
Returns the global translation vector.