From: DaveG <da...@us...> - 2005-12-08 19:39:43
|
Update of /cvsroot/planeshift/planeshift/src/common/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9948/src/common/util Modified Files: psmeshutil.cpp psmeshutil.h Log Message: Failed texture changes will now keep the last valid texture, instead of resorting to checkerboard. Index: psmeshutil.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/util/psmeshutil.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** psmeshutil.cpp 8 Dec 2005 16:57:46 -0000 1.3 --- psmeshutil.cpp 8 Dec 2005 19:39:32 -0000 1.4 *************** *** 26,29 **** --- 26,30 ---- #include <iutil/object.h> #include <iutil/objreg.h> + #include <iutil/vfs.h> #include <iengine/engine.h> #include <iengine/material.h> *************** *** 41,44 **** --- 42,46 ---- engine = CS_QUERY_REGISTRY (obj_reg, iEngine); loader = CS_QUERY_REGISTRY (obj_reg, iLoader); + vfs = CS_QUERY_REGISTRY (obj_reg, iVFS); g3d = CS_QUERY_REGISTRY (obj_reg, iGraphics3D); txtmgr = g3d->GetTextureManager(); *************** *** 49,74 **** if ( !name || !texture ) return NULL; ! ! iMaterialWrapper *mat_wrapper = NULL; ! mat_wrapper = engine->FindMaterial( name ); if ( mat_wrapper ) return mat_wrapper; csRef<iTextureHandle> th = loader->LoadTexture(texture); if ( !th ) return NULL; ! iTextureWrapper *tex_wrapper; // Add the texture to the engine's list of textures ! iTextureList *txlist = engine->GetTextureList(); ! tex_wrapper = txlist->NewTexture(th); ! ! // Create the material and register with the engine mat_wrapper = engine->CreateMaterial(name,tex_wrapper); ! ! if (region) region->Add(mat_wrapper->QueryObject()); ! return mat_wrapper; } --- 51,82 ---- if ( !name || !texture ) return NULL; ! ! iMaterialWrapper* mat_wrapper = engine->FindMaterial(name); if ( mat_wrapper ) return mat_wrapper; + // Check to see if we even have this texture + if ( !vfs->Exists(texture) ) + return NULL; + csRef<iTextureHandle> th = loader->LoadTexture(texture); if ( !th ) return NULL; ! iTextureList *txlist = engine->GetTextureList(); ! if ( !txlist ) ! return NULL; // Add the texture to the engine's list of textures ! iTextureWrapper* tex_wrapper = txlist->NewTexture(th); ! if ( !tex_wrapper ) ! return NULL; ! ! // Create the material and register it with the engine mat_wrapper = engine->CreateMaterial(name,tex_wrapper); ! ! if (region && mat_wrapper) region->Add(mat_wrapper->QueryObject()); ! return mat_wrapper; } *************** *** 108,112 **** if ( !material ) { ! Error3("Failed to load material for mesh \"%s\" with texture \"%s\"",meshNameParsed,textureNameParsed); return false; } --- 116,120 ---- if ( !material ) { ! Error3("Failed to load texture \"%s\" for part \"%s\"",textureNameParsed,part); return false; } Index: psmeshutil.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/util/psmeshutil.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** psmeshutil.h 3 Dec 2005 08:37:44 -0000 1.1 --- psmeshutil.h 8 Dec 2005 19:39:32 -0000 1.2 *************** *** 26,29 **** --- 26,30 ---- struct iEngine; struct iLoader; + struct iVFS; struct iTextureManager; struct iGraphics3D; *************** *** 36,51 **** psMeshUtil(iObjectRegistry *obj_reg); ! /** returns an iMaterialWrapper to the given texture, creates one if one doesn't exist. ! * @param name the name of the texture, as stored in CS ! * @param texture the vfs file path to the texture ! * @param region the region to add the effect to (leave 0 for none) ! * @return NULL on failure, the iMaterialWrapper of the texture on success ! */ iMaterialWrapper* LoadMaterial(const char* name, const char* texture, iRegion* region=0 ); /** Parse the string and change $F with factname * @param mesh The object to take data from * @param str The string to parse - * * @return Resulting string with replased variables. */ --- 37,53 ---- psMeshUtil(iObjectRegistry *obj_reg); ! /** Returns an iMaterialWrapper to the given texture, creates one if one doesn't exist. ! * ! * @param name the name of the texture, as stored in CS ! * @param texture the vfs file path to the texture ! * @param region the region to add the effect to (leave 0 for none) ! * @return NULL on failure, the iMaterialWrapper of the texture on success ! */ iMaterialWrapper* LoadMaterial(const char* name, const char* texture, iRegion* region=0 ); /** Parse the string and change $F with factname + * * @param mesh The object to take data from * @param str The string to parse * @return Resulting string with replased variables. */ *************** *** 53,70 **** /** Changes the material that is on a mesh. ! * Assumes that the mesh is infact a cal3d state mesh. ! * @param mesh The main mesh wrapper ! * @param part The name of the sub mesh that we want to change the material on. ! * @param material The name of the new material that this part( submesh ) should be. ! * @param texture The name of the texture to be used for material if material not found. ! * ! * @return true if the material was placed on the mesh successfully. ! */ bool ChangeMaterial(iMeshWrapper* mesh, const char* part, const char* material, const char* texture); /** Changes the materail on a submesh back to the default material. * @param mesh The main mesh wrapper * @param part The name of the sub mesh that we want to revert back to using default. - * * @return true if the default material was placed back on the submesh. */ --- 55,72 ---- /** Changes the material that is on a mesh. ! * Assumes that the mesh is infact a cal3d state mesh. ! * ! * @param mesh The main mesh wrapper ! * @param part The name of the sub mesh that we want to change the material on. ! * @param material The name of the new material that this part (submesh) should be. ! * @param texture The name of the texture to be used for material if material not found. ! * @return true if the material was placed on the mesh successfully. ! */ bool ChangeMaterial(iMeshWrapper* mesh, const char* part, const char* material, const char* texture); /** Changes the materail on a submesh back to the default material. + * * @param mesh The main mesh wrapper * @param part The name of the sub mesh that we want to revert back to using default. * @return true if the default material was placed back on the submesh. */ *************** *** 76,81 **** * @param socket The name of the socket to attach to. * @param meshName The name of the mesh that should be attached. ! * ! * @param True if the mesh was attached properly. */ bool Attach(iMeshWrapper* mesh, const char* socket, const char* meshName); --- 78,82 ---- * @param socket The name of the socket to attach to. * @param meshName The name of the mesh that should be attached. ! * @return True if the mesh was attached properly. */ bool Attach(iMeshWrapper* mesh, const char* socket, const char* meshName); *************** *** 85,89 **** * @param mesh The parent mesh that has the child mesh attached. * @param socket The name of the socket to remove the mesh from. - * * @return True if the detach was successful. */ --- 86,89 ---- *************** *** 94,97 **** --- 94,98 ---- csRef<iEngine> engine; csRef<iLoader> loader; + csRef<iVFS> vfs; csRef<iGraphics3D> g3d; csRef<iTextureManager> txtmgr; |