Files
blender-portable-repo/extensions/user_default/amzncharactertools/ops/hh_shapekey.py
T
2026-03-17 15:16:34 -06:00

55 lines
1.3 KiB
Python

import bpy
def popup_error(message: str):
def _draw(self, context):
self.layout.label(text=message)
try:
bpy.context.window_manager.popup_menu(_draw, title="HardHat", icon='ERROR')
except Exception:
print(f"ERROR: {message}")
def selected_hair_meshes():
names = (bpy.context.scene.get('HH_HairTargets') or '').split(';')
names = [n for n in names if n]
if names:
objs = [bpy.data.objects.get(n) for n in names]
return [o for o in objs if o and o.type == 'MESH']
popup_error("No HardHat hair targets set. Click 'Set HardHat Hair Targets' first.")
return []
def ensure_basis(obj):
if not obj.data.shape_keys:
obj.shape_key_add(name='Basis', from_mix=False)
def ensure_hardhat_key(obj):
# Ensure Basis
ensure_basis(obj)
# Find or create HardHat shapekey
key = obj.data.shape_keys.key_blocks.get('HardHat')
if not key:
key = obj.shape_key_add(name='HardHat', from_mix=False)
key.value = 0.0
return key
def run():
hair_objs = selected_hair_meshes()
if not hair_objs:
print("Error: Select hair mesh object(s) before running")
return
for obj in hair_objs:
ensure_hardhat_key(obj)
print(f"Ensured 'HardHat' shapekey on '{obj.name}' (value=0.0)")
print("hh_shapekey: Done.")
run()