Light and MD3

Hi!

I have a little problem with md3 models. In my scene I have a pointlight that follows the cam. But moving the cam (and with it my pointlight) doesn't have any shading effect on my models. At the beginning they are lighted correct from the cam direction, but moving the cam and the light doesn't change the lighting on the models. Everything else in the scene works fine with the changing light direction. Does anyone know if this i a bug, or am I doing something wrong???

Sounds like the models have their own copy of the light.  Try recursively removing all lightstates from your model nodes and then attach them to your scene and update their renderstate so they get the scene lighting.

Hmm…no, they don't seem to have a copy of the light. I figured out that the models take effect of the light(because I switched off all the other lights in the scene), but they do that very strange…Sometimes it seems that they are lighter from the other side. Perhaps the normals are flipped?? Or my model is not exported correctly. Does anyone know a good md3 exporter for Blender?

I flipped the normals and now it is better. But I still ave a problem:

my models are always lighted from the wrong side. When everything is lighted from the right, my models are lighted from the back. when everything in the scene is lighted from the left, my models are lighted from the front…

Did I forget to call an update??

It sounds as if you are still using the wrong normals caused by a difference in reading/writing the normals between your MD3-exporter and the importer in jME. If you have extended SimpleGame, try hitting the "n"-key to view the normals. If you have not extended SimpleGame, Debugger.drawNormals(…) does the trick. From your description it sounds as if you simply need to rotate the normals 90 degrees around the y-axis.

thank you. I'll see whats wrong with the normals.

I notice normals are still messed up on md3 models. Im referring to the new nordhorse model and TestMd3JmeWrite. I exported an md3 from blender and had the same problem I just couldnt get the normals to behave. The model was always lit from the wrong side. Im assuming this is a bug in the blender exporter,  Ive also noticed problems with normals when exporting to md5 also. Im wondering what the best solution is? would it make more sense to fix the blender exporters, or somehow recompute the normals in jme when loading. is that even possible?  :?

looking at Md3ToJme there is method readNormal so I exported a simple textured md3 cube and put some printlns to see what kinda info its reading.

For one thing readNormal gets called hundreds of times which seemed odd for a cube, but heres the method(for reference) and a small portion of the output. Its wrong but is it exported from blender wrong or imported into jme wrong? Im trying to figure this out but dont hold your breath it may take awhile  .


private void readNormal(Vector3f norm) {
            int zenith = file.readByte();
            System.out.println("Zenith: "+ zenith);
            int azimuth = file.readByte();
            System.out.println("Azimuth: "+ azimuth);
            float lat = (zenith * 2 * FastMath.PI) / 255;
            System.out.println("Latitude: "+ lat);
            float lng = (azimuth * 2 * FastMath.PI) / 255;
            System.out.println("Longitude: "+ lng);
            norm.x = FastMath.cos(lat) * FastMath.sin(lng);
            norm.y = FastMath.sin(lat) * FastMath.sin(lng);
            norm.z = FastMath.cos(lng);
            System.out.println("XYZ: "+ norm.x + " " + norm.y + " " + norm.z);
        }

Zenith: 88
Azimuth: 31
Latitude: 2.1683152
Longitude: 0.76383823
XYZ: -0.3891443 0.57185066 0.7221865
Zenith: 88
Azimuth: 225
Latitude: 2.1683152
Longitude: 5.543987
XYZ: 0.37901625 -0.5569674 0.7390087
Zenith: 88
Azimuth: 161
Latitude: 2.1683152
Longitude: 3.9670308
XYZ: 0.41341814 -0.60752124 -0.6782353
Zenith: 88
Azimuth: 95
Latitude: 2.1683152
Longitude: 2.3407948
XYZ: -0.40389174 0.59352213 -0.69613373
Zenith: 38
Azimuth: 31
Latitude: 0.93631786
Longitude: 0.76383823
XYZ: 0.41000953 0.55708075 0.7221865
Zenith: 38
Azimuth: 95
Latitude: 0.93631786
Longitude: 2.3407948
XYZ: 0.4255477 0.5781925 -0.69613373
Zenith: 38
Azimuth: 161
Latitude: 0.93631786
Longitude: 3.9670308
XYZ: -0.43558487 -0.59183 -0.6782353