1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Get the new animation framework properly working

Store start and end frames as v2f

Also move bone animations to their own function instead of object properties
This commit is contained in:
MirceaKitsune 2012-10-26 18:03:24 +03:00 committed by Perttu Ahola
parent ba4d93027f
commit 118285e6ba
10 changed files with 139 additions and 135 deletions

View file

@ -576,6 +576,10 @@ private:
v2s16 m_tx_basepos;
bool m_initial_tx_basepos_set;
bool m_tx_select_horiz_by_yawpitch;
v2f m_frames;
int m_frame_speed;
int m_frame_blend;
std::map<std::string, core::vector2d<v3f> > m_bone_posrot;
int m_anim_frame;
int m_anim_num_frames;
float m_anim_framelength;
@ -924,6 +928,8 @@ public:
m_visuals_expired = false;
removeFromScene();
addToScene(m_smgr, m_gamedef->tsrc(), m_irr);
updateAnimations();
updateBonePosRot();
}
if(m_prop.physical){
@ -1136,32 +1142,27 @@ public:
}
}
void updateAnimations(int frame_start, int frame_end, float frame_speed, float frame_blend)
void updateAnimations()
{
if(!m_animated_meshnode)
return;
m_animated_meshnode->setFrameLoop(frame_start, frame_end);
m_animated_meshnode->setAnimationSpeed(frame_speed);
m_animated_meshnode->setTransitionTime(frame_blend);
m_animated_meshnode->setFrameLoop((int)m_frames.X, (int)m_frames.Y);
m_animated_meshnode->setAnimationSpeed(m_frame_speed);
m_animated_meshnode->setTransitionTime(m_frame_blend);
}
if(m_prop.animation_bone_position.size() > 0)
void updateBonePosRot()
{
if(m_bone_posrot.size() > 0)
{
for(std::map<std::string, v3f>::const_iterator ii = m_prop.animation_bone_position.begin(); ii != m_prop.animation_bone_position.end(); ++ii){
m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render
m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render
for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_posrot.begin(); ii != m_bone_posrot.end(); ++ii){
std::string bone_name = (*ii).first;
v3f bone_pos = (*ii).second;
v3f bone_pos = (*ii).second.X;
v3f bone_rot = (*ii).second.Y;
irr::scene::IBoneSceneNode* bone = m_animated_meshnode->getJointNode(bone_name.c_str());
bone->setPosition(bone_pos);
}
}
if(m_prop.animation_bone_rotation.size() > 0)
{
for(std::map<std::string, v3f>::const_iterator ii = m_prop.animation_bone_rotation.begin(); ii != m_prop.animation_bone_rotation.end(); ++ii){
m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render
std::string bone_name = (*ii).first;
v3f bone_rot = (*ii).second;
irr::scene::IBoneSceneNode* bone = m_animated_meshnode->getJointNode(bone_name.c_str());
bone->setRotation(bone_rot);
}
}
@ -1236,12 +1237,22 @@ public:
}
else if(cmd == GENERIC_CMD_SET_ANIMATIONS)
{
int frame_start = readU16(is);
int frame_end = readU16(is);
float frame_speed = readF1000(is);
float frame_blend = readF1000(is);
m_frames = readV2F1000(is);
m_frame_speed = readF1000(is);
m_frame_blend = readF1000(is);
updateAnimations(frame_start, frame_end, frame_speed, frame_blend);
updateAnimations();
expireVisuals();
}
else if(cmd == GENERIC_CMD_SET_BONE_POSROT)
{
std::string bone = deSerializeString(is);
v3f position = readV3F1000(is);
v3f rotation = readV3F1000(is);
m_bone_posrot[bone] = core::vector2d<v3f>(position, rotation);
updateBonePosRot();
expireVisuals();
}
else if(cmd == GENERIC_CMD_PUNCHED)
{