From 0bd223159442e32e2f705a992cb413b3ba972949 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Thu, 6 Jun 2024 16:20:35 +0200 Subject: [PATCH 1/2] Import Bone scale / shape option --- addons/io_scene_gltf2/__init__.py | 25 ++++++++++++++++++- .../blender/imp/gltf2_blender_node.py | 4 +-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/addons/io_scene_gltf2/__init__.py b/addons/io_scene_gltf2/__init__.py index 6c2e74f80..6406c19ad 100644 --- a/addons/io_scene_gltf2/__init__.py +++ b/addons/io_scene_gltf2/__init__.py @@ -1782,6 +1782,18 @@ class ImportGLTF2(Operator, ConvertGLTF2_Base, ImportHelper): default="BLENDER", ) + disable_bone_shape: BoolProperty( + name='Disable Bone Shape', + description='Do not create bone shapes', + default=False, + ) + + bone_shape_scale_factor: FloatProperty( + name='Bone Shape Scale', + description='Scale factor for bone shapes', + default=1.0, + ) + guess_original_bind_pose: BoolProperty( name='Guess Original Bind Pose', description=( @@ -1802,6 +1814,7 @@ class ImportGLTF2(Operator, ConvertGLTF2_Base, ImportHelper): ) def draw(self, context): + operator = self layout = self.layout layout.use_property_split = True @@ -1811,9 +1824,9 @@ def draw(self, context): layout.prop(self, 'merge_vertices') layout.prop(self, 'import_shading') layout.prop(self, 'guess_original_bind_pose') - layout.prop(self, 'bone_heuristic') layout.prop(self, 'export_import_convert_lighting_mode') layout.prop(self, 'import_webp_texture') + import_bone_panel(layout, operator) import_panel_user_extension(context, layout) @@ -1908,6 +1921,16 @@ def set_debug_log(self): elif bpy.app.debug_value == 4: self.loglevel = logging.DEBUG +def import_bone_panel(layout, operator): + header, body = layout.panel("GLTF_import_bone", default_closed=False) + header.label(text="Bones") + if body: + body.prop(operator, 'bone_heuristic') + if operator.bone_heuristic == 'BLENDER': + body.prop(operator, 'disable_bone_shape') + body.prop(operator, 'bone_shape_scale_factor') + + def import_panel_user_extension(context, layout): for draw in importer_extension_layout_draw.values(): draw(context, layout) diff --git a/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py b/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py index d531166b1..62e6dc3ae 100644 --- a/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py +++ b/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py @@ -237,10 +237,10 @@ def visit(id): # Depth-first walk pynode = gltf.data.nodes[id] set_extras(pose_bone, pynode.extras) - if gltf.import_settings['bone_heuristic'] == "BLENDER": + if gltf.import_settings['bone_heuristic'] == "BLENDER" and gltf.import_settings['disable_bone_shape'] is False: pose_bone.custom_shape = bpy.data.objects[gltf.bone_shape] armature_min_dim = min([blender_arma.dimensions[0] / blender_arma.scale[0], blender_arma.dimensions[1] / blender_arma.scale[1], blender_arma.dimensions[2] / blender_arma.scale[2]]) - pose_bone.custom_shape_scale_xyz = Vector([armature_min_dim * 0.05] * 3) + pose_bone.custom_shape_scale_xyz = Vector([armature_min_dim * 0.05] * 3) * gltf.import_settings['bone_shape_scale_factor'] pose_bone.use_custom_shape_bone_size = False @staticmethod From 5bb9744cec7d063fc67a6c87b4adb69cb3739979 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Thu, 6 Jun 2024 16:26:09 +0200 Subject: [PATCH 2/2] Do not create collection/bone shape is not needed --- addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py b/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py index 62e6dc3ae..82ac62ae9 100644 --- a/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py +++ b/addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py @@ -139,6 +139,10 @@ def armature_display(gltf, obj): obj.show_in_front = True obj.data.relation_line_position = "HEAD" + + if gltf.import_settings['disable_bone_shape'] is True: + return + # Create a special collection (if not exists already) # Content of this collection will not be exported if BLENDER_GLTF_SPECIAL_COLLECTION not in bpy.data.collections: