Skip to content

Commit

Permalink
Merge branch 'main' into fix_2399_option_not_select_created_objects
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduroure committed Nov 28, 2024
2 parents 86cf8f3 + 594aec4 commit a65e58a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea/
addons/.idea/
addons/io_scene_gltf2/.idea/
addons/io_scene_gltf2/libextern_draco.so
addons/blender-debugger-for-vscode/
mochawesome-report
/scenes/
Expand Down
16 changes: 12 additions & 4 deletions addons/io_scene_gltf2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
bl_info = {
'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
"version": (4, 4, 12),
"version": (4, 4, 16),
'blender': (4, 3, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',
Expand Down Expand Up @@ -1483,10 +1483,10 @@ def export_panel_data_material(layout, operator):
if operator.export_image_format in ["AUTO", "JPEG", "WEBP"]:
col.prop(operator, 'export_image_quality')
col = body.column()
col.active = operator.export_image_format != "WEBP"
col.active = operator.export_image_format != "WEBP" and not operator.export_materials in ['PLACEHOLDER', 'NONE']
col.prop(operator, "export_image_add_webp")
col = body.column()
col.active = operator.export_image_format != "WEBP"
col.active = operator.export_image_format != "WEBP" and not operator.export_materials in ['PLACEHOLDER', 'NONE']
col.prop(operator, "export_image_webp_fallback")

header, sub_body = body.panel("GLTF_export_data_material_unused", default_closed=True)
Expand Down Expand Up @@ -1676,7 +1676,7 @@ def export_panel_animation_sampling(layout, operator):
header.prop(operator, "export_force_sampling", text="")
header.label(text="Sampling Animations")
if body:
body.active = operator.export_animations
body.active = operator.export_animations and operator.export_force_sampling

body.prop(operator, 'export_frame_step')

Expand Down Expand Up @@ -1866,6 +1866,13 @@ class ImportGLTF2(Operator, ConvertGLTF2_Base, ImportHelper):
default=True,
)

import_scene_extras: BoolProperty(
name='Import Scene Extras',
description='Import scene extras as custom properties. '
'Existing custom properties will be overwritten',
default=True,
)

def draw(self, context):
operator = self
layout = self.layout
Expand All @@ -1879,6 +1886,7 @@ def draw(self, context):
layout.prop(self, 'guess_original_bind_pose')
layout.prop(self, 'export_import_convert_lighting_mode')
layout.prop(self, 'import_webp_texture')
layout.prop(self, 'import_scene_extras')
import_bone_panel(layout, operator)
import_ux_panel(layout, operator)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def get_channel_groups(obj_uuid: str, blender_action: bpy.types.Action, export_s
target_property = fcurve.data_path
target_data = targets_extra.get(target, {})
target_data['type'] = type_
target_data['bone'] = target.name
target_data['bone'] = target.name if type_ == "BONE" else None
target_data['obj_uuid'] = obj_uuid
target_properties = target_data.get('properties', {})
channels = target_properties.get(target_property, [])
Expand Down
17 changes: 12 additions & 5 deletions addons/io_scene_gltf2/blender/exp/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,20 @@ def recursive_get_all_bones(uuid):
else:
return self.nodes[uuid].all_bones

def get_root_bones_uuid(self, uuid): # For armature only
def get_root_bones_uuid(self, uuid, cache=True): # For armature only
if not hasattr(self.nodes[uuid], "root_bones_uuid"):
if self.nodes[uuid].blender_type == VExportNode.ARMATURE:
all_armature_children = self.nodes[uuid].children
self.nodes[uuid].root_bones_uuid = [
root_bones_uuid = [
c for c in all_armature_children if self.nodes[c].blender_type == VExportNode.BONE]
# Not really needed to return, we are just baking it before export really starts
return self.nodes[uuid].root_bones_uuid
if self.export_settings['gltf_def_bones'] is True:
root_bones_uuid = [
c for c in root_bones_uuid if self.nodes[c].use_deform is True]
if cache:
self.nodes[uuid].root_bones_uuid = root_bones_uuid
# in case of caching (first call), we return the value even if not needed
# (because we call the function only to cache the value)
return root_bones_uuid
else:
self.nodes[uuid].root_bones_uuid = []
return []
Expand Down Expand Up @@ -920,7 +926,8 @@ def check_if_we_can_remove_armature(self):
# If is impossible to remove it if armature has multiple root bones. (glTF validator error)
# Currently, we manage it at export level, not at each armature level
for arma_uuid in [n for n in self.nodes.keys() if self.nodes[n].blender_type == VExportNode.ARMATURE]:
if len(self.get_root_bones_uuid(arma_uuid)) > 1:
# Do not cache bones here, as we will filter them later, so the cache will be wrong
if len(self.get_root_bones_uuid(arma_uuid, cache=False)) > 1:
# We can't remove armature
self.export_settings['gltf_armature_object_remove'] = False
self.export_settings['log'].warning(
Expand Down
6 changes: 5 additions & 1 deletion addons/io_scene_gltf2/blender/imp/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ def create(gltf):
if gltf.data.scene is not None:
import_user_extensions('gather_import_scene_before_hook', gltf, gltf.data.scenes[gltf.data.scene], scene)
pyscene = gltf.data.scenes[gltf.data.scene]
set_extras(scene, pyscene.extras)
# Special case for scene extras:
# As the scene may already exists in Blender, custom properties can be overwritten
# So, there is an option to know if the user want to set extras or not
if gltf.import_settings['import_scene_extras']:
set_extras(scene, pyscene.extras)

compute_vnodes(gltf)

Expand Down

0 comments on commit a65e58a

Please sign in to comment.