Add a subfolder for models and transfer models from server to client
authorMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>
Tue, 23 Oct 2012 21:11:24 +0000 (00:11 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 25 Nov 2012 16:14:15 +0000 (18:14 +0200)
(obj, md2 and md3 are currently allowed)

Get rid of the texture string and use the existing textures array. Segmented meshes have multiple materials, and this will allow us to texture each. Do not switch to this commit yet!

If a texture string is left empty in LUA, don't modify that material. Useful so a script can change specific textures without affecting others

src/client.cpp
src/content_cao.cpp
src/object_properties.cpp
src/object_properties.h
src/scriptapi.cpp
src/server.cpp

index e47bce1421f76559c09d344e9a44f9ad44d6ae3e..504297a6d87fb5710e6ed970b98e4442b47b3421 100644 (file)
@@ -860,6 +860,25 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
                return true;
        }
 
+       const char *model_ext[] = {
+               ".b3d", ".md2", ".obj",
+               NULL
+       };
+       name = removeStringEnd(filename, model_ext);
+       if(name != "")
+       {
+               verbosestream<<"Client: Storing model into Irrlicht: "
+                               <<"file \""<<filename<<"\""<<std::endl;
+
+               io::IFileSystem *irrfs = m_device->getFileSystem();
+
+               // Create an irrlicht memory file
+               io::IReadFile *rfile = irrfs->createMemoryReadFile(*data_rw, data_rw.getSize(), filename.c_str(), true);
+               assert(rfile);
+               //rfile->drop();
+               return true;
+       }
+
        errorstream<<"Client: Don't know how to load file \""
                        <<filename<<"\""<<std::endl;
        return false;
index c0be4e4cd067c069e17f8c03031303870b504416..b3c0370b8a058977b8731dfdb973372535e3cfcc 100644 (file)
@@ -1060,16 +1060,26 @@ public:
                {
                        if(m_prop.visual == "mesh")
                        {
-                               // fallback texture
-                               if(m_prop.texture == "")
-                                       m_prop.texture = "unknown_block.png";
-                               video::IVideoDriver* driver = m_animated_meshnode->getSceneManager()->getVideoDriver();
-                               m_animated_meshnode->setMaterialTexture(0, driver->getTexture(m_prop.texture.c_str()));
-
-                               // Set material flags and texture
-                               video::SMaterial& material = m_animated_meshnode->getMaterial(0);
-                               material.setFlag(video::EMF_LIGHTING, false);
-                               material.setFlag(video::EMF_BILINEAR_FILTER, false);
+                               for (u32 i = 0; i < m_prop.textures.size(); ++i)
+                               {
+                                       std::string texturestring = m_prop.textures[i];
+                                       if(texturestring == "")
+                                               continue; // Empty texture string means don't modify that material
+                                       texturestring += mod;
+                                       video::IVideoDriver* driver = m_animated_meshnode->getSceneManager()->getVideoDriver();
+                                       video::ITexture* texture = driver->getTexture(texturestring.c_str());
+                                       if(!texture)
+                                       {
+                                               errorstream<<"GenericCAO::updateTextures(): Could not load texture "<<texturestring<<std::endl;
+                                               continue;
+                                       }
+
+                                       // Set material flags and texture
+                                       m_animated_meshnode->setMaterialTexture(i, texture);
+                                       video::SMaterial& material = m_animated_meshnode->getMaterial(i);
+                                       material.setFlag(video::EMF_LIGHTING, false);
+                                       material.setFlag(video::EMF_BILINEAR_FILTER, false);
+                               }
                        }
                }
                if(m_meshnode)
index 3a36addc75e57265f4a761bfb7552f21bacac3a2..c91384ada3569643534ea426ad1208825a2db962 100644 (file)
@@ -31,7 +31,6 @@ ObjectProperties::ObjectProperties():
        collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5),
        visual("sprite"),
        mesh(""),
-       texture(""),
        visual_size(1,1),
        spritediv(1,1),
        initial_sprite_basepos(0,0),
@@ -51,7 +50,6 @@ std::string ObjectProperties::dump()
        os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
        os<<", visual="<<visual;
        os<<", mesh="<<mesh;
-       os<<", texture="<<texture;
        os<<", visual_size="<<PP2(visual_size);
        os<<", textures=[";
        for(u32 i=0; i<textures.size(); i++){
@@ -76,7 +74,6 @@ void ObjectProperties::serialize(std::ostream &os) const
        writeV3F1000(os, collisionbox.MaxEdge);
        os<<serializeString(visual);
        os<<serializeString(mesh);
-       os<<serializeString(texture);
        writeV2F1000(os, visual_size);
        writeU16(os, textures.size());
        for(u32 i=0; i<textures.size(); i++){
@@ -101,7 +98,6 @@ void ObjectProperties::deSerialize(std::istream &is)
        collisionbox.MaxEdge = readV3F1000(is);
        visual = deSerializeString(is);
        mesh = deSerializeString(is);
-       texture = deSerializeString(is);
        visual_size = readV2F1000(is);
        textures.clear();
        u32 texture_count = readU16(is);
index f60ecefa471f61f30a8b8ecb73ed81dc58b45659..48240e6ea45fc9c3bf46f93d5ff772fa459b2396 100644 (file)
@@ -33,7 +33,6 @@ struct ObjectProperties
        core::aabbox3d<f32> collisionbox;
        std::string visual;
        std::string mesh;
-       std::string texture;
        v2f visual_size;
        core::array<std::string> textures;
        v2s16 spritediv;
index 7eda636e39163aa26bc769695d410858a5a7924c..9293e2b6535b2d62a96bcdfd6204b3f46201ff64 100644 (file)
@@ -938,7 +938,6 @@ static void read_object_properties(lua_State *L, int index,
        getstringfield(L, -1, "visual", prop->visual);
 
        getstringfield(L, -1, "mesh", prop->mesh);
-       getstringfield(L, -1, "texture", prop->texture);
        
        lua_getfield(L, -1, "visual_size");
        if(lua_istable(L, -1))
@@ -6591,6 +6590,8 @@ void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
        lua_pop(L, 1);
 
        getstringfield(L, -1, "visual", prop->visual);
+
+       getstringfield(L, -1, "mesh", prop->mesh);
        
        // Deprecated: read object properties directly
        read_object_properties(L, -1, prop);
index 2da9cbe24496253a7caddddc9b52d8ec08b5635d..92fd567e5163fa5dc2695c08c319ecb6eccad570 100644 (file)
@@ -4029,6 +4029,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 + "models");
        }
        std::string path_all = "textures";
        paths.push_back(path_all + DIR_DELIM + "all");
@@ -4054,6 +4055,7 @@ void Server::fillMediaCache()
                                ".png", ".jpg", ".bmp", ".tga",
                                ".pcx", ".ppm", ".psd", ".wal", ".rgb",
                                ".ogg",
+                               ".b3d", ".md2", ".obj",
                                NULL
                        };
                        if(removeStringEnd(filename, supported_ext) == ""){