shadows on mesh faces

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
Icare
Posts: 14
Joined: Tue Jun 24, 2008 3:44 am

shadows on mesh faces

Post by Icare »

Hi there,

I am trying to load a mesh object (so an obj file) into irrlicht.
When i load for example a cylinder, i cannot view different color for the faces.
All faces have the same gray, whatever i am doing, like moving the light, etc.

I have this :

Image

when i want something like that :

Image

here is my code :


Code: Select all

scene::ILightSceneNode* light1 = 0;
	light1 = SceneManager->addLightSceneNode();
	
	video::SLight lightdatas;    
	
	lightdatas.Position = core::vector3df(0, 0, 0);    
	lightdatas.Type = video::ELT_POINT;
	lightdatas.Radius=2.0f;
	lightdatas.AmbientColor = video::SColorf(0.3f,0.3f,0.3f,0.5f);
	lightdatas.SpecularColor= video::SColorf(0.4f,0.0f,0.0f,1);
	lightdatas.DiffuseColor = video::SColorf(1.0f,1.0f,1.0f,0.6f);
	lightdatas.CastShadows = false;
	
	light1->setLightData(lightdatas);

And for my IAnimatedSceneNode :

Code: Select all

iscenenode= t_pSceneMngr->addAnimatedMeshSceneNode(MyObject);
iscenenode->setMaterialType(video::EMT_LIGHTMAP_LIGHTING);
iscenenode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
iscenenode->getMaterial(0).AmbientColor.set(255,255,255,255);
iscenenode->getMaterial(0).SpecularColor.set(255,255,255,255);
thanks,
Last edited by Icare on Fri Aug 01, 2008 2:47 am, edited 2 times in total.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Why have you set the node's material to lightmap? Do you know what a lightmap is? It's a texture which is put on the model to give it pre-baked static lighting, rather than dynamic lighting from a light source.

So if you remove the line that sets it to lightmap material it could work.

Another thing that could be causing problems is that the normals are borked. For me .obj normals are always horrific, but they normally give some, fudged, lighting. If cutting out the lightmap material bit doesn't fix it try using the MeshManipulator (get it from your smgr) to recalculate the normals. (check the API/docs for the necessary functions)
Image Image Image
Icare
Posts: 14
Joined: Tue Jun 24, 2008 3:44 am

Post by Icare »

Well, i have tested all the Material Type, no one works.

About the normals, i have no any normals in my obj file (only vertices and faces). So I will try to use the mesh manipulator to recalculate the normals.
Icare
Posts: 14
Joined: Tue Jun 24, 2008 3:44 am

Post by Icare »

Its working great when i recalculate the normals with the mesh manipulator !

thanks a lot !

Code: Select all

t_pSceneMngr->getMeshManipulator()->recalculateNormals(MyObject);
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

OMG, I forgot to recalculate the normals in the loader :oops: Latest SVN trunk should have this feature...
Icare
Posts: 14
Joined: Tue Jun 24, 2008 3:44 am

Post by Icare »

Just a little last point :

These normals are wrong, no ?

Image
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Hard to tell because the normals are being drawn in the wrong place, not sure why that would be though!
Image Image Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The normals are often not drawn correctly. Try to getMesh(0) your mesh to get a static IMesh. Sometimes the normals are drawn better for those meshes.
Icare
Posts: 14
Joined: Tue Jun 24, 2008 3:44 am

Post by Icare »

I found that maybe my problem come from the left hand x, y, z axis in irrlicht doesn't corresponding to the right han x, y, z axis of my mesh...

Can i change the x, y, z axis of irrlicht to a right hand one ?

Thanks (i hope you will understand the left, right hand story, actually i don't know how to say that in irrlicht)

BTW, i can have good normals with normals from my obj file (and without recalculate normals with the mesh manipulator) but just at the position 0,0,0

more my cybe is far from the 0,0,0 point and more the normals are far from my cube ! :shock:

here some pics :

a cube at (0,0,0)

Image

a cube at (1,0,0)

Image
Post Reply