Manipulating Materials ...

futnuh

08-04-2006 07:58:04

I'd be very interested in seeing pyOgre demo code for manipulating materials. At the moment I'm trying to render multiple copies of one specific entity with different materials. The materials are all identical except for the texture map (not known until run-time).

In Ogre, I'd start with a template material (likely loaded from a material script) and then clone it. From the Ogre Forums, something like:


MaterialPtr templateMaterial = MaterialManager::getSingleton().getByName(String ("TemplateMaterial"));
MaterialPtr myMaterial = templateMaterial->clone("CopyMaterial");
String diffmapname = "texturemap.png";
TexturePtr Texture = TextureManager::getSingleton().load (diffmapname , ResourcesgroupName, TEX_TYPE_2D, 7, 1.0f);
myMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName (diffmapname);


Question then, how do you clone materials in pyOgre?


matman = ogre.MaterialManager_getSingleton()
mptr = matman.getByName('TemplateMaterial')
m = mptr.get() # hoping this gives me a Material
print "*****: ", dir(m) # hmm, it doesn't ...

# change texture on cloned version of m
nptr = mptr.clone() # no such method
texman = ogre.TextureManager_getSingleton()
texnew = texman.load ('newtexture.tif', 'General', ogre.TEX_TYPE_2D, 7, 1.0)
nptr.getTechnique(0).getPass(0).getTextureUnitState(0).setTextureName ('newtexture.tif')



As always, any help is much appreciated.

dermont

08-04-2006 08:47:16

I think this is what your looking for:
http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=192&highlight=materialptr


mptr =ogre.MaterialPointer(ogre.MaterialManager.getSingleton().getByName("Examples/TransparentTest"))