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

Import Bone scale / shape option #2265

Merged
merged 2 commits into from
Jun 6, 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
25 changes: 24 additions & 1 deletion addons/io_scene_gltf2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=(
Expand All @@ -1802,6 +1814,7 @@ class ImportGLTF2(Operator, ConvertGLTF2_Base, ImportHelper):
)

def draw(self, context):
operator = self
layout = self.layout

layout.use_property_split = True
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions addons/io_scene_gltf2/blender/imp/gltf2_blender_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -237,10 +241,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
Expand Down
Loading