Jan 30, 2012
Klas

Md2 to json converter

Tried to make a simple little “webapp” that converts Md2 models(the old quake 2 model format) into the json format(version 3) that is used by three.js.

You simply open the page, and then drag and drop a *.md2 file and it will be converted and a preview of the mesh should appear. You can then drag and drop jpg/png images for the texture to be previewed as well.
Left click and drag to rotate, right click and drag to move. Scrollwheel to zoom.
If it looks ok, enter a filename and hit “Save”.
It should now be downloaded(in Chrome at least, Firefox opens it in a new window).

You can then load in the json files into your three.js projects and use them as morphTargets.

MD2 to JSON Converter (a model to test with, if you don’t have one)

Example of converted model as morphTarget

Stresstest

Three.js

I have only tested this in Chrome and Firefox, so not sure if it works anywhere else. Mostly done as an exercise for myself to understand the format, drag and drop and filehandling etc. But might be useful to someone else out there.

Edit (Mar 08, 2012): Looks like I had the exporter output a horizontally flipped model, should be fixed now. Thanks to @alteredq for letting me know.

Edit (May 11 2013): Updated it to export to the latest format(3.1).

Edit (Feb 10 2014): Fixed it, was broken due to some webgl changes in recent browsers.

13 Comments

  • Awesome!

    I tested it with some models from

    http://telias.free.fr/Models_menu.html

    They came in just fine…

  • Thanks a lot for this amazing tool!
    Could you please let me know where you get the MD2 models? looking for a place I can get few for free or buy.

  • When i download it with Firefox, it’s saved like “name.part” file. Why i can’t save it like .js? It’s only a .part file

    • Not sure why that is, I guess it´s just the way Firefox handles these “blobs” differently. But all the data is there and you can just rename the *.part-file to “whatever.js”.

  • I’ve got an issue with a two-materials model (a single texture seems to be used for the whole model), is it possible to convert it from md2 to json using your tool ?

    • You mean two textures are used on a single model? Do you have an example of such a model somewhere? Might be better to go with the three.js blender pipeline for such a model though.

  • This is really awesome work.

    Do you think it’s possible to convert the normal indexes to the json format ?

  • I’ve tried to use the converter under different versions of Three.js and since r50 the texture mapping fails as the mapping vertices seem to be wrong.

    Do you have any idea of what has changed in Three.js since r50 that might have caused the problem ?

    • Yes, I think something with the texture-flipping changed in Three.js. Between 3.0 and 3.1 of the json-format: https://github.com/mrdoob/three.js/wiki/JSON-Model-format-3.1

      I´ll see if I have time to change the converter to output v 3.1 instead, should be an easy fix.

      In the meantime you could probably set texture.flipY = false;

      • You’re right the flipY trick worked just fine.

Leave a comment

Twitter

Categories