MD2 Lighting etc.

Hi,

I hope someone can help - I am using an MD2 file which I load into my scene

I attached material like so :

Material mat2 = new Material(true);
mat2.setEmissiveColor(0.0f, 0.0f, 1.0f);
mat2.setSpecularColor(0.2f, 0.2f, 1.2f);
mat2.setAmbientColor(0.7f, 0.7f, 0.7f);
mat2.setDiffuseColor(0.1f, 0.1f, 1.1f);
mat2.setAmbientColor(0.75f,0.75f,0.75f);
mat2.setDiffuseColor(0.75f,0.75f,0.75f);

		mat2.setLightingEnable(true); 

//recusively add materials
addMaterial(modelTransformGroup, mat2);

But the model appears very flat without any shadows - I used the same “mat2” on both .OBJ and .ASE and the result is fine.

does MD2 not respond to the above Material?

I followed the example from within the MD2 loader file - and thats much the same

what am I doing wrong?

Thanks

Rmdire

I think your recursive function just don’t work with the MD2 loader because it has a special class : MD2ModelInstance, which probably doesn’t respond to appearances. One more time I encourage you to read the source code, you’ll find where nodes are constructed in a relatively short time span and we can then see together if there’s actually a possibility to change the appearance without modifying the loader, or what’s the best way to implement that.

Cheers

Have you also played around withsetColorTarget? Maybe that would help?

HI ,

Have tried several combinations - including setColorTarget for each setting as suggested - no joy

I have even tried to turn up the Red , Green and Blue individually to see if there is a singular colour effect - again no joy

arne - was setColorTarget a shot in the dark or have you had success already?

From the source code I see there is a MD2Model.getAppearance() Method - I have also tried using this to set appearance prior to getting the model instance
again - no joy

any Ideas?

Have you done MD2Model.getAppearance.set[…], or MD2Model.setAppearance(new Appearance(…)) ?

                                       Material mat2 = new Material(false);
  		//mat2.setColorTarget(mat2.EMISSIVE);
		mat2.setEmissiveColor(new Color3f(2.3f, 0.3f, 0.3f));
		//mat2.setColorTarget(mat2.SPECULAR);
		mat2.setSpecularColor(new Color3f(2.2f, 0.2f, 1.2f));
		//mat2.setColorTarget(mat2.AMBIENT);
		mat2.setAmbientColor(new Color3f(2.7f, 0.7f, 0.7f));
		//mat2.setColorTarget(mat2.DIFFUSE);
		mat2.setDiffuseColor(new Color3f(2.0f, 0.5f, 0.5f));
		mat2.setShininess(0.9f);
		mat2.setLightingEnable(true);   

		model.getAppearance().setMaterial(mat2);

                                     character = model.getInstance();
            		  
                                     BranchGroup temp = new BranchGroup();
                                      temp.addChild(character);

nah - more a shot into the dark, because I use different settings when having textures and when not.
If I don’t have textures I use setColorTarget(Material.NONE) else setColorTarget(Material.AMBIENT_AND_DIFFUSE)

maybe you could try this setting for ambient-light:


 mat2.setAmbientColor(new Color3f(0f, 0.0f, 0.0f));

what do you see then?

No Change really - maybe a teeny bit darker - but can’t be sure

Try to change :

To :

However this may loose your previous MD2 material.

including textures

unfortuately - that wont work either - MD2Model has its own private Method getAppearance()
but no setAppearance() - (Im using eclipse - so all native and inherited properties/methods show in the intelli-sense)

I don’t think this gonna happen somehow.

no we mean to call setAppearance on the returned Shape3D’s.

If you changed the appearance returned by the MD2Model it seems to me clear, why it didn’t work before, because you didn’t change the appearance of the Shape3D’s that got returned by the model, but changed a Appearance that might even got created directly in that method and that is not referenced anywhere else.

Ok - this has some effect - however - it seems to just darken or lighten the texture -

i will play around a bit more a & see whats happens

cheers

rmdire

Wasn’t there a fix to do with normals recently - have you got this in the code you’re using?

You shouldn’t have to traverse the scenegraph yourself setting appearences, doesn’t the MD2 loader use the NodeFactory pattern - so you can supply your own node factory which sets the appearances as the model is loaded.

Kev

Sorry - but this still doesn’t work

I added in the Normals Fix etc.
the texture is coming thru - but I am still getting a flat model

Rmdire

also - the strange “Light up effect” when the model faces the light is still there