Skip to content

Commit

Permalink
feat(i3d mapping): add i3d mapping support for bones (#233)
Browse files Browse the repository at this point in the history
Co-authored-by: LKAMinco <[email protected]>
  • Loading branch information
NMC-TBone and LKAMinco authored Dec 20, 2024
1 parent 2410c80 commit 4578113
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions addon/i3dio/i3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def add_armature(self, armature_object: bpy.types.Armature, parent: SceneGraphNo
elif is_located:
if not self.settings['collapse_armatures']:
if parent is not None:
# The armature was created from a modifier, which may introduce a parent relationship.
# However, the parent might not have been known at the time of creation.
if self.skinned_meshes[armature_object.name].parent is None:
self.skinned_meshes[armature_object.name].parent = parent
parent.add_child(self.skinned_meshes[armature_object.name])
parent.element.append(self.skinned_meshes[armature_object.name].element)
else:
Expand Down
2 changes: 2 additions & 0 deletions addon/i3dio/node_classes/skinned_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ def update_bone_parent(self, parent):
self.element.remove(bone.element)
self.children.remove(bone)
if parent is not None:
bone.parent = parent
parent.add_child(bone)
parent.element.append(bone.element)
else:
bone.parent = None
self.i3d.scene_root_nodes.append(bone)
self.i3d.xml_elements['Scene'].append(bone.element)

Expand Down
33 changes: 31 additions & 2 deletions addon/i3dio/ui/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ class I3DMappingData(bpy.types.PropertyGroup):
default=''
)


@register
class I3D_IO_PT_mapping_attributes(Panel):
bl_space_type = 'PROPERTIES'
Expand All @@ -864,20 +865,45 @@ def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
obj = bpy.context.active_object
obj = context.object

row = layout.row()
row.prop(obj.i3d_mapping, 'is_mapped')
row = layout.row()
row.prop(obj.i3d_mapping, 'mapping_name')


@register
class I3D_IO_PT_mapping_bone_attributes(Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_label = "I3D Mapping"
bl_context = 'bone'

@classmethod
def poll(cls, context):
return context.bone or context.edit_bone

def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
bone = context.bone or context.edit_bone

row = layout.row()
row.prop(bone.i3d_mapping, 'is_mapped')
row = layout.row()
row.prop(bone.i3d_mapping, 'mapping_name')


def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Object.i3d_attributes = PointerProperty(type=I3DNodeObjectAttributes)
bpy.types.Object.i3d_merge_group_index = IntProperty(default = -1)
bpy.types.Object.i3d_merge_group_index = IntProperty(default=-1)
bpy.types.Object.i3d_mapping = PointerProperty(type=I3DMappingData)
bpy.types.Bone.i3d_mapping = PointerProperty(type=I3DMappingData)
bpy.types.EditBone.i3d_mapping = PointerProperty(type=I3DMappingData)
bpy.types.Object.i3d_reference_path = StringProperty(
name="Reference Path",
description="Put the path to the .i3d file you want to reference here",
Expand All @@ -886,10 +912,13 @@ def register():
bpy.types.Scene.i3dio_merge_groups = CollectionProperty(type=I3DMergeGroup)
load_post.append(handle_old_merge_groups)


def unregister():
load_post.remove(handle_old_merge_groups)
del bpy.types.Scene.i3dio_merge_groups
del bpy.types.Object.i3d_reference_path
del bpy.types.EditBone.i3d_mapping
del bpy.types.Bone.i3d_mapping
del bpy.types.Object.i3d_mapping
del bpy.types.Object.i3d_merge_group_index
del bpy.types.Object.i3d_attributes
Expand Down

0 comments on commit 4578113

Please sign in to comment.