Zylann / godot_voxel

Voxel module for Godot Engine
MIT License
2.63k stars 246 forks source link

VoxLoader loads models flipped #265

Open Zylann opened 3 years ago

Zylann commented 3 years ago

Quick bug note referring to #260

loaded objects from vox file are flipped (at last for vox from magica ver 0.99.6 that I use) Need swap x,y,z in vox_loader.cpp to x,z,y

Zylann commented 3 years ago

It appears MagicaVoxel uses a coordinate system similar to 3DS Max: image

While in Godot coordinates are OpenGL: image

So from what you can see in those screenshots, the loader actually has to choose a conversion strategy by swapping axes, which seems to be correct? From MagicaVoxel to Godot: X becomes Z, Y becomes X, Z becomes Y. Which in code translates as: https://github.com/Zylann/godot_voxel/blob/8ba9f0797882c4998ed6b0301dfd89d32188253a/streams/vox_loader.cpp#L86-L88

So models are not really flipped, it's just that Godot uses a different coordinate system and the loader has to remap axes.

Size however does not apply this remap so it sounds like non-cubic models will fail to load properly. This may be fixed in a rewrite I'm planning to do, which will also bring support for more recent MagicaVoxel features such as multiple models, layers and transforms.

KarloNet commented 3 years ago

Yours aproach to zxy is more accurate to magica model view. +1 As long as I was testing, loading non cubic models are correct. Btw, to save you some time: As mentioned in oryginal extended magica vox file format nTRN saves chunk position but they didnt mention that it's not position of left down corner (voxel (0,0,0)) as everyone can suspect (at last me xD) but its the center of chunk. Position is saved not as three int values but as string of x,y,z values separated by space ^^. Creazy... If ther is no "_t" key in nTRN dictionary (the one that have chunk position) you still need to remember that default position is center of chunk not the corner one. Cheers.

Complete loading code for extended vox format: https://github.com/mchorse/blockbuster/tree/e95fc7c08b662b5f1ca221f73a002ca4720b1826/src/main/java/mchorse/blockbuster/api/formats/vox

KarloNet commented 3 years ago

OK just saw that you already updated source code to the full loading extended vox format xD will move my work -> trash ;) Btw i cant see that you move chunks position from center to bottom left ( as paste use it) ?

Zylann commented 3 years ago

I do it here https://github.com/Zylann/godot_voxel/blob/6b3991c6959fe80403dba21cb7f49e6d99b730d4/editor/vox/vox_importer.cpp#L58