How to set new Material to an IMeshBuffer*?

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
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

How to set new Material to an IMeshBuffer*?

Post by Masterhawk »

Hi folks,
I have a simple question:

I have to change the Material for a specific mesh buffer in my mesh, but I can't find a function like "meshbuffer->setMaterial()".
How do I achieve to change the material?

Code: Select all

if(mb_idx >= 0 && mb_idx <this->getMesh()->getMeshBufferCount())
    {
        IMeshBuffer* mb = this->getMesh()->getMeshBuffer(mb_idx);
        
//SET NEW MATERIAL HERE
 
        video::S3DVertex* verts = (video::S3DVertex*)mb->getVertices();
        for(s32 v=0; v<mb->getVertexCount(); v++)
        {
            verts[v].Color = clr;
        }
    }
Thanks in advance
Image
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: How to set new Material to an IMeshBuffer*?

Post by zerochen »

hi,

i would say that

Code: Select all

driver->setMaterial(Material);
should work.

regards
zerochen
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Re: How to set new Material to an IMeshBuffer*?

Post by Masterhawk »

well this meshbuffer is part of a huge mesh containing a huge amount of other meshbuffers.

The mesh is rendered as a scenenode in smgr->drawAll(). So I want to apply a new material to the meshbuffer structure so the material is chosen automatically in the drawAll function.
Image
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: How to set new Material to an IMeshBuffer*?

Post by serengeor »

Masterhawk wrote:well this meshbuffer is part of a huge mesh containing a huge amount of other meshbuffers.

The mesh is rendered as a scenenode in smgr->drawAll(). So I want to apply a new material to the meshbuffer structure so the material is chosen automatically in the drawAll function.
Scene node has:
http://irrlicht.sourceforge.net/docu/cl ... 4fc2ed05b2

Which returns a reference, so you can just assign your material to it like this:

Code: Select all

 
node->getMaterial(some_mesh_buffer_index) = otherMaterial;
 
Last edited by serengeor on Wed Feb 27, 2013 2:03 pm, edited 1 time in total.
Working on game: Marrbles (Currently stopped).
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: How to set new Material to an IMeshBuffer*?

Post by greenya »

Masterhawk wrote: //SET NEW MATERIAL HERE
mb->getMaterial() = somematerial;
Post Reply