Just Triangle Faces
Posted at  2016-12-30 10:00:00+01:00
Author   Kostas "Bad Sector" Michalopoulos
Tags   tech tools jtf fileformat placer qt qtcreator

A couple of days ago i decided to try -again- learning Qt Creator and Qt5 since i've been told a few times by a couple of different people that it is really a "RAD" IDE similar to Delphi, Lazarus, C++ Builder, etc. And to actually get familiar with it though i couldn't just throw a few buttons and switches together and call it a day - instead i had to work on something i already have worked with in Lazarus and C++ Builder to make a good comparison.

Placer

Last year (Summer 2015) i wrote a small program in Lazarus which i call Placer - Placer is a simple 3D scene editor where you just place objects in space (hence the name). Objects can have a 3D model associated with them and a bunch of key-value properties (the properties are freeform, but Placer can understand and automatically update a few of them, like position, rotation and scale).

It took me a single day to make Placer in Lazarus, yet it deals with many things that i expect 3D gamedev tools to deal with. Because of that, i decided to try and make a Placer-like 3D scene editor with Qt and Qt Creator to learn (and judge) it. While with Placer i used the RTTK (RunTime Tools Kit, a Lazarus package with a bunch of units that i use across several tools), for the Qt scene editor i use a bunch of classes i wrote for C++ Builder that include more or less the same stuff and i call with the very original name bcbcmn. These classes contain stuff like dynamic arrays and hashmaps with a sane API (i am not a fan of STL, although even if i was the C++ Builder STL is broken anyway), vectors, matrices, hit testing, a json-like (but simpler) tree-based file format (it is even compatible with Placer's file format), geometric tools, texture database and a bunch of other stuff.

One thing that is missing from bcbcmn is mesh handling and mesh loading. I didn't want to bother writing an OBJ loader (and the RTTK OBJ loader is quite slow and in dire need of a rewrite) and while i could just create a DLL in Lazarus that exposed the RTTK OBJ loader, i decided instead to do something that i had in my mind for a while:

Inflict a new mesh file format upon the world!

JTF Viewer

Well, it is actually more like making a common format for something i already did in an adhoc manner a bunch of times using the RTTK OBJ loader to convert meshes. My OBJ loader doesn't bother with all the intricacies of OBJ files - it only loads mesh data and ignores objects, materials, etc. And the new file format would only contain what i used from OBJ files for the last few years: just the faces.

Indeed that was the initial idea for the file format's name, Just The Faces (JTF) but since "faces" can also mean quads and ngons, i made it explicit that i mean triangles by making T to stand for triangle. So the name for the new format is Just Triangle Faces.

The format is very simple: a small header file with four magic bytes spelling JTF!, a 32bit integer for the vertex format which must be 0 (a 32bit integer is really a waste so in the future i might use the first byte for the mesh version and the other three for other things - since it has to be 0 at the moment it is more of a placeholder than anything else anyway) and a 32bit integer for the triangle count followed by the vertex data that make up the triangles - each one being eight floats: three for position, three for normal and two for texture coordinates.

The entire thing can be loaded in one go (or even just memory mapped) and given directly to OpenGL (minus the header of course) in 5-6 lines of C code. It hardly gets any simpler than that.

Of course a format by itself is pretty useless without tools to work with it. At the moment the only two tools are the JTF viewer (pictured above) which can be used to show JTF files (you can also load a texture image) and a Python script for Blender that exports the selected object as a JTF file.

In the future i might make another one for skinned meshes, but for now JTF will do for the uses i have in mind. I already added support for it in RTTK (so now my Lazarus tools can load both OBJ and JTF files) and wrote the code for loading JTF files in the Qt-based scene editor.

The JTF homepage can be found here.


   © 2009‑2016 Kostas Michalopoulos