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

Update glTF add-on imports to support Blender 4.3 #322

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions addons/io_hubs_addon/io/gltf_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import traceback

if bpy.app.version < (3, 0, 0):
from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions
from io_scene_gltf2.blender.exp import gltf2_blender_export
from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions

# gather_gltf_hook does not expose the info we need, make a custom hook for now
# ideally we can resolve this upstream somehow https://github.com/KhronosGroup/glTF-Blender-IO/issues/1009
Expand Down Expand Up @@ -73,15 +73,26 @@ def export_callback(callback_method, export_settings):


def glTF2_pre_export_callback(export_settings):
from io_scene_gltf2.blender.com.gltf2_blender_extras import BLACK_LIST
# Import BLACK_LIST here instead of at the beginning of the file to make sure we're always referencing the same one as the glTF add-on.
# https://github.com/Hubs-Foundation/hubs-blender-exporter/pull/166#issuecomment-1335083605
if bpy.app.version >= (4, 3, 0):
from io_scene_gltf2.blender.com.extras import BLACK_LIST
else:
from io_scene_gltf2.blender.com.gltf2_blender_extras import BLACK_LIST

BLACK_LIST.extend(glTF2ExportUserExtension.EXCLUDED_PROPERTIES)
export_callback("pre_export", export_settings)


def glTF2_post_export_callback(export_settings):
export_callback("post_export", export_settings)
# Import BLACK_LIST here instead of at the beginning of the file to make sure we're always referencing the same one as the glTF add-on.
# https://github.com/Hubs-Foundation/hubs-blender-exporter/pull/166#issuecomment-1335083605
if bpy.app.version >= (4, 3, 0):
from io_scene_gltf2.blender.com.extras import BLACK_LIST
else:
from io_scene_gltf2.blender.com.gltf2_blender_extras import BLACK_LIST

from io_scene_gltf2.blender.com.gltf2_blender_extras import BLACK_LIST
export_callback("post_export", export_settings)
for excluded_prop in glTF2ExportUserExtension.EXCLUDED_PROPERTIES:
if excluded_prop in BLACK_LIST:
BLACK_LIST.remove(excluded_prop)
Expand Down
20 changes: 14 additions & 6 deletions addons/io_hubs_addon/io/gltf_importer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import bpy
from bpy.props import BoolProperty, PointerProperty
from io_scene_gltf2.blender.imp.gltf2_blender_node import BlenderNode
from io_scene_gltf2.blender.imp.gltf2_blender_material import BlenderMaterial
from io_scene_gltf2.blender.imp.gltf2_blender_scene import BlenderScene
from io_scene_gltf2.blender.imp.gltf2_blender_image import BlenderImage
import traceback
from .utils import HUBS_CONFIG, import_image, import_all_textures
from ..components.components_registry import get_component_by_name
import traceback
from bpy.props import BoolProperty, PointerProperty

# Version-specific imports
if bpy.app.version >= (4, 3, 0):
from io_scene_gltf2.blender.imp.image import BlenderImage
from io_scene_gltf2.blender.imp.node import BlenderNode
from io_scene_gltf2.blender.imp.material import BlenderMaterial
from io_scene_gltf2.blender.imp.scene import BlenderScene
else:
from io_scene_gltf2.blender.imp.gltf2_blender_image import BlenderImage
from io_scene_gltf2.blender.imp.gltf2_blender_node import BlenderNode
from io_scene_gltf2.blender.imp.gltf2_blender_material import BlenderMaterial
from io_scene_gltf2.blender.imp.gltf2_blender_scene import BlenderScene

EXTENSION_NAME = HUBS_CONFIG["gltfExtensionName"]

