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

Assign extensions if the didn't exist already #25

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 7 additions & 9 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,30 +133,28 @@ def gather_object_property(export_settings, blender_object):
return None


def get_hubs_ext(export_settings):
exts = export_settings["gltf_user_extensions"]
import io_hubs_addon
for ext in exts:
if type(ext) is io_hubs_addon.io.gltf_exporter.glTF2ExportUserExtension:
return ext


def add_component_to_node(gltf2_object, dep, value, export_settings):
try:
from io_hubs_addon.io.utils import HUBS_CONFIG
except ImportError:
# A version of the io_hubs_addon below 1.5 is being used
from io_hubs_addon.io.gltf_exporter import hubs_config as HUBS_CONFIG
hubs_ext = get_hubs_ext(export_settings)

hubs_ext_name = HUBS_CONFIG["gltfExtensionName"]
if type(gltf2_object) is tuple:
extensions = gltf2_object[0].extensions
else:
extensions = gltf2_object.extensions

if extensions is None:
extensions = {}

if hubs_ext_name not in extensions:
extensions[hubs_ext_name] = {dep.get_name(): value}
if type(gltf2_object) is tuple:
gltf2_object[0].extensions = extensions
else:
gltf2_object.extensions = extensions
Comment on lines +154 to +157
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine, but it seems kind of hard to reason about to me.
Are you sure this shouldn't be up under the if extensions is None: block?

else:
if hasattr(extensions[hubs_ext_name], "extension"):
if not dep.get_name() in extensions[hubs_ext_name].extension:
Expand Down