graphics3dgltf

glTF: how can we store basic geometry primitives?


I'm new to glTF and I would have a very basic, and maybe naive, question. Sorry, and thanks for your understanding and your help.

We have a C++ application where we handle geometry primitive entities, like boxes, cones, cylinders, and so forth.

For visualizing the geometry entities we currently use Coin3D, which have corresponding geometry shapes: Box, Cone, ...

We now would like to add a glTF exporter too, and I have started to explore the glTF specs. I must say, in the official documentation, and on the web, I could not find any support in glTF for basic geometry shapes.

Therefore, my questions are:

  1. is that true, that glTF has no notion of, let's say, a Box, or a Cone? Or did I missed something obvious?

  2. If the answer to 1) is "NO", are there tested/supported/suggested implementations for basic shapes? I have only found some "example" shapes, like the Box here; but I could not find any collection of implementations of basic shapes. Again, did I miss something?

  3. Are there any best practices, or documentation, on how to implement basic geometry shapes in glTF?


Solution

  • The short answer is you're correct, glTF does not currently store basic geometric shapes directly as a box, cone, cylinder, etc. The format is intended to be a runtime delivery format, not an asset interchange format.

    As such, the internal data structures within glTF are designed to mimic the raw data that would typically be fed into a GPU using a graphics API such as OpenGL, WebGL, etc. Entire blocks of glTF data can often be pulled off a disk or network and handed over directly to a graphics API for rendering, with minimal pre-processing.

    This means that all of your basic shapes must arrive as the GPU expects to find them: triangulated. Even a simple box is made up of twelve triangles, and because the sides don't share normal vectors, the normal "vertex attributes" are different, hence triangles from different sides of the box don't share vertices (again, because the GPU wouldn't accept that as a raw input). The benefit is that a WebGL client doesn't have to think very hard about what to do when it receives a glTF, it can just start cramming data into the graphics pipeline to get things moving.

    For a broader overview, the ever-popular glTF - What the Duck diagram is widely considered an excellent starting point, and the glTF Tutorials are a good follow-up to that.

    glTF what the