1 (edited by Mr. Picklesworth 2006-07-19 16:16:18)

Topic: .3ds lighting problems

I'm using gg.irrb3d...

Meshes loaded from .3ds files are not recieving lighting from light objects in my scene. They are just displayed as though completely lit.
I also cannot adjust the object's colour using ib3d_EntityColor.

Lighting seems to work fine with md2s, such as in the irrb3d example. (Sorry, I can't find it...)
I haven't tried any other formats.

Can I fix this, or is it just normal behaviour?

Strict

Framework gg.IrrB3D
Import PUB.Newton

ib3d_Graphics3D(640,480)

Local cam:CAMERA=ib3d_CreateCamera()
ib3d_PositionEntity(cam , 0 , 0 , -10)

Local board:MESH = ib3d_LoadMesh("media/board/base.3ds")
ib3d_EntityColor(board,255,0,0)

Local LIGHT:LIGHT = ib3d_CreateLight()
ib3d_PositionEntity(LIGHT, 5 , 50 , 0)
ib3d_LightColor(LIGHT,0,255,0)
ib3d_LightRange(LIGHT,1000)

ib3d_CameraClsColor(100 , 0 , 200)

While Not ib3d_KeyDown(EKEY_ESCAPE)    
     ' move the camera
    If ib3d_KeyDown(EKEY_NUMPAD9) Then ib3d_MoveEntity(cam,0,50,0)
    If ib3d_KeyDown(EKEY_NUMPAD3) Then ib3d_MoveEntity(cam,0,-50,0)
    If ib3d_KeyDown(EKEY_NUMPAD6) Then ib3d_MoveEntity(cam,50,0,0)
    If ib3d_KeyDown(EKEY_NUMPAD4) Then ib3d_MoveEntity(cam,-50,0,0)
    If ib3d_KeyDown(EKEY_NUMPAD8) Then ib3d_MoveEntity(cam,0,0,50)
    If ib3d_KeyDown(EKEY_NUMPAD2) Then ib3d_MoveEntity(cam,0,0,-50)
    
    ' turn the camera
    If ib3d_KeyDown(EKEY_LEFT) Then ib3d_TurnEntity(cam,0,-50,0)
    If ib3d_KeyDown(EKEY_RIGHT) Then ib3d_TurnEntity(cam,0,50,0)
    If ib3d_KeyDown(EKEY_UP) Then ib3d_TurnEntity(cam,50,0,0)
    If ib3d_KeyDown(EKEY_DOWN) Then ib3d_TurnEntity(cam,-50,0,0)
    If ib3d_KeyDown(EKEY_SPACE) Then ib3d_TurnEntity(cam,0,0,50)

    ' perform collisions and reposition entities based on collisions
    ib3d_UpdateWorld()
    ' render the current world
    ib3d_RenderWorld()
Wend

ib3d_EndGraphics()

Re: .3ds lighting problems

interesting.  it must be something with the model.  i loaded up a couple of 3ds from the game im working on using your code.  one model, certain areas that were a a very light color were definately affected by the light.  then i loaded up another model which was mostly dark and it didnt seem to be affected at all.  im not sure about models, but im wondering what the difference is there?  do any of them have a light color on them?  i have tried some .x files i had lying around and they are definately more affected by the light.  i think its something with Irrlicht.  you might hit the Irrlicht forums and see if there is anything there.  as for entitycolor not working im not sure why its not being affected.  the calls are correct and their not failing.  ill see if i can investigate further.

Re: .3ds lighting problems

I'll ask at the Irrlicht forums.

Were the models you tried modelled in Wings 3d, by chance?
That program seems to do a few unexpected extra things.
I will try a few different files, too.

Thanks for the response!

4 (edited by Mr. Picklesworth 2006-07-22 23:50:05)

Re: .3ds lighting problems

OK, looks like the 3ds loader is garbage, and I'm not having much luck with the .obj one.
Someone appears to have patched the 3ds loader, but I'm not sure how easy that is to apply when it's all running through a wrapper.
.x from Cinema4d seems to work well.
...And, at long last, it has pixel perfect lighting!

Also had to give the entity colour 255,255,255 to achieve proper lighting, which makes sense.

Thankfully, I'll eventually be switching to a custom runtime mesh creation function using 2d images as sources (it has to be a convex shape, sometimes with anti-collision physics objects at places, so nothing to worry about).

Now to throw in a billion shaders and I can get on with everything else tongue

As I gradually get the feel of this, it's turning out to be an excellent engine smile


Edit:
Heh, some vertices facing the wrong way on this model.
Oh well... still some work to do, then.

How can I set my scene's Ambient Light?
I have tried things like board.SetAmbientColor and Light.SetAmbientColor, but with no success.
Right now, I can only light my object with point lights. (Which is possibly useable, with the excuse being that the scenes are lit entirely by beautiful dynamic lights as opposed to arbitrary unseen ambient lights).

Having trouble with colours. It seems that only extremities such as 0 or 255 are understood. If I set a colour as 255,200,200 it still appears as red as 255,0,0.
Could this be trouble with variable conversions?

5 (edited by HondaDirtBiker 2006-07-23 07:22:44)

Re: .3ds lighting problems

When I create ambient lights I use this.

'Set Ambient Light color
Video.setAmbientLight (T_irrSColorf.createFromRGBA (0.5, 0.5, 0.5, 1.0))

Where Video is the "VideoDriver" handle. Also could there be a chance you were using "T_irrSColorf.createfromRGB" and not "T_irrSColor.createfromvals"? "T_irrSColor" uses values from 0 to 255 as integer, T_irrSColorf would use 0.0 to 1.0 as decimal.

6 (edited by Mr. Picklesworth 2006-07-24 10:23:01)

Re: .3ds lighting problems

Thanks, DirtBiker.

I was suspecting something like that.
IrrB3d is doing a lot of colour conversion stuff, so it's probably just an integer that should be a float...


My problem is only happening with entity.setColor; LIGHT.setColor works fine.
(A light coloured 50,50,50 still lights stuff, and looks very different than a light coloured 255,255,255)

Re: .3ds lighting problems

Honda is correct on the ambient setting.  i hadnt done the ib3d version of the AmbientLight yet.  it should look something like:

Function SetAmbientLight(red:Int=127,green:Int=127,blue:Int=127)
    If Not driver Or Not driver.IsValid() Then Throw "Graphics have not yet been initialized"        
       driver.setAmbientLight(T_irrSColorf.createFromSColor(T_irrSColor.createFromVals(0,red,green,blue)))
EndFunction

where driver would be your instance to IVideoDriver.

8 (edited by Mr. Picklesworth 2006-07-28 00:15:03)

Re: .3ds lighting problems

The plot thickens!

In the ib3d_entity Type in irrb3d, I changed the setColor method for a bit of debugging...

        Method SetColor(red:Float,green:Float,blue:Float,MaterialIDX:Int=0)
            If not _node or not _node.isValid() Then RuntimeError "Node is invalid"
            Local color:T_irrSColor=T_irrSColor.createFromVals(0,red,green,blue)
            Local colorf:T_irrSColorf=T_irrSColorf.createFromSColor(color)
            
            Local alpha:Float=colorf.GetAlpha()
            red=colorf.getRed()            
            green=colorf.getGreen()
            blue=colorf.getBlue()
            DebugLog(blue)
            
            _node.getMaterial(MaterialIDX).getDiffuseColor().set(alpha,red,green,blue)
            _node.getMaterial(MaterialIDX).getAmbientColor().set(alpha,red,green,blue)
        EndMethod

When blue is set to 200, this is added to the debug log: DebugLog:0.784313798
That looks right, so the problem must be further down, around that very scary looking material stuff. (EEEK!!! :S)


Edit:

Okay, this is a quick modification of the T_irrSColor Type in scolor.bmx of irrb3d.

    Method set(a:Int,r:Int,g:Int,b:Int)
        IrrVideo_SColor_set(Handle,a,r,g,b)
        DebugLog(b)
    EndMethod

With this, it outputs 0 to the debug log.
Changing b to a Float causes it to output 0.784313798 as before!
Still no change in the end result, though.

I'm confused sad
Should the entity's material be using sColorf to store colours?
(Perhaps this is due to how well the mesh is loaded again...)

9 (edited by Mr. Picklesworth 2006-08-28 20:54:25)

Re: .3ds lighting problems

Okay, I finally realized that the variables are fine up until IrrVideo_SColorf_set which is an extern function, thus out of my realm of understanding and probably not broken in any way.

I loaded my mesh with IrrEdit and colouring it seems to work fine... I guess the problem here is my own code.

Anyway, doesn't really matter that much since I'd have to be crazy to use solid mesh colours as opposed to textures in this project!

10 (edited by Mr. Picklesworth 2006-09-16 00:56:29)

Re: .3ds lighting problems

Sorry, replying to myself again...

I am now using the new Irrlicht module now, but I'm still getting weird results with loaded meshes.

I think I may have found a potential source of my problems, but I don't have a clue how to fix it.

I tried some commands like mesh.ScaleMesh, which resulted in one of the following:
"Mesh is not editable" (Does not happen with ScaleMesh, but happens with ib3d_CreateSurface)
"Unhandled Memory Exception Error" (Not all that helpful... happened with a 3ds file)
Or, most interestingly (since this is not an animated mesh): "Animated meshes are not editable" which occured with both .obj and .x files even when exported with Wings3d which doesn't even do animations.

So, every mesh crashes the program when I try to edit it in a different way, based on what file it was loaded from.
Joy!

Sorry I can't be more helpful...

Re: .3ds lighting problems

a couple of things...  the first, along with OBJ, 3DS has confirmed problems in v1.1 and some will cause a crash when loaded.  i would like to know where the crash you had was at though.  was it on the load line?

second, Irrlicht only allows editing of mesh formats that do not support animations... so the B3D mod tries to prevent you from getting the surfaces of those.   still, i would very much appreciate code sample of what you were trying to make sure i am limiting only where necessary.

Re: .3ds lighting problems

Okay, here is an example:

rem
Physics - Based Strategy Game , By Dylan McCall.
BlitzMax gg.IrrB3d Prototype
end rem

Strict

Framework irrlicht.B3d
Import pub.newton

ib3d_Graphics3D(640,480)

Local cam:CAMERA=ib3d_CreateCamera()
ib3d_PositionEntity(cam , 0 , 0 , -20)

ib3d_SetAmbientLight(255,255,255)

Local board:MESH = ib3d_LoadMesh("media/board/base.obj")
board.scaleMesh(2,2,2)
'ib3d_CreateSurface(board)
board.SetColor(255,255,255)

'Local l1:LIGHT = ib3d_CreateLight()
'l1.Position(0,50,0,True)
'l1.SetColor(150,150,150)
'l1.setRange(80)

ib3d_CameraClsColor(100 , 0 , 200)

While not ib3d_KeyDown(EKEY_ESCAPE)
     ' move the camera
    If ib3d_KeyDown(EKEY_NUMPAD9) Then ib3d_MoveEntity(cam,0,.5,0)
    If ib3d_KeyDown(EKEY_NUMPAD3) Then ib3d_MoveEntity(cam,0,-.5,0)
    If ib3d_KeyDown(EKEY_NUMPAD6) Then ib3d_MoveEntity(cam,.5,0,0)
    If ib3d_KeyDown(EKEY_NUMPAD4) Then ib3d_MoveEntity(cam,-.5,0,0)
    If ib3d_KeyDown(EKEY_NUMPAD8) Then ib3d_MoveEntity(cam,0,0,.5)
    If ib3d_KeyDown(EKEY_NUMPAD2) Then ib3d_MoveEntity(cam,0,0,-.5)
    
    ' turn the camera
    If ib3d_KeyDown(EKEY_LEFT) Then ib3d_TurnEntity(cam,0,-.5,0)
    If ib3d_KeyDown(EKEY_RIGHT) Then ib3d_TurnEntity(cam,0,.5,0)
    If ib3d_KeyDown(EKEY_UP) Then ib3d_TurnEntity(cam,.5,0,0)
    If ib3d_KeyDown(EKEY_DOWN) Then ib3d_TurnEntity(cam,-.5,0,0)
    If ib3d_KeyDown(EKEY_SPACE) Then ib3d_TurnEntity(cam,0,0,.5)

    ' perform collisions and reposition entities based on collisions
    ib3d_UpdateWorld()
    ' render the current world
    ib3d_RenderWorld()
Wend

ib3d_EndGraphics()

Should scaling animated meshes be disabled?
Thanks for the information.

So, I guess I should look at the Irrlicht forums to find a working format that's right for me.
(Or I could build meshes in code...)