deformer_containers.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. from .node_container_common import *
  2. from .xForm_containers import xFormGeometryObject
  3. from .misc_containers import InputExistingGeometryObject
  4. from bpy.types import Node
  5. from .base_definitions import MantisNode
  6. from .utilities import (prRed, prGreen, prPurple, prWhite, prOrange,
  7. wrapRed, wrapGreen, wrapPurple, wrapWhite,
  8. wrapOrange,)
  9. def TellClasses():
  10. return [
  11. DeformerArmature,
  12. DeformerMorphTarget,
  13. DeformerMorphTargetDeform,
  14. ]
  15. def default_evaluate_input(nc, input_name):
  16. # duped from link_containers... should be common?
  17. # should catch 'Target', 'Pole Target' and ArmatureConstraint targets, too
  18. if ('Target' in input_name) and input_name != "Target Space":
  19. socket = nc.inputs.get(input_name)
  20. if socket.is_linked:
  21. return socket.links[0].from_node
  22. return None
  23. else:
  24. return evaluate_input(nc, input_name)
  25. # semi-duplicated from link_containers
  26. def GetxForm(nc):
  27. trace = trace_single_line_up(nc, "Deformer")
  28. for node in trace[0]:
  29. if (node.__class__ in [xFormGeometryObject, InputExistingGeometryObject]):
  30. return node
  31. raise GraphError("%s is not connected to a downstream xForm" % nc)
  32. class DeformerArmature:
  33. '''A node representing an armature deformer'''
  34. def __init__(self, signature, base_tree):
  35. self.base_tree=base_tree
  36. self.signature = signature
  37. self.inputs = {
  38. "Input Relationship" : NodeSocket(is_input = True, name = "Input Relationship", node = self,),
  39. "Armature Object" : NodeSocket(is_input = True, name = "Armature Object", node = self,),
  40. "Blend Vertex Group" : NodeSocket(is_input = True, name = "Blend Vertex Group", node = self),
  41. "Invert Vertex Group" : NodeSocket(is_input = True, name = "Invert Vertex Group", node = self),
  42. "Preserve Volume" : NodeSocket(is_input = True, name = "Preserve Volume", node = self),
  43. "Use Multi Modifier" : NodeSocket(is_input = True, name = "Use Multi Modifier", node = self),
  44. "Use Envelopes" : NodeSocket(is_input = True, name = "Use Envelopes", node = self),
  45. "Use Vertex Groups" : NodeSocket(is_input = True, name = "Use Vertex Groups", node = self),
  46. "Skinning Method" : NodeSocket(is_input = True, name = "Skinning Method", node = self),
  47. "Deformer" : NodeSocket(is_input = True, name = "Deformer", node = self),
  48. "Copy Skin Weights From" : NodeSocket(is_input = True, name = "Copy Skin Weights From", node = self),
  49. }
  50. self.outputs = {
  51. "Deformer" : NodeSocket(is_input = False, name = "Deformer", node=self), }
  52. self.parameters = {
  53. "Name" : None,
  54. "Armature Object" : None,
  55. "Blend Vertex Group" : None,
  56. "Invert Vertex Group" : None,
  57. "Preserve Volume" : None,
  58. "Use Multi Modifier" : None,
  59. "Use Envelopes" : None,
  60. "Use Vertex Groups" : None,
  61. "Skinning Method" : None,
  62. "Deformer" : None,
  63. "Copy Skin Weights From" : None,
  64. }
  65. # now set up the traverse target...
  66. self.inputs["Deformer"].set_traverse_target(self.outputs["Deformer"])
  67. self.outputs["Deformer"].set_traverse_target(self.inputs["Deformer"])
  68. self.node_type = "LINK"
  69. self.hierarchy_connections, self.connections = [], []
  70. self.hierarchy_dependencies, self.dependencies = [], []
  71. self.prepared = True
  72. self.executed = False
  73. def evaluate_input(self, input_name):
  74. return default_evaluate_input(self, input_name)
  75. def GetxForm(self, socket="Deformer"):
  76. if socket == "Deformer":
  77. return GetxForm(self)
  78. else:
  79. from .xForm_containers import xFormGeometryObject
  80. from .misc_containers import InputExistingGeometryObject
  81. from bpy.types import Object
  82. if (trace := trace_single_line(self, socket)[0] ) :
  83. for i in range(len(trace)): # have to look in reverse, actually
  84. if ( isinstance(trace[ i ], xFormGeometryObject ) ) or ( isinstance(trace[ i ], InputExistingGeometryObject ) ):
  85. return trace[ i ].bGetObject()
  86. raise GraphError(wrapRed(f"No other object found for {self}."))
  87. # DUPLICATED FROM xForm_containers::xFormBone
  88. # DEDUP HACK HACK HACK HACK HACK
  89. def bGetParentArmature(self):
  90. from .xForm_containers import xFormArmature
  91. from .misc_containers import InputExistingGeometryObject
  92. from bpy.types import Object
  93. if (trace := trace_single_line(self, "Armature Object")[0] ) :
  94. for i in range(len(trace)):
  95. # have to look in reverse, actually
  96. if ( isinstance(trace[ i ], xFormArmature ) ):
  97. return trace[ i ].bGetObject()
  98. elif ( isinstance(trace[i], InputExistingGeometryObject)):
  99. if (ob := trace[i].bGetObject()).type == "ARMATURE":
  100. return ob
  101. raise RuntimeError(f"Cannot find armature for node {self}")
  102. return None
  103. #should do the trick...
  104. def bExecute(self, bContext = None,):
  105. self.executed = True
  106. def initialize_vgroups(self,):
  107. ob = self.GetxForm().bGetObject()
  108. armOb = self.bGetParentArmature()
  109. for b in armOb.data.bones:
  110. if b.use_deform == False:
  111. continue
  112. vg = ob.vertex_groups.get(b.name)
  113. if not vg:
  114. vg = ob.vertex_groups.new(name=b.name)
  115. num_verts = len(ob.data.vertices)
  116. vg.add(range(num_verts), 0, 'REPLACE')
  117. def copy_weights(self):
  118. # we'll use modifiers for this, maybe use GN for it in the future tho
  119. import bpy
  120. ob = self.GetxForm().bGetObject()
  121. try:
  122. copy_from = self.GetxForm(socket="Copy Skin Weights From")
  123. except GraphError:
  124. copy_from = None
  125. prRed(f"No object found for copying weights in {self}, continuing anyway.")
  126. m = ob.modifiers.new(type="DATA_TRANSFER", name="Mantis_temp_data_transfer")
  127. m.object = None; m.use_vert_data = True
  128. m.data_types_verts = {'VGROUP_WEIGHTS'}
  129. m.vert_mapping = 'POLYINTERP_NEAREST'
  130. m.layers_vgroup_select_src = 'ALL'
  131. m.layers_vgroup_select_dst = 'NAME'
  132. m.object = copy_from
  133. # m.use_object_transform = False # testing reveals that this is undesirable - since the objects may not have their transforms applied.
  134. ob.modifiers.move(len(ob.modifiers)-1, 0)
  135. # ob.data = ob.data.copy()
  136. if False: #MAYBE the mouse needs to be in the 3D viewport, no idea how to set this in an override
  137. # TODO: figure out how to apply this, context is incorrect because armature is still in pose mode
  138. original_active = bpy.context.active_object
  139. original_mode = original_active.mode
  140. bpy.ops.object.mode_set(mode='OBJECT')
  141. with bpy.context.temp_override(**{'active_object':ob, 'selected_objects':[ob, copy_from]}):
  142. # bpy.ops.object.datalayout_transfer(modifier=m.name) # note: this operator is used by the modifier or stand-alone in the UI
  143. # the poll for this operator is defined in blender/source/blender/editors/object/object_data_transfer.cc
  144. # and blender/source/blender/editors/object/object_modifier.cc
  145. # bpy.ops.object.modifier_apply(modifier=m.name, single_user=True)
  146. bpy.ops.object.datalayout_transfer(data_type='VGROUP_WEIGHTS')
  147. bpy.ops.object.data_transfer(data_type='VGROUP_WEIGHTS')
  148. bpy.ops.object.mode_set(mode=original_mode)
  149. def bFinalize(self, bContext=None):
  150. prGreen("Executing Armature Deform Node")
  151. mod_name = self.evaluate_input("Name")
  152. try:
  153. d = self.GetxForm().bGetObject().modifiers[mod_name]
  154. except KeyError:
  155. d = self.GetxForm().bGetObject().modifiers.new(mod_name, type='ARMATURE')
  156. if d is None:
  157. raise RuntimeError(f"Modifier was not created in node {self} -- the object is invalid.")
  158. self.bObject = d
  159. d.object = self.bGetParentArmature()
  160. props_sockets = {
  161. 'vertex_group' : ("Blend Vertex Group", ""),
  162. 'invert_vertex_group' : ("Invert Vertex Group", ""),
  163. 'use_deform_preserve_volume' : ("Preserve Volume", False),
  164. 'use_multi_modifier' : ("Use Multi Modifier", False),
  165. 'use_bone_envelopes' : ("Use Envelopes", False),
  166. 'use_vertex_groups' : ("Use Vertex Groups", False),
  167. }
  168. evaluate_sockets(self, d, props_sockets)
  169. #
  170. if (skin_method := self.evaluate_input("Skinning Method")) == "AUTOMATIC_HEAT":
  171. # This is bad and leads to somewhat unpredictable
  172. # behaviour, e.g. what object will be selected? What mode?
  173. # also bpy.ops is ugly and prone to error when used in
  174. # scripts. I don't intend to use bpy.ops when I can avoid it.
  175. import bpy
  176. self.initialize_vgroups()
  177. bContext.view_layer.depsgraph.update()
  178. ob = self.GetxForm().bGetObject()
  179. armOb = self.bGetParentArmature()
  180. deform_bones = []
  181. for pb in armOb.pose.bones:
  182. if pb.bone.use_deform == True:
  183. deform_bones.append(pb)
  184. context_override = {
  185. 'active_object':ob,
  186. 'selected_objects':[ob, armOb],
  187. 'active_pose_bone':deform_bones[0],
  188. 'selected_pose_bones':deform_bones,}
  189. #
  190. with bContext.temp_override(**{'active_object':armOb}):
  191. bpy.ops.object.mode_set(mode='POSE')
  192. bpy.ops.pose.select_all(action='SELECT')
  193. with bContext.temp_override(**context_override):
  194. bpy.ops.paint.weight_paint_toggle()
  195. bpy.ops.paint.weight_from_bones(type='AUTOMATIC')
  196. bpy.ops.paint.weight_paint_toggle()
  197. #
  198. with bContext.temp_override(**{'active_object':armOb}):
  199. bpy.ops.object.mode_set(mode='POSE')
  200. bpy.ops.pose.select_all(action='DESELECT')
  201. bpy.ops.object.mode_set(mode='OBJECT')
  202. # TODO: modify Blender to make this available as a Python API function.
  203. elif skin_method == "EXISTING_GROUPS":
  204. pass
  205. elif skin_method == "COPY_FROM_OBJECT":
  206. self.initialize_vgroups()
  207. self.copy_weights()
  208. class DeformerMorphTarget:
  209. '''A node representing an armature deformer'''
  210. def __init__(self, signature, base_tree):
  211. self.base_tree=base_tree
  212. self.signature = signature
  213. self.inputs = {
  214. "Relative to" : NodeSocket(is_input = True, name = "Relative To", node = self,),
  215. "Object" : NodeSocket(is_input = True, name = "Object", node = self,),
  216. "Deformer" : NodeSocket(is_input = True, name = "Deformer", node = self),
  217. "Vertex Group" : NodeSocket(is_input = True, name = "Vertex Group", node = self),
  218. }
  219. self.outputs = {
  220. "Deformer" : NodeSocket(is_input = False, name = "Deformer", node=self),
  221. "Morph Target" : NodeSocket(is_input = False, name = "Morph Target", node=self), }
  222. self.parameters = {
  223. "Name" : None,
  224. "Relative to" : None,
  225. "Object" : None,
  226. "Morph Target" : None,
  227. "Deformer" : None,
  228. "Vertex Group" : None,
  229. }
  230. # now set up the traverse target...
  231. self.inputs["Deformer"].set_traverse_target(self.outputs["Deformer"])
  232. self.outputs["Deformer"].set_traverse_target(self.inputs["Deformer"])
  233. self.node_type = "LINK"
  234. self.hierarchy_connections, self.connections = [], []
  235. self.hierarchy_dependencies, self.dependencies = [], []
  236. self.prepared = True
  237. self.executed = False
  238. def GetxForm(self, trace_input="Object"):
  239. trace = trace_single_line(self, trace_input)
  240. for node in trace[0]:
  241. if (node.__class__ in [xFormGeometryObject, InputExistingGeometryObject]):
  242. return node
  243. raise GraphError("%s is not connected to an upstream xForm" % self)
  244. def bExecute(self, bContext = None,):
  245. prGreen("Executing Morph Target Node")
  246. name = ''
  247. ob = None; relative = None
  248. try:
  249. ob = self.GetxForm().bGetObject().name
  250. except Exception as e: # this will and should throw an error if it fails
  251. prRed(f"Execution failed at {self}: no object found for morph target.")
  252. raise e
  253. if self.inputs["Relative to"].is_linked:
  254. try:
  255. relative = self.GetxForm("Relative to").bGetObject().name
  256. except Exception as e: # same here
  257. prRed(f"Execution failed at {self}: no relative object found for morph target, despite link existing.")
  258. raise e
  259. vg = self.evaluate_input("Vertex Group") if self.evaluate_input("Vertex Group") else "" # just make sure it is a string
  260. mt={"object":ob, "vertex_group":vg, "relative_shape":relative}
  261. self.parameters["Morph Target"] = mt
  262. self.executed = True
  263. class DeformerMorphTargetDeform:
  264. '''A node representing an armature deformer'''
  265. def __init__(self, signature, base_tree):
  266. self.base_tree=base_tree
  267. self.signature = signature
  268. self.inputs = {
  269. "Deformer" : NodeSocket(is_input = True, name = "Deformer", node = self),
  270. }
  271. self.outputs = {
  272. "Deformer" : NodeSocket(is_input = False, name = "Deformer", node=self), }
  273. self.parameters = {
  274. "Name" : None,
  275. "Deformer" : None,}
  276. # now set up the traverse target...
  277. self.inputs["Deformer"].set_traverse_target(self.outputs["Deformer"])
  278. self.outputs["Deformer"].set_traverse_target(self.inputs["Deformer"])
  279. self.node_type = "LINK"
  280. self.hierarchy_connections, self.connections = [], []
  281. self.hierarchy_dependencies, self.dependencies = [], []
  282. self.prepared = True
  283. self.executed = True
  284. self.bObject = None
  285. setup_custom_props(self)
  286. def GetxForm(self):
  287. return GetxForm(self)
  288. def gen_morph_target_modifier(self):
  289. mod_name = self.evaluate_input("Name")
  290. try:
  291. m = self.GetxForm().bGetObject().modifiers[mod_name]
  292. except KeyError:
  293. m = self.GetxForm().bGetObject().modifiers.new(mod_name, type='NODES')
  294. self.bObject = m
  295. # at this point we make the node tree
  296. from bpy import data
  297. ng = data.node_groups.new(mod_name, "GeometryNodeTree")
  298. m.node_group = ng
  299. ng.interface.new_socket("Geometry", in_out="INPUT", socket_type="NodeSocketGeometry")
  300. ng.interface.new_socket("Geometry", in_out="OUTPUT", socket_type="NodeSocketGeometry")
  301. inp = ng.nodes.new("NodeGroupInput")
  302. out = ng.nodes.new("NodeGroupOutput")
  303. # TODO CLEANUP here
  304. if (position := ng.nodes.get("Position")) is None: position = ng.nodes.new("GeometryNodeInputPosition")
  305. if (index := ng.nodes.get("Index")) is None: index = ng.nodes.new("GeometryNodeInputIndex")
  306. rest_position = position
  307. add_these = []
  308. props_sockets={}
  309. object_map = {}
  310. targets = []
  311. for k,v in self.inputs.items():
  312. if "Target" in k:
  313. targets.append(v)
  314. for i, t in enumerate(targets):
  315. mt_node = t.links[0].from_node
  316. mt_name = mt_node.GetxForm().bGetObject().name
  317. vg = mt_node.parameters["Morph Target"]["vertex_group"]
  318. if vg: mt_name = mt_name+"."+vg
  319. try:
  320. ob_relative = t.links[0].from_node.inputs["Relative to"].links[0].from_node.bGetObject()
  321. except IndexError:
  322. ob_relative = None
  323. ng.interface.new_socket(mt_name, in_out = "INPUT", socket_type="NodeSocketObject")
  324. ng.interface.new_socket(mt_name+" Value", in_out = "INPUT", socket_type="NodeSocketFloat")
  325. ob_node = ng.nodes.new("GeometryNodeObjectInfo")
  326. sample_index = ng.nodes.new("GeometryNodeSampleIndex"); sample_index.data_type = 'FLOAT_VECTOR'
  327. subtract = ng.nodes.new("ShaderNodeVectorMath"); subtract.operation="SUBTRACT"
  328. scale1 = ng.nodes.new("ShaderNodeVectorMath"); scale1.operation="SCALE"
  329. ng.links.new(input=inp.outputs[mt_name], output=ob_node.inputs["Object"])
  330. ng.links.new(input=index.outputs["Index"], output=sample_index.inputs["Index"])
  331. ng.links.new(input=position.outputs["Position"], output=sample_index.inputs["Value"])
  332. ng.links.new(input=sample_index.outputs["Value"], output=subtract.inputs[0])
  333. ng.links.new(input=ob_node.outputs["Geometry"], output=sample_index.inputs["Geometry"])
  334. if ob_relative: # TODO: this should also be exposed as an input
  335. ob_node1 = ng.nodes.new("GeometryNodeObjectInfo"); ob_node1.inputs["Object"].default_value = ob_relative
  336. sample_index1 = ng.nodes.new("GeometryNodeSampleIndex"); sample_index1.data_type = 'FLOAT_VECTOR'
  337. ng.links.new(input=index.outputs["Index"], output=sample_index1.inputs["Index"])
  338. ng.links.new(input=position.outputs["Position"], output=sample_index1.inputs["Value"])
  339. ng.links.new(input=ob_node1.outputs["Geometry"], output=sample_index1.inputs["Geometry"])
  340. ng.links.new(input=sample_index1.outputs["Value"], output=subtract.inputs[1])
  341. else:
  342. # ng.links.new(input=rest_position.outputs["Attribute"], output=subtract.inputs[1])
  343. ng.links.new(input=rest_position.outputs["Position"], output=subtract.inputs[1])
  344. ng.links.new(input=subtract.outputs["Vector"], output=scale1.inputs[0])
  345. # TODO: this should be exposed as a node tree input
  346. if vg:= mt_node.evaluate_input("Vertex Group"): # works
  347. vg_att = ng.nodes.new("GeometryNodeInputNamedAttribute"); vg_att.inputs["Name"].default_value=vg
  348. multiply = ng.nodes.new("ShaderNodeMath"); multiply.operation = "MULTIPLY"
  349. ng.links.new(input=vg_att.outputs["Attribute"], output=multiply.inputs[1])
  350. ng.links.new(input=inp.outputs[mt_name+" Value"], output=multiply.inputs[0])
  351. ng.links.new(input=multiply.outputs[0], output=scale1.inputs["Scale"])
  352. else:
  353. ng.links.new(input=inp.outputs[mt_name+" Value"], output=scale1.inputs["Scale"])
  354. add_these.append(scale1)
  355. object_map["Socket_"+str((i+1)*2)]=mt_node.GetxForm().bGetObject()
  356. props_sockets["Socket_"+str((i+1)*2+1)]= ("Value."+str(i).zfill(3), 1.0)
  357. set_position = ng.nodes.new("GeometryNodeSetPosition")
  358. ng.links.new(inp.outputs["Geometry"], output=set_position.inputs["Geometry"])
  359. ng.links.new(set_position.outputs["Geometry"], output=out.inputs["Geometry"])
  360. prev_node = rest_position
  361. for i, node in enumerate(add_these):
  362. add = ng.nodes.new("ShaderNodeVectorMath"); add.operation="ADD"
  363. ng.links.new(prev_node.outputs[0], output=add.inputs[0])
  364. ng.links.new(node.outputs[0], output=add.inputs[1])
  365. prev_node = add
  366. ng.links.new(add.outputs[0], output=set_position.inputs["Position"])
  367. from .utilities import SugiyamaGraph
  368. SugiyamaGraph(ng, 12)
  369. evaluate_sockets(self, m, props_sockets)
  370. for socket, ob in object_map.items():
  371. m[socket]=ob
  372. finish_drivers(self)
  373. def gen_shape_key(self): # TODO: make this a feature of the node definition that appears only when there are no prior deformers - and shows a warning!
  374. # 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.
  375. # there are a number of things I need to fix here
  376. # - reuse shape keys if possible
  377. # - figure out how to make this a lot faster
  378. # - edit the xForm stuff to delete drivers from shape key ID's, since they belong to the Key, not the Object.
  379. from time import time
  380. start_time = time()
  381. from bpy import data
  382. ob = self.GetxForm().bGetObject()
  383. m = data.meshes.new_from_object(ob, preserve_all_data_layers=True)
  384. ob.data = m
  385. ob.add_rest_position_attribute = True
  386. ob.shape_key_clear()
  387. targets = []
  388. for k,v in self.inputs.items():
  389. if "Target" in k:
  390. targets.append(v)
  391. for i, t in enumerate(targets):
  392. mt_node = t.links[0].from_node
  393. mt_name = "Morph Target."+str(i).zfill(3)
  394. # using the built-in shapekey feature is actually a lot harder in terms of programming because I need...
  395. # min/max, as it is just not a feature of the GN version
  396. # to carry info from the morph target node regarding relative shapes and vertex groups and all that
  397. # the drivers may be more difficult to apply, too.
  398. # hafta make new geometry for the object and add shape keys and all that
  399. # the benefit to all this being maybe better performence and exporting to game engines via .fbx
  400. # first make a basis shape key
  401. ob.shape_key_add(name='Basis', from_mix=False)
  402. keys={}
  403. props_sockets={}
  404. for i, t in enumerate(targets):
  405. mt_node = t.links[0].from_node
  406. # mt_name = "Morph Target."+str(i).zfill(3)
  407. sk_ob = mt_node.GetxForm().bGetObject()
  408. mt_name = sk_ob.name
  409. vg = mt_node.parameters["Morph Target"]["vertex_group"]
  410. if vg: mt_name = mt_name+"."+vg
  411. sk = ob.shape_key_add(name=mt_name, from_mix=False)
  412. # the shapekey data is absolute point data for each vertex, in order, very simple
  413. for j in range(len(m.vertices)):
  414. sk.data[j].co = sk_ob.data.vertices[j].co # assume they match
  415. sk.vertex_group = vg
  416. sk.slider_min = -10
  417. sk.slider_max = 10
  418. keys[mt_name]=sk
  419. props_sockets[mt_name]= ("Value."+str(i).zfill(3), 1.0)
  420. for i, t in enumerate(targets):
  421. mt_node = t.links[0].from_node
  422. # mt_name = "Morph Target."+str(i).zfill(3)
  423. sk_ob = mt_node.GetxForm().bGetObject()
  424. mt_name = sk_ob.name
  425. vg = mt_node.parameters["Morph Target"]["vertex_group"]
  426. if vg: mt_name = mt_name+"."+vg
  427. if rel := mt_node.parameters["Morph Target"]["relative_shape"]:
  428. sk = keys.get(mt_name)
  429. sk.relative_key = keys.get(rel)
  430. # for k,v in props_sockets.items():
  431. # print(wrapWhite(k), wrapOrange(v), wrapRed(self.evaluate_input(v)))
  432. self.bObject = sk.id_data
  433. evaluate_sockets(self, sk.id_data, props_sockets)
  434. finish_drivers(self)
  435. prWhite(f"Initializing morph target took {time() -start_time} seconds")
  436. # then we need to get all the data from the morph targets, pull all the relative shapes first and add them, vertex groups and properties
  437. # next we add all the shape keys that are left, and their vertex groups
  438. # set the slider ranges to -10 and 10
  439. # then set up the drivers
  440. def bFinalize(self, bContext=None):
  441. # let's find out if there is a prior deformer.
  442. # if not, then there should be an option to use plain 'ol shape keys
  443. # GN is always desirable as an option though because it can be baked.
  444. if self.inputs["Deformer"].is_linked and True:
  445. # for now we won't do Blender Shape Keys
  446. self.gen_morph_target_modifier()
  447. else: # TODO: give the user the option to do this via a node property.
  448. self.gen_shape_key()
  449. for c in TellClasses():
  450. setup_container(c)