[SOLVED] Trouble Changing SceneNode Materials

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
EvilDavo
Posts: 17
Joined: Sun Sep 27, 2009 12:20 pm
Location: Australia

[SOLVED] Trouble Changing SceneNode Materials

Post by EvilDavo »

I have a tree with two materials: bark and leaves. I want the bark to be solid and the leaves to be transparent by alpha channel.

I'm doing this:

Code: Select all

scene::IMeshSceneNode *mesh = smgr->addMeshSceneNode( smgr->getMesh("models/mesh.3ds") );
mesh->setMaterialFlag( video::EMF_LIGHTING, false );

video::SMaterial mat = mesh->getMaterial(1);
mat.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; 
but any changes I make to a single material have no effect on anything. Setting the material of the whole mesh works, but I need the leaves to be transparent while the rest of the tree stays solid. I'm sure the problem must be something simple, but don't know what it is. Need help. Thx.
Last edited by EvilDavo on Sun Jun 06, 2010 5:18 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9934
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

getMaterial returns a reference - that's why you can change it. So put into into a reference (video::SMaterial&) otherwise you create a copy. Also materials start counting at 0 - just mentioning it in case you try to access the first one.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
EvilDavo
Posts: 17
Joined: Sun Sep 27, 2009 12:20 pm
Location: Australia

Post by EvilDavo »

of course!
Forgot to make it a reference. I really shouldn't programme this late at night
:)

Thank you.
Post Reply