LWJGL Models

I’m working on a LWJGL 3d model thing at the moment in the new-and-upcoming org.lwjgl.util subpackages.

It’s got bones and animation in it, and will come with example renderer and example loader from XML format. Some of the code will no doubt be heavily influenced by Elias’ TT code coz he’s helping me write it :stuck_out_tongue:

Should come in handy methinks. The only snag is exporting from the various tools out there.

Cas :slight_smile:

We use a .obj loader, you will keep it open for new formats ?

org.lwjgl.utils, it’s new ? how heavy it’s going to be ? ;D

Sounds interesting, I take it this is your own custom format then?

ohhh fun :slight_smile:

any ETA on that? (well the alpha version or smthg)
I’d love to mess around with models (w/o paying for a modeler or learning Blender) :wink:

The difference here being that the Model class I am designing is format agnostic. It’s just an internal way to represent an animated boned skinned 3d model.

The clever part, as I say, is in the implementation of a Loader and Renderer. I’m going to write an XML Loader and hopefully tweak an existing 3ds exporter to output the correct XML. And I shall also write a “trivial” low-performance renderer as example code.

Cas :slight_smile:

Feature set? Is it a quick-and-dirty list of triangles, or are you making it a general-purpose NURBS/voxels/IK description?

Would you mind posting your current thoughts on the contents of the XML file, just so we have an idea of where you’re headed?

something like:


<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<!--
      LWJGL model format template
-->

<!DOCTYPE model [

      <!ELEMENT model (vertex+, triangle+, animation+)>
      <!ATTLIST model material CDATA #REQUIRED>
      <!ATTLIST model bones CDATA #REQUIRED>

      <!ELEMENT vertex (skin+)>
      <!ATTLIST vertex x CDATA #REQUIRED>
      <!ATTLIST vertex y CDATA #REQUIRED>
      <!ATTLIST vertex z CDATA #REQUIRED>
      <!ATTLIST vertex u CDATA #REQUIRED>
      <!ATTLIST vertex v CDATA #REQUIRED>
      <!ATTLIST vertex nx CDATA #REQUIRED>
      <!ATTLIST vertex ny CDATA #REQUIRED>
      <!ATTLIST vertex nz CDATA #REQUIRED>
      
      <!ELEMENT skin EMPTY>
      <!ATTLIST skin bone CDATA #REQUIRED>
      <!ATTLIST skin weight CDATA #REQUIRED>

      <!ELEMENT triangle EMPTY>
      <!ATTLIST triangle a CDATA #REQUIRED>
      <!ATTLIST triangle b CDATA #REQUIRED>
      <!ATTLIST triangle c CDATA #REQUIRED>
      
      <!ELEMENT animation (frame+)>
      <!ATTLIST animation name CDATA #REQUIRED>
      
      <!ELEMENT frame (bone+)>
      <!ATTLIST frame time CDATA>
      
      <!ELEMENT bone EMPTY>
      <!ATTLIST bone m00 CDATA #REQUIRED>
      <!ATTLIST bone m01 CDATA #REQUIRED>
      <!ATTLIST bone m02 CDATA #REQUIRED>
      <!ATTLIST bone m03 CDATA #REQUIRED>
      <!ATTLIST bone m10 CDATA #REQUIRED>
      <!ATTLIST bone m11 CDATA #REQUIRED>
      <!ATTLIST bone m12 CDATA #REQUIRED>
      <!ATTLIST bone m13 CDATA #REQUIRED>
      <!ATTLIST bone m20 CDATA #REQUIRED>
      <!ATTLIST bone m21 CDATA #REQUIRED>
      <!ATTLIST bone m22 CDATA #REQUIRED>
      <!ATTLIST bone m23 CDATA #REQUIRED>
      <!ATTLIST bone m30 CDATA #REQUIRED>
      <!ATTLIST bone m31 CDATA #REQUIRED>
      <!ATTLIST bone m32 CDATA #REQUIRED>
      <!ATTLIST bone m33 CDATA #REQUIRED>
      
]>

<!--
      The model can be made of one material only, given an arbitrary name.
      The number of bones must be specified here.
      
      If you need models made of multiple materials or multiple parts, then
      what you really need is multiple models.
