deformer_containers.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. from .node_container_common import *
  2. from .xForm_containers import xFormGeometryObject, xFormObjectInstance
  3. from .misc_nodes import InputExistingGeometryObject
  4. from .base_definitions import MantisNode, MantisSocketTemplate
  5. from .utilities import (prRed, prGreen, prPurple, prWhite, prOrange,
  6. wrapRed, wrapGreen, wrapPurple, wrapWhite,
  7. wrapOrange,)
  8. from .deformer_socket_templates import *
  9. from bpy.types import NodeTree
  10. def TellClasses():
  11. return [
  12. DeformerArmature,
  13. DeformerHook,
  14. DeformerMorphTarget,
  15. DeformerMorphTargetDeform,
  16. ]
  17. # object instance probably can't use the deformer but it doesn't hurt to try.
  18. deformable_types= (xFormGeometryObject, InputExistingGeometryObject, xFormObjectInstance)
  19. def trace_xForm_back(nc, socket):
  20. if (trace := trace_single_line(nc, socket)[0] ) :
  21. for i in range(len(trace)): # have to look in reverse, actually
  22. if ( isinstance(trace[ i ], deformable_types ) ):
  23. return trace[ i ].bGetObject()
  24. raise GraphError(wrapRed(f"No other object found for {nc}."))
  25. class MantisDeformerNode(MantisNode):
  26. def __init__(self, signature : tuple,
  27. base_tree : NodeTree,
  28. socket_templates : list[MantisSocketTemplate]=[]):
  29. super().__init__(signature, base_tree, socket_templates)
  30. self.node_type = 'LINK'
  31. self.prepared = True
  32. self.bObject=[]
  33. # we need evaluate_input to have the same behaviour as links.
  34. def evaluate_input(self, input_name, index=0):
  35. if ('Target' in input_name):
  36. socket = self.inputs.get(input_name)
  37. if socket.is_linked:
  38. return socket.links[0].from_node
  39. return None
  40. else:
  41. return super().evaluate_input(input_name, index)
  42. def GetxForm(nc, output_name="Deformer"):
  43. break_condition= lambda node : node.__class__ in deformable_types
  44. xforms = trace_line_up_branching(nc, output_name, break_condition)
  45. return_me=[]
  46. for xf in xforms:
  47. if xf.node_type != 'XFORM':
  48. continue
  49. if xf in return_me:
  50. continue
  51. return_me.append(xf)
  52. return return_me
  53. class DeformerArmature(MantisDeformerNode):
  54. '''A node representing an armature deformer'''
  55. def __init__(self, signature, base_tree):
  56. super().__init__(signature, base_tree)
  57. inputs = [
  58. "Input Relationship",
  59. "Armature Object",
  60. "Blend Vertex Group",
  61. "Invert Vertex Group",
  62. "Preserve Volume",
  63. "Use Multi Modifier",
  64. "Use Envelopes",
  65. "Use Vertex Groups",
  66. "Skinning Method",
  67. "Deformer",
  68. "Copy Skin Weights From"
  69. ]
  70. outputs = [
  71. "Deformer"
  72. ]
  73. self.outputs.init_sockets(outputs)
  74. self.inputs.init_sockets(inputs)
  75. self.init_parameters(additional_parameters={"Name":None})
  76. self.set_traverse([("Deformer", "Deformer")])
  77. self.node_type = "LINK"
  78. self.prepared = True
  79. def GetxForm(self, socket="Deformer"):
  80. if socket == "Deformer":
  81. return super().GetxForm()
  82. else:
  83. trace_xForm_back(self, socket)
  84. # DUPLICATED FROM xForm_containers::xFormBone
  85. # DEDUP HACK HACK HACK HACK HACK
  86. def bGetParentArmature(self):
  87. from .xForm_containers import xFormArmature
  88. from .misc_nodes import InputExistingGeometryObject
  89. from bpy.types import Object
  90. if (trace := trace_single_line(self, "Armature Object")[0] ) :
  91. for i in range(len(trace)):
  92. # have to look in reverse, actually
  93. if ( isinstance(trace[ i ], xFormArmature ) ):
  94. return trace[ i ].bGetObject()
  95. elif ( isinstance(trace[i], InputExistingGeometryObject)):
  96. if (ob := trace[i].bGetObject()).type == "ARMATURE":
  97. return ob
  98. raise RuntimeError(f"Cannot find armature for node {self}")
  99. return None
  100. #should do the trick...
  101. def bExecute(self, bContext = None,):
  102. self.executed = True
  103. def initialize_vgroups(self, xf):
  104. ob = xf.bGetObject()
  105. armOb = self.bGetParentArmature()
  106. for b in armOb.data.bones:
  107. if b.use_deform == False:
  108. continue
  109. vg = ob.vertex_groups.get(b.name)
  110. if not vg:
  111. vg = ob.vertex_groups.new(name=b.name)
  112. num_verts = len(ob.data.vertices)
  113. vg.add(range(num_verts), 0, 'REPLACE')
  114. def copy_weights(self, xf):
  115. # we'll use modifiers for this, maybe use GN for it in the future tho
  116. import bpy
  117. ob = xf.bGetObject()
  118. try:
  119. copy_from = self.GetxForm(socket="Copy Skin Weights From")
  120. except GraphError:
  121. copy_from = None
  122. prRed(f"No object found for copying weights in {self}, continuing anyway.")
  123. m = ob.modifiers.new(type="DATA_TRANSFER", name="Mantis_temp_data_transfer")
  124. m.object = None; m.use_vert_data = True
  125. m.data_types_verts = {'VGROUP_WEIGHTS'}
  126. m.vert_mapping = 'POLYINTERP_NEAREST'
  127. m.layers_vgroup_select_src = 'ALL'
  128. m.layers_vgroup_select_dst = 'NAME'
  129. m.object = copy_from
  130. # m.use_object_transform = False # testing reveals that this is undesirable - since the objects may not have their transforms applied.
  131. ob.modifiers.move(len(ob.modifiers)-1, 0)
  132. # ob.data = ob.data.copy()
  133. if False: #MAYBE the mouse needs to be in the 3D viewport, no idea how to set this in an override
  134. # TODO: figure out how to apply this, context is incorrect because armature is still in pose mode
  135. original_active = bpy.context.active_object
  136. original_mode = original_active.mode
  137. bpy.ops.object.mode_set(mode='OBJECT')
  138. with bpy.context.temp_override(**{'active_object':ob, 'selected_objects':[ob, copy_from]}):
  139. # bpy.ops.object.datalayout_transfer(modifier=m.name) # note: this operator is used by the modifier or stand-alone in the UI
  140. # the poll for this operator is defined in blender/source/blender/editors/object/object_data_transfer.cc
  141. # and blender/source/blender/editors/object/object_modifier.cc
  142. # bpy.ops.object.modifier_apply(modifier=m.name, single_user=True)
  143. bpy.ops.object.datalayout_transfer(data_type='VGROUP_WEIGHTS')
  144. bpy.ops.object.data_transfer(data_type='VGROUP_WEIGHTS')
  145. bpy.ops.object.mode_set(mode=original_mode)
  146. def bFinalize(self, bContext=None):
  147. prGreen("Executing Armature Deform Node")
  148. mod_name = self.evaluate_input("Name")
  149. for xf in self.GetxForm():
  150. ob = xf.bGetObject()
  151. d = ob.modifiers.new(mod_name, type='ARMATURE')
  152. if d is None:
  153. raise RuntimeError(f"Modifier was not created in node {self} -- the object is invalid.")
  154. self.bObject.append(d)
  155. d.object = self.bGetParentArmature()
  156. props_sockets = {
  157. 'vertex_group' : ("Blend Vertex Group", ""),
  158. 'invert_vertex_group' : ("Invert Vertex Group", ""),
  159. 'use_deform_preserve_volume' : ("Preserve Volume", False),
  160. 'use_multi_modifier' : ("Use Multi Modifier", False),
  161. 'use_bone_envelopes' : ("Use Envelopes", False),
  162. 'use_vertex_groups' : ("Use Vertex Groups", False),
  163. }
  164. evaluate_sockets(self, d, props_sockets)
  165. #
  166. if (skin_method := self.evaluate_input("Skinning Method")) == "AUTOMATIC_HEAT":
  167. # This is bad and leads to somewhat unpredictable
  168. # behaviour, e.g. what object will be selected? What mode?
  169. # also bpy.ops is ugly and prone to error when used in
  170. # scripts. I don't intend to use bpy.ops when I can avoid it.
  171. import bpy
  172. self.initialize_vgroups(xf)
  173. bContext.view_layer.depsgraph.update()
  174. armOb = self.bGetParentArmature()
  175. deform_bones = []
  176. for pb in armOb.pose.bones:
  177. if pb.bone.use_deform == True:
  178. deform_bones.append(pb)
  179. context_override = {
  180. 'active_object':ob,
  181. 'selected_objects':[ob, armOb],
  182. 'active_pose_bone':deform_bones[0],
  183. 'selected_pose_bones':deform_bones,}
  184. for b in armOb.data.bones:
  185. b.select = True
  186. with bContext.temp_override(**context_override):
  187. bpy.ops.paint.weight_paint_toggle()
  188. bpy.ops.paint.weight_from_bones(type='AUTOMATIC')
  189. bpy.ops.paint.weight_paint_toggle()
  190. for b in armOb.data.bones:
  191. b.select = False
  192. # TODO: modify Blender to make this available as a Python API function.
  193. elif skin_method == "COPY_FROM_OBJECT":
  194. self.initialize_vgroups(xf)
  195. self.copy_weights(xf)
  196. # elif skin_method == "EXISTING_GROUPS":
  197. # pass
  198. class DeformerHook(MantisDeformerNode):
  199. '''A node representing a hook deformer'''
  200. def __init__(self, signature, base_tree):
  201. super().__init__(signature, base_tree, HookSockets)
  202. # now set up the traverse target...
  203. self.init_parameters(additional_parameters={"Name":None})
  204. self.set_traverse([("Deformer", "Deformer")])
  205. self.prepared = True
  206. def driver_for_radius(self, object, hook, index, influence, bezier=True):
  207. """ Creates a driver to control the radius of a curve point with the hook."""
  208. from bpy.types import Bone, PoseBone
  209. var_template = {"owner":hook,
  210. "name":"a",
  211. "type":"TRANSFORMS",
  212. "space":'WORLD_SPACE',
  213. "channel":'SCALE_X',}
  214. var1_template = {"owner":hook.id_data,
  215. "name":"b",
  216. "type":"TRANSFORMS",
  217. "space":'WORLD_SPACE',
  218. "channel":'SCALE_X',}
  219. keys_template = [{"co":(0,0),
  220. "interpolation": "LINEAR",
  221. "type":"KEYFRAME",},
  222. {"co":(1,influence),
  223. "interpolation": "LINEAR",
  224. "type":"KEYFRAME",},]
  225. if bezier:
  226. owner=object.data.splines[0].bezier_points
  227. else:
  228. owner=object.data.splines[0].points
  229. driver = {
  230. "owner":owner[index],
  231. "prop":"radius",
  232. "ind":-1,
  233. "extrapolation":"LINEAR",
  234. "type":"AVERAGE",
  235. "vars":[],
  236. "keys":keys_template,
  237. }
  238. if isinstance(hook, (Bone, PoseBone)):
  239. driver['type']='SCRIPTED'
  240. driver['expression']="(((1/b)*a)+((1/b_001)*a_001)+((1/b_002)*a_002))/3"
  241. from .drivers import CreateDrivers
  242. axes='XYZ'
  243. for i in range(3):
  244. var = var_template.copy()
  245. var["channel"]="SCALE_"+axes[i]
  246. driver["vars"].append(var)
  247. if isinstance(hook, (Bone, PoseBone)):
  248. var1=var1_template.copy()
  249. var1['channel']="SCALE_"+axes[i]
  250. driver['vars'].append(var1)
  251. CreateDrivers([driver])
  252. def bExecute(self, bContext = None,):
  253. self.executed = True
  254. def bFinalize(self, bContext=None):
  255. from bpy.types import Bone, PoseBone, Object
  256. prGreen(f"Executing Hook Deform Node: {self}")
  257. mod_name = self.evaluate_input("Name")
  258. affect_radius = self.evaluate_input("Affect Curve Radius")
  259. auto_bezier = self.evaluate_input("Auto-Bezier")
  260. target_node = self.evaluate_input('Hook Target')
  261. target = target_node.bGetObject(); subtarget = ""
  262. props_sockets = self.gen_property_socket_map()
  263. if isinstance(target, Bone) or isinstance(target, PoseBone):
  264. subtarget = target.name; target = target.id_data
  265. for xf in self.GetxForm():
  266. ob=xf.bGetObject()
  267. if ob.type == 'CURVE':
  268. spline_index = self.evaluate_input("Spline Index")
  269. from .utilities import get_extracted_spline_object
  270. ob = get_extracted_spline_object(ob, spline_index, self.mContext)
  271. reuse = False
  272. for m in ob.modifiers:
  273. if m.type == 'HOOK' and m.object == target and m.subtarget == subtarget:
  274. if self.evaluate_input("Influence") != m.strength:
  275. continue # make a new modifier so they can have different strengths
  276. if ob.animation_data: # this can be None
  277. drivers = ob.animation_data.drivers
  278. for k in props_sockets.keys():
  279. if driver := drivers.find(k):
  280. # TODO: I should check to see if the drivers are the same...
  281. break # continue searching for an equivalent modifier
  282. else: # There was no driver - use this one.
  283. d = m; reuse = True; break
  284. else: # use this one, there can't be drivers without animation_data.
  285. d = m; reuse = True; break
  286. else:
  287. d = ob.modifiers.new(mod_name, type='HOOK')
  288. if d is None:
  289. raise RuntimeError(f"Modifier was not created in node {self} -- the object is invalid.")
  290. self.bObject.append(d)
  291. self.get_target_and_subtarget(d, input_name="Hook Target")
  292. vertices_used=[]
  293. if reuse: # Get the verts in the list... filter out all the unneeded 0's
  294. vertices_used = list(d.vertex_indices)
  295. include_0 = 0 in vertices_used
  296. vertices_used = list(filter(lambda a : a != 0, vertices_used))
  297. if include_0: vertices_used.append(0)
  298. # now we add the selected vertex to the list, too
  299. vertex = self.evaluate_input("Point Index")
  300. if ob.type == 'CURVE' and ob.data.splines[0].type == 'BEZIER' and auto_bezier:
  301. if affect_radius:
  302. self.driver_for_radius(ob, target_node.bGetObject(), vertex, d.strength)
  303. vertex*=3
  304. vertices_used.extend([vertex, vertex+1, vertex+2])
  305. else:
  306. vertices_used.append(vertex)
  307. # if we have a curve and it is NOT using auto-bezier for the verts..
  308. if ob.type == 'CURVE' and ob.data.splines[0].type == 'BEZIER' and affect_radius and not auto_bezier:
  309. print (f"WARN: {self}: \"Affect Radius\" may not behave as expected"
  310. " when used on Bezier curves without Auto-Bezier")
  311. #bezier point starts at 1, and then every third vert, so 4, 7, 10...
  312. if vertex%3==1:
  313. self.driver_for_radius(ob, target_node.bGetObject(), vertex, d.strength)
  314. if ob.type == 'CURVE' and ob.data.splines[0].type != 'BEZIER' and \
  315. affect_radius:
  316. self.driver_for_radius(ob, target_node.bGetObject(), vertex, d.strength, bezier=False)
  317. d.vertex_indices_set(vertices_used)
  318. evaluate_sockets(self, d, props_sockets)
  319. finish_drivers(self)
  320. # todo: this node should be able to take many indices in the future.
  321. # Also: I have a Geometry Nodes implementation of this I can use... maybe...
  322. class DeformerMorphTarget(MantisDeformerNode):
  323. '''A node representing an armature deformer'''
  324. def __init__(self, signature, base_tree):
  325. super().__init__(signature, base_tree)
  326. inputs = [
  327. "Relative to",
  328. "Object",
  329. "Deformer",
  330. "Vertex Group",
  331. ]
  332. outputs = [
  333. "Deformer",
  334. "Morph Target",
  335. ]
  336. # now set up the traverse target...
  337. self.outputs.init_sockets(outputs)
  338. self.inputs.init_sockets(inputs)
  339. self.init_parameters(additional_parameters={"Name":None})
  340. self.set_traverse([("Deformer", "Deformer")])
  341. self.node_type = "LINK"
  342. self.prepared = True
  343. def GetxForm(self, trace_input="Object"):
  344. trace = trace_single_line(self, trace_input)
  345. for node in trace[0]:
  346. if (isinstance(node, deformable_types)):
  347. return node
  348. raise GraphError("%s is not connected to an upstream xForm" % self)
  349. def bExecute(self, bContext = None,):
  350. prGreen("Executing Morph Target Node")
  351. ob = None; relative = None
  352. # do NOT check if the object exists here. Just let the next node deal with that.
  353. try:
  354. ob = self.GetxForm().bGetObject().name
  355. except Exception as e: # this will and should throw an error if it fails
  356. ob = self.GetxForm().evaluate_input("Name")
  357. if self.inputs["Relative to"].is_linked:
  358. try:
  359. relative = self.GetxForm("Relative to").bGetObject().name
  360. except Exception as e: # same here
  361. prRed(f"Execution failed at {self}: no relative object found for morph target, despite link existing.")
  362. raise e
  363. vg = self.evaluate_input("Vertex Group") if self.evaluate_input("Vertex Group") else "" # just make sure it is a string
  364. mt={"object":ob, "vertex_group":vg, "relative_shape":relative}
  365. self.parameters["Morph Target"] = mt
  366. self.parameters["Name"] = ob # this is redundant but it's OK since accessing the mt is tedious
  367. self.executed = True
  368. class DeformerMorphTargetDeform(MantisDeformerNode):
  369. '''A node representing an armature deformer'''
  370. def __init__(self, signature, base_tree):
  371. super().__init__(signature, base_tree)
  372. inputs = [
  373. "Deformer",
  374. "Use Shape Key",
  375. "Use Offset",
  376. ]
  377. outputs = [
  378. "Deformer",
  379. ]
  380. self.outputs.init_sockets(outputs)
  381. self.inputs.init_sockets(inputs)
  382. self.init_parameters(additional_parameters={"Name":None})
  383. self.set_traverse([("Deformer", "Deformer")])
  384. self.node_type = "LINK"
  385. self.prepared = True
  386. self.executed = True
  387. setup_custom_props(self)
  388. # bpy.data.node_groups["Morph Deform.045"].nodes["Named Attribute.020"].data_type = 'FLOAT_VECTOR'
  389. # bpy.context.object.add_rest_position_attribute = True
  390. def gen_morph_target_modifier(self, xf, context):
  391. # first let's see if this is a no-op
  392. targets = []
  393. for k,v in self.inputs.items():
  394. if "Target" in k:
  395. targets.append(v)
  396. if not targets:
  397. return # nothing to do here.
  398. # at this point we make the node tree
  399. from .geometry_node_graphgen import gen_morph_target_nodes
  400. m, props_sockets = gen_morph_target_nodes(
  401. self.evaluate_input("Name"),
  402. xf.bGetObject(),
  403. targets,
  404. context,
  405. use_offset=self.evaluate_input("Use Offset"))
  406. self.bObject.append(m)
  407. evaluate_sockets(self, m, props_sockets)
  408. finish_drivers(self)
  409. def gen_shape_key(self, xf, context): # TODO: make this a feature of the node definition that appears only when there are no prior deformers - and shows a warning!
  410. # TODO: the below works well, but it is quite slow. It does not seem to have better performence. Its only advantage is export to FBX.
  411. # there are a number of things I need to fix here
  412. # - reuse shape keys if possible
  413. # - figure out how to make this a lot faster
  414. # - edit the xForm stuff to delete drivers from shape key ID's, since they belong to the Key, not the Object.
  415. # first check if we need to do anythign
  416. targets = []
  417. for k,v in self.inputs.items():
  418. if "Target" in k:
  419. targets.append(v)
  420. if not targets:
  421. return # nothing to do here
  422. from time import time
  423. start_time = time()
  424. from bpy import data
  425. ob = xf.bGetObject()
  426. dg = context.view_layer.depsgraph
  427. dg.update()
  428. if xf.has_shape_keys == False:
  429. m = data.meshes.new_from_object(ob, preserve_all_data_layers=True, depsgraph=dg)
  430. ob.data = m
  431. ob.add_rest_position_attribute = True
  432. ob.shape_key_clear()
  433. ob.shape_key_add(name='Basis', from_mix=False)
  434. else:
  435. m = ob.data
  436. xf.has_shape_keys = True
  437. # using the built-in shapekey feature is actually a lot harder in terms of programming because I need...
  438. # min/max, as it is just not a feature of the GN version
  439. # to carry info from the morph target node regarding relative shapes and vertex groups and all that
  440. # the drivers may be more difficult to apply, too.
  441. # hafta make new geometry for the object and add shape keys and all that
  442. # the benefit to all this being exporting to game engines via .fbx
  443. # first make a basis shape key
  444. keys={}
  445. props_sockets={}
  446. for i, t in enumerate(targets):
  447. mt_node = t.links[0].from_node; sk_ob = mt_node.GetxForm().bGetObject()
  448. if sk_ob is None:
  449. sk_ob = data.objects.new(mt_node.evaluate_input("Name"), data.meshes.new_from_object(ob))
  450. context.collection.objects.link(sk_ob)
  451. prOrange(f"WARN: no object found for f{mt_node}; creating duplicate of current object ")
  452. sk_ob = dg.id_eval_get(sk_ob)
  453. mt_name = sk_ob.name
  454. vg = mt_node.parameters["Morph Target"]["vertex_group"]
  455. if vg: mt_name = mt_name+"."+vg
  456. sk = ob.shape_key_add(name=mt_name, from_mix=False)
  457. # the shapekey data is absolute point data for each vertex, in order, very simple
  458. # SERIOUSLY IMPORTANT:
  459. # use the current position of the vertex AFTER SHAPE KEYS AND DEFORMERS
  460. # easiest way to do it is to eval the depsgraph
  461. # TODO: try and get it without depsgraph update, since that may be (very) slow
  462. sk_m = sk_ob.data#data.meshes.new_from_object(sk_ob, preserve_all_data_layers=True, depsgraph=dg)
  463. for j in range(len(m.vertices)):
  464. sk.data[j].co = sk_m.vertices[j].co # assume they match
  465. # data.meshes.remove(sk_m)
  466. sk.vertex_group = vg
  467. sk.slider_min = -10
  468. sk.slider_max = 10
  469. keys[mt_name]=sk
  470. props_sockets[mt_name]= ("Value."+str(i).zfill(3), 1.0)
  471. for i, t in enumerate(targets):
  472. mt_node = t.links[0].from_node; sk_ob = mt_node.GetxForm().bGetObject()
  473. if sk_ob is None: continue
  474. if rel := mt_node.parameters["Morph Target"]["relative_shape"]:
  475. sk = keys.get(mt_name)
  476. sk.relative_key = keys.get(rel)
  477. self.bObject.append(sk.id_data)
  478. evaluate_sockets(self, sk.id_data, props_sockets)
  479. finish_drivers(self)
  480. prWhite(f"Initializing morph target took {time() -start_time} seconds")
  481. def bFinalize(self, bContext=None):
  482. prGreen(f"Executing Morph Deform node {self}")
  483. use_shape_keys = self.evaluate_input("Use Shape Key")
  484. # if there is a not a prior deformer then there should be an option to use plain 'ol shape keys
  485. # GN is always desirable as an option though because it can be baked & many other reasons
  486. if use_shape_keys: # check and see if we can.
  487. if self.inputs.get("Deformer"): # I guess this isn't available in some node group contexts... bad. FIXME
  488. if (links := self.inputs["Deformer"].links):
  489. if not links[0].from_node.parameters.get("Use Shape Key"):
  490. use_shape_keys = False
  491. elif links[0].from_node.parameters.get("Use Shape Key") == False:
  492. use_shape_keys = False
  493. self.parameters["Use Shape Key"] = use_shape_keys
  494. for xf in self.GetxForm():
  495. if use_shape_keys:
  496. self.gen_shape_key(xf, bContext)
  497. else:
  498. self.gen_morph_target_modifier(xf, bContext)