unfuck digitgrade leg tools
the heck happened here!? anyways it's working
This commit is contained in:
@@ -11,6 +11,7 @@ from ...core.common import (
|
|||||||
remove_unused_vertex_groups,
|
remove_unused_vertex_groups,
|
||||||
identify_bones,
|
identify_bones,
|
||||||
)
|
)
|
||||||
|
import traceback
|
||||||
from ...core.armature_validation import validate_armature, validate_bone_hierarchy
|
from ...core.armature_validation import validate_armature, validate_bone_hierarchy
|
||||||
|
|
||||||
def duplicate_bone(bone: EditBone) -> EditBone:
|
def duplicate_bone(bone: EditBone) -> EditBone:
|
||||||
@@ -41,25 +42,7 @@ class AvatarToolKit_OT_CreateDigitigradeLegs(Operator):
|
|||||||
context.mode == 'EDIT_ARMATURE' and
|
context.mode == 'EDIT_ARMATURE' and
|
||||||
context.selected_editable_bones is not None and
|
context.selected_editable_bones is not None and
|
||||||
len(context.selected_editable_bones) == 2)
|
len(context.selected_editable_bones) == 2)
|
||||||
|
|
||||||
def store_bone_chain_data(self, digi0: EditBone) -> Dict[str, Any]:
|
|
||||||
"""Store initial bone chain data"""
|
|
||||||
chain_data = {}
|
|
||||||
current = digi0
|
|
||||||
while current:
|
|
||||||
chain_data[current.name] = {
|
|
||||||
'head': current.head.copy(),
|
|
||||||
'tail': current.tail.copy(),
|
|
||||||
'roll': current.roll,
|
|
||||||
'matrix': current.matrix.copy(),
|
|
||||||
'parent': current.parent.name if current.parent else None
|
|
||||||
}
|
|
||||||
if current.children:
|
|
||||||
current = current.children[0]
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
return chain_data
|
|
||||||
|
|
||||||
def process_leg_chain(self, digi0: EditBone) -> bool:
|
def process_leg_chain(self, digi0: EditBone) -> bool:
|
||||||
"""Process a single leg bone chain"""
|
"""Process a single leg bone chain"""
|
||||||
try:
|
try:
|
||||||
@@ -74,24 +57,22 @@ class AvatarToolKit_OT_CreateDigitigradeLegs(Operator):
|
|||||||
bone.select = True
|
bone.select = True
|
||||||
bpy.ops.armature.roll_clear()
|
bpy.ops.armature.roll_clear()
|
||||||
bpy.ops.armature.select_all(action='DESELECT')
|
bpy.ops.armature.select_all(action='DESELECT')
|
||||||
|
|
||||||
# Create thigh bone
|
|
||||||
thigh = duplicate_bone(digi0)
|
|
||||||
base_name = digi0.name.split('.')[0]
|
|
||||||
thigh.name = base_name
|
|
||||||
|
|
||||||
# Create and position calf bone
|
# Create and position calf bone
|
||||||
calf = duplicate_bone(digi1)
|
calf = duplicate_bone(digi1)
|
||||||
calf.name = digi1.name.split('.')[0]
|
calf.name = digi1.name.split('.')[0]
|
||||||
calf.parent = thigh
|
calf.parent = digi0
|
||||||
|
|
||||||
# Calculate new positions
|
# Calculate new positions
|
||||||
midpoint = (digi1.tail + digi2.tail) * 0.5
|
end = ((digi0.tail) + (digi2.tail-digi2.head))
|
||||||
calf.head = thigh.tail
|
calf.head = end
|
||||||
calf.tail = midpoint
|
calf.tail = digi2.tail
|
||||||
|
|
||||||
# Reparent foot to new calf
|
# Reparent foot to new calf
|
||||||
digi3.parent = calf
|
digi3.parent = calf
|
||||||
|
|
||||||
|
#enforce parallelagram onto midparts.
|
||||||
|
digi1.tail = (digi0.tail)+(calf.tail-calf.head)
|
||||||
|
|
||||||
# Mark original bones as non-IK
|
# Mark original bones as non-IK
|
||||||
for bone in [digi0, digi1, digi2]:
|
for bone in [digi0, digi1, digi2]:
|
||||||
@@ -101,7 +82,7 @@ class AvatarToolKit_OT_CreateDigitigradeLegs(Operator):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.report({'ERROR'}, t("Tools.digitigrade_error", error=str(e)))
|
self.report({'ERROR'}, t("Tools.digitigrade_error", error=traceback.format_exc()))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def execute(self, context: Context) -> set[str]:
|
def execute(self, context: Context) -> set[str]:
|
||||||
|
|||||||
Reference in New Issue
Block a user