Color a node/mesh (RGB) without active lightning

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
cr_itm
Posts: 57
Joined: Sun May 01, 2005 10:13 am

Color a node/mesh (RGB) without active lightning

Post by cr_itm »

Hello,

I must do a schematical 3D render of some data, mainly simple colored nodes/cube models.

My problem is, I do not want to have lighting in the scene, every object (node/cube) should have the same brightness (no lightning), but at the same time, I must set an RGB color to them.

The emissive and diffuse color settings for the material only work with active lightning, is that correct?

If yes, how can I just give my cube mesh an RGB color? I can't pre-render textures, because I have to visualize different shades of colors that are measured during run time.

Additionally I must use Jirr, the Java binding for Irrlicht, so I can't do deep modifications to the engine, I'm bound to what Jirr offers me.


I really hope anyone has an idea how to color a node/mesh without active lightning.


Thanks a lot for your help!
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

color is stored in vertex so you need to get acces to them. Once done, change color atribute of them one by one. See video::S3DVertex struct reference in irrlicht help.

So howe to get acces to vertices?
if you load model than I don't know since I was newer doing it but there should be way ...basicly you need to get mesh of scene node then mesh buffer. That is were wertices are stored.

You may on the other hand use this code to make your own cube:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=17028 then you can acces vertices easily.

You may also create your own cube using Irlicht 03.CustomSceneNode example.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Another solution I'm thinking of is to create the textures "on the fly" and change their colors as needed...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Right, it is fairly easy and like that your cube would be light independent.
Here is some code example which create 1x1 texture on fly:

Code: Select all

// create empty texture of 1 pixel size in 32 bit A8R8G8B8 color format
	video::ITexture* texture = driver->addTexture(core::dimension2d<s32>(1,1), "testtexture", video::ECF_A8R8G8B8);
    
    // get pointer to texture data
    s32* p = (s32*)texture->lock();
    
    // set single pixel of texture to be white
    p[0] = video::SColor(255,255,255,255).color;
    
    texture->unlock();
cr_itm
Posts: 57
Joined: Sun May 01, 2005 10:13 am

Post by cr_itm »

Hello,

thanks a lot for your answers.
arras wrote: ...basicly you need to get mesh of scene node then mesh buffer. That is were wertices are stored.
I have done this, here is the code. It is Java (as you remember, I must use the Java Binding Jirr for the project), but you should not have any problem understanding it:

Code: Select all

IMesh mesh = scene.getMesh( mesh_file ).getMesh( 1 );
ISceneNode node = scene.addMeshSceneNode( mesh );

node.setMaterialFlag( E_MATERIAL_FLAG.EMF_LIGHTING, false );
node.setMaterialTexture( 0, null );

S3DVertex[] v = mesh.getMeshBuffer( 0 ).getVertices();

for ( int i = 0; i < v.length; i++ )
{
	v[ i ].setColor( new SColor( 120, 100, 200, 150 ) );
	v[ i ].setPos( new vector3df( 100, 100, 100 ) );
}

You see I load a mesh (successfully) and then I get the meshbuffer and iterate over all vertices in a for-loop. But this has absolutely no effect on my model. Even the line with "v[ i ].setPos..." (for testing purposes) should have an effect, but it has not (debugging reveals, that "v" has a array size of 36, so the mesh buffer seems to be ok).

Am I doing anything wrong here? Must I set any material flags or something?

arras wrote: You may also create your own cube using Irlicht 03.CustomSceneNode example.
Sadly, I can't create a custom scene node. More sadly, I can't derive my own class from any Irrlicht class in Java, this gives me a really dirty engine crash.

Please note: If anyone has ever successfully derived a java class from a Irrlicht class using the Irrlicht binding Jirr, please say so!

arras wrote:Right, it is fairly easy and like that your cube would be light independent.
Here is some code example which create 1x1 texture on fly:
...

This is interesting, it would be absolutely great to be able to render in my own texture. But this is a bad-ass problem in Java - you know why? Because Java does not know about Pointers. The thing behind the Irrlicht binding Jirr is "SWIG" (www.swig.org). Please have a look at the following (Java) code:

Code: Select all

ITexture texture = driver.addTexture( new dimension2di( 1, 1 ), "test", ECOLOR_FORMAT.ECF_A8R8G8B8 );
		
SWIGTYPE_p_void p = texture.lock();

SColor c = new SColor( 200, 100, 200, 100 );

// *** p = c.getColor();

texture.unlock();

The line with "p = c.getColor()" is the big problem: texture.lock() returns in the Java binding the type "SWIGTYPE_p_void". This is neither a real array nor a real Pointer (hell, I don't know what it is, probably just an integer...), so the line "p = c.getColor()" makes no sense. I must find a way to get Java writing the color value into the memory area where the returned pointer of texture.lock() points to. You get the idea? ;-)


Usually the people stop answering me now, because this problem is really hard to solve, I know that.


Perhaps the way setting each vertex color is right, have I anything done wrong (please see the first code-snippet)?

But if you have _any_ ideas, it would be great when you share them with me!


Thanks a LOT from a frustrated Irrlicht user, using Jirr with Java.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Ohhh, that would be bad !!! :shock:
Unfortunately I never used Jirr...
And Java a long time ago... ;)

