Added Jeija's 3D code, with a few edits from me

master
Joel Leclerc 2012-05-03 14:42:49 -06:00
parent b781e89238
commit efc626fb84
7 changed files with 35 additions and 2 deletions

View File

@ -1369,7 +1369,21 @@ public:
u8 li = m_last_light;
setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
}
} else {
}
else if(m_prop.visual == "file")
{
scene::IMesh *mesh = createMeshFromFile(m_prop.meshfile, v3f(BS,BS,BS), smgr);
m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
mesh->drop();
m_meshnode->setScale(v3f(m_prop.visual_size.X,
m_prop.visual_size.Y,
m_prop.visual_size.X));
u8 li = m_last_light;
setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
}
else
{
infostream<<"GenericCAO::addToScene(): \""<<m_prop.visual
<<"\" not supported"<<std::endl;
}

View File

@ -92,6 +92,13 @@ scene::IAnimatedMesh* createCubeMesh(v3f scale)
return anim_mesh;
}
scene::IAnimatedMesh* createMeshFromFile(std::string filename, v3f scale, scene::ISceneManager* smgr)
{
scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(smgr->getMesh(filename.c_str()));
scaleMesh(anim_mesh, scale); // also recalculates bounding box
return anim_mesh;
}
static scene::IAnimatedMesh* extrudeARGB(u32 twidth, u32 theight, u8 *data)
{
const s32 argb_wstep = 4 * twidth;

View File

@ -32,6 +32,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
scene::IAnimatedMesh* createCubeMesh(v3f scale);
/*
Create a mesh from a file.
*/
scene::IAnimatedMesh* createMeshFromFile(std::string filename, v3f scale, scene::ISceneManager* smgr);
/*
Create a new extruded mesh from a texture.
Maximum bounding box is (+-scale.X/2, +-scale.Y/2, +-scale.Z).

View File

@ -34,7 +34,8 @@ ObjectProperties::ObjectProperties():
initial_sprite_basepos(0,0),
is_visible(true),
makes_footstep_sound(false),
automatic_rotate(0)
automatic_rotate(0),
meshfile()
{
textures.push_back("unknown_object.png");
textures_3d.push_back("unknown_object.png");
@ -48,6 +49,7 @@ std::string ObjectProperties::dump()
os<<", weight="<<weight;
os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
os<<", visual="<<visual;
os<<", meshfile="<<meshfile;
os<<", visual_size="<<PP2(visual_size);
os<<", textures=[";
for(u32 i=0; i<textures.size(); i++){
@ -74,6 +76,7 @@ void ObjectProperties::serialize(std::ostream &os) const
writeV3F1000(os, collisionbox.MinEdge);
writeV3F1000(os, collisionbox.MaxEdge);
os<<serializeString(visual);
os<<serializeString(meshfile);
writeV2F1000(os, visual_size);
writeU16(os, textures.size());
for(u32 i=0; i<textures.size(); i++){
@ -101,6 +104,7 @@ void ObjectProperties::deSerialize(std::istream &is)
collisionbox.MinEdge = readV3F1000(is);
collisionbox.MaxEdge = readV3F1000(is);
visual = deSerializeString(is);
meshfile = deSerializeString(is);
visual_size = readV2F1000(is);
textures.clear();
u32 texture_count = readU16(is);

View File

@ -40,6 +40,7 @@ struct ObjectProperties
bool is_visible;
bool makes_footstep_sound;
float automatic_rotate;
std::string meshfile;
ObjectProperties();
std::string dump();

View File

@ -924,6 +924,7 @@ static void read_object_properties(lua_State *L, int index,
getboolfield(L, -1, "is_visible", prop->is_visible);
getboolfield(L, -1, "makes_footstep_sound", prop->makes_footstep_sound);
getfloatfield(L, -1, "automatic_rotate", prop->automatic_rotate);
getstringfield(L, -1, "meshfile", prop->meshfile);
}
/*

View File

@ -4094,6 +4094,7 @@ void Server::fillMediaCache()
paths.push_back(mod.path + DIR_DELIM + "textures");
paths.push_back(mod.path + DIR_DELIM + "sounds");
paths.push_back(mod.path + DIR_DELIM + "media");
paths.push_back(mod.path + DIR_DELIM + "meshes");
}
// Collect media file information from paths into cache