* Fix animation frame_speed and blend loosing precision due to incorrect data type
Add lua function set_animation_frame_speed to update the frame speed without resetting the animation to start
* `set_wielded_item(item)`: replaces the wielded item, returns `true` if successful
* `set_armor_groups({group1=rating, group2=rating, ...})`
* `get_armor_groups()`: returns a table with the armor group ratings
-* `set_animation({x=1,y=1}, frame_speed=15, frame_blend=0, frame_loop=true)`
+* `set_animation({x=1,y=1}, frame_speed=15.0, frame_blend=0, frame_loop=true)`
* `get_animation()`: returns `range`, `frame_speed`, `frame_blend` and `frame_loop`
+* `set_animation_frame_speed(frame_speed=15.0)`
* `set_attach(parent, bone, position, rotation)`
* `bone`: string
* `position`: `{x=num, y=num, z=num}` (relative)
#endif
}
+void GenericCAO::updateAnimationSpeed()
+{
+ if (!m_animated_meshnode)
+ return;
+
+ m_animated_meshnode->setAnimationSpeed(m_animation_speed);
+}
+
void GenericCAO::updateBonePosition()
{
- if(m_bone_position.empty() || !m_animated_meshnode)
+ if (m_bone_position.empty() || !m_animated_meshnode)
return;
m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render
updateAnimation();
}
}
+ } else if (cmd == GENERIC_CMD_SET_ANIMATION_SPEED) {
+ m_animation_speed = readF1000(is);
+ updateAnimationSpeed();
} else if (cmd == GENERIC_CMD_SET_BONE_POSITION) {
std::string bone = deSerializeString(is);
v3f position = readV3F1000(is);
bool m_initial_tx_basepos_set = false;
bool m_tx_select_horiz_by_yawpitch = false;
v2s32 m_animation_range;
- int m_animation_speed = 15;
- int m_animation_blend = 0;
+ float m_animation_speed = 15.0f;
+ float m_animation_blend = 0.0f;
bool m_animation_loop = true;
// stores position and rotation for each bone name
std::unordered_map<std::string, core::vector2d<v3f>> m_bone_position;
void updateAnimation();
+ void updateAnimationSpeed();
+
void updateBonePosition();
void updateAttachments();
*frame_loop = m_animation_loop;
}
+void UnitSAO::setAnimationSpeed(float frame_speed)
+{
+ m_animation_speed = frame_speed;
+ m_animation_speed_sent = false;
+}
+
void UnitSAO::setBonePosition(const std::string &bone, v3f position, v3f rotation)
{
// store these so they can be updated to clients
m_messages_out.push(aom);
}
+ if (!m_animation_speed_sent) {
+ m_animation_speed_sent = true;
+ std::string str = gob_cmd_update_animation_speed(m_animation_speed);
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), true, str);
+ m_messages_out.push(aom);
+ }
+
if (!m_bone_position_sent) {
m_bone_position_sent = true;
for (std::unordered_map<std::string, core::vector2d<v3f>>::const_iterator
const ItemGroupList &getArmorGroups();
void setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop);
void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop);
+ void setAnimationSpeed(float frame_speed);
void setBonePosition(const std::string &bone, v3f position, v3f rotation);
void getBonePosition(const std::string &bone, v3f *position, v3f *rotation);
void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation);
float m_animation_blend = 0.0f;
bool m_animation_loop = true;
bool m_animation_sent = false;
+ bool m_animation_speed_sent = false;
// Stores position and rotation for each bone name
std::unordered_map<std::string, core::vector2d<v3f>> m_bone_position;
return os.str();
}
+std::string gob_cmd_update_animation_speed(float frame_speed)
+{
+ std::ostringstream os(std::ios::binary);
+ // command
+ writeU8(os, GENERIC_CMD_SET_ANIMATION_SPEED);
+ // parameters
+ writeF1000(os, frame_speed);
+ return os.str();
+}
+
std::string gob_cmd_update_bone_position(const std::string &bone, v3f position,
v3f rotation)
{
GENERIC_CMD_ATTACH_TO,
GENERIC_CMD_SET_PHYSICS_OVERRIDE,
GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES,
- GENERIC_CMD_SPAWN_INFANT
+ GENERIC_CMD_SPAWN_INFANT,
+ GENERIC_CMD_SET_ANIMATION_SPEED
};
#include "object_properties.h"
std::string gob_cmd_update_animation(v2f frames, float frame_speed, float frame_blend, bool frame_loop);
+std::string gob_cmd_update_animation_speed(float frame_speed);
+
std::string gob_cmd_update_bone_position(const std::string &bone, v3f position,
v3f rotation);
return 2;
}
+// set_animation_frame_speed(self, frame_speed)
+int ObjectRef::l_set_animation_frame_speed(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ ServerActiveObject *co = getobject(ref);
+ if (co == NULL)
+ return 0;
+
+ // Do it
+ if (!lua_isnil(L, 2)) {
+ float frame_speed = lua_tonumber(L, 2);
+ co->setAnimationSpeed(frame_speed);
+ lua_pushboolean(L, true);
+ } else {
+ lua_pushboolean(L, false);
+ }
+ return 1;
+}
+
// set_bone_position(self, std::string bone, v3f position, v3f rotation)
int ObjectRef::l_set_bone_position(lua_State *L)
{
luamethod(ObjectRef, get_armor_groups),
luamethod(ObjectRef, set_animation),
luamethod(ObjectRef, get_animation),
+ luamethod(ObjectRef, set_animation_frame_speed),
luamethod(ObjectRef, set_bone_position),
luamethod(ObjectRef, get_bone_position),
luamethod(ObjectRef, set_attach),
// set_animation(self, frame_range, frame_speed, frame_blend, frame_loop)
static int l_set_animation(lua_State *L);
+ // set_animation_frame_speed(self, frame_speed)
+ static int l_set_animation_frame_speed(lua_State *L);
+
// get_animation(self)
static int l_get_animation(lua_State *L);
{}
virtual void getAnimation(v2f *frames, float *frame_speed, float *frame_blend, bool *frame_loop)
{}
+ virtual void setAnimationSpeed(float frame_speed)
+ {}
virtual void setBonePosition(const std::string &bone, v3f position, v3f rotation)
{}
virtual void getBonePosition(const std::string &bone, v3f *position, v3f *lotation)