Removing Strips and Fans From MD2 Exporter

Ok - I have a strange question. Not even sure if this is possible but I’ll give it a go:

The md2 exporter for blender is not working properly, and hasn’t been working properly for the past few years. The result is due to using strips and fans, and I am curious to see if we can get the MD2 Importer to work without using strips and fans?

If Kev, etc. could get it working without them, it would be a HUGE help to me and the many others who are trying to import MD2’s. Is it possible?

Thanks!

Since you asked so nicely :slight_smile: - can you post an example model with which the MD2 importer fails and I’m sure we can work out a way round the issue.

Kev

Maybe I wasn’t clear. There’s nothing wrong with the MD2 Importer you wrote(in fact I think it is a godsend if you ask me). But the way the Blender MD2 Exporter is programmed right now, the geometry of the model gets messed up when using strips and fans. There’s something wrong with the exporter code and they haven’t been to expedient in fixing it :). I was hoping we could get the md2 importer to not use them so the geometry would be fine again.

As an example model, I’ve been using marvin the good ol’ martian enclosed in your sample. Try importing it into blender, then exporting it as an md2.

Yeah, I got ya - I don’t have blender or any knowledge on how to use it - if you could just post your imported then exported version of marvin I can work from there.

Kev

EDIT: No worries, got blender etc.

Ok, just done some hacking tonight and it seems we can get the model to display correctly from a MD2 exported from blender. The current version of the model loader assumes that the GLCommands stored at the MD2 model are correct and uses them for rendering. Unfortunately the blender exported completely buggers these up.

So, locally I’ve hacked in a change that reads the triangles direct from the body of the MD2 and hey presto - we have a proper model.

Haven’t got time to firm this up yet - hopefully tomorrow.

Xith maintainers - are we interested in keeping both versions of the loading code intact - or just centralising on the version that works with blender? (since it’ll work for other models also).

Pros: We have backwards compatibility just in case there are any quirks
Cons: Two paths of code to support - one of which is redundant.

Kev

First, great job Kev. But if the Blender MD2 exporter is still supported by someone maybe it’s just easier to fix it.
Anyway, I suggest (I can do so if you agree) building a jar containing the old version (non-blender compatible) and commit the blender-compatible version to the CVS so it’ll be just fine for 0.8

I presume if someone with the required skills could fix the MD2 exporter they would have done it already? Apparantly its only a python script - looks pretty crappy as language to me but I’m sure it suits someone out there :slight_smile:

If it makes more sense to wait for someone to fix it there - lets do that :slight_smile:

Kev

I believe that there’s something wrong with Blender internally in the way that it processes glcommands(according to the author of the exporter). Bug reports have been submitted but there hasn’t been anything done about it.

Kev you’re a friggin genius. Let me know when you have everything firmed up. I can’t wait to import Md2’s!

Here it is:

http://www.cokeandcode.com/xith/xith-md2-0.2.0.zip

If someone could apply it in the right place that’d be great. :slight_smile:

  • Collapsed all the geometry into one triangle array (rather than strips and fans) - if Xith is using buffers intenerally this should be faster
  • Added some stuff to parse triangles and texture coordinates from the body of the MD2
  • Removed GLCommand classes since we’re not using them now
  • Remove MD2Loader2 - collapsed its functionality into MD2Loader.
    a) Because I couldn’t read MD2Loader2
    b) Because it seems pointless just to have it a number 2 for the sake of it
    c) Because theres no way to use MD2 usefully using the “Scene” interface (which is now noted in the docs)

Seems to work with the models I tested, including import/export from blender. However, theres an additional problem with blender it seems - the normals are stripped on export - so there lighting doesn’t look right. I’ve left a the computeNormals() line in the source to show one way of resolving this - however, this gives a very faceted look rather than the smoothed look normally associated with MD2s :slight_smile:

Test included - seems to work on the MD2s (lit and unlit) that I’ve got locally. Let me know if you have additional issues.

Kev

Who is going to be doing that?

Dang. I just spent the last two weeks modifying the COLLADA import/export to use trifans and tristrips so that it could accept the MD2 Loader geometries.

Recently we replaced MD2Loader with MD2Loader2 and renamed it MD2Loader.

I see that your new MD2Loader extends LoaderBase. That is just what I need to support DefaultLoader:
http://earth.whoola.com:8080/javadoc/xith-tk/org/xith3d/loaders/ext/DefaultLoader.html

Well to be honest, take it or leave it - I couldn’t give a flying ferret either way.

Kev

Kevin Glass,

I think you misinterpreted my message. When I asked, “Who is going to be doing that?”, I did not mean “Kevin Glass, you should do it as you should not expect anyone else to do it for you.” I meant “Which of us regulars is going to integrate Kevin Glass’s latest contribution? If no one responds within a day or two, I will volunteer to do it.”

I could. I refactored the loaders a while ago and the CVS is very different (package names) from last releases so I don’t want to let anybody get into troubles because of my changes (unless I disappear suddenly…)

Thanks for your help kev! Still having some problems though. I wasn’t sure where to put the code you placed, so I tried sticking it in a new folder and putting that in my classpath. Compiles fine, but I get this error when trying to run:

C:\xith3d\xith3d-0.7.1\xith3d>java -cp libs/xith3d.jar;C:\xith3d\third-party\thi
rd-party\vecmath\vecmath.jar;C:\xith3d\third-party\third-party\jogl\jogl.zip;cla
sses;c:/xith3d/md2loader2/xith-md2.jar org.xith3d.gsg.HelloXith3D
Exception in thread "main" java.lang.NoClassDefFoundError: org/xith3d/loaders/md
2/util/ModelLoadingException

Any ideas? Thanks!

Or you could just do this in blender:

Tab to go into Edit mode, A to select all vertices, Cntrl + T to triangulify

Out comes nice neat triangles…

DP

I tried that. It was already made of triangles unfortunately. Thanks for the interest though!

But it gives you twice as much polygons… bad for performances it’s annoying as my 3D artists mostly uses quads and I’m obliged to convert all to triangles, losing some performances (cause OBJ and MD2 supports Quads only).

For reference neither MD2 or OBJ support only Quads. Infact, MD2 only supports triangles. Triagulation in most cases wouldn’t any effect on performance since alot of cards render quads as two triangles anyway - so all trigulation would do for you would make your geometry data explcit.

However, more to the point. Triagulation in blender would have absolute no effect on the MD2 exporter - it generates a set of triangles based on the current geometry. It might help the exporter I suppose (?) but certainly wouldn’t fix the issue that the data exported from blender in the GLCommands at the end of the MD2 is plain wrong - so the loader had to be changed to use the body triangles.

As to the problem with the exception not being found. I’m not sure which version of the loader you were using originally - if you’re using the now official version the class that isn’t found isn’t used in it. I think maybe you’ve been using an old version up to this point - time to move to the next one.

Since I’m not a Xith developer I need someone to integrate the changes I made into the real code - I don’t want to be fixing this issue (if there is an issue?) against the wrong source code since that seems to have caused problems above. If there are any problems or when the integration is complete posting here would be helpful.

@arkdm - sorry not to be more help right now. Seems we’re so nearly there :slight_smile:

Kev

You’re right I mean that they support triangles only ^^

Ah ok.

You’re right. It won’t export if it contains quads.

Na, actually you can support Quads in OBJ files. Its just loaders I generally write don’t :slight_smile: Triangles used to be cheaper to render than quads in the good ole’ days </old_git>

Kev