Challenge: "cube scene node" properly colored

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
Rulatir
Posts: 17
Joined: Tue Aug 26, 2008 11:10 am

Challenge: "cube scene node" properly colored

Post by Rulatir »

How do I assign solid red color to node returned by addCubeSceneNode? Here is what surprisingly fails:

Code: Select all

node->setMaterialFlag(EMF_LIGHTING, false);
node->getMaterial(0).DiffuseColor.set(255,255,0,0);
node->getMaterial(0).AmbientColor.set(255,255,0,0);
node->getMaterial(0).SpecularColor.set(255,255,0,0);
The result is completely white cube.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I don't think you can use the material for coloring without texture and without lighting. With lighting you can set the emissive-color to guarantee a red color.

I think it should work by setting the color of the vertices directly, but I haven't tried and missing the time at the moment to write an example. Checkout S3DVertex - you can get that from the Meshbuffer, I'm sure you figure it out somehow :-)
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
Rulatir
Posts: 17
Joined: Tue Aug 26, 2008 11:10 am

Post by Rulatir »

CuteAlien wrote:Checkout S3DVertex - you can get that from the Meshbuffer, I'm sure you figure it out somehow :-)
No, I cannot get S3DVertex from meshbuffer because no documented method of IMeshBuffer returns S3DVertex or array thereof. What do I do with the void* returned by getVertices()? Static_cast it to S3DVertex? If there is only one S3DVertex that covers all vertex types then why doesn't IMeshBuffer::getVertices just return S3DVertex* in the first place?

edit: Oh yes, there's are also S3DVertex2TCoords and S3DVertexTangents, so:

Code: Select all

switch(meshBuf->getVertexType()) {

case EVT_STANDARD: {

    S3DVertex* begin=static_cast<S3DVertex*>(meshBuf->getVertices());
    S3DVertex* end = begin + meshBuf->getVertexCount();

    //... code

    break;
}

case EVT_2TCOORDS: {

    S3DVertex2TCoords* begin=static_cast<S3DVertex2TCoords*>(meshBuf->getVertices());
    S3DVertex2TCoords* end = begin + meshBuf->getVertexCount();

    //... exact same code

    break;
}

case EVT_TANGENTS: {

    S3DVertexTangents* begin=static_cast<S3DVertexTangents*>(meshBuf->getVertices());
    S3DVertexTangents* end = begin + meshBuf->getVertexCount();

    //... exact same code yet again

    break;
}
}
... because I cannot KNOW that addCubeSceneNode returns a mesh with S3DVertex vertices. It is not documented.

Just... wonderful.
Last edited by Rulatir on Wed Nov 18, 2009 7:02 am, edited 1 time in total.
Reiko
Posts: 105
Joined: Sun Aug 16, 2009 7:06 am
Location: Australia

Post by Reiko »

Perhaps getVertex() and getVertexCount() ?

edit: oops, thats on SSkinMeshBuffer
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

You can find out which type it has with getVertexType () and the clean solution is checking that and then casting to the corresponding type. But in the case of the cube it will be an video::S3DVertex unless you changed it yourself, so yes, you can static_cast to that.
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
Rulatir
Posts: 17
Joined: Tue Aug 26, 2008 11:10 am

Post by Rulatir »

CuteAlien wrote:You can find out which type it has with getVertexType () and the clean solution is checking that and then casting to the corresponding type.
Your response and my edit collided mid-air. Still, even if I know the vertex type for the "cube scene node", handling more general cases would require the nasty boilerplate :(
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I just checked and I think in your case it might be possible to avoid the boilerplate code. All vertex types are derived from S3DVertex and you can get the size of the vertex-type with getVertexPitchFromType.
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
Rulatir
Posts: 17
Joined: Tue Aug 26, 2008 11:10 am

Post by Rulatir »

CuteAlien wrote:I just checked and I think in your case it might be possible to avoid the boilerplate code. All vertex types are derived from S3DVertex and you can get the size of the vertex-type with getVertexPitchFromType.
Like this?

Code: Select all

S3DVertex* v = (S3DVertex*)(buf->getVertices());
E_VERTEX_TYPE vtype = buf->getVertexType();
u32 pitch = v->getVertexPitchFromType(vtype);

S3DVertex* vEnd = (S3DVertex*)((char*)v+pitch*buf->getVertexCount());

while(v < vEnd) {

    //... code

    v = (S3DVertex*)((char*)v+pitch);
}
:shock: :shock: :shock:
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

MeshManipulator->setVertexColor(cubeMesh, SColor(255,255,0,0));
But the color settings of the material would also work if lighting is enabled.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Btw, you can obtain the mesh manipulator using sceneManager->getMeshManipulator().

But I don't know why you want to go the vertex route, I think that you can just set diffuse color and specular color to black, enable lighting, and set emissive to the one that you need, this should satisfy all cases.

Code: Select all

node->setMaterialFlag(EMF_LIGHTING, true);
node->getMaterial(0).DiffuseColor.set(0,0,0,0);
node->getMaterial(0).AmbientColor.set(0,0,0,0);
node->getMaterial(0).SpecularColor.set(0,0,0,0);
node->getMaterial(0).EmissiveColor.set(255,255,0,0);
Should work.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Post Reply