Closed ElectronicBlueberry closed 3 years ago
Thanks for the quick response and surface review!
I resolved the requested changes, and added a importer base class, removing the duplicate code. For the centering to work consistently across importers, I changed the voxel_object centering function to assume that 0 represents the lowest relative position in the mesh, and 1 the highest. Since this might be a breaking change for some projects, I could alternatively change the scene importer to swap the relative coordinates around.
As for the per object voxel size: It's definitely not a must have feature, but can be helpful in some cases, as scaling the root for a voxel scene can become confusing when working with local coordinates in code.
Good catch on that edge case! It was caused by the x axis being rounded down with floor()
, while it should be rounded up during import, because it is flipped from MagicaVoxel. This also caused the origin to shift on the knight model, which is now also fixed.
No objections to a merge from my side, I used the importer the past couple of days, and it seems stable.
A rewrite on the vox file importer, with minor additions, tweaks and fixes to the other importers, and voxel objects. Importer partially based on: https://github.com/jpaver/opengametools/blob/master/src/ogt_vox.h
The main new feature is the ability to fully import Magica Voxel files as scenes, while keeping all groups and objects separate. This allows for a faster workflow with Magica Voxel, skipping previously required import steps, when importing complex vox files.
This PR also fixes a missing sRGB flag on the default material, wrong forward orientation for imported voxel models, and incompatibility with newer vox files. It also introduces a new option for a per-model voxel size, and allows for more control over centering on import.
sRGB Color, and Vox compatibility example:
As seen in the pictures, the forward direction is also changed. Previously the vox importer kept Magica Voxels x axis direction, but as a result models faced backwards by default. The new importer flips the x-axis, keeping the forward direction from Magica Voxel aligned to Godots -z forward direction.
New import options, and importer:
The "Voxel Size" is now no longer global, and can be set per object. This works with voxel meshes, as well as voxel objects, and the voxel editor. A new editor option has been added, to re-scale the voxels while editing.
The new Magica Voxel Scene importer imports a vox file as seperate objects, keeping all included groups, shapes, and their respective transforms and names. Shapes are imported as Mesh Instances, and Groups as Spatials. This feature was the key reason for starting this PR, as it drastically speeds up the workflow in my current project.
Note: In it's current form this PR is a WIP. While all features I set out to add are present, it has not yet been tested thoroughly enough to be considered production ready. I would appreciate testing and feedback.