ephtracy / voxel-model

1.22k stars 406 forks source link

How to check if a nTRN chunk is a duplicate of geometry? #46

Open capslpop opened 2 years ago

capslpop commented 2 years ago

The way I have the .vox reader set up is that it reads each object in as a texture. Then it reads the position and rotation of the object in the nTRN chunk. However, since the objects that are stored in the XYZI chunks are not duplicated then how do you know which object the nTRN data belongs to?

I assume that happens in the nGRP or the LAYR chunk but after testing the output of both the chunks I can't find anything that correlates to the object reference. Or does that not exist?

spaarmann commented 2 years ago

To parse general .vox files, you need to construct the scene graph from the nTRN, nGRP, and nSHP chunks. Each instance of one of these chunks defines one element in the tree scene hierarchy with an ID. A nGRP node can have many children (identified by their ID), an nTRN node has exactly one child and transform information, and an nSHP node has no children and defines where a model is placed in the hierarchy. The nSHP node contains an extra ID that identifies the model it represents (model IDs are assigned sequentially: the first (SIZE + ) XYZI chunk has ID 0, the next ID 1, etc.).

To find the effective transform information of a given model, you need its corresponding nSHP node and the whole scene hierarchy above it (because it can be affected my multiple nTRN nodes).