-->
<model material="arbitrary_name" bones="numbones">
      <!--
            Any number of vertices. The order of the vertices determines their index number
            which is used by the triangle definitions.
      -->
      <vertex x="" y="" z="" u="" v="" nx="" ny="" nz="">
            <!-- Any number of skin elements, describing how bones weight the vertex position -->
            <skin bone="0" weight="1.0" />
      </vertex>

      <!-- Any number of discrete triangles. -->
      <triangle a="0" b="1" c="2" />
      
      <!-- Any number of animation frames, referenced by name for easy reference -->
      <animation name="animation_name">
            <!-- Any number of animation frames, with timing information -->
            <frame time="0.0">
                  <!-- All bones need to be specified -->
                  <bone m00="" m01="" m02="" m03="" m10="" m11="" m12="" m13="" m20="" m21="" m22="" m23="" m30="" m31="" m32="" m33="" />
            </frame>
      </animation>

</model>

Cas :slight_smile:

In other words, bones-triangles-animation, and not much else. See how it spreads the problem out into other areas?

Cas :slight_smile:

Ok, the model package now contains two kinds of model - mesh animated models, where the whole mesh is respecified every frame, and bone animated models, where only bones are updated every frame.

The base Model class is composed of a set of triangle index definitions, a skin of UV coordinates, and a map of animations.

The loader can load both from XML.

Comments please?

Now on to a trivial renderer.

Cas :slight_smile:

Hehe, I’ve just taken a look to the model source code and it seems that you’ve made an amazing work once again !!!
Keep this up ! (and include it into lwjgl 1.0 ?)

I’ve just a question (it’s not the good place to ask it but I don’t want to make a specific thread for it) : when will be released the full 0.9 version ? because it still an alpha release…

Thanks for the great work ! I love lwjgl, it’s an impressive lib 8)

Chman

Here’s a few questions/comments for you:

[*]Is there a specified format for the material name, a URL for example, or is it a logical name that the app should understand?

[*]It’s not exactly how I like to see XML written - I prefer elements to be in a section etc, but that’s personal preference. :wink:

[*]Is it worth putting an id on repeated elements? It’d be easier to use if the numbers used by e.g. triangle definitions are present in the file - not for the computer, but for the user. You’d have to change things to not work on file order but on id number instead - probably not a big change.

[*]I don’t know anything about bone animation - I trust that the system presented both works and will be implementable in many different modellers! I’ve always seen bones described as having length, but I guess that’s just a visual aid.

[*]You have a bone count field, but not a vertex, triangle or animation count. Why?

[*]What are nx, ny and nz? Ah, normals. Gotcha.

[*]What is the timing information - specified units or application-interpreted?

[*]Do you have updated XML fragments for us? I don’t see any examples in CVS.

[]Loader.loadBone(): if you’re making m3 optional, shouldn’t you make m*3 optional as well?

[*]Might vertex colours be worth considering, for non-textured worlds?

Edit - added more items, 12:08, 12:13.

[quote]I’ve just a question (it’s not the good place to ask it but I don’t want to make a specific thread for it) : when will be released the full 0.9 version ? because it still an alpha release…
[/quote]
0.9 is the “full” 0.9 version. The “Alpha” designation has been used for all releases so far because the API is still subject to change. “Alpha” will go away by 1.0. (Oh, and ignore the “pre-0.9” version string - that’s a typo!)

Sounds pretty nice so far.

How big will these xmls be (in compressed form) compared to 3ds? (no big difference right?)

Thanks :stuck_out_tongue: Once again I asked a stupid question ;D
Ok, so when do you plan to release the 1.0 ? lol I know that the 0.9 version has just been released, but I’m very impatient :wink:

Chman

No specific format - it’s a string which identifies some other thing. Use a URL or whatever you like. The only thing it has to do is help whatever renderer you are using to determine how to draw the triangles. It could, for example, just be a colour “r,g,b,a”, or it could be the name of a texture. The reference implementation renderer is going to use it to lookup something that is Renderable in a Map and call render() on it before drawing driangles.

I might add surrounding tags but they’re almost redundant, and I so hate redundancy :stuck_out_tongue:

