lugre_material_L.cpp

Go to the documentation of this file.
00001 #include "lugre_prefix.h"
00002 #include "lugre_ogrewrapper.h"
00003 #include "lugre_luabind.h"
00004 #include "lugre_scripting.h"
00005 #include <Ogre.h>
00006 
00007 extern "C" {
00008     #include "lua.h"
00009     #include "lauxlib.h"
00010     #include "lualib.h"
00011 }
00012 
00013 
00014 
00015 namespace Lugre {
00016 
00017 /*
00018 
00019          createTextureUnitState(RenderTexture_name) 
00020         setTextureAddressingMode(clamp)
00021 
00022 
00023         // mat    bound to rttTex
00024         MaterialPtr mat = MaterialManager::getSingleton().create("RttMat",
00025             ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00026         TextureUnitState* t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RustedMetal.jpg");
00027         t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
00028         // Blend with base texture
00029         t->setColourOperationEx(LBX_BLEND_MANUAL, LBS_TEXTURE, LBS_CURRENT, ColourValue::White, 
00030             ColourValue::White, 0.25);
00031         t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
00032         t->setProjectiveTexturing(true, mReflectCam);
00033         
00034         lua : CreateMaterial :  MaterialPtr mat = MaterialManager::getSingleton().create("RttMat",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00035         cpp : load : MaterialPtr from name
00036         lua : CreateTextureUnitState : mat->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
00037 */
00038 
00039 /*
00040 todo : enable creating plain color materials
00041 todo : enable creating plain materials from textures
00042 todo : enable cloning and editing existing materials (change texture)
00043 todo : change alpha, depthwrite, clamp, filtering
00044 material matDebugGranny
00045 {
00046     technique
00047     {
00048         pass
00049         {
00050             //lighting off
00051             ambient 0.0 0.0 0.0
00052             diffuse 1.0 1.0 1.0
00053             cull_hardware none
00054             cull_software none
00055             
00056             texture_unit
00057             {
00058                 //texture Ut256_Robe_Gm.tga
00059                 texture UT256_Armor_Ring_V2.tga
00060                 //tex_address_mode clamp
00061                 //filtering none
00062             }
00063         }
00064     }
00065 }
00066 */
00067 
00068 class cMaterial_L { public:
00069     
00070     static void     LuaRegister (lua_State *L) {
00071         lua_register(L,"CloneMaterial",             &cMaterial_L::CloneMaterial);
00072         lua_register(L,"SaveTextureToFile",         &cMaterial_L::SaveTextureToFile);
00073         lua_register(L,"CreateMaterial",            &cMaterial_L::CreateMaterial);
00074         lua_register(L,"SetAmbient",                &cMaterial_L::SetAmbient);
00075         lua_register(L,"SetDiffuse",                &cMaterial_L::SetDiffuse);
00076         lua_register(L,"SetTextureIsAlpha",         &cMaterial_L::SetTextureIsAlpha);
00077         lua_register(L,"SetTexture",                &cMaterial_L::SetTexture);
00078         lua_register(L,"GetTexture",                &cMaterial_L::GetTexture);
00079         lua_register(L,"SetSceneBlend",             &cMaterial_L::SetSceneBlend);
00080         lua_register(L,"SetSceneBlending",          &cMaterial_L::SetSceneBlending);
00081         lua_register(L,"SetHardwareCulling",        &cMaterial_L::SetHardwareCulling);
00082         lua_register(L,"SetSoftwareCulling",        &cMaterial_L::SetSoftwareCulling);
00083         lua_register(L,"SetShaderParamByIndex",     &cMaterial_L::SetShaderParamByIndex);
00084         lua_register(L,"SetShaderParamByName",      &cMaterial_L::SetShaderParamByName);
00085         lua_register(L,"SetReceiveShadows",         &cMaterial_L::SetReceiveShadows);
00086         lua_register(L,"SetTextureAddressingMode",          &cMaterial_L::SetTextureAddressingMode);
00087         lua_register(L,"SetTextureFiltering",           &cMaterial_L::SetTextureFiltering);
00088 
00089         lua_register(L,"SetDepthWriteEnabled",      &cMaterial_L::SetDepthWriteEnabled);
00090         lua_register(L,"SetAlphaRejection",     &cMaterial_L::SetAlphaRejection);
00091         
00092         lua_register(L,"SetMaterialParam",      &cMaterial_L::SetMaterialParam);
00093         //~ lua_register(L,"SetMaterialTechniqueParam",     &cMaterial_L::SetMaterialTechniqueParam);
00094         //~ lua_register(L,"SetMaterialPassParam",      &cMaterial_L::SetMaterialPassParam);
00095             
00096         #define RegisterClassConstant(name,constant) cScripting::SetGlobal(L,#name,constant)
00097         RegisterClassConstant(TAM_WRAP,Ogre::TextureUnitState::TAM_WRAP);
00098         RegisterClassConstant(TAM_MIRROR,Ogre::TextureUnitState::TAM_MIRROR);
00099         RegisterClassConstant(TAM_CLAMP,Ogre::TextureUnitState::TAM_CLAMP);
00100         RegisterClassConstant(TAM_BORDER,Ogre::TextureUnitState::TAM_BORDER);
00101 
00102         RegisterClassConstant(TFO_NONE,Ogre::TFO_NONE);
00103         RegisterClassConstant(TFO_BILINEAR,Ogre::TFO_BILINEAR);
00104         RegisterClassConstant(TFO_TRILINEAR,Ogre::TFO_TRILINEAR);
00105         RegisterClassConstant(TFO_ANISOTROPIC,Ogre::TFO_ANISOTROPIC);
00106 
00107         RegisterClassConstant(SBT_TRANSPARENT_ALPHA,Ogre::SBT_TRANSPARENT_ALPHA);
00108         RegisterClassConstant(SBT_TRANSPARENT_COLOUR,Ogre::SBT_TRANSPARENT_COLOUR);
00109         RegisterClassConstant(SBT_ADD,Ogre::SBT_ADD);
00110         RegisterClassConstant(SBT_MODULATE,Ogre::SBT_MODULATE);
00111         RegisterClassConstant(SBT_REPLACE,Ogre::SBT_REPLACE);
00112 
00113         // alpha rejection compare functions
00114         RegisterClassConstant(CMPF_ALWAYS_FAIL,Ogre::CMPF_ALWAYS_FAIL);
00115         RegisterClassConstant(CMPF_ALWAYS_PASS,Ogre::CMPF_ALWAYS_PASS);
00116         RegisterClassConstant(CMPF_LESS,Ogre::CMPF_LESS);
00117         RegisterClassConstant(CMPF_LESS_EQUAL,Ogre::CMPF_LESS_EQUAL);
00118         RegisterClassConstant(CMPF_EQUAL,Ogre::CMPF_EQUAL);
00119         RegisterClassConstant(CMPF_NOT_EQUAL,Ogre::CMPF_NOT_EQUAL);
00120         RegisterClassConstant(CMPF_GREATER_EQUAL,Ogre::CMPF_GREATER_EQUAL);
00121         RegisterClassConstant(CMPF_GREATER,Ogre::CMPF_GREATER);
00122         #undef RegisterClassConstant    
00123 }
00124     
00125     
00127     static int      SaveTextureToFile   (lua_State *L) { PROFILE
00128         std::string sTexName        = luaL_checkstring(L,1);
00129         std::string sFilePath       = luaL_checkstring(L,2);
00130         
00131         // current texture
00132         Ogre::TexturePtr otex = Ogre::TextureManager::getSingleton().load(sTexName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00133         if (otex.isNull()) return 0;
00134             
00135         Ogre::TexturePtr tex = otex;
00136         if (0) {
00137             tex = Ogre::TextureManager::getSingleton().createManual(cOgreWrapper::GetSingleton().GetUniqueName(),
00138                 otex->getGroup(), otex->getTextureType(),
00139                 otex->getWidth(), otex->getHeight(), otex->getDepth(), otex->getFormat (), Ogre::TU_STATIC ); 
00140             
00141             // vram to vram blit before download to cpu-ram
00142             // inspired by http://www.ogre3d.org/phpBB2/viewtopic.php?t=22082 
00143             // assuming tex is your default texture and rtt is your render texture
00144             tex->getBuffer()->blit(otex->getBuffer()); 
00145         }
00146             
00147         // lock and read access buffer
00148         Ogre::HardwarePixelBufferSharedPtr b = tex->getBuffer();
00149         if (b.isNull()) return 0;
00150             
00151         // see also l_HueMesh in iris scripting
00152         
00153         Ogre::PixelFormat myformat = Ogre::PF_A8R8G8B8;
00154         int dstpixelsize = Ogre::PixelUtil::getNumElemBytes(myformat);
00155         int mysize = b->getWidth() * b->getHeight() * dstpixelsize;
00156         char *dst = new char[mysize + 1024*32]; // add a little security oversize
00157 
00158         b->blitToMemory(Ogre::PixelBox(Ogre::Box(0, 0, b->getWidth(), b->getHeight()),myformat,dst));
00159 
00160         Ogre::Image img;
00161         img.loadDynamicImage((Ogre::uchar*)dst,b->getWidth(), b->getHeight(),1,myformat);
00162         //Ogre::DataStreamPtr texstream(new Ogre::MemoryDataStream(dst_start, mysize));
00163         //img.loadRawData(texstream,box.getWidth(),box.getHeight(),myformat);
00164         img.save(sFilePath);
00165 
00166         // free memory
00167         delete [] dst;
00168         
00169         return 0;
00170     }
00171                 
00172                 
00173     
00175     static int      CloneMaterial   (lua_State *L) { PROFILE
00176         std::string sOldMatName         = luaL_checkstring(L,1);
00177         std::string sNewMatName         = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? luaL_checkstring(L,2) : cOgreWrapper::GetSingleton().GetUniqueName();
00178         Ogre::MaterialPtr oldmat = Ogre::MaterialManager::getSingleton().getByName(sOldMatName);
00179         if (oldmat.isNull()) { printf("warning, CloneMaterial : failed to load old mat %s\n",sOldMatName.c_str()); return 0; }
00180         Ogre::MaterialPtr newmat = oldmat->clone(sNewMatName);
00181         lua_pushstring(L,sNewMatName.c_str());
00182         return 1;
00183     }
00184     
00186     static int      CreateMaterial  (lua_State *L) { PROFILE
00187         std::string sMatName        = (lua_gettop(L) >= 1 && !lua_isnil(L,1)) ? luaL_checkstring(L,1) : cOgreWrapper::GetSingleton().GetUniqueName();
00188         Ogre::MaterialManager::getSingleton().create(sMatName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00189         lua_pushstring(L,sMatName.c_str());
00190         return 1;
00191     }
00192     
00194     static int      SetAmbient  (lua_State *L) { PROFILE
00195         std::string sMatName    = luaL_checkstring(L,1);
00196         int         iTech       = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ?    luaL_checkint(L,2) : 0;
00197         int         iPass       = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ?    luaL_checkint(L,3) : 0;
00198         float       r           = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ? luaL_checknumber(L,4) : 1.0;
00199         float       g           = (lua_gettop(L) >= 5 && !lua_isnil(L,5)) ? luaL_checknumber(L,5) : 1.0;
00200         float       b           = (lua_gettop(L) >= 6 && !lua_isnil(L,6)) ? luaL_checknumber(L,6) : 1.0;
00201         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00202         if (mat.isNull()) return 0;
00203         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00204         if (!mypass) return 0;
00205         mypass->setAmbient(r,g,b);
00206         return 0;
00207     }
00208     
00212     static int      SetShaderParamByIndex   (lua_State *L) { PROFILE
00213         std::string sMatName    = luaL_checkstring(L,1);
00214         int         iTech       = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ?    luaL_checkint(L,2) : 0;
00215         int         iPass       = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ?    luaL_checkint(L,3) : 0;
00216         int         iParam      = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ?    luaL_checkint(L,4) : 0;
00217         float       x           = (lua_gettop(L) >= 5 && !lua_isnil(L,5)) ? luaL_checknumber(L,5) : 1.0;
00218         float       y           = (lua_gettop(L) >= 6 && !lua_isnil(L,6)) ? luaL_checknumber(L,6) : 1.0;
00219         float       z           = (lua_gettop(L) >= 7 && !lua_isnil(L,7)) ? luaL_checknumber(L,7) : 1.0;
00220         float       w           = (lua_gettop(L) >= 8 && !lua_isnil(L,8)) ? luaL_checknumber(L,8) : 1.0;
00221         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00222         if (mat.isNull()) return 0;
00223         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00224         if (!mypass) return 0;
00225         Ogre::GpuProgramParametersSharedPtr p = mypass->getVertexProgramParameters();
00226         p->setConstant(iParam,Ogre::Vector4(x,y,z,w));
00227         mypass->setVertexProgramParameters(p);
00228         return 0;
00229     }
00230     
00234     static int      SetShaderParamByName    (lua_State *L) { PROFILE
00235         std::string sMatName    = luaL_checkstring(L,1);
00236         int         iTech       = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ?    luaL_checkint(L,2) : 0;
00237         int         iPass       = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ?    luaL_checkint(L,3) : 0;
00238         std::string sParam      = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ?    luaL_checkstring(L,4) : 0;
00239         float       x           = (lua_gettop(L) >= 5 && !lua_isnil(L,5)) ? luaL_checknumber(L,5) : 1.0;
00240         float       y           = (lua_gettop(L) >= 6 && !lua_isnil(L,6)) ? luaL_checknumber(L,6) : 1.0;
00241         float       z           = (lua_gettop(L) >= 7 && !lua_isnil(L,7)) ? luaL_checknumber(L,7) : 1.0;
00242         float       w           = (lua_gettop(L) >= 8 && !lua_isnil(L,8)) ? luaL_checknumber(L,8) : 1.0;
00243         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00244         if (mat.isNull()) return 0;
00245         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00246         if (!mypass) return 0;
00247         Ogre::GpuProgramParametersSharedPtr p = mypass->getVertexProgramParameters();
00248         p->setNamedConstant(sParam,Ogre::Vector4(x,y,z,w));
00249         mypass->setVertexProgramParameters(p);
00250         return 0;
00251     }
00252     
00254     static int      SetDiffuse  (lua_State *L) { PROFILE
00255         std::string sMatName    = luaL_checkstring(L,1);
00256         int         iTech       = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ?    luaL_checkint(L,2) : 0;
00257         int         iPass       = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ?    luaL_checkint(L,3) : 0;
00258         float       r           = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ? luaL_checknumber(L,4) : 1.0;
00259         float       g           = (lua_gettop(L) >= 5 && !lua_isnil(L,5)) ? luaL_checknumber(L,5) : 1.0;
00260         float       b           = (lua_gettop(L) >= 6 && !lua_isnil(L,6)) ? luaL_checknumber(L,6) : 1.0;
00261         float       a           = (lua_gettop(L) >= 7 && !lua_isnil(L,7)) ? luaL_checknumber(L,7) : 1.0;
00262         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00263         if (mat.isNull()) return 0;
00264         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00265         if (!mypass) return 0;
00266         mypass->setDiffuse(r,g,b,a);
00267         return 0;
00268     }
00269     
00271     static int      SetSceneBlend   (lua_State *L) { PROFILE
00272         std::string sMatName    = luaL_checkstring(L,1);
00273         int         iTech       = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ?    luaL_checkint(L,2) : 0;
00274         int         iPass       = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ?    luaL_checkint(L,3) : 0;
00275         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00276         if (mat.isNull()) return 0;
00277         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00278         if (!mypass) return 0;
00279         mypass->setSceneBlending((luaL_checkint(L,4) == 1) ? Ogre::SBT_TRANSPARENT_ALPHA : Ogre::SBT_REPLACE);
00280         return 0;
00281     }
00282     
00284     static int      SetDepthWriteEnabled    (lua_State *L) { PROFILE
00285         std::string sMatName    = luaL_checkstring(L,1);
00286         int         iTech       = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ?    luaL_checkint(L,2) : 0;
00287         int         iPass       = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ?    luaL_checkint(L,3) : 0;
00288         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00289         if (mat.isNull()) return 0;
00290         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00291         if (!mypass) return 0;
00292         mypass->setDepthWriteEnabled(luaL_checkint(L,4) != 0);
00293         return 0;
00294     }
00295 
00297     //~ compare_methods (see oger api for details):
00298     //~ CMPF_ALWAYS_FAIL    
00299     //~ CMPF_ALWAYS_PASS    
00300     //~ CMPF_LESS   
00301     //~ CMPF_LESS_EQUAL     
00302     //~ CMPF_EQUAL  
00303     //~ CMPF_NOT_EQUAL  
00304     //~ CMPF_GREATER_EQUAL  
00305     //~ CMPF_GREATER    
00306     static int      SetAlphaRejection   (lua_State *L) { PROFILE
00307         std::string sMatName    = luaL_checkstring(L,1);
00308         int         iTech       = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ?    luaL_checkint(L,2) : 0;
00309         int         iPass       = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ?    luaL_checkint(L,3) : 0;
00310         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00311         if (mat.isNull()) return 0;
00312         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00313         if (!mypass) return 0;
00314         
00315         Ogre::CompareFunction cmp = (Ogre::CompareFunction)luaL_checkint(L,4);
00316         int v = (Ogre::CompareFunction)luaL_checkint(L,5);
00317         
00318         mypass->setAlphaRejectSettings(cmp,v);
00319         
00320         return 0;
00321     }
00322 
00325 
00341 
00354 
00355     static int      SetMaterialParam    (lua_State *L) { PROFILE
00356         std::string name = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? luaL_checkstring(L,2) : "";
00357         std::string value = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ? luaL_checkstring(L,3) : "";
00358 
00359         std::string sMatName    = luaL_checkstring(L,1);
00360         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00361         if (mat.isNull()) return 0;
00362         mat->setParameter(name, value);
00363         return 0;
00364     }
00365     
00368     static int      SetHardwareCulling  (lua_State *L) { PROFILE
00369         std::string sMatName    = luaL_checkstring(L,1);
00370         int         iTech       = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ?    luaL_checkint(L,2) : 0;
00371         int         iPass       = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ?    luaL_checkint(L,3) : 0;
00372         int         iCullMode   = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ?    luaL_checkint(L,4) : 0;
00373         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00374         if (mat.isNull()) return 0;
00375         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00376         if (!mypass) return 0;
00377         mypass->setCullingMode((iCullMode==0)?Ogre::CULL_NONE:((iCullMode==1)?Ogre::CULL_CLOCKWISE:Ogre::CULL_ANTICLOCKWISE));
00378         return 0;
00379     }
00380     
00383     static int      SetSoftwareCulling  (lua_State *L) { PROFILE
00384         std::string sMatName    = luaL_checkstring(L,1);
00385         int         iTech       = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ?    luaL_checkint(L,2) : 0;
00386         int         iPass       = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ?    luaL_checkint(L,3) : 0;
00387         int         iCullMode   = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ?    luaL_checkint(L,4) : 0;
00388         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00389         if (mat.isNull()) return 0;
00390         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00391         if (!mypass) return 0;
00392         mypass->setManualCullingMode((iCullMode==0)?Ogre::MANUAL_CULL_NONE:((iCullMode==1)?Ogre::MANUAL_CULL_BACK:Ogre::MANUAL_CULL_FRONT));
00393         return 0;
00394     }
00395     
00397     static int      SetTextureIsAlpha   (lua_State *L) { PROFILE
00398         std::string sMatName            = luaL_checkstring(L,1);
00399         bool        bIsAlpha            = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? lua_toboolean(L,2) : false;
00400         int         iTech               = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ? luaL_checkint(L,3) : 0;
00401         int         iPass               = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ? luaL_checkint(L,4) : 0;
00402         int         iTextureUnitState   = (lua_gettop(L) >= 5 && !lua_isnil(L,5)) ? luaL_checkint(L,5) : 0;
00403         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00404         if (mat.isNull()) return 0;
00405         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00406         if (!mypass) return 0;
00407         while (mypass->getNumTextureUnitStates() <= iTextureUnitState) mypass->createTextureUnitState();
00408         mypass->getTextureUnitState(iTextureUnitState)->setIsAlpha(bIsAlpha);
00409         return 0;
00410     }
00411     
00413     static int      SetSceneBlending    (lua_State *L) { PROFILE
00414         std::string sMatName            = luaL_checkstring(L,1);
00415         int         iMode               = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? luaL_checkint(L,2) : Ogre::SBT_TRANSPARENT_ALPHA;
00416         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00417         if (mat.isNull()) return 0;
00418         mat->setSceneBlending((Ogre::SceneBlendType)iMode);
00419         return 0;
00420     }
00421     
00423     static int      SetTextureAddressingMode    (lua_State *L) { PROFILE
00424         std::string sMatName            = luaL_checkstring(L,1);
00425         int         iMode               = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? luaL_checkint(L,2) : Ogre::TextureUnitState::TAM_WRAP;
00426         int         iTech               = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ? luaL_checkint(L,3) : 0;
00427         int         iPass               = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ? luaL_checkint(L,4) : 0;
00428         int         iTextureUnitState   = (lua_gettop(L) >= 5 && !lua_isnil(L,5)) ? luaL_checkint(L,5) : 0;
00429         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00430         if (mat.isNull()) return 0;
00431         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00432         if (!mypass) return 0;
00433         if (mypass->getNumTextureUnitStates() <= iTextureUnitState) return 0;
00434         mypass->getTextureUnitState(iTextureUnitState)->setTextureAddressingMode((Ogre::TextureUnitState::TextureAddressingMode)iMode);
00435         return 0;
00436     }
00437     
00439     static int      SetTextureFiltering (lua_State *L) { PROFILE
00440         std::string sMatName            = luaL_checkstring(L,1);
00441         int         iMode               = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? luaL_checkint(L,2) : Ogre::TFO_NONE;
00442         int         iTech               = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ? luaL_checkint(L,3) : 0;
00443         int         iPass               = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ? luaL_checkint(L,4) : 0;
00444         int         iTextureUnitState   = (lua_gettop(L) >= 5 && !lua_isnil(L,5)) ? luaL_checkint(L,5) : 0;
00445         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00446         if (mat.isNull()) return 0;
00447         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00448         if (!mypass) return 0;
00449         if (mypass->getNumTextureUnitStates() <= iTextureUnitState) return 0;
00450         mypass->getTextureUnitState(iTextureUnitState)->setTextureFiltering((Ogre::TextureFilterOptions)iMode);
00451         return 0;
00452     }
00453 
00456     static int      SetTexture  (lua_State *L) { PROFILE
00457         std::string sMatName            = luaL_checkstring(L,1);
00458         std::string sTextureName        = luaL_checkstring(L,2);
00459         int         iTech               = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ? luaL_checkint(L,3) : 0;
00460         int         iPass               = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ? luaL_checkint(L,4) : 0;
00461         int         iTextureUnitState   = (lua_gettop(L) >= 5 && !lua_isnil(L,5)) ? luaL_checkint(L,5) : 0;
00462         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00463         if (mat.isNull()) return 0;
00464         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00465         if (!mypass) return 0;
00466         while (mypass->getNumTextureUnitStates() <= iTextureUnitState) mypass->createTextureUnitState();
00467         mypass->getTextureUnitState(iTextureUnitState)->setTextureName(sTextureName);
00468         return 0;
00469     }
00470     
00471     
00474     static int      GetTexture  (lua_State *L) { PROFILE
00475         std::string sMatName            = luaL_checkstring(L,1);
00476         int         iTech               = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? luaL_checkint(L,2) : 0;
00477         int         iPass               = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ? luaL_checkint(L,3) : 0;
00478         int         iTextureUnitState   = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ? luaL_checkint(L,4) : 0;
00479         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00480         if (mat.isNull()) return 0;
00481         Ogre::Pass* mypass = mat->getTechnique(iTech)->getPass(iPass);
00482         if (!mypass) return 0;
00483         if (mypass->getNumTextureUnitStates() <= iTextureUnitState) return 0;
00484         lua_pushstring(L,mypass->getTextureUnitState(iTextureUnitState)->getTextureName().c_str());
00485         return 1;
00486     }
00487     
00489     static int      SetReceiveShadows   (lua_State *L) { PROFILE
00490         std::string sMatName            = luaL_checkstring(L,1);
00491         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(sMatName);
00492         if (mat.isNull()) return 0;
00493         mat->setReceiveShadows(luaL_checkbool(L,2));
00494         return 0;
00495     }
00496 };
00497 
00498 void    Material_LuaRegister    (void *L) {
00499     cMaterial_L::LuaRegister((lua_State*) L) ;
00500 }
00501 
00502 };

Generated on Wed May 23 06:00:14 2012 for cpp by  doxygen 1.5.6