Expand Down
82 changes: 64 additions & 18 deletions addons/io_hubs_addon/io/utils.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,71 @@
import os
import bpy
from io_scene_gltf2.blender.com import gltf2_blender_extras
if bpy.app.version >= (3, 6, 0):
from io_scene_gltf2.blender.exp import gltf2_blender_gather_nodes, gltf2_blender_gather_joints
from io_scene_gltf2.blender.exp.material import gltf2_blender_gather_materials, gltf2_blender_gather_texture_info
from io_scene_gltf2.blender.exp.material.extensions import gltf2_blender_image
else:
from io_scene_gltf2.blender.exp import gltf2_blender_gather_materials, gltf2_blender_gather_nodes, gltf2_blender_gather_joints
from io_scene_gltf2.blender.exp import gltf2_blender_gather_texture_info, gltf2_blender_export_keys
from io_scene_gltf2.blender.exp import gltf2_blender_image
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
if bpy.app.version >= (4, 1, 0):
from io_scene_gltf2.blender.exp.material import gltf2_blender_search_node_tree
import os
import re
from ..nodes.lightmap import MozLightmapNode
from io_scene_gltf2.io.com import gltf2_io_extensions
from io_scene_gltf2.io.com import gltf2_io
from io_scene_gltf2.io.exp import gltf2_io_binary_data
from io_scene_gltf2.io.exp import gltf2_io_image_data
from io_scene_gltf2.blender.imp.gltf2_blender_image import BlenderImage
from typing import Optional, Tuple, Union
from ..nodes.lightmap import MozLightmapNode
import re

# Version-specific imports
if bpy.app.version >= (4, 3, 0):
from io_scene_gltf2.blender.com import extras as gltf2_blender_extras
from io_scene_gltf2.blender.exp import joints as gltf2_blender_gather_joints
from io_scene_gltf2.blender.exp import nodes as gltf2_blender_gather_nodes
from io_scene_gltf2.blender.exp.cache import cached
from io_scene_gltf2.blender.exp.material import encode_image as gltf2_blender_image
from io_scene_gltf2.blender.exp.material import materials as gltf2_blender_gather_materials
from io_scene_gltf2.blender.exp.material import search_node_tree as gltf2_blender_search_node_tree
from io_scene_gltf2.blender.exp.material import texture_info as gltf2_blender_gather_texture_info
from io_scene_gltf2.blender.imp.image import BlenderImage
from io_scene_gltf2.io.exp import binary_data as gltf2_io_binary_data
from io_scene_gltf2.io.exp import image_data as gltf2_io_image_data
elif bpy.app.version >= (4, 1, 0):
from io_scene_gltf2.blender.com import gltf2_blender_extras
# import the gather_nodes before the gather_joints to avoid a circular import specific to Blender 4.1
from io_scene_gltf2.blender.exp import (
gltf2_blender_gather_nodes,
gltf2_blender_gather_joints
)
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
from io_scene_gltf2.blender.exp.material import (
gltf2_blender_gather_materials,
gltf2_blender_search_node_tree,
gltf2_blender_gather_texture_info
)
from io_scene_gltf2.blender.exp.material.extensions import gltf2_blender_image
from io_scene_gltf2.blender.imp.gltf2_blender_image import BlenderImage
from io_scene_gltf2.io.exp import gltf2_io_binary_data
from io_scene_gltf2.io.exp import gltf2_io_image_data
elif bpy.app.version >= (3, 6, 0):
from io_scene_gltf2.blender.com import gltf2_blender_extras
from io_scene_gltf2.blender.exp import (
gltf2_blender_gather_joints,
gltf2_blender_gather_nodes
)
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
from io_scene_gltf2.blender.exp.material import (
gltf2_blender_gather_materials,
gltf2_blender_gather_texture_info
)
from io_scene_gltf2.blender.exp.material.extensions import gltf2_blender_image
from io_scene_gltf2.blender.imp.gltf2_blender_image import BlenderImage
from io_scene_gltf2.io.exp import gltf2_io_binary_data
from io_scene_gltf2.io.exp import gltf2_io_image_data
else:
from io_scene_gltf2.blender.com import gltf2_blender_extras
from io_scene_gltf2.blender.exp import (
gltf2_blender_export_keys,
gltf2_blender_image,
gltf2_blender_gather_materials,
gltf2_blender_gather_joints,
gltf2_blender_gather_nodes,
gltf2_blender_gather_texture_info
)
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
from io_scene_gltf2.blender.imp.gltf2_blender_image import BlenderImage
from io_scene_gltf2.io.exp import gltf2_io_binary_data
from io_scene_gltf2.io.exp import gltf2_io_image_data


HUBS_CONFIG = {
"gltfExtensionName": "MOZ_hubs_components",
Expand Down
Loading