xForm_definitions.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. import bpy
  2. from .base_definitions import xFormNode
  3. from bpy.types import Node
  4. from .utilities import (prRed, prGreen, prPurple, prWhite,
  5. prOrange,
  6. wrapRed, wrapGreen, wrapPurple, wrapWhite,
  7. wrapOrange,)
  8. from .base_definitions import get_signature_from_edited_tree
  9. from .xForm_socket_templates import *
  10. def TellClasses():
  11. return [
  12. # xFormNullNode,
  13. xFormBoneNode,
  14. xFormArmatureNode,
  15. xFormGeometryObjectNode,
  16. xFormObjectInstance,
  17. xFormCurvePin,
  18. ]
  19. def default_traverse(self, socket):
  20. if (socket == self.outputs["xForm Out"]):
  21. return self.inputs["Relationship"]
  22. if (socket == self.inputs["Relationship"]):
  23. return self.outputs["xForm Out"]
  24. return None
  25. # Representing an Empty or non-armature-Object
  26. # class xFormNullNode(Node, xFormNode):
  27. # '''A node representing a Null node'''
  28. # bl_idname = 'xFormNullNode'
  29. # bl_label = "Null"
  30. # bl_icon = 'EMPTY_AXIS'
  31. # # === Optional Functions ===
  32. # def init(self, context):
  33. # self.inputs.new('StringSocket', "Name")
  34. # self.inputs.new('RelationshipSocket', "Relationship")
  35. # self.inputs.new('RotationOrderSocket', "Rotation Order")
  36. # self.inputs.new('MatrixSocket', "Matrix")
  37. # self.outputs.new('xFormSocket', "xForm Out")
  38. def check_if_connected(start, end, line):
  39. started=False
  40. for path_nc in line:
  41. prWhite(" ", path_nc.signature)
  42. if path_nc.signature == start.signature:
  43. started = True
  44. elif path_nc.signature == end.signature:
  45. break
  46. if started:
  47. if path_nc.inputs.get("Connected"):
  48. if path_nc.evaluate_input("Connected") == False:
  49. return False
  50. else:
  51. return False
  52. return True
  53. def main_draw_label(self): # this will prefer a user-set label, or return the evaluated name
  54. if self.label:
  55. return self.label
  56. if self.inputs['Name'].display_text:
  57. return self.inputs['Name'].display_text
  58. return self.name
  59. # I had chat gpt flip these so they may be a little innacurate
  60. # always visible
  61. main_names = {
  62. "Name":'StringSocket',
  63. "Rotation Order":'RotationOrderSocket',
  64. "Relationship":'RelationshipSocket',
  65. "Matrix":'MatrixSocket',}
  66. # IK SETTINGS
  67. ik_names = {
  68. "IK Stretch":'FloatFactorSocket',
  69. "Lock IK":'BooleanThreeTupleSocket',
  70. "IK Stiffness":'NodeSocketVector',
  71. "Limit IK":'BooleanThreeTupleSocket',
  72. "X Min":'NodeSocketFloatAngle',
  73. "X Max":'NodeSocketFloatAngle',
  74. "Y Min":'NodeSocketFloatAngle',
  75. "Y Max":'NodeSocketFloatAngle',
  76. "Z Min":'NodeSocketFloatAngle',
  77. "Z Max":'NodeSocketFloatAngle',
  78. }
  79. #display settings
  80. display_names = {
  81. "Bone Collection":'BoneCollectionSocket',
  82. "Custom Object":'xFormSocket',
  83. "Custom Object xForm Override":'xFormSocket',
  84. "Custom Object Scale to Bone Length":'BooleanSocket',
  85. "Custom Object Wireframe":'BooleanSocket',
  86. "Custom Object Scale":'VectorScaleSocket',
  87. "Custom Object Translation":'VectorSocket',
  88. "Custom Object Rotation":'VectorEulerSocket',
  89. "Color":'ColorSetSocket',
  90. }
  91. # deform_names
  92. deform_names = {
  93. "Deform":'BooleanSocket',
  94. "Envelope Distance":'FloatPositiveSocket',
  95. "Envelope Weight":'FloatFactorSocket',
  96. "Envelope Multiply":'BooleanSocket',
  97. "Envelope Head Radius":'FloatPositiveSocket',
  98. "Envelope Tail Radius":'FloatPositiveSocket',
  99. }
  100. bbone_names = {
  101. "BBone Segments":"IntSocket", # BONE
  102. "BBone X Size":"FloatSocket", # BONE
  103. "BBone Z Size":"FloatSocket", # BONE
  104. # "bbone_mapping_mode":"StringSocket", <== BONE
  105. "BBone HQ Deformation":"BooleanSocket", # BONE bbone_mapping_mode
  106. "BBone X Curve-In":"FloatSocket", # BONE AND POSE
  107. "BBone Z Curve-In":"FloatSocket", # BONE AND POSE
  108. "BBone X Curve-Out":"FloatSocket", # BONE AND POSE
  109. "BBone Z Curve-Out":"FloatSocket", # BONE AND POSE
  110. "BBone Roll-In":"FloatSocket", # BONE AND POSE
  111. "BBone Roll-Out":"FloatSocket", # BONE AND POSE
  112. "BBone Inherit End Roll":"BooleanSocket", # BONE
  113. "BBone Scale-In":"VectorSocket", # BONE AND POSE
  114. "BBone Scale-Out":"VectorSocket", # BONE AND POSE
  115. "BBone Ease-In":"FloatSocket", # BONE AND POSE
  116. "BBone Ease-Out":"FloatSocket", # BONE AND POSE
  117. "BBone Easing":"BooleanSocket", # BONE
  118. "BBone Start Handle Type":"EnumBBoneHandleType", # BONE
  119. "BBone Custom Start Handle":"StringSocket", # BONE
  120. "BBone Start Handle Scale":"BooleanThreeTupleSocket", # BONE
  121. "BBone Start Handle Ease":"BooleanSocket", # BONE
  122. "BBone End Handle Type":"EnumBBoneHandleType", # BONE
  123. "BBone Custom End Handle":"StringSocket", # BONE
  124. "BBone End Handle Scale":"BooleanThreeTupleSocket", # BONE
  125. "BBone End Handle Ease":"BooleanSocket", # BONE
  126. }
  127. other_names = {
  128. "Lock Location":'BooleanThreeTupleSocket',
  129. "Lock Rotation":'BooleanThreeTupleSocket',
  130. "Lock Scale":'BooleanThreeTupleSocket',
  131. "Hide":'HideSocket',
  132. }
  133. from mathutils import Color
  134. xFormColor = Color((0.093172, 0.047735, 0.028036)).from_scene_linear_to_srgb()
  135. class xFormBoneNode(Node, xFormNode):
  136. '''A node representing a Bone'''
  137. bl_idname = 'xFormBoneNode'
  138. bl_label = "Bone"
  139. bl_icon = 'BONE_DATA'
  140. display_ik_settings : bpy.props.BoolProperty(default=False)
  141. display_vp_settings : bpy.props.BoolProperty(default=False)
  142. display_def_settings : bpy.props.BoolProperty(default=False)
  143. display_bb_settings : bpy.props.BoolProperty(default=False)
  144. socket_count : bpy.props.IntProperty()
  145. initialized : bpy.props.BoolProperty(default = False)
  146. mantis_node_class_name=bl_idname[:-4]
  147. def init(self, context):
  148. for name, sock_type in main_names.items():
  149. self.inputs.new(sock_type, name)
  150. for name, sock_type in ik_names.items():
  151. s = self.inputs.new(sock_type, name)
  152. s.hide = True
  153. for name, sock_type in display_names.items():
  154. if name == 'Bone Collection': # HACK because I am not using Socket Templates yet
  155. s = self.inputs.new(sock_type, name, use_multi_input=True)
  156. else:
  157. s = self.inputs.new(sock_type, name)
  158. if s.name in ['Custom Object', 'Bone Collection']:
  159. continue
  160. s.hide = True
  161. for name, sock_type in deform_names.items():
  162. s = self.inputs.new(sock_type, name)
  163. if s.name == 'Deform':
  164. continue
  165. s.hide = True
  166. for name, sock_type in bbone_names.items():
  167. s = self.inputs.new(sock_type, name)
  168. if s.name == "BBone Segments":
  169. continue
  170. s.hide = True
  171. for name, sock_type in other_names.items():
  172. self.inputs.new(sock_type, name)
  173. # could probably simplify this further with iter_tools.chain() but meh
  174. self.socket_count = len(self.inputs)
  175. #
  176. self.outputs.new('xFormSocket', "xForm Out")
  177. # set up some defaults...
  178. self.inputs['Rotation Order'].default_value = "XYZ"
  179. self.inputs['Lock Location'].default_value[0] = True
  180. self.inputs['Lock Location'].default_value[1] = True
  181. self.inputs['Lock Location'].default_value[2] = True
  182. self.inputs['Lock Rotation'].default_value[0] = True
  183. self.inputs['Lock Rotation'].default_value[1] = True
  184. self.inputs['Lock Rotation'].default_value[2] = True
  185. self.inputs['Lock Scale'].default_value[0] = True
  186. self.inputs['Lock Scale'].default_value[1] = True
  187. self.inputs['Lock Scale'].default_value[2] = True
  188. # color
  189. self.use_custom_color = True
  190. self.color = xFormColor
  191. #
  192. self.initialized=True
  193. def draw_buttons(self, context, layout):
  194. # return
  195. layout.operator("mantis.add_custom_property", text='+Add Custom Parameter')
  196. # layout.label(text="Edit Parameter ... not implemented")
  197. if (len(self.inputs) > self.socket_count):
  198. layout.operator("mantis.edit_custom_property", text=' Edit Custom Parameter')
  199. layout.operator("mantis.remove_custom_property", text='-Remove Custom Parameter')
  200. else:
  201. layout.label(text="")
  202. def draw_label(self): # this will prefer a user-set label, or return the evaluated name
  203. return main_draw_label(self)
  204. def display_update(self, parsed_tree, context):
  205. if context.space_data:
  206. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  207. self.display_ik_settings = False
  208. if nc and (pb := nc.bGetObject(mode='POSE')):
  209. self.display_ik_settings = pb.is_in_ik_chain
  210. self.inputs['Name'].display_text = ""
  211. if nc:
  212. try:
  213. self.inputs['Name'].display_text = nc.evaluate_input("Name")
  214. self.display_vp_settings = nc.inputs["Custom Object"].is_connected
  215. self.display_def_settings = nc.evaluate_input("Deform")
  216. self.display_bb_settings = nc.evaluate_input("BBone Segments") > 1
  217. except KeyError:
  218. return # the tree isn't ready yet.
  219. for name in ik_names.keys():
  220. self.inputs[name].hide = not self.display_ik_settings
  221. for name in display_names.keys():
  222. if name in ['Custom Object', 'Bone Collection']: continue
  223. self.inputs[name].hide = not self.display_vp_settings
  224. for name in deform_names.keys():
  225. if name in ['Deform']: continue
  226. self.inputs[name].hide = not self.display_def_settings
  227. for name in bbone_names.keys():
  228. if name in ['BBone Segments']: continue
  229. self.inputs[name].hide = not self.display_bb_settings
  230. class xFormArmatureNode(Node, xFormNode):
  231. '''A node representing an Armature object node'''
  232. bl_idname = 'xFormArmatureNode'
  233. bl_label = "Armature"
  234. bl_icon = 'OUTLINER_OB_ARMATURE'
  235. initialized : bpy.props.BoolProperty(default = False)
  236. mantis_node_class_name=bl_idname[:-4]
  237. def init(self, context):
  238. self.init_sockets(xFormArmatureSockets)
  239. self.use_custom_color = True
  240. self.color = xFormColor
  241. self.initialized=True
  242. def draw_label(self): # this will prefer a user-set label, or return the evaluated name
  243. return main_draw_label(self)
  244. def display_update(self, parsed_tree, context):
  245. if context.space_data:
  246. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  247. self.inputs['Name'].display_text = ""
  248. if nc:
  249. self.inputs['Name'].display_text = nc.evaluate_input("Name")
  250. class xFormGeometryObjectNode(Node, xFormNode):
  251. """Represents a curve or mesh object."""
  252. bl_idname = "xFormGeometryObject"
  253. bl_label = "Geometry Object"
  254. bl_icon = "EMPTY_AXIS"
  255. initialized : bpy.props.BoolProperty(default = False)
  256. mantis_node_class_name=bl_idname
  257. def init(self, context):
  258. self.init_sockets(xFormGeometryObjectSockets)
  259. self.use_custom_color = True
  260. self.color = xFormColor
  261. self.initialized=True
  262. def draw_label(self): # this will prefer a user-set label, or return the evaluated name
  263. return main_draw_label(self)
  264. def display_update(self, parsed_tree, context):
  265. if context.space_data:
  266. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  267. self.inputs['Name'].display_text = ""
  268. if nc:
  269. self.inputs['Name'].display_text = nc.evaluate_input("Name")
  270. class xFormObjectInstance(Node, xFormNode):
  271. """Represents an instance of an existing geometry object."""
  272. bl_idname = "xFormObjectInstance"
  273. bl_label = "Object Instance"
  274. bl_icon = "EMPTY_AXIS"
  275. initialized : bpy.props.BoolProperty(default = False)
  276. mantis_node_class_name=bl_idname
  277. def init(self, context):
  278. self.init_sockets(xFormGeometryObjectInstanceSockets)
  279. self.use_custom_color = True
  280. self.color = xFormColor
  281. self.initialized=True
  282. def draw_label(self): # this will prefer a user-set label, or return the evaluated name
  283. return main_draw_label(self)
  284. def display_update(self, parsed_tree, context):
  285. if context.space_data:
  286. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  287. self.inputs['Name'].display_text = ""
  288. if nc:
  289. self.inputs['Name'].display_text = nc.evaluate_input("Name")
  290. from .xForm_containers import xFormCurvePinSockets
  291. class xFormCurvePin(Node, xFormNode):
  292. """"A node representing a curve pin"""
  293. bl_idname = "xFormCurvePin"
  294. bl_label = "Curve Pin"
  295. bl_icon = "FORCE_CURVE"
  296. initialized : bpy.props.BoolProperty(default = False)
  297. mantis_node_class_name=bl_idname
  298. def init(self, context):
  299. self.init_sockets(xFormCurvePinSockets)
  300. self.use_custom_color = True
  301. self.color = xFormColor
  302. self.initialized = True
  303. for cls in TellClasses():
  304. cls.set_mantis_class()