-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed PACK implementation for read/write #38
Conversation
Also, there is some debate to be had as to using a It makes sense to be able to read them for backwards compatibility, but does it make sense to write them? |
Thank you for your contribution! I believe the right thing to do here is to deprecate the The deserializer works correctly when importing a file with multiple models, so the bug is most likely on the serializer. It would be great if you can help me to debug this. Should the serializer emit the Again, lots of thanks! |
Sure, here is the updated behavior of this PR:
Feel free to tell me specific parts I should add/remove/modify! |
src/parser.rs
Outdated
@@ -25,7 +25,7 @@ pub enum Chunk { | |||
Main(Vec<Chunk>), | |||
Size(Size), | |||
Voxels(Vec<Voxel>), | |||
Pack(Model), | |||
Pack(Vec<Chunk>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding of the MagicaVoxel spec is that the PACK chunk only encodes "how many SIZE and XYZI chunks do we have in this file?". We don't need actually need this number because we just stop the parser whenever we run out of bytes. It doesn't make much sense to have the Pack chunk owning a list of Chunks, since the XYZI chunks aren't exactly childrens of PACK.
Let's just remove the PACK chunk and have the deserializer ignore all PACK chunks. Old users who have PACK chunks wouldn't be impacted at all - again, we don't need this number because we stop the parser whenever we run out of bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding of the MagicaVoxel spec is that the PACK chunk only encodes "how many SIZE and XYZI chunks do we have in this file?".
This is correct.
We don't need actually need this number because we just stop the parser whenever we run out of bytes. It doesn't make much sense to have the Pack chunk owning a list of Chunks, since the XYZI chunks aren't exactly childrens of PACK.
This is also right, I was misled by the implementation of the PACK chunk writer that the models where children of the PACK.
In my most recent changes, I have completely removed PACK chunk writing as well as PACK chunk parsing (they are ignored).
While I was playing around with this module I came across (what I assume to be) a bug:
I wasn't able to
write_vox
to a file then immediately read it withload
. To be a bit more specific, I was writing multiple models to the.vox
file and when I would read it, the models array would be empty.Turns out this is because
write_vox
usesPACK
chunks andload
is incorrectly loading thePACK
chunks according to the vox spec.After I reimplemented that, I noticed that
num_vox_bytes
is incorrectly calculating thePACK
chunk children length because it's missing 28 bytes per model. (Mostly because of headers detailed in the spec)Anyways, this PR is intended to make the module parse/write
PACK
headers correctly. Feel free to critique the code as harshly as you want, I'm not that proficient in rust so there may be shorter ways to do things.