Fix dropped nodeitem visuals

master
Perttu Ahola 2012-04-04 13:16:09 +03:00
parent b9b56bac6b
commit b22168d3da
6 changed files with 58 additions and 42 deletions

View File

@ -12,7 +12,7 @@ minetest.register_entity("__builtin:item", {
initial_properties = { initial_properties = {
hp_max = 1, hp_max = 1,
physical = true, physical = true,
collisionbox = {-0.25,-0.25,-0.25, 0.25,0.25,0.25}, collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17},
visual = "sprite", visual = "sprite",
visual_size = {x=0.5, y=0.5}, visual_size = {x=0.5, y=0.5},
textures = {""}, textures = {""},
@ -33,14 +33,26 @@ minetest.register_entity("__builtin:item", {
itemname = stack:to_table().name itemname = stack:to_table().name
end end
local item_texture = nil local item_texture = nil
local item_type = ""
if minetest.registered_items[itemname] then if minetest.registered_items[itemname] then
item_texture = minetest.registered_items[itemname].inventory_image item_texture = minetest.registered_items[itemname].inventory_image
item_type = minetest.registered_items[itemname].type
end end
item_texture = item_texture or "unknown_item.png" prop = {
self.object:set_properties({
textures = {item_texture},
is_visible = true, is_visible = true,
}) visual = "sprite",
textures = {"unknown_item.png"}
}
if item_texture and item_texture ~= "" then
prop.visual = "sprite"
prop.textures = {item_texture}
else
prop.visual = "wielditem"
prop.textures = {itemname}
prop.visual_size = {x=0.20, y=0.20}
prop.automatic_rotate = math.pi * 0.25
end
self.object:set_properties(prop)
end, end,
get_staticdata = function(self) get_staticdata = function(self)

View File

@ -781,9 +781,27 @@ public:
m_meshnode = smgr->addMeshSceneNode(mesh, NULL); m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
mesh->drop(); mesh->drop();
m_meshnode->setScale(v3f(1)); m_meshnode->setScale(v3f(m_prop.visual_size.X/2,
m_prop.visual_size.Y/2,
m_prop.visual_size.X/2));
u8 li = m_last_light; u8 li = m_last_light;
setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li)); setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
} else if(m_prop.visual == "wielditem"){
infostream<<"GenericCAO::addToScene(): node"<<std::endl;
infostream<<"textures: "<<m_prop.textures.size()<<std::endl;
if(m_prop.textures.size() >= 1){
infostream<<"textures[0]: "<<m_prop.textures[0]<<std::endl;
IItemDefManager *idef = m_gamedef->idef();
ItemStack item(m_prop.textures[0], 1, 0, "", idef);
scene::IMesh *mesh = item.getDefinition(idef).wield_mesh;
m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
m_meshnode->setScale(v3f(m_prop.visual_size.X/2,
m_prop.visual_size.Y/2,
m_prop.visual_size.X/2));
u8 li = m_last_light;
setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
}
} else { } else {
infostream<<"GenericCAO::addToScene(): \""<<m_prop.visual infostream<<"GenericCAO::addToScene(): \""<<m_prop.visual
<<"\" not supported"<<std::endl; <<"\" not supported"<<std::endl;
@ -916,6 +934,10 @@ public:
updateTextures(""); updateTextures("");
} }
} }
if(fabs(m_prop.automatic_rotate > 0.001)){
m_yaw += dtime * m_prop.automatic_rotate * 180 / PI;
updateNodePos();
}
} }
void updateTexturePos() void updateTexturePos()
@ -1064,7 +1086,8 @@ public:
m_position = readV3F1000(is); m_position = readV3F1000(is);
m_velocity = readV3F1000(is); m_velocity = readV3F1000(is);
m_acceleration = readV3F1000(is); m_acceleration = readV3F1000(is);
m_yaw = readF1000(is); if(fabs(m_prop.automatic_rotate < 0.001))
m_yaw = readF1000(is);
bool do_interpolate = readU8(is); bool do_interpolate = readU8(is);
bool is_end_position = readU8(is); bool is_end_position = readU8(is);
float update_interval = readF1000(is); float update_interval = readF1000(is);

View File

