vehicles(kestrel): articulate Thigh -> Shin -> Foot leg pivots for 2-bone IK
This commit is contained in:
parent
dccfbb95b5
commit
b35a50327c
5 changed files with 133 additions and 32 deletions
Binary file not shown.
|
|
@ -129,5 +129,5 @@
|
|||
4.4533
|
||||
]
|
||||
},
|
||||
"triCount": 41374
|
||||
"triCount": 41382
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
|
@ -451,42 +451,120 @@ def _strip_mesh_islands(strip_islands: tuple[tuple[str, str, float], ...]) -> di
|
|||
return removed
|
||||
|
||||
|
||||
def _reparent_keep_world(obj: bpy.types.Object, parent: bpy.types.Object) -> None:
|
||||
mw = obj.matrix_world.copy()
|
||||
obj.parent = parent
|
||||
obj.matrix_parent_inverse = Matrix.Identity(4)
|
||||
obj.matrix_local = parent.matrix_world.inverted() @ mw
|
||||
|
||||
|
||||
def _split_mesh_by_world_z(
|
||||
obj: bpy.types.Object,
|
||||
z_split: float,
|
||||
upper_name: str,
|
||||
lower_name: str,
|
||||
) -> tuple[bpy.types.Object, bpy.types.Object]:
|
||||
"""Split a disconnected multi-island mesh object into upper (z > z_split) and lower (z <= z_split) objects."""
|
||||
lower_obj = obj.copy()
|
||||
lower_obj.data = obj.data.copy()
|
||||
for col in obj.users_collection:
|
||||
col.objects.link(lower_obj)
|
||||
if not obj.users_collection:
|
||||
bpy.context.scene.collection.objects.link(lower_obj)
|
||||
|
||||
mw = obj.matrix_world.copy()
|
||||
for target, keep_upper in ((obj, True), (lower_obj, False)):
|
||||
bm = bmesh.new()
|
||||
bm.from_mesh(target.data)
|
||||
drop_verts = [
|
||||
v for v in bm.verts
|
||||
if (keep_upper and (mw @ v.co).z <= z_split) or (not keep_upper and (mw @ v.co).z > z_split)
|
||||
]
|
||||
if drop_verts:
|
||||
bmesh.ops.delete(bm, geom=drop_verts, context="VERTS")
|
||||
bm.to_mesh(target.data)
|
||||
bm.free()
|
||||
target.data.update()
|
||||
|
||||
obj.name = upper_name
|
||||
obj.data.name = upper_name
|
||||
lower_obj.name = lower_name
|
||||
lower_obj.data.name = lower_name
|
||||
return obj, lower_obj
|
||||
|
||||
|
||||
def _assemble_kestrel_hierarchy() -> None:
|
||||
"""Group Kestrel's flat root parts under Pelvis, Torso.pose, ArmL, and ArmR pivots."""
|
||||
"""Group Kestrel's flat root parts under Pelvis, Leg{L,R}.{Thigh,Shin,Foot}, Torso.pose, ArmL, and ArmR pivots."""
|
||||
torso_pose = bpy.data.objects.get("Torso.pose")
|
||||
if torso_pose is None:
|
||||
return
|
||||
|
||||
def reparent_keep_world(obj: bpy.types.Object, parent: bpy.types.Object) -> None:
|
||||
mw = obj.matrix_world.copy()
|
||||
obj.parent = parent
|
||||
obj.matrix_parent_inverse = Matrix.Identity(4)
|
||||
obj.matrix_local = parent.matrix_world.inverted() @ mw
|
||||
|
||||
pelvis = vc.make_empty("Pelvis", parent=None, location=(0.0, 0.0, 0.0))
|
||||
arm_l = vc.make_empty("ArmL", parent=torso_pose, location=(-1.62, 0.65, 1.50))
|
||||
arm_r = vc.make_empty("ArmR", parent=torso_pose, location=(1.62, 0.65, 1.50))
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
# Split combined LegJoints{L,R}.* (hip + knee drums in one mesh) into distinct hip (z > 5.0) and knee (z <= 5.0) meshes
|
||||
for side in ("L", "R"):
|
||||
for mat_suffix in ("gunmetal", "khaki", "machine"):
|
||||
joint_obj = bpy.data.objects.get(f"LegJoints{side}.{mat_suffix}")
|
||||
if joint_obj is not None and joint_obj.type == "MESH":
|
||||
_split_mesh_by_world_z(
|
||||
joint_obj,
|
||||
z_split=5.0,
|
||||
upper_name=f"LegJoints{side}Hip.{mat_suffix}",
|
||||
lower_name=f"LegJoints{side}Knee.{mat_suffix}",
|
||||
)
|
||||
|
||||
# Create articulated leg pivot chains at exact hip, knee, and ankle drum centers
|
||||
leg_pivots: dict[str, tuple[bpy.types.Object, bpy.types.Object, bpy.types.Object]] = {}
|
||||
for side in ("L", "R"):
|
||||
hip_b = _obj_bounds_in_ref([f"LegJoints{side}Hip.gunmetal"], pelvis)
|
||||
knee_b = _obj_bounds_in_ref([f"LegJoints{side}Knee.gunmetal"], pelvis)
|
||||
ankle_b = _obj_bounds_in_ref([f"Ankle{side}.foot.machine.body"], pelvis)
|
||||
assert hip_b is not None and knee_b is not None and ankle_b is not None, (
|
||||
f"kestrel: missing leg drum bounds for side {side}"
|
||||
)
|
||||
hip_c = 0.5 * (hip_b[0] + hip_b[1])
|
||||
knee_c = 0.5 * (knee_b[0] + knee_b[1])
|
||||
ankle_c = 0.5 * (ankle_b[0] + ankle_b[1])
|
||||
|
||||
leg_thigh = vc.make_empty(f"Leg{side}.Thigh", parent=pelvis, location=tuple(hip_c))
|
||||
bpy.context.view_layer.update()
|
||||
leg_shin = vc.make_empty(f"Leg{side}.Shin", parent=leg_thigh, location=tuple(knee_c - hip_c))
|
||||
bpy.context.view_layer.update()
|
||||
leg_foot = vc.make_empty(f"Leg{side}.Foot", parent=leg_shin, location=tuple(ankle_c - knee_c))
|
||||
bpy.context.view_layer.update()
|
||||
leg_pivots[side] = (leg_thigh, leg_shin, leg_foot)
|
||||
|
||||
protected = {pelvis, torso_pose, arm_l, arm_r}
|
||||
for pivots in leg_pivots.values():
|
||||
protected.update(pivots)
|
||||
|
||||
for obj in list(bpy.data.objects):
|
||||
if obj in (pelvis, torso_pose, arm_l, arm_r):
|
||||
if obj in protected:
|
||||
continue
|
||||
name = obj.name
|
||||
if obj.parent is None and (
|
||||
name.startswith("Pelvis.")
|
||||
or name.startswith("LegJoints")
|
||||
or name.startswith("Thigh")
|
||||
or name.startswith("Shin")
|
||||
or name.startswith("Ankle")
|
||||
or name.startswith("Foot")
|
||||
):
|
||||
reparent_keep_world(obj, pelvis)
|
||||
if obj.parent is None and name.startswith("Pelvis."):
|
||||
_reparent_keep_world(obj, pelvis)
|
||||
elif obj.parent is None and name.startswith(("ThighL.", "LegJointsLHip.")):
|
||||
_reparent_keep_world(obj, leg_pivots["L"][0])
|
||||
elif obj.parent is None and name.startswith(("ThighR.", "LegJointsRHip.")):
|
||||
_reparent_keep_world(obj, leg_pivots["R"][0])
|
||||
elif obj.parent is None and name.startswith(("ShinL.", "LegJointsLKnee.", "AnkleL.root.")):
|
||||
_reparent_keep_world(obj, leg_pivots["L"][1])
|
||||
elif obj.parent is None and name.startswith(("ShinR.", "LegJointsRKnee.", "AnkleR.root.")):
|
||||
_reparent_keep_world(obj, leg_pivots["R"][1])
|
||||
elif obj.parent is None and name.startswith(("FootL.", "AnkleL.foot.")):
|
||||
_reparent_keep_world(obj, leg_pivots["L"][2])
|
||||
elif obj.parent is None and name.startswith(("FootR.", "AnkleR.foot.")):
|
||||
_reparent_keep_world(obj, leg_pivots["R"][2])
|
||||
elif obj.parent is None and (name.startswith("Neck.") or name.startswith("Shoulder")):
|
||||
reparent_keep_world(obj, torso_pose)
|
||||
_reparent_keep_world(obj, torso_pose)
|
||||
elif name.startswith("UpperArmL.") or name.startswith("ElbowL.") or name.startswith("ForearmL.") or name.startswith("HandL."):
|
||||
reparent_keep_world(obj, arm_l)
|
||||
_reparent_keep_world(obj, arm_l)
|
||||
elif name.startswith("UpperArmR.") or name.startswith("ElbowR.") or name.startswith("WeaponArm."):
|
||||
reparent_keep_world(obj, arm_r)
|
||||
_reparent_keep_world(obj, arm_r)
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
|
||||
|
|
@ -1515,7 +1593,10 @@ def _add_kestrel_shrouds() -> list[bpy.types.Object]:
|
|||
bevel=0.010,
|
||||
)
|
||||
)
|
||||
# Outer hip drum shield cap
|
||||
leg_thigh = bpy.data.objects.get(f"Leg{side}.Thigh") or pelvis
|
||||
leg_shin = bpy.data.objects.get(f"Leg{side}.Shin") or pelvis
|
||||
|
||||
# Outer hip drum shield cap (rotates with Leg{side}.Thigh)
|
||||
hip_cap_rings: list[list[Vector]] = []
|
||||
for x_off, r in ((1.46, 0.36), (1.58, 0.36), (1.64, 0.25)):
|
||||
px = sx * x_off
|
||||
|
|
@ -1526,7 +1607,11 @@ def _add_kestrel_shrouds() -> list[bpy.types.Object]:
|
|||
if sx < 0:
|
||||
pts = list(reversed(pts))
|
||||
hip_cap_rings.append(pts)
|
||||
created.append(_make_loft_shroud(f"Shroud.Kestrel.HipCap{side}", hip_cap_rings, pelvis, "olive_armor", bevel=0.008))
|
||||
hip_cap = _make_loft_shroud(f"Shroud.Kestrel.HipCap{side}", hip_cap_rings, pelvis, "olive_armor", bevel=0.008)
|
||||
if leg_thigh != pelvis:
|
||||
bpy.context.view_layer.update()
|
||||
_reparent_keep_world(hip_cap, leg_thigh)
|
||||
created.append(hip_cap)
|
||||
created.append(
|
||||
_make_arc_fender(
|
||||
f"Shroud.Kestrel.HipFlange{side}",
|
||||
|
|
@ -1547,14 +1632,19 @@ def _add_kestrel_shrouds() -> list[bpy.types.Object]:
|
|||
)
|
||||
)
|
||||
|
||||
# 4. Faceted knee caps + outer cheek shields over bare black knee drums (parented to Pelvis)
|
||||
knee_bounds = _obj_bounds_in_ref([f"LegJoints{side}.gunmetal"], pelvis, z_filter=(3.0, 4.4))
|
||||
# 4. Faceted knee caps + outer cheek shields over bare black knee drums (parented to Leg{side}.Shin)
|
||||
knee_bounds = _obj_bounds_in_ref(
|
||||
[f"LegJoints{side}Knee.gunmetal", f"LegJoints{side}.gunmetal"],
|
||||
pelvis,
|
||||
z_filter=(3.0, 4.4),
|
||||
)
|
||||
if knee_bounds is not None:
|
||||
kmin, kmax = knee_bounds
|
||||
kcx = 0.5 * (kmin.x + kmax.x)
|
||||
kcy = 0.5 * (kmin.y + kmax.y)
|
||||
kcz = 0.5 * (kmin.z + kmax.z)
|
||||
created.append(
|
||||
knee_shrouds: list[bpy.types.Object] = []
|
||||
knee_shrouds.append(
|
||||
_make_arc_fender(
|
||||
f"Shroud.Kestrel.KneeCap{side}",
|
||||
center=Vector((kcx, kcy, kcz)),
|
||||
|
|
@ -1573,7 +1663,7 @@ def _add_kestrel_shrouds() -> list[bpy.types.Object]:
|
|||
bevel=0.010,
|
||||
)
|
||||
)
|
||||
created.append(
|
||||
knee_shrouds.append(
|
||||
_make_chamfer_box_shroud(
|
||||
f"Shroud.Kestrel.KneeCapFront{side}",
|
||||
kcx - 0.25,
|
||||
|
|
@ -1599,9 +1689,14 @@ def _add_kestrel_shrouds() -> list[bpy.types.Object]:
|
|||
if sx < 0:
|
||||
pts = list(reversed(pts))
|
||||
knee_side_rings.append(pts)
|
||||
created.append(_make_loft_shroud(f"Shroud.Kestrel.KneeCheek{side}", knee_side_rings, pelvis, "olive_armor", bevel=0.008))
|
||||
knee_shrouds.append(_make_loft_shroud(f"Shroud.Kestrel.KneeCheek{side}", knee_side_rings, pelvis, "olive_armor", bevel=0.008))
|
||||
if leg_shin != pelvis:
|
||||
bpy.context.view_layer.update()
|
||||
for ks in knee_shrouds:
|
||||
_reparent_keep_world(ks, leg_shin)
|
||||
created.extend(knee_shrouds)
|
||||
|
||||
# 5. Armored calf/shin shrouds wrapping rear twin ankle hydraulic pistons (parented to Pelvis)
|
||||
# 5. Armored calf/shin shrouds wrapping rear twin ankle hydraulic pistons (parented to Leg{side}.Shin)
|
||||
ram_objs = [f"Ankle{side}.root.machine.ram", f"Ankle{side}.root.steel.ram", f"Ankle{side}.root.steel.eye"]
|
||||
top_b = _obj_bounds_in_ref(ram_objs, pelvis, z_filter=(2.05, 2.75))
|
||||
bot_b = _obj_bounds_in_ref(ram_objs, pelvis, z_filter=(0.95, 1.65))
|
||||
|
|
@ -1638,12 +1733,13 @@ def _add_kestrel_shrouds() -> list[bpy.types.Object]:
|
|||
Vector((px - hw, py + y_back + 0.05, zz)),
|
||||
]
|
||||
greave_rings.append(pts)
|
||||
created.append(_make_loft_shroud(f"Shroud.Kestrel.AnkleGreave{side}", greave_rings, pelvis, "olive_armor", bevel=0.010))
|
||||
shin_shrouds: list[bpy.types.Object] = []
|
||||
shin_shrouds.append(_make_loft_shroud(f"Shroud.Kestrel.AnkleGreave{side}", greave_rings, pelvis, "olive_armor", bevel=0.010))
|
||||
for idx_band, zb in enumerate((1.38, 2.38)):
|
||||
t_u = (zb - 1.30) / 1.10
|
||||
px = b_cx + (t_cx - b_cx) * t_u
|
||||
py = b_cy + (t_cy - b_cy) * t_u
|
||||
created.append(
|
||||
shin_shrouds.append(
|
||||
_make_chamfer_box_shroud(
|
||||
f"Shroud.Kestrel.AnkleBand{side}{idx_band}",
|
||||
px - 0.18,
|
||||
|
|
@ -1658,6 +1754,11 @@ def _add_kestrel_shrouds() -> list[bpy.types.Object]:
|
|||
bevel=0.006,
|
||||
)
|
||||
)
|
||||
if leg_shin != pelvis:
|
||||
bpy.context.view_layer.update()
|
||||
for ss in shin_shrouds:
|
||||
_reparent_keep_world(ss, leg_shin)
|
||||
created.extend(shin_shrouds)
|
||||
|
||||
# 3. Segmented armored spine shroud over exposed rear waist hydraulic rods (parented to Torso.pose)
|
||||
# In Torso.pose local space (offset 0, -0.15, 6.75), neck rings step forward in Y as Z rises from -0.05 to +0.88
|
||||
|
|
|
|||
Loading…
Reference in a new issue