dust-engine / dot_vox

Rust parser for MagicaVoxel .vox files.
MIT License
51 stars 20 forks source link

Transform relative point of model #49

Closed davids91 closed 2 months ago

davids91 commented 3 months ago

Hi, and thank you for this great lib once more! :) I am deep in parsing the file format and in most cases I am able to read in simpler models. However I am unable to parse complex models as the provided transforms seem to be off. The following model starts from the center bottom:

image

But upon reading it in with the library the following scene array is parsed:

[0] Transform { attributes: {}, frames: [Frame { attributes: {} }], child: 1, layer_id: 4294967295 }
[1] Group { attributes: {}, children: [2] }
[2] Transform { attributes: {}, frames: [Frame { attributes: {"_t": "-1 -2 57"} }], child: 3, layer_id: 0 }
[3] Group { attributes: {}, children: [4, 6] }
[4] Transform { attributes: {}, frames: [Frame { attributes: {"_t": "0 0 48"} }], child: 5, layer_id: 0 }
[5] Shape { attributes: {}, models: [ShapeModel { model_id: 0, attributes: {} }] }
[6] Transform { attributes: {}, frames: [Frame { attributes: {"_t": "0 0 -8"} }], child: 7, layer_id: 0 }
[7] Shape { attributes: {}, models: [ShapeModel { model_id: 1, attributes: {} }] }

vox tree model sizes: 
[0] Size { x: 16, y: 16, z: 16 }
[1] Size { x: 16, y: 16, z: 96 }

The way I understand this: https://github.com/ephtracy/voxel-model/blob/master/MagicaVoxel-file-format-vox-extension.txt guide, the positions just don't add up.

First of the leaves part of the model tree is added up to start from Z value 105 ( Right handed Z up coordinate system ), so that seems to be correct. This is added up from its parent transforms, [2] and [4].

However, the second model, which is the trunk of the tree model just doesn't add up to its position, as supposedly it starts at z value 48, which overrides the other model, and is much higher, than it is supposed to be.. In the below rendering of the parsed tree the result is shown, the heights ( z coord ) are marked at 105 0nd 120: image

Do the models start at the bottom-left-near corner of the transform?

davids91 commented 3 months ago

They start from the middle of the model! I'm updating #48 to reflect this

Neo-Zhixing commented 2 months ago

Yeah they do. Sorry for not being able to get back to you sooner.

davids91 commented 2 months ago

No worries! It was a satisfying HEUREKA moment 💡