Get the mesh working through the memory cache properly. Most credit goes to celeron55 for the help on this code

Get the texture from memory as well

Add .x to the list of supported formats

Update LUA API documentation
This commit is contained in:
MirceaKitsune 2012-10-24 22:10:05 +03:00 committed by Perttu Ahola
parent f9675bd2b4
commit 9c8ba42750
4 changed files with 28 additions and 14 deletions

View File

@ -1227,8 +1227,9 @@ Object Properties
physical = true, physical = true,
weight = 5, weight = 5,
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
visual = "cube"/"sprite"/"upright_sprite", visual = "cube"/"sprite"/"upright_sprite"/"mesh",
visual_size = {x=1, y=1}, visual_size = {x=1, y=1},
mesh = "model",
textures = {}, -- number of required textures depends on visual textures = {}, -- number of required textures depends on visual
spritediv = {x=1, y=1}, spritediv = {x=1, y=1},
initial_sprite_basepos = {x=0, y=0}, initial_sprite_basepos = {x=0, y=0},

View File

@ -41,6 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "sound.h" #include "sound.h"
#include "util/string.h" #include "util/string.h"
#include "hex.h" #include "hex.h"
#include "IMeshCache.h"
static std::string getMediaCacheDir() static std::string getMediaCacheDir()
{ {
@ -820,8 +821,8 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
name = removeStringEnd(filename, image_ext); name = removeStringEnd(filename, image_ext);
if(name != "") if(name != "")
{ {
verbosestream<<"Client: Attempting to load image " verbosestream<<"Client: Storing image into Irrlicht: "
<<"file \""<<filename<<"\""<<std::endl; <<"\""<<filename<<"\""<<std::endl;
io::IFileSystem *irrfs = m_device->getFileSystem(); io::IFileSystem *irrfs = m_device->getFileSystem();
video::IVideoDriver *vdrv = m_device->getVideoDriver(); video::IVideoDriver *vdrv = m_device->getVideoDriver();
@ -854,28 +855,31 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
name = removeStringEnd(filename, sound_ext); name = removeStringEnd(filename, sound_ext);
if(name != "") if(name != "")
{ {
verbosestream<<"Client: Attempting to load sound " verbosestream<<"Client: Storing sound into Irrlicht: "
<<"file \""<<filename<<"\""<<std::endl; <<"\""<<filename<<"\""<<std::endl;
m_sound->loadSoundData(name, data); m_sound->loadSoundData(name, data);
return true; return true;
} }
const char *model_ext[] = { const char *model_ext[] = {
".b3d", ".md2", ".obj", ".x", ".b3d", ".md2", ".obj",
NULL NULL
}; };
name = removeStringEnd(filename, model_ext); name = removeStringEnd(filename, model_ext);
if(name != "") if(name != "")
{ {
verbosestream<<"Client: Storing model into Irrlicht: " verbosestream<<"Client: Storing model into Irrlicht: "
<<"file \""<<filename<<"\""<<std::endl; <<"\""<<filename<<"\""<<std::endl;
io::IFileSystem *irrfs = m_device->getFileSystem(); io::IFileSystem *irrfs = m_device->getFileSystem();
io::IReadFile *rfile = irrfs->createMemoryReadFile(
// Create an irrlicht memory file *data_rw, data_rw.getSize(), filename.c_str());
io::IReadFile *rfile = irrfs->createMemoryReadFile(*data_rw, data_rw.getSize(), filename.c_str(), true);
assert(rfile); assert(rfile);
//rfile->drop();
scene::ISceneManager *smgr = m_device->getSceneManager();
scene::IAnimatedMesh *mesh = smgr->getMesh(rfile);
smgr->getMeshCache()->addMesh(filename.c_str(), mesh);
return true; return true;
} }

View File

@ -979,6 +979,8 @@ public:
updateTexturePos(); updateTexturePos();
updateAnimations();
if(m_reset_textures_timer >= 0){ if(m_reset_textures_timer >= 0){
m_reset_textures_timer -= dtime; m_reset_textures_timer -= dtime;
if(m_reset_textures_timer <= 0){ if(m_reset_textures_timer <= 0){
@ -1066,8 +1068,7 @@ public:
if(texturestring == "") if(texturestring == "")
continue; // Empty texture string means don't modify that material continue; // Empty texture string means don't modify that material
texturestring += mod; texturestring += mod;
video::IVideoDriver* driver = m_animated_meshnode->getSceneManager()->getVideoDriver(); video::ITexture* texture = tsrc->getTextureRaw(texturestring);
video::ITexture* texture = driver->getTexture(texturestring.c_str());
if(!texture) if(!texture)
{ {
errorstream<<"GenericCAO::updateTextures(): Could not load texture "<<texturestring<<std::endl; errorstream<<"GenericCAO::updateTextures(): Could not load texture "<<texturestring<<std::endl;
@ -1135,6 +1136,14 @@ public:
} }
} }
void updateAnimations()
{
if(!m_animated_meshnode)
return;
m_animated_meshnode->setFrameLoop(0, 50);
}
void processMessage(const std::string &data) void processMessage(const std::string &data)
{ {
//infostream<<"GenericCAO: Got message"<<std::endl; //infostream<<"GenericCAO: Got message"<<std::endl;

View File

@ -4055,7 +4055,7 @@ void Server::fillMediaCache()
".png", ".jpg", ".bmp", ".tga", ".png", ".jpg", ".bmp", ".tga",
".pcx", ".ppm", ".psd", ".wal", ".rgb", ".pcx", ".ppm", ".psd", ".wal", ".rgb",
".ogg", ".ogg",
".b3d", ".md2", ".obj", ".x", ".b3d", ".md2", ".obj",
NULL NULL
}; };
if(removeStringEnd(filename, supported_ext) == ""){ if(removeStringEnd(filename, supported_ext) == ""){