Pages

Wednesday 27 July 2011

Getting started with 3D model formats

Brief tutorial that should get you started, based on what I did.
Provides very informal (and possibly wrong) explanations for all the technical concepts. Is meant for you to get an idea what you're getting yourself into, rather than information.

You should go and read better explanations on wikipedia or other formal sources.
Or you can just read this; it's much more formal and accurate:

http://wiki.xentax.com/index.php/DGTEFF

  1. Hex

    The hexadecimal number system. You can read more about it on wikipedia if you really want to, but just know is that it's a different number system from the one you usually use (decimal) and everything is in base 16.

    Decimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
    Hexadecimal: 0, 1, 2, 3, 4, 5, 6,7 ,8, 9, A, B, C, D, E, F

    One of them has 10 different values, the other has 16. Decimal is base 10, hex is base 16. The naming should now be clear.

    It can be useful to be able to convert hex to decimal and back in your head quickly, but who really cares chances are you'll be working on a computer and there's plenty of software out there that will do this for you.

  2. Hex Editor

    What you will be using the majority of the time since most are stored in binary formats, though at times you may run into ASCII text files. You can read about the rationale behind binary formats on your own since it's not too important either if you just want to get some models.

    Some hex editors that I've used and liked:

    HxD - Free. Very simple hex editor.

    Hex workshop - Free. Automatically displays the short, integer, float, double float, and other interpretations of the current string of hex bytes. Useful if you don't want to bother learning hex

    010 editor - Not free. 30 day trial version is enough. Buy it if you like it. Provides all of the above functionality and more (that you will probably never use)

    I would recommend anything that translates what you're looking at to something you can understand because it's convenient.

  3. Data types

    If you want to know the details, you can look it up on wikipedia.

    Short - 2 byte number. I guess common people call it "whole numbers"
    Integer - 4 byte number.
    Long - 4 byte number
    Half-float - 2-byte floating point number based on some standard...maybe
    Float - 4-byte floating point number based on the IEEE standard
    Double-float - 8-byte floating point number based on IEEE standard

    All you need to know about what a byte is, is that in the hex editors I listed, you will see a bunch of digits in groups of 2. That is a byte. If you want to know what a byte is, google it. I am not sure if having a thorough understanding of the terminology will help you, but it might.

  4. Compression and Encryption

    Stuff that I don't like. Protects data, makes it hard for you. To get the data you need to decompress and/or decrypt the data. I don't have much clue on this.
  5. Reading 3D file formats

    Sometimes people post up the specs for some file format. This is useful because all you need to do is follow it and write a parser for it. Though you really should only use them as reference when looking at the hex. It also gives you a better idea what

  6. Understanding a binary 3D file

    Not easy. Basically, to understand what you're looking at, you have to understand what it represents in the first place.

    If you're looking at a model format, you should go figure out the different parts of a 3D format. If you know what kind of data there is, then the chances of you accurately guessing what a particular section represents suddenly goes up a lot.

    People say it takes experience, and that's true. Having a thorough understanding of 3D files is also essential.

  7. Where you should start

    If you don't know what a 3D model might have, then you should start with common (text) formats that are documented and write some parsers for that. I started with the metasequoia MQO format and the wavefront OBJ format since they cover the basics for the geometry and the materials/textures. Neither formats support bones or weights, so I don't really understand those things.

    If you have experience working with 3D modeling software or 3D graphics in general, you probably know more than I do already.

  8. Writing the parsers and exporters

    You have plenty of options here. Any programming language out there can be used to read the file, and any software can be used to display the model. You can even write your own model viewer, but I would rather just use an existing model viewer and export what I've read to that format.

    Blender and 3D max scripts are fairly common since you can load everything immediately to check your results.

    Alternatively, you can use Sanae 3D, an attempt to simplify the binary reading process by breaking it down to a couple simple methods like "read_float" and "read_short". Sanae 3D also comes with an MQO exporter, so all you need to do is write your parser functions and then just export it and view it. But because I wrote the program, it only does things that I know and therefore you can only get the simple things like meshes materials and textures, no bones or weights.

  9. Easy formats to start with

    I've found that MMORPG's have fairly simple formats. Other games like console games tend to fill all sorts of information along with the model so that may be difficult. Plus there's compression and encryption to worry about, so maybe you can just start with some MMORPG's.

    If you think you're up for it, consider this tutorial and write a parser.

No comments:

Post a Comment