Skip to content
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

Hooks for object transformations (in particular for object locations) #2398

Open
vvoovv opened this issue Nov 6, 2024 · 0 comments
Open
Labels
enhancement New feature or request hook

Comments

@vvoovv
Copy link

vvoovv commented Nov 6, 2024

Is your feature request related to a problem? Please describe.

The goal of this feature request is to reduce numerical errors after an import of a dataset in the open 3D Tiles format. Each dataset in the 3D Tiles format is a collection of glTF files typically containing a mesh that represents 3D geospatial content (buildings, trees, terrain, etc).

image

The origin of the system of reference of a 3D Tiles dataset is located in the center of Earth, so an object in the glTF file typically has the coordinates of millions of units. That leads to noticeable gaps between separate 3D tiles due to numerical errors caused by the single floating number precision in Blender.

Describe the solution you'd like

Provide a hook to change at least the location of objects in a glTF file. For example, a constant offset can be applied to all objects in the glTF file to bring the objects to Blender's origin and decrease the resulting numerical errors.

Describe alternatives you've considered

Currently I am patching the function set_convert_functions and apply an offset in convert_loc:

from io_scene_gltf2.io.imp.gltf2_io_gltf import glTFImporter
from io_scene_gltf2.blender.imp.blender_gltf import BlenderGlTF

def my_set_convert_functions(gltf):
    if bpy.app.debug_value != 100:
        # Unit conversion factor in (Blender units) per meter
        u = 1.0 / bpy.context.scene.unit_settings.scale_length
        
        offset = gltf._offset
        # We will apply <offset> before creating a <Vector> to decrease numerical errors caused by
        # 32 bits floats useb by <Vector> and other <mathutils> classes.

        # glTF Y-Up space --> Blender Z-up space
        # X,Y,Z --> X,-Z,Y
        def convert_loc(x): return u * Vector([x[0] - gltf._offset[0], -x[2] - gltf._offset[1], x[1] - gltf._offset[2]])
   
    #
    # the rest of the function is omitted for bravity
    #


glTFImporter._offset = (X, Y, Z)
BlenderGlTF.set_convert_functions = my_set_convert_functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hook
Projects
None yet
Development

No branches or pull requests

2 participants