midstreeeam / MidVoxIO

A python io to load/write/visualize vox files (MagicalVoxel's .vox format).
MIT License
21 stars 2 forks source link

"_t in nTRN not match models, transform not applied" Error in Scenarios Involving Groups or Origin-Positioned Objects #8

Open rrenode opened 5 months ago

rrenode commented 5 months ago

Useful Stuff

Breif Description

I've encountered a persistent issue in MidVoxIO where transformations fail to apply under specific conditions. This results in the error message "_t in nTRN not match models, transform not applied." The issue arises in two main scenarios:

When the .vox file contains groups of models.
When an object's position in all of x, y, and z coordinates is set to 0.

Steps to Reproduce:

Expected Behavior:

Transformations should apply correctly to all models, including those within groups or positioned at the origin.

Actual Behavior:

The specified error message appears, and transformations are not applied as expected.


Me Rambling

Further Musings

In these scenarios, the Vox class is aware of the transforms as well as the groups and is correctly reading them from the vox file. It appears that how it is written there is no support for groups.

I'm unsure if this is intended and considered as being in-scope or if this is something that hasn't been touched on yet. If handling groups is something that is planned for the future, the hardstop if statement in vox.py could be written.

if len(transforms) != len(self.voxels):
            print(f"_t in nTRN not match models, transform not applied")
            return

As it is written now, when objects are in groups and when objects have no explicit transform (such as when they're at the origin) the _trans method of the Vox class won't combine two models.

Possible Tempoary Band-Aid

Temporary band-aid is a gross nested-if to still allow Vox class to at least attempt to combine the models. Though, this will obviously result in the models likely being in the incorrect orientaion or having some other unexpected transforms.

def _trans(self, transforms):
    """Transform all models and merge into one"""
    if len(transforms) != len(self.voxels):
        print(f"_t in nTRN not match models")
        if len(transforms) < len(self.voxels):
            # Notify that _t in nTRN not match models and weird errors may occur but will still proceed
            ...
        if len(transforms) > len(self.voxels):
            # Notify that groups are not currently supported
            return

Long-Term Solution

For a sustainable resolution, MidVoxIO would need to integrate comprehensive support for group transformations. This enhancement would entail developing the capability within the Vox class to accurately recognize and process group hierarchies, applying transformations recursively from groups down to their child models. Implementing this feature would not only align MidVoxIO more closely with the .vox format's complexities but also significantly improve its utility for users dealing with advanced modeling scenarios. Such an improvement would mark a significant step forward in making MidVoxIO a more versatile and powerful tool for voxel model manipulation.

midstreeeam commented 5 months ago

@rrenode Thank you for highlighting this issue! A quick fix will be pushed soon to fix this bug.

As you mentioned, better support for group transformation is needed. The MidVoxIO is a fork of py-vox-io, which is created when the vox file does not support group. Although we added group support subsequently, it was done without a comprehensive overhaul to fully integrate this feature from a holistic standpoint.

Thanks for pointing this out! I will keep this issue open as a reminder.