MD2 Import

I exported a MD2 file from Blender and tried to import it into jME. The result was weird textures.

The problem is that Blender maps the UV coordinates per face and jME reads the coordinates per vertex.

In the class Md2ToJme is the comment “//reorginize coordinates to match the vertex index.” In this code block gets the “per face uv mapping info” lost.

My solution is to duplicate a read vertex if it has more than one uv coordinate to match the jME file format.



I don’t understand why other MD2 files work accurately.



Sigi

Hi!



Obviously it’s not clear what I meant. It could also be my poor english ://. Let me try to explain it.

I make a model with Wings3D. Then I export it to the Wavefront OBJ file format. I import it into Blender and animate it. I export it to the MD2 file format. Then I load the model into jME. The mesh is OK but the texture (a jpg file) looks weird.

To find out what’s going wrong, I made a cube in Blender (12 triangles). I textured the cube with UV Mapping. The jpg file I used shows on every side of the cube another color. I exported the cube to the MD2 file format. I loaded it into jME. The texture was only shown on two sides correctly. The other sides become distorted. I looked at the Md2ToJme class. In the method convertDataStructures() you have the assumption (? german: Annahme) that every vertex has exactly one UV-coordinates pair. But MD2 files have the possibility to store more than one UV-coordinates pair per vertex. They store a UV-coordinates pair for every vertex per face. That means that on my cube there are between three and six UV-coordinates pairs per vertex dependent on the arrangement of the triangles.

The values of the variable texCoords2 in convertDataStructures() are overwritten more times. Many UV-coordinates get lost and that’s the reason why the textures look weird.

I changed the code. It duplicates every vertex so many times as the vertex has UV-coordinates pairs.

Now I can import every model made in Blender.



My question is: Have I done something wrong or is it a bug in the export script of Blender or is it a bug in jME?



Sigi

It was mojo that coded that part of the MD2 code, so I don’t know too much about how MD2 loading works. I’ll look at it when I get home tonight, and see if there’s an easy fix (unless you’ve made one from what it sounds. If so, post the code here)

Sigi, can you post the text of your fix? Are you using the Model Loader, or the Model Exporter (to .jme format)?

Hi!



I’m using the Model Exporter. The file is too big to post.

You can find the new class here:

http://www.fmi.uni-passau.de/~webersf/Md2ToJme.java



Sigi

Hmmm one of those things that slipped my mind, but I never integrated this fix into the baseline. Cep, did you happen to?

btw, the md2, *.3ds and md3 do not support two uv vertices per 3d vertex. that’s its format design limits -one of them-



That means: most exporters what actually do is…duplicate a vertex in 3d, when the exporter detects a single 3d vertex is having two UVs. the weird thing of this is…it will generate a seam in the geometry,a clean cut of the smoothing, never seen good where it appears. Dealing with this in the art side is hiding very well the seams (the uv shapes contours, the borders of the uv chunks) in unseen model parts where doe snot matter that match then that appears a seam.



I don’t know if it’s related to what u say.



Is another reason why I prefer *.x or md5…