But I found out that SWIGTYPE_p_void is a class and it seems there is a function for getting a C pointer out of it called getCPtr (but I'm not really sure) !?!?!
I found this: http://www.eeng.dcu.ie/~whelanp/osmia/t ... _void.html
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Well I am sorry but I dont have experience with Java so somebody skilled may help.

I am not sure if mesh you pass as argument in to addMeshSceneNode is going to end there however. Instead node itself can contain its copy. In such case you would acces mesh which looks to be ok but which is not one node realy use. But I am not sure about it.

When accesing mesh of node I would use code:

Code: Select all

scene::IMesh* mesh = node->getMesh();
I have no idea howe all this can work without pointers. texture->lock() returns void and (s32*)texture->lock() means in fact that I cast it to int pointer if that can help you somehowe. I dont know however if casting works in Java and howe.

I know nothing of SWIGTYPE_p_void but that doesnt seem like somethyng close to int ...more like C++ void of kind.

I dont know if void is type at all ...by having function returning void you declare it returns something ...which can be anything. In this case we know function return color as 32 bit value which is int or s32 in case of Irrilicht so we can safely cast.

But howe this can be done in Java I dont know...
cr_itm
Posts: 57
Joined: Sun May 01, 2005 10:13 am

Post by cr_itm »

Thanks for your answers
Acki wrote:Ohhh, that would be bad !!! :shock:
Unfortunately I never used Jirr...
And Java a long time ago... ;)

But I found out that SWIGTYPE_p_void is a class and it seems there is a function for getting a C pointer out of it called getCPtr (but I'm not really sure) !?!?!
I found this: http://www.eeng.dcu.ie/~whelanp/osmia/t ... _void.html
Ah, yes you a right, with getCPtr I get a long integer, this must just be the address/the pointer. The thing is, Java does not allow writing at a memory address. In C#, there is the possibility to switch to an "unmanaged code" block, where one can use pointers and write to memory just like in C++. But in Java, I never heard of it... maybe I can write a small DLL and call it from java, that allows me to write to the address (long) that I get from getCPtr...

arras wrote:I am not sure if mesh you pass as argument in to addMeshSceneNode is going to end there however. Instead node itself can contain its copy. In such case you would acces mesh which looks to be ok but which is not one node realy use. But I am not sure about it.

When accesing mesh of node I would use code:

Code: Select all

scene::IMesh* mesh = node->getMesh();
Well, I don't see a "getMesh" method of the class ISceneNode? Or is "node" in your example of different type than ISceneNode?


I'm happy that you try to help me. You can't imagine how long I struggle with this problem now.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

it is IAnimatedMeshSceneNode but also IMeshSceneNode which is created in your scene.addMeshSceneNode( mesh ) have getMesh() function.

Code: Select all

IMesh mesh = scene.getMesh( mesh_file ).getMesh( 1 );
IMeshSceneNode node = scene.addMeshSceneNode( mesh );

IMesh mesh1 = node.getMesh();

node.setMaterialFlag( E_MATERIAL_FLAG.EMF_LIGHTING, false );
node.setMaterialTexture( 0, null );

S3DVertex[] v = mesh1.getMeshBuffer( 0 ).getVertices();

for ( int i = 0; i < v.length; i++ )
{
   v[ i ].setColor( new SColor( 120, 100, 200, 150 ) );
   v[ i ].setPos( new vector3df( 100, 100, 100 ) );
} 
...just a suggestion, I dont know if it would work.
Problem is that in Irrlicht getMesh() does not return mesh it returns only pointer in to node mesh. That way you acces directly mesh inside node. If there are no pointers in Java.... well I have no idea.
cr_itm
Posts: 57
Joined: Sun May 01, 2005 10:13 am

Post by cr_itm »

Thanks for your answer, I will try it out as soon as I get Jirr 0.8 running (this is the java binding version that is compatible with Irrlicht 1.1, and the IMeshSceneNode is first available in Irrlicht 1.1, not 1.0 I was using ;) ).
cr_itm
Posts: 57
Joined: Sun May 01, 2005 10:13 am

Post by cr_itm »

Sadly, I was wrong... I finally got Jirr 0.8 running (with Irrlicht 1.1), but the method "virtual IMesh* getMesh(void) = 0;" of IMeshSceneNode is only available in Irrlicht 1.2. So I must wait until a new Jirr version is released... :(

Is there any other way to get the current mesh a MeshSceneNode is using?
cr_itm
Posts: 57
Joined: Sun May 01, 2005 10:13 am

Post by cr_itm »

Ok, with the new Jirr version compatible with Irrlicht 1.2 I was finally able to color the vertices of the mesh.

Thanks for your help!
Post Reply