@ -25,43 +25,14 @@ std::string gob_cmd_set_properties(const ObjectProperties &prop)
{ {
std::ostringstream os(std::ios::binary); std::ostringstream os(std::ios::binary);
writeU8(os, GENERIC_CMD_SET_PROPERTIES); writeU8(os, GENERIC_CMD_SET_PROPERTIES);
writeS16(os, prop.hp_max); prop.serialize(os);
writeU8(os, prop.physical);
writeF1000(os, prop.weight);
writeV3F1000(os, prop.collisionbox.MinEdge);
writeV3F1000(os, prop.collisionbox.MaxEdge);
os<<serializeString(prop.visual);
writeV2F1000(os, prop.visual_size);
writeU16(os, prop.textures.size());
for(u32 i=0; i<prop.textures.size(); i++){
os<<serializeString(prop.textures[i]);
}
writeV2S16(os, prop.spritediv);
writeV2S16(os, prop.initial_sprite_basepos);
writeU8(os, prop.is_visible);
writeU8(os, prop.makes_footstep_sound);
return os.str(); return os.str();
} }
ObjectProperties gob_read_set_properties(std::istream &is) ObjectProperties gob_read_set_properties(std::istream &is)
{ {
ObjectProperties prop; ObjectProperties prop;
prop.hp_max = readS16(is); prop.deSerialize(is);
prop.physical = readU8(is);
prop.weight = readF1000(is);
prop.collisionbox.MinEdge = readV3F1000(is);
prop.collisionbox.MaxEdge = readV3F1000(is);
prop.visual = deSerializeString(is);
prop.visual_size = readV2F1000(is);
prop.textures.clear();
u32 texture_count = readU16(is);
for(u32 i=0; i<texture_count; i++){
prop.textures.push_back(deSerializeString(is));
}
prop.spritediv = readV2S16(is);
prop.initial_sprite_basepos = readV2S16(is);
prop.is_visible = readU8(is);
prop.makes_footstep_sound = readU8(is);
return prop; return prop;
} }

View File

@ -33,7 +33,8 @@ ObjectProperties::ObjectProperties():
spritediv(1,1), spritediv(1,1),
initial_sprite_basepos(0,0), initial_sprite_basepos(0,0),
is_visible(true), is_visible(true),
makes_footstep_sound(false) makes_footstep_sound(false),
automatic_rotate(0)
{ {
textures.push_back("unknown_object.png"); textures.push_back("unknown_object.png");
} }
@ -54,12 +55,13 @@ std::string ObjectProperties::dump()
os<<"]"; os<<"]";
os<<", spritediv="<<PP2(spritediv); os<<", spritediv="<<PP2(spritediv);
os<<", initial_sprite_basepos="<<PP2(initial_sprite_basepos); os<<", initial_sprite_basepos="<<PP2(initial_sprite_basepos);
os<<", is_visible"<<is_visible; os<<", is_visible="<<is_visible;
os<<", makes_footstep_sound="<<makes_footstep_sound; os<<", makes_footstep_sound="<<makes_footstep_sound;
os<<", automatic_rotate="<<automatic_rotate;
return os.str(); return os.str();
} }
void ObjectProperties::serialize(std::ostream &os) void ObjectProperties::serialize(std::ostream &os) const
{ {
writeU8(os, 1); // version writeU8(os, 1); // version
writeS16(os, hp_max); writeS16(os, hp_max);
@ -77,6 +79,7 @@ void ObjectProperties::serialize(std::ostream &os)
writeV2S16(os, initial_sprite_basepos); writeV2S16(os, initial_sprite_basepos);
writeU8(os, is_visible); writeU8(os, is_visible);
writeU8(os, makes_footstep_sound); writeU8(os, makes_footstep_sound);
writeF1000(os, automatic_rotate);
} }
void ObjectProperties::deSerialize(std::istream &is) void ObjectProperties::deSerialize(std::istream &is)
@ -100,6 +103,9 @@ void ObjectProperties::deSerialize(std::istream &is)
initial_sprite_basepos = readV2S16(is); initial_sprite_basepos = readV2S16(is);
is_visible = readU8(is); is_visible = readU8(is);
makes_footstep_sound = readU8(is); makes_footstep_sound = readU8(is);
try{
automatic_rotate = readF1000(is);
}catch(SerializationError &e){}
} }

View File

@ -38,10 +38,11 @@ struct ObjectProperties
v2s16 initial_sprite_basepos; v2s16 initial_sprite_basepos;
bool is_visible; bool is_visible;
bool makes_footstep_sound; bool makes_footstep_sound;
float automatic_rotate;
ObjectProperties(); ObjectProperties();
std::string dump(); std::string dump();
void serialize(std::ostream &os); void serialize(std::ostream &os) const;
void deSerialize(std::istream &is); void deSerialize(std::istream &is);
}; };

View File

@ -915,6 +915,9 @@ static void read_object_properties(lua_State *L, int index,
getboolfield(L, -1, "is_visible", prop->is_visible); getboolfield(L, -1, "is_visible", prop->is_visible);
getboolfield(L, -1, "makes_footstep_sound", prop->makes_footstep_sound); getboolfield(L, -1, "makes_footstep_sound", prop->makes_footstep_sound);
getfloatfield(L, -1, "automatic_rotate", prop->automatic_rotate);
dstream<<"scriptapi: prop->automatic_rotate="
<<prop->automatic_rotate<<std::endl;
} }
/* /*