Color a node/mesh (RGB) without active lightning
Color a node/mesh (RGB) without active lightning
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!
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!
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.
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.
Another solution I'm thinking of is to create the textures "on the fly" and change their colors as needed...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
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:
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();
Hello,
thanks a lot for your answers.
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?
Please note: If anyone has ever successfully derived a java class from a Irrlicht class using the Irrlicht binding Jirr, please say so!
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:
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.
thanks a lot for your answers.
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:arras wrote: ...basicly you need to get mesh of scene node then mesh buffer. That is were wertices are stored.
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?
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.arras wrote: You may also create your own cube using Irlicht 03.CustomSceneNode example.
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.
Ohhh, that would be bad !!!
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
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:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
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:
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...
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 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...
Thanks for your answers
I'm happy that you try to help me. You can't imagine how long I struggle with this problem now.
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...Acki wrote:Ohhh, that would be bad !!!
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
Well, I don't see a "getMesh" method of the class ISceneNode? Or is "node" in your example of different type than ISceneNode?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();
I'm happy that you try to help me. You can't imagine how long I struggle with this problem now.
it is IAnimatedMeshSceneNode but also IMeshSceneNode which is created in your scene.addMeshSceneNode( mesh ) have getMesh() function....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.
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 ) );
}
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.
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?
Is there any other way to get the current mesh a MeshSceneNode is using?