def hyper3d_generate_object()

in tools.py [0:0]


def hyper3d_generate_object(context: Any, filepath: str, mesh_name: str):
    try:
        existing_objects = set(bpy.data.objects)
        bpy.ops.import_scene.gltf(filepath=filepath)
        bpy.context.view_layer.update()

        imported_objects = list(set(bpy.data.objects) - existing_objects)

        if not imported_objects:
            raise RuntimeError("Error: No objects were imported.")

        mesh_obj = None

        if len(imported_objects) == 1 and imported_objects[0].type == "MESH":
            mesh_obj = imported_objects[0]
            print("Single mesh imported, no cleanup needed.")
        else:
            parent_obj = imported_objects[0]
            if parent_obj.type == "EMPTY" and len(parent_obj.children) == 1:
                potential_mesh = parent_obj.children[0]
                if potential_mesh.type == "MESH":
                    print("GLB structure confirmed: Empty node with one mesh child.")
                    potential_mesh.parent = None

                    bpy.data.objects.remove(parent_obj)
                    print("Removed empty node, keeping only the mesh.")
                    mesh_obj = potential_mesh
                else:
                    raise RuntimeError("Error: Child is not a mesh object.")
            else:
                raise RuntimeError(
                    "Error: Expected an empty node with one mesh child or a single mesh object."
                )

        try:
            if mesh_obj and mesh_obj.name is not None and mesh_name:
                mesh_obj.name = mesh_name
                if mesh_obj.data.name is not None:
                    mesh_obj.data.name = mesh_name
                print(f"Mesh renamed to: {mesh_name}")
        except Exception:
            print("Having issue with renaming, give up renaming.")
        result = {
            "name": mesh_obj.name,
            "type": mesh_obj.type,
            "location": [mesh_obj.location.x, mesh_obj.location.y, mesh_obj.location.z],
            "rotation": [
                mesh_obj.rotation_euler.x,
                mesh_obj.rotation_euler.y,
                mesh_obj.rotation_euler.z,
            ],
            "scale": [mesh_obj.scale.x, mesh_obj.scale.y, mesh_obj.scale.z],
        }

        if mesh_obj.type == "MESH":
            bounding_box = get_aabb(mesh_obj)
            result["world_bounding_box"] = bounding_box

        return {"status": "success", "data": result}
    except Exception as e:
        print(f"Error in hyper3d_generate: {str(e)}")
        traceback.print_exc()
        return {"status": "error", "data": str(e)}