No, not really worth it. The order of the elements in the XML file is significant, so why not use the implicit ordering? Besides - this XML is almost 100% certain to be machine generated anyway.

Neither do I :stuck_out_tongue: Elias is hopefully going to help me here. A bone is apparently just a matrix which transforms a vertex. In the 3d modeller it will be represented probably with actual “bones” with length and so on, but when they are exported they just boil down to a matrix.

The bone count and vertex counts (there’s a vertex count in cvs too) are used as sanity checks to check the triangle indicies and ensure that the animation frames and skin specify the correct number of elements. The triangle count need not be checked against anything so it’s not specified.

Application-interpreted floats. So probably “seconds” to most apps.

Later tonight.

You need to learn more maths :slight_smile: The last row in the matrix should pretty much always be 0,0,0,1 or some really freaky things happen. That’s why they’re optional, and if not specified, default to 0,0,0,1. The right hand column, on the other hand, specifies a translation.

I considered it and then thought - no-one ever uses vertex colours in a real game! Leastways, not specified in the actual model data. But seeing as you’ve asked for them, I’ll add them in the skin as optional data.

Note that the model provides for no animation of texture coordinates, nor will it provide for animation of colours, nor will it provide compound models. Although I have some ideas to create a compound model class.

Here’s what I will do tonight then:

  1. Wrap tags around the data sets to make Charlie happy

  2. Create 2 example XML files

  3. Play Morrowind a bit more.

  4. Add colours.

  5. Play Morrowind a bit more.

  6. Do a little bit more on the simple Renderer implementation

Cas :slight_smile:

If we get some help on the Mac port, documentation, examples, and util code, we’ll get 1.0 out for JavaOne. Otherwise it might be some time in the summer…

The util packages are independent of the releases.

Would anybody like to volunteer to write some exporters to the LWJGL XML model format? Or converters?

Cas :slight_smile:

[quote]The bone count and vertex counts (there’s a vertex count in cvs too) are used as sanity checks […]
[/quote]
Hmm. I’m rather tempted to say that that’s the loader’s problem, not the data file. An element count is easy to do from the loader side, so putting the value in the data as well adds little. shrug

[quote]You need to learn more maths :slight_smile: The last row in the matrix should pretty much always be 0,0,0,1 or some really freaky things happen. That’s why they’re optional, and if not specified, default to 0,0,0,1. The right hand column, on the other hand, specifies a translation.
[/quote]
Ah, heh. Yep, absolutely right. Totally the wrong end of the stick. Move along… ;D

[quote]I considered it and then thought - no-one ever uses vertex colours in a real game! Leastways, not specified in the actual model data. But seeing as you’ve asked for them, I’ll add them in the skin as optional data.
[/quote]
Cheers!

[quote]1. Wrap tags around the data sets to make Charlie happy
[/quote]
Ooh, no. It’s your baby, don’t change something like that because of one comment.

[quote]3. Play Morrowind a bit more.
5. Play Morrowind a bit more.
[/quote]
An excellent choice! :wink:

[quote]I considered it and then thought - no-one ever uses vertex colours in a real game!
[/quote]
Maybe not on animated geometry like skinned meshes. But static meshes that don’t move can use vertex colors for lighting. In quake3 vertex colors is used instead of lightmaps on some meshes. Is this a general format or only designed for animations?

Is the format going to support multiple sets of texture coords. Is nice to have when you wan’t to add normal maps and other shader data.

[quote]How big will these xmls be (in compressed form) compared to 3ds? (no big difference right?)
[/quote]
I’m guessing it’s going to be a bit bigger than a 3ds file. The uncompressed files will be huge and slow to parse compared to a binary file. If you wan’t to use it in a game I suggest you convert it into a binary format first.

Btw. I did something similar a couple of years ago. Made a maya script that exported skeleton animation to a text file. Also had a importer and java 3d viewer.

I could try modifying it to confirm to your xml format. It is slow as hell though. Takes several minutes to export 100 frames of animation :frowning:

I might take a look at it when you get the viewer up.

Check out my post in Game News regarding the announcement of a universal 3d file format.

Hopefully in the future we’ll only need one loader!

Andy.