misc_nodes_ui.py 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. import bpy
  2. from bpy.types import Node
  3. from .base_definitions import MantisUINode, get_signature_from_edited_tree
  4. from .misc_nodes_socket_templates import *
  5. from .utilities import (prRed, prGreen, prPurple, prWhite,
  6. prOrange,
  7. wrapRed, wrapGreen, wrapPurple, wrapWhite,
  8. wrapOrange,)
  9. def TellClasses():
  10. return [ InputFloatNode,
  11. InputIntNode,
  12. InputVectorNode,
  13. InputBooleanNode,
  14. InputBooleanThreeTupleNode,
  15. InputRotationOrderNode,
  16. InputTransformSpaceNode,
  17. InputStringNode,
  18. InputMatrixNode,
  19. # InputGeometryNode,
  20. InputExistingGeometryObjectNode,
  21. InputExistingGeometryDataNode,
  22. InputThemeBoneColorSets,
  23. UtilityDeclareCollections,
  24. UtilityCollectionJoin,
  25. UtilityCollectionHierarchy,
  26. UtilityGeometryOfXForm,
  27. UtilityNameOfXForm,
  28. # ComposeMatrixNode,
  29. MetaRigMatrixNode,
  30. UtilityPointFromCurve,
  31. UtilityMatrixFromCurve,
  32. UtilityMatricesFromCurve,
  33. UtilityNumberOfCurveSegments,
  34. UtilityNumberOfSplines,
  35. UtilityMatrixFromCurveSegment,
  36. UtilityGetCurvePoint,
  37. UtilityGetNearestFactorOnCurve,
  38. UtilityKDChoosePoint,
  39. UtilityKDChooseXForm,
  40. # ScaleBoneLengthNode,
  41. UtilityMetaRigNode,
  42. UtilityBonePropertiesNode,
  43. UtilityDriverVariableNode,
  44. UtilityFCurveNode,
  45. UtilityDriverNode,
  46. UtilitySwitchNode,
  47. UtilityKeyframe,
  48. UtilityCombineThreeBoolNode,
  49. UtilityCombineVectorNode,
  50. UtilitySeparateVector,
  51. UtilityCatStringsNode,
  52. UtilityGetBoneLength,
  53. UtilityPointFromBoneMatrix,
  54. UtilitySetBoneLength,
  55. UtilityMatrixSetLocation,
  56. UtilityMatrixGetLocation,
  57. UtilityMatrixFromXForm,
  58. UtilityAxesFromMatrix,
  59. UtilityBoneMatrixHeadTailFlip,
  60. UtilityMatrixTransform,
  61. UtilityMatrixInvert,
  62. UtilityMatrixCompose,
  63. UtilityMatrixAlignRoll,
  64. UtilityTransformationMatrix,
  65. UtilitySetBoneMatrixTail,
  66. UtilityIntToString,
  67. UtilityArrayGet,
  68. UtilityArrayLength,
  69. #
  70. UtilityCompare,
  71. UtilityChoose,
  72. # for testing
  73. UtilityPrint,
  74. ]
  75. def default_traverse(self,socket):
  76. return None
  77. class InputFloatNode(Node, MantisUINode):
  78. '''A node representing inheritance'''
  79. bl_idname = 'InputFloatNode'
  80. bl_label = "Float"
  81. bl_icon = 'NODE'
  82. initialized : bpy.props.BoolProperty(default = False)
  83. mantis_node_class_name=bl_idname[:-4]
  84. def init(self, context):
  85. self.outputs.new('FloatSocket', "Float Input").input = True
  86. self.initialized = True
  87. class InputIntNode(Node, MantisUINode):
  88. '''A node representing inheritance'''
  89. bl_idname = 'InputIntNode'
  90. bl_label = "Integer"
  91. bl_icon = 'NODE'
  92. initialized : bpy.props.BoolProperty(default = False)
  93. mantis_node_class_name=bl_idname
  94. def init(self, context):
  95. self.outputs.new('IntSocket', "Integer").input = True
  96. self.initialized = True
  97. class InputVectorNode(Node, MantisUINode):
  98. '''A node representing inheritance'''
  99. bl_idname = 'InputVectorNode'
  100. bl_label = "Vector"
  101. bl_icon = 'NODE'
  102. initialized : bpy.props.BoolProperty(default = False)
  103. mantis_node_class_name=bl_idname[:-4]
  104. def init(self, context):
  105. self.outputs.new('VectorSocket', "").input = True
  106. self.initialized = True
  107. class InputBooleanNode(Node, MantisUINode):
  108. '''A node representing inheritance'''
  109. bl_idname = 'InputBooleanNode'
  110. bl_label = "Boolean"
  111. bl_icon = 'NODE'
  112. initialized : bpy.props.BoolProperty(default = False)
  113. mantis_node_class_name=bl_idname[:-4]
  114. def init(self, context):
  115. self.outputs.new('BooleanSocket', "").input = True
  116. self.initialized = True
  117. class InputBooleanThreeTupleNode(Node, MantisUINode):
  118. '''A node representing inheritance'''
  119. bl_idname = 'InputBooleanThreeTupleNode'
  120. bl_label = "Boolean Vector"
  121. bl_icon = 'NODE'
  122. initialized : bpy.props.BoolProperty(default = False)
  123. mantis_node_class_name=bl_idname[:-4]
  124. def init(self, context):
  125. self.outputs.new('BooleanThreeTupleSocket', "")
  126. self.initialized = True
  127. class InputRotationOrderNode(Node, MantisUINode):
  128. '''A node representing inheritance'''
  129. bl_idname = 'InputRotationOrderNode'
  130. bl_label = "Rotation Order"
  131. bl_icon = 'NODE'
  132. initialized : bpy.props.BoolProperty(default = False)
  133. mantis_node_class_name=bl_idname[:-4]
  134. def init(self, context):
  135. self.outputs.new('RotationOrderSocket', "").input = True
  136. self.initialized = True
  137. class InputTransformSpaceNode(Node, MantisUINode):
  138. '''A node representing inheritance'''
  139. bl_idname = 'InputTransformSpaceNode'
  140. bl_label = "Transform Space"
  141. bl_icon = 'NODE'
  142. initialized : bpy.props.BoolProperty(default = False)
  143. mantis_node_class_name=bl_idname[:-4]
  144. def init(self, context):
  145. self.outputs.new('TransformSpaceSocket', "").input = True
  146. self.initialized = True
  147. class InputStringNode(Node, MantisUINode):
  148. '''A node representing inheritance'''
  149. bl_idname = 'InputStringNode'
  150. bl_label = "String"
  151. bl_icon = 'NODE'
  152. initialized : bpy.props.BoolProperty(default = False)
  153. mantis_node_class_name=bl_idname[:-4]
  154. def init(self, context):
  155. self.outputs.new('StringSocket', "").input = True
  156. self.initialized = True
  157. class InputMatrixNode(Node, MantisUINode):
  158. '''A node representing inheritance'''
  159. bl_idname = 'InputMatrixNode'
  160. bl_label = "Matrix"
  161. bl_icon = 'NODE'
  162. first_row : bpy.props.FloatVectorProperty(name="", size=4, default = (1.0, 0.0, 0.0, 0.0,))
  163. second_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 1.0, 0.0, 0.0,))
  164. third_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 1.0, 0.0,))
  165. fourth_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 0.0, 1.0,))
  166. initialized : bpy.props.BoolProperty(default = False)
  167. mantis_node_class_name=bl_idname[:-4]
  168. def set_matrix(self):
  169. return (self.first_row[ 0], self.first_row[ 1], self.first_row[ 2], self.first_row[ 3],
  170. self.second_row[0], self.second_row[1], self.second_row[2], self.second_row[3],
  171. self.third_row[ 0], self.third_row[ 1], self.third_row[ 2], self.third_row[ 3],
  172. self.fourth_row[0], self.fourth_row[1], self.fourth_row[2], self.fourth_row[3],)
  173. def init(self, context):
  174. self.outputs.new('MatrixSocket', "Matrix")
  175. self.initialized = True
  176. def draw_buttons(self, context, layout):
  177. # return
  178. layout.prop(self, "first_row")
  179. layout.prop(self, "second_row")
  180. layout.prop(self, "third_row")
  181. layout.prop(self, "fourth_row")
  182. def update(self):
  183. mat_sock = self.outputs[0]
  184. mat_sock.default_value = self.set_matrix()
  185. class ScaleBoneLengthNode(Node, MantisUINode):
  186. '''Scale Bone Length'''
  187. bl_idname = 'ScaleBoneLength'
  188. bl_label = "Scale Bone Length"
  189. bl_icon = 'NODE'
  190. initialized : bpy.props.BoolProperty(default = False)
  191. # === Optional Functions ===
  192. def init(self, context):
  193. self.inputs.new('MatrixSocket', "In Matrix")
  194. self.inputs.new('FloatSocket', "Factor")
  195. self.outputs.new('MatrixSocket', "Out Matrix")
  196. self.initialized = True
  197. class MetaRigMatrixNode(Node, MantisUINode):
  198. # Identical to the above, except
  199. '''A node representing a bone's matrix'''
  200. bl_idname = 'MetaRigMatrixNode'
  201. bl_label = "Matrix"
  202. bl_icon = 'NODE'
  203. first_row : bpy.props.FloatVectorProperty(name="", size=4, default = (1.0, 0.0, 0.0, 0.0,))
  204. second_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 1.0, 0.0, 0.0,))
  205. third_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 1.0, 0.0,))
  206. fourth_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 0.0, 1.0,))
  207. initialized : bpy.props.BoolProperty(default = False)
  208. mantis_node_class_name="UtilityMetaRig"
  209. def set_matrix(self):
  210. return (self.first_row[ 0], self.first_row[ 1], self.first_row[ 2], self.first_row[ 3],
  211. self.second_row[0], self.second_row[1], self.second_row[2], self.second_row[3],
  212. self.third_row[ 0], self.third_row[ 1], self.third_row[ 2], self.third_row[ 3],
  213. self.fourth_row[0], self.fourth_row[1], self.fourth_row[2], self.fourth_row[3],)
  214. def init(self, context):
  215. self.outputs.new('MatrixSocket', "Matrix")
  216. self.initialized = True
  217. def update(self):
  218. mat_sock = self.outputs[0]
  219. mat_sock.default_value = self.set_matrix()
  220. class UtilityMatrixFromCurve(Node, MantisUINode):
  221. """Gets a matrix from a curve."""
  222. bl_idname = "UtilityMatrixFromCurve"
  223. bl_label = "Matrix from Curve"
  224. bl_icon = "NODE"
  225. initialized : bpy.props.BoolProperty(default = False)
  226. mantis_node_class_name=bl_idname
  227. def init(self, context):
  228. self.init_sockets(MatrixFromCurveSockets)
  229. self.initialized = True
  230. class UtilityPointFromCurve(Node, MantisUINode):
  231. """Gets a point from a curve."""
  232. bl_idname = "UtilityPointFromCurve"
  233. bl_label = "Point from Curve"
  234. bl_icon = "NODE"
  235. initialized : bpy.props.BoolProperty(default = False)
  236. mantis_node_class_name=bl_idname
  237. def init(self, context):
  238. self.init_sockets(PointFromCurveSockets)
  239. self.initialized = True
  240. class UtilityNumberOfCurveSegments(Node, MantisUINode):
  241. """Tells the number of segments in a curve."""
  242. bl_idname = "UtilityNumberOfCurveSegments"
  243. bl_label = "Number of Curve Segments"
  244. bl_icon = "NODE"
  245. initialized : bpy.props.BoolProperty(default = False)
  246. mantis_node_class_name=bl_idname
  247. def init(self, context):
  248. self.inputs.new("EnumCurveSocket", "Curve")
  249. self.inputs.new('UnsignedIntSocket', 'Spline Index')
  250. self.outputs.new("UnsignedIntSocket", "Number of Segments")
  251. self.initialized = True
  252. class UtilityNumberOfSplines(Node, MantisUINode):
  253. """Tells the number of splines in a curve."""
  254. bl_idname = "UtilityNumberOfSplines"
  255. bl_label = "Number of Splines"
  256. bl_icon = "NODE"
  257. initialized : bpy.props.BoolProperty(default = False)
  258. mantis_node_class_name=bl_idname
  259. def init(self, context):
  260. self.init_sockets(NumberOfSplinesSockets)
  261. self.initialized = True
  262. class UtilityMatrixFromCurveSegment(Node, MantisUINode):
  263. """Gets a matrix from a curve segment."""
  264. bl_idname = "UtilityMatrixFromCurveSegment"
  265. bl_label = "Matrix from Curve Segment"
  266. bl_icon = "NODE"
  267. initialized : bpy.props.BoolProperty(default = False)
  268. mantis_node_class_name=bl_idname
  269. def init(self, context):
  270. self.init_sockets(MatrixFromCurveSegmentSockets)
  271. self.initialized = True
  272. class UtilityGetCurvePoint(Node, MantisUINode):
  273. bl_idname = 'UtilityGetCurvePoint'
  274. bl_label = "Control Point from Curve"
  275. bl_icon = 'NODE'
  276. initialized : bpy.props.BoolProperty(default = False)
  277. mantis_node_class_name=bl_idname
  278. def init(self, context):
  279. self.init_sockets(GetCurvePointSockets)
  280. self.initialized = True
  281. def display_update(self, parsed_tree, context):
  282. self.outputs["Point"].hide=False
  283. self.outputs["Left Handle"].hide=True
  284. self.outputs["Right Handle"].hide=True
  285. spline_index = self.inputs['Spline Index'].default_value
  286. index = self.inputs['Index'].default_value
  287. curve = self.inputs['Curve'].default_value
  288. if self.inputs['Spline Index'].is_linked or self.inputs['Index'].is_linked \
  289. or self.inputs['Curve'].is_linked:
  290. mantis_node = parsed_tree.get(get_signature_from_edited_tree(self, context))
  291. spline_index = mantis_node.evaluate_input("Spline Index")
  292. index = mantis_node.evaluate_input("Index")
  293. curve = mantis_node.evaluate_input("Curve")
  294. if curve := bpy.data.objects.get(curve):
  295. if curve.type != "CURVE":
  296. self.outputs["Point"].hide=True
  297. spline = curve.data.splines[spline_index]
  298. if spline.type == 'BEZIER':
  299. self.outputs["Left Handle"].hide=False
  300. self.outputs["Right Handle"].hide=False
  301. class UtilityMatricesFromCurve(Node, MantisUINode):
  302. """Gets a matrix from a curve."""
  303. bl_idname = "UtilityMatricesFromCurve"
  304. bl_label = "Matrices from Curve"
  305. bl_icon = "NODE"
  306. initialized : bpy.props.BoolProperty(default = False)
  307. mantis_node_class_name=bl_idname
  308. def init(self, context):
  309. self.init_sockets(MatricesFromCurveSockets)
  310. self.initialized = True
  311. def display_update_choose_nearest(self, parsed_tree, context):
  312. number_of_points = self.inputs['Number to Find'].default_value
  313. if self.inputs["Number to Find"].is_linked:
  314. mantis_node = parsed_tree.get(get_signature_from_edited_tree(self, context))
  315. number_of_points = mantis_node.evaluate_input("Number to Find")
  316. elif number_of_points == 0:
  317. self.inputs['Number to Find'].default_value=1
  318. if number_of_points > 1:
  319. # then we need to make it an array out
  320. self.outputs.display_shape = 'SQUARE_DOT'
  321. else:
  322. self.outputs.display_shape = 'CIRCLE'
  323. class UtilityGetNearestFactorOnCurve(Node, MantisUINode):
  324. bl_idname = 'UtilityGetNearestFactorOnCurve'
  325. bl_label = "Get Factor on Curve at Point"
  326. bl_icon = 'NODE'
  327. initialized : bpy.props.BoolProperty(default = False)
  328. mantis_node_class_name=bl_idname
  329. def init(self, context):
  330. self.init_sockets(GetNearestFactorOnCurveSockets)
  331. self.initialized = True
  332. class UtilityKDChoosePoint(Node, MantisUINode):
  333. """Chooses the nearest point with a KD Tree."""
  334. bl_idname = "UtilityKDChoosePoint"
  335. bl_label = "Choose Nearest Point"
  336. bl_icon = "NODE"
  337. initialized : bpy.props.BoolProperty(default = False)
  338. mantis_node_class_name=bl_idname
  339. def init(self, context):
  340. self.inputs.new("VectorSocket", "Reference Point")
  341. a = self.inputs.new('VectorSocket', 'Points', use_multi_input=True)
  342. a.display_shape='SQUARE_DOT'
  343. s = self.inputs.new("UnsignedIntSocket", "Number to Find")
  344. s.default_value=1
  345. self.outputs.new("VectorSocket", "Result Point")
  346. self.outputs.new("UnsignedIntSocket", "Result Index")
  347. self.outputs.new("FloatSocket", "Result Distance")
  348. self.initialized = True
  349. def display_update(self, parsed_tree, context):
  350. display_update_choose_nearest(self, parsed_tree, context)
  351. class UtilityKDChooseXForm(Node, MantisUINode):
  352. """Chooses the nearest xForm with a KD Tree."""
  353. bl_idname = "UtilityKDChooseXForm"
  354. bl_label = "Choose Nearest xForm"
  355. bl_icon = "NODE"
  356. initialized : bpy.props.BoolProperty(default = False)
  357. mantis_node_class_name=bl_idname
  358. def init(self, context):
  359. self.inputs.new("VectorSocket", "Reference Point")
  360. self.inputs.new('xFormSocket', 'xForm Nodes', use_multi_input=True)
  361. self.inputs.new("FloatFactorSocket", "Get Point Head/Tail")
  362. s = self.inputs.new("UnsignedIntSocket", "Number to Find")
  363. s.default_value=1
  364. self.outputs.new("xFormSocket", "Result xForm")
  365. self.outputs.new("UnsignedIntSocket", "Result Index")
  366. self.outputs.new("FloatSocket", "Result Distance")
  367. self.initialized = True
  368. def display_update(self, parsed_tree, context):
  369. display_update_choose_nearest(self, parsed_tree, context)
  370. class UtilityMetaRigNode(Node, MantisUINode):
  371. """Gets a matrix from a meta-rig bone."""
  372. bl_idname = "UtilityMetaRig"
  373. bl_label = "Meta-Rig"
  374. bl_icon = "NODE"
  375. armature:bpy.props.StringProperty()
  376. pose_bone:bpy.props.StringProperty()
  377. initialized : bpy.props.BoolProperty(default = False)
  378. mantis_node_class_name=bl_idname
  379. def init(self, context):
  380. armt = self.inputs.new("EnumMetaRigSocket", "Meta-Armature")
  381. bone = self.inputs.new("EnumMetaBoneSocket", "Meta-Bone")
  382. bone.hide=True
  383. self.outputs.new("MatrixSocket", "Matrix")
  384. self.initialized = True
  385. def display_update(self, parsed_tree, context):
  386. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  387. if nc:
  388. self.armature= nc.evaluate_input("Meta-Armature")
  389. self.pose_bone= nc.evaluate_input("Meta-Bone")
  390. if not self.armature:
  391. self.inputs["Meta-Bone"].hide=True
  392. else:
  393. self.inputs["Meta-Bone"].hide=False
  394. if self.inputs["Meta-Armature"].is_linked:
  395. self.inputs["Meta-Armature"].search_prop = None
  396. if self.inputs["Meta-Bone"].is_linked:
  397. self.inputs["Meta-Bone"].search_prop = None
  398. class UtilityBonePropertiesNode(Node, MantisUINode):
  399. """Provides as sockets strings identifying bone transform properties."""
  400. bl_idname = "UtilityBoneProperties"
  401. bl_label = "Bone Properties"
  402. bl_icon = "NODE"
  403. #bl_width_default = 250
  404. initialized : bpy.props.BoolProperty(default = False)
  405. mantis_node_class_name=bl_idname
  406. def init(self, context):
  407. self.outputs.new("StringSocket", "matrix")
  408. self.outputs.new("StringSocket", "matrix_local")
  409. self.outputs.new("StringSocket", "matrix_basis")
  410. self.outputs.new("StringSocket", "head")
  411. self.outputs.new("StringSocket", "tail")
  412. self.outputs.new("StringSocket", "length")
  413. self.outputs.new("StringSocket", "rotation")
  414. self.outputs.new("StringSocket", "location")
  415. self.outputs.new("StringSocket", "scale")
  416. self.initialized = True
  417. class UtilityDriverVariableNode(Node, MantisUINode):
  418. """Creates a variable for use in a driver."""
  419. bl_idname = "UtilityDriverVariable"
  420. bl_label = "Driver Variable"
  421. bl_icon = "NODE"
  422. initialized : bpy.props.BoolProperty(default = False)
  423. mantis_node_class_name=bl_idname
  424. def init(self, context):
  425. self.inputs.new("EnumDriverVariableType", "Variable Type") # 0
  426. self.inputs.new("ParameterStringSocket", "Property") # 1
  427. self.inputs.new("IntSocket", "Property Index") # 2
  428. self.inputs.new("EnumDriverVariableEvaluationSpace", "Evaluation Space") # 3
  429. self.inputs.new("EnumDriverRotationMode", "Rotation Mode") # 4
  430. self.inputs.new("xFormSocket", "xForm 1") # 5
  431. self.inputs.new("xFormSocket", "xForm 2") # 6
  432. self.outputs.new("DriverVariableSocket", "Driver Variable")
  433. self.inputs[3].hide = True
  434. self.initialized = True
  435. def display_update(self, parsed_tree, context):
  436. if self.inputs["Variable Type"].is_linked:
  437. if context.space_data:
  438. node_tree = context.space_data.path[0].node_tree
  439. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  440. if nc:
  441. driver_type = nc.evaluate_input("Variable Type")
  442. else:
  443. driver_type = self.inputs[0].default_value
  444. if driver_type == 'SINGLE_PROP':
  445. self.inputs[1].hide = False
  446. self.inputs[2].hide = False
  447. self.inputs[3].hide = False
  448. self.inputs[4].hide = False
  449. self.inputs[5].hide = False
  450. self.inputs[6].hide = True
  451. elif driver_type == 'LOC_DIFF':
  452. self.inputs[1].hide = True
  453. self.inputs[2].hide = True
  454. self.inputs[3].hide = True
  455. self.inputs[4].hide = True
  456. self.inputs[5].hide = False
  457. self.inputs[6].hide = False
  458. elif driver_type == 'ROTATION_DIFF':
  459. self.inputs[1].hide = True
  460. self.inputs[2].hide = True
  461. self.inputs[3].hide = True
  462. self.inputs[4].hide = False
  463. self.inputs[5].hide = False
  464. self.inputs[6].hide = False
  465. elif driver_type == 'TRANSFORMS':
  466. self.inputs[1].hide = True
  467. self.inputs[2].hide = True
  468. self.inputs[3].hide = False
  469. self.inputs[4].hide = False
  470. self.inputs[5].hide = False
  471. self.inputs[6].hide = True
  472. # TODO: make a way to edit the fCurve directly.
  473. # I had a working version of this in the past, but it required doing sinful things like
  474. # keeping track of the RAM address of the window.
  475. class UtilityFCurveNode(Node, MantisUINode):
  476. """Creates an fCurve for use with a driver."""
  477. bl_idname = "UtilityFCurve"
  478. bl_label = "fCurve"
  479. bl_icon = "NODE"
  480. use_kf_nodes : bpy.props.BoolProperty(default=True)
  481. initialized : bpy.props.BoolProperty(default = False)
  482. mantis_node_class_name=bl_idname
  483. def init(self, context):
  484. self.inputs.new("eFCrvExtrapolationMode", "Extrapolation Mode")
  485. self.outputs.new("FCurveSocket", "fCurve")
  486. self.initialized = True
  487. def draw_buttons(self, context, layout):
  488. layout.operator( 'mantis.fcurve_node_add_kf' )
  489. if (len(self.inputs) > 1):
  490. layout.operator( 'mantis.fcurve_node_remove_kf' )
  491. class UtilityDriverNode(Node, MantisUINode):
  492. """Represents a Driver relationship"""
  493. bl_idname = "UtilityDriver"
  494. bl_label = "Driver"
  495. bl_icon = "NODE"
  496. initialized : bpy.props.BoolProperty(default = False)
  497. mantis_node_class_name=bl_idname
  498. def init(self, context):
  499. self.inputs.new("EnumDriverType", "Driver Type")
  500. self.inputs.new("FCurveSocket", "fCurve")
  501. self.inputs.new("StringSocket", "Expression")
  502. self.outputs.new("DriverSocket", "Driver")
  503. self.initialized = True
  504. def display_update(self, parsed_tree, context):
  505. if not self.inputs["Driver Type"].is_linked:
  506. dType = self.inputs["Driver Type"].default_value
  507. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  508. if nc:
  509. dType = nc.evaluate_input("Driver Type")
  510. if dType == 'SCRIPTED':
  511. self.inputs["Expression"].hide = False
  512. else:
  513. self.inputs["Expression"].hide = True
  514. def draw_buttons(self, context, layout):
  515. # return
  516. layout.operator( 'mantis.driver_node_add_variable' )
  517. if (len(self.inputs) > 3):
  518. layout.operator( 'mantis.driver_node_remove_variable' )
  519. class UtilitySwitchNode(Node, MantisUINode):
  520. """Represents a switch relationship between one driver property and one or more driven properties."""
  521. bl_idname = "UtilitySwitch"
  522. bl_label = "Switch"
  523. bl_icon = "NODE"
  524. initialized : bpy.props.BoolProperty(default = False)
  525. mantis_node_class_name=bl_idname
  526. def init(self, context):
  527. # self.inputs.new("xFormSocket", "xForm")
  528. self.inputs.new("ParameterStringSocket", "Parameter")
  529. self.inputs.new("IntSocket", "Parameter Index")
  530. self.inputs.new("BooleanSocket", "Invert Switch")
  531. self.outputs.new("DriverSocket", "Driver")
  532. self.initialized = True
  533. class UtilityCombineThreeBoolNode(Node, MantisUINode):
  534. """Combines three booleans into a three-bool."""
  535. bl_idname = "UtilityCombineThreeBool"
  536. bl_label = "CombineThreeBool"
  537. bl_icon = "NODE"
  538. initialized : bpy.props.BoolProperty(default = False)
  539. mantis_node_class_name=bl_idname
  540. def init(self, context):
  541. self.inputs.new("BooleanSocket", "X")
  542. self.inputs.new("BooleanSocket", "Y")
  543. self.inputs.new("BooleanSocket", "Z")
  544. self.outputs.new("BooleanThreeTupleSocket", "Three-Bool")
  545. self.initialized = True
  546. class UtilityCombineVectorNode(Node, MantisUINode):
  547. """Combines three floats into a vector."""
  548. bl_idname = "UtilityCombineVector"
  549. bl_label = "CombineVector"
  550. bl_icon = "NODE"
  551. initialized : bpy.props.BoolProperty(default = False)
  552. mantis_node_class_name=bl_idname
  553. def init(self, context):
  554. self.inputs.new("FloatSocket", "X")
  555. self.inputs.new("FloatSocket", "Y")
  556. self.inputs.new("FloatSocket", "Z")
  557. self.outputs.new("VectorSocket", "Vector")
  558. self.initialized = True
  559. class UtilitySeparateVector(Node, MantisUINode):
  560. """Separates a vector into three floats"""
  561. bl_idname = "UtilitySeparateVector"
  562. bl_label = "Separate Vector"
  563. bl_icon = "NODE"
  564. initialized : bpy.props.BoolProperty(default = False)
  565. mantis_node_class_name=bl_idname
  566. def init(self, context):
  567. self.inputs.new("VectorSocket", "Vector")
  568. self.outputs.new("FloatSocket", "X")
  569. self.outputs.new("FloatSocket", "Y")
  570. self.outputs.new("FloatSocket", "Z")
  571. self.initialized = True
  572. class UtilityCatStringsNode(Node, MantisUINode):
  573. """Adds a suffix to a string"""
  574. bl_idname = "UtilityCatStrings"
  575. bl_label = "Concatenate Strings"
  576. bl_icon = "NODE"
  577. initialized : bpy.props.BoolProperty(default = False)
  578. mantis_node_class_name=bl_idname
  579. def init(self, context):
  580. self.inputs.new("StringSocket", "String_1")
  581. self.inputs.new("StringSocket", "String_2")
  582. self.outputs.new("StringSocket", "OutputString")
  583. self.initialized = True
  584. def draw_label(self): # this will prefer a user-set label, or return the evaluated name
  585. if self.label:
  586. return self.label
  587. if self.outputs['OutputString'].display_text:
  588. return self.outputs['OutputString'].display_text
  589. return self.name
  590. def display_update(self, parsed_tree, context):
  591. if context.space_data:
  592. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  593. self.inputs['String_1'].display_text = ""
  594. self.inputs['String_2'].display_text = ""
  595. self.outputs['OutputString'].display_text = ""
  596. if nc:
  597. try:
  598. self.inputs['String_1'].display_text = a = nc.evaluate_input("String_1")
  599. self.inputs['String_2'].display_text = b = nc.evaluate_input("String_2")
  600. # cat the strings here, since the node may not have run yet.
  601. self.outputs['OutputString'].display_text = a+b
  602. except KeyError:
  603. return # the tree isn't ready yet.
  604. class InputLayerMaskNode(Node, MantisUINode):
  605. """Represents a layer mask for a bone."""
  606. bl_idname = "InputLayerMaskNode"
  607. bl_label = "Layer Mask"
  608. bl_icon = "NODE"
  609. initialized : bpy.props.BoolProperty(default = False)
  610. mantis_node_class_name=bl_idname
  611. def init(self, context):
  612. self.outputs.new("LayerMaskInputSocket", "Layer Mask")
  613. self.initialized = True
  614. class InputExistingGeometryObjectNode(Node, MantisUINode):
  615. """Represents an existing geometry object from within the scene."""
  616. bl_idname = "InputExistingGeometryObject"
  617. bl_label = "Existing Object"
  618. bl_icon = "NODE"
  619. initialized : bpy.props.BoolProperty(default = False)
  620. mantis_node_class_name=bl_idname
  621. # We want Mantis to import widgets and stuff, so we hold a reference to the object
  622. object_reference : bpy.props.PointerProperty(type=bpy.types.Object,)
  623. def init(self, context):
  624. self.inputs.new("StringSocket", "Name")
  625. self.outputs.new("xFormSocket", "Object")
  626. self.initialized = True
  627. def display_update(self, parsed_tree, context):
  628. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  629. if nc: # this is done here so I don't have to define yet another custom socket.
  630. self.object_reference = bpy.data.objects.get(nc.evaluate_input("Name"))
  631. # TODO: maybe I should hold a data reference here, too.
  632. # but it is complicated by the fact that Mantis does not distinguish b/tw geo types
  633. class InputExistingGeometryDataNode(Node, MantisUINode):
  634. """Represents a mesh or curve datablock from the scene."""
  635. bl_idname = "InputExistingGeometryData"
  636. bl_label = "Existing Geometry"
  637. bl_icon = "NODE"
  638. initialized : bpy.props.BoolProperty(default = False)
  639. mantis_node_class_name=bl_idname
  640. def init(self, context):
  641. self.inputs.new("StringSocket", "Name")
  642. self.outputs.new("GeometrySocket", "Geometry")
  643. self.initialized = True
  644. class InputThemeBoneColorSets(Node, MantisUINode):
  645. """Displays the theme's colors."""
  646. bl_idname = "InputThemeBoneColorSets"
  647. bl_label = "Theme Colors"
  648. bl_icon = "NODE"
  649. bl_width_min=280
  650. initialized : bpy.props.BoolProperty(default = False)
  651. mantis_node_class_name=bl_idname
  652. def init(self, context):
  653. for i in range(20):
  654. s = self.outputs.new("ColorSetDisplaySocket", f"Color {str(i).zfill(2)}")
  655. s.color_index=i
  656. self.initialized = True
  657. def socket_data_from_collection_paths(root_data, root_name, path, socket_data):
  658. # so we need to 'push' the socket names and their paths in order
  659. # socket_data is a list of tuples of ( name, path, )
  660. for key, value in root_data.items():
  661. path.append(key)
  662. socket_data.append( (key, path))
  663. if hasattr(value , 'items'):
  664. socket_data = socket_data_from_collection_paths(value, key, path.copy(), socket_data)
  665. path.pop()
  666. return socket_data
  667. class UtilityDeclareCollections(Node, MantisUINode):
  668. """A utility used to declare bone collections."""
  669. bl_idname = "UtilityDeclareCollections"
  670. bl_label = "Collections"
  671. bl_icon = "NODE"
  672. bl_width_min = 320
  673. initialized : bpy.props.BoolProperty(default = False)
  674. mantis_node_class_name=bl_idname
  675. # Here is the layout of the data:
  676. # nested dicts of key:dict ( key = name, dict = children)
  677. # the 'leaf nodes' are empty dicts
  678. # we'll store it as a JSON string in order to make it a bpy.props
  679. # and still have the ability to use it as a dict and save it
  680. # TODO: check and see if these strings have a character limit
  681. collection_declarations : bpy.props.StringProperty(default="")
  682. def update_interface(self):
  683. from .utilities import get_socket_maps, do_relink
  684. # we need to do dynamic stuff here like with interfaces
  685. socket_map_out = get_socket_maps(self)[1]
  686. self.outputs.clear()
  687. current_data = self.read_declarations_from_json()
  688. socket_data = socket_data_from_collection_paths(current_data, self.name, [], [])
  689. for item in socket_data:
  690. full_path_name = '>'.join(item[1]+[item[0]])
  691. s = self.outputs.new('CollectionDeclarationSocket', name=item[0],identifier=full_path_name )
  692. s.collection_path = full_path_name
  693. for s in self.outputs:
  694. if s.identifier in socket_map_out.keys():
  695. do_relink(self, s, socket_map_out, 'OUTPUT')
  696. def init(self, context):
  697. self.initialized = True
  698. if self.collection_declarations == "":
  699. self.push_declarations_to_json({})
  700. def push_declarations_to_json(self, dict):
  701. import json
  702. j_str = json.dumps(dict)
  703. self.collection_declarations = j_str
  704. def read_declarations_from_json(self):
  705. import json
  706. j_data = json.loads(self.collection_declarations)
  707. return j_data
  708. def draw_buttons(self, context, layout):
  709. op_props = layout.operator('mantis.collection_add_new')
  710. op_props.socket_invoked = '' # this isn't reset between invocations
  711. # so we have to make sure to unset it when running it from the node
  712. class UtilityCollectionJoin(Node, MantisUINode):
  713. """A utility used to join bone collection declarations."""
  714. bl_idname = "UtilityCollectionJoin"
  715. bl_label = "Join Collection Declarations"
  716. bl_icon = "NODE"
  717. initialized : bpy.props.BoolProperty(default = False)
  718. mantis_node_class_name=bl_idname
  719. def init(self, context):
  720. self.init_sockets(CollectionJoinSockets)
  721. self.initialized = True
  722. class UtilityCollectionHierarchy(Node, MantisUINode):
  723. """A utility used to declare bone collection hierarchies."""
  724. bl_idname = "UtilityCollectionHierarchy"
  725. bl_label = "Collection Child Declaration"
  726. bl_icon = "NODE"
  727. initialized : bpy.props.BoolProperty(default = False)
  728. mantis_node_class_name=bl_idname
  729. def init(self, context):
  730. self.init_sockets(CollectionHierarchySockets)
  731. self.initialized = True
  732. class UtilityGeometryOfXForm(Node, MantisUINode):
  733. """Retrieves a mesh or curve datablock from an xForm."""
  734. bl_idname = "UtilityGeometryOfXForm"
  735. bl_label = "Geometry of xForm"
  736. bl_icon = "NODE"
  737. initialized : bpy.props.BoolProperty(default = False)
  738. mantis_node_class_name=bl_idname
  739. def init(self, context):
  740. self.inputs.new("xFormSocket", "xForm")
  741. self.outputs.new("GeometrySocket", "Geometry")
  742. self.initialized = True
  743. class UtilityNameOfXForm(Node, MantisUINode):
  744. """Retrieves the name of a xForm."""
  745. bl_idname = "UtilityNameOfXForm"
  746. bl_label = "Name of xForm"
  747. bl_icon = "NODE"
  748. initialized : bpy.props.BoolProperty(default = False)
  749. mantis_node_class_name=bl_idname
  750. def init(self, context):
  751. self.inputs.new("xFormSocket", "xForm")
  752. self.outputs.new("StringSocket", "Name")
  753. self.initialized = True
  754. class UtilityGetBoneLength(Node, MantisUINode):
  755. """Returns the length of the bone from its matrix."""
  756. bl_idname = "UtilityGetBoneLength"
  757. bl_label = "Get Bone Length"
  758. bl_icon = "NODE"
  759. initialized : bpy.props.BoolProperty(default = False)
  760. mantis_node_class_name=bl_idname
  761. def init(self, context):
  762. self.inputs.new("MatrixSocket", "Bone Matrix")
  763. self.outputs.new("FloatSocket", "Bone Length")
  764. self.initialized = True
  765. # TODO: make it work with BBones!
  766. class UtilityPointFromBoneMatrix(Node, MantisUINode):
  767. """Returns a point representing the location along a bone, given a matrix representing that bone's shape."""
  768. bl_idname = "UtilityPointFromBoneMatrix"
  769. bl_label = "Point from Bone Matrix"
  770. bl_icon = "NODE"
  771. initialized : bpy.props.BoolProperty(default = False)
  772. mantis_node_class_name=bl_idname
  773. def init(self, context):
  774. self.inputs.new("MatrixSocket", "Bone Matrix")
  775. self.inputs.new("FloatFactorSocket", "Head/Tail")
  776. self.outputs.new("VectorSocket", "Point")
  777. self.initialized = True
  778. class UtilitySetBoneLength(Node, MantisUINode):
  779. """Sets the length of a bone matrix."""
  780. bl_idname = "UtilitySetBoneLength"
  781. bl_label = "Set Bone Matrix Length"
  782. bl_icon = "NODE"
  783. initialized : bpy.props.BoolProperty(default = False)
  784. mantis_node_class_name=bl_idname
  785. def init(self, context):
  786. self.inputs.new("MatrixSocket", "Bone Matrix")
  787. self.inputs.new("FloatSocket", "Length")
  788. self.outputs.new("MatrixSocket", "Bone Matrix")
  789. self.initialized = True
  790. # TODO: more keyframe types should be supported in the future.
  791. # Some of the code that can do this is commented out here until I can implement it properly.
  792. class UtilityKeyframe(Node, MantisUINode):
  793. """A keyframe for a FCurve"""
  794. bl_idname = "UtilityKeyframe"
  795. bl_label = "KeyFrame"
  796. bl_icon = "NODE"
  797. initialized : bpy.props.BoolProperty(default = False)
  798. mantis_node_class_name=bl_idname
  799. def init(self, context):
  800. # x and y
  801. # output is keyframe
  802. # self.inputs.new("EnumKeyframeInterpolationTypeSocket", "Interpolation")
  803. # self.inputs.new("EnumKeyframeBezierHandleType", "Left Handle Type")
  804. # self.inputs.new("EnumKeyframeBezierHandleType", "Right Handle Type")
  805. # self.inputs.new("FloatSocket", "Left Handle Distance")
  806. # self.inputs.new("FloatSocket", "Left Handle Value")
  807. # self.inputs.new("FloatSocket", "Right Handle Frame")
  808. # self.inputs.new("FloatSocket", "Right Handle Value")
  809. self.inputs.new("FloatSocket", "Frame")
  810. self.inputs.new("FloatSocket", "Value")
  811. self.outputs.new("KeyframeSocket", "Keyframe")
  812. # there will eventually be inputs for e.g. key type, key handles, etc.
  813. # right now I am gonna hardcode LINEAR keyframes so I don't have to deal with anything else
  814. # TODO TODO TODO
  815. # def display_update(self, parsed_tree, context):
  816. # if context.space_data:
  817. # nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  818. # if nc.evaluate_input("Interpolation") in ["CONSTANT", "LINEAR"]:
  819. # for inp in self.inputs[1:6]:
  820. # inp.hide = True
  821. # else:
  822. # if nc.evaluate_input("Left Handle Type") in ["FREE", "ALIGNED"]:
  823. # for inp in self.inputs[1:6]:
  824. # inp.hide = False
  825. self.initialized = True
  826. class UtilityBoneMatrixHeadTailFlip(Node, MantisUINode):
  827. """Flips a bone matrix so that the head is where the tail was and visa versa."""
  828. bl_idname = "UtilityBoneMatrixHeadTailFlip"
  829. bl_label = "Flip Head/Tail"
  830. bl_icon = "NODE"
  831. initialized : bpy.props.BoolProperty(default = False)
  832. mantis_node_class_name=bl_idname
  833. def init(self, context):
  834. self.inputs.new("MatrixSocket", "Bone Matrix")
  835. self.outputs.new("MatrixSocket", "Bone Matrix")
  836. self.initialized = True
  837. class UtilityMatrixTransform(Node, MantisUINode):
  838. """Transforms a matrix by another."""
  839. bl_idname = "UtilityMatrixTransform"
  840. bl_label = "Multiply Matrices"
  841. bl_icon = "NODE"
  842. initialized : bpy.props.BoolProperty(default = False)
  843. mantis_node_class_name=bl_idname
  844. def init(self, context):
  845. self.inputs.new("MatrixSocket", "Matrix 1")
  846. self.inputs.new("MatrixSocket", "Matrix 2")
  847. self.outputs.new("MatrixSocket", "Out Matrix")
  848. self.initialized = True
  849. class UtilityMatrixInvert(Node, MantisUINode):
  850. """Inverts an invertable matrix, otherwise throws an error."""
  851. bl_idname = "UtilityMatrixInvert"
  852. bl_label = "Invert Matrix"
  853. bl_icon = "NODE"
  854. initialized : bpy.props.BoolProperty(default = False)
  855. mantis_node_class_name=bl_idname
  856. def init(self, context):
  857. self.init_sockets(MatrixInvertSockets)
  858. self.initialized = True
  859. class UtilityMatrixCompose(Node, MantisUINode):
  860. """Inverts an invertable matrix, otherwise throws an error."""
  861. bl_idname = "UtilityMatrixCompose"
  862. bl_label = "Compose Matrix"
  863. bl_icon = "NODE"
  864. initialized : bpy.props.BoolProperty(default = False)
  865. mantis_node_class_name=bl_idname
  866. def init(self, context):
  867. self.init_sockets(MatrixComposeSockets)
  868. self.initialized = True
  869. class UtilityMatrixAlignRoll(Node, MantisUINode):
  870. """Aligns the Z axis of a matrix to point in a direction."""
  871. bl_idname = "UtilityMatrixAlignRoll"
  872. bl_label = "Align Matrix Roll"
  873. bl_icon = "NODE"
  874. initialized : bpy.props.BoolProperty(default = False)
  875. mantis_node_class_name=bl_idname
  876. def init(self, context):
  877. self.init_sockets(MatrixAlignRollSockets)
  878. self.initialized = True
  879. class UtilityMatrixSetLocation(Node, MantisUINode):
  880. """Sets a matrix's location."""
  881. bl_idname = "UtilityMatrixSetLocation"
  882. bl_label = "Set Matrix Location"
  883. bl_icon = "NODE"
  884. initialized : bpy.props.BoolProperty(default = False)
  885. mantis_node_class_name=bl_idname
  886. def init(self, context):
  887. self.inputs.new("MatrixSocket", "Matrix")
  888. self.inputs.new("VectorSocket", "Location")
  889. self.outputs.new("MatrixSocket", "Matrix")
  890. self.initialized = True
  891. class UtilityMatrixGetLocation(Node, MantisUINode):
  892. """Gets a matrix's location."""
  893. bl_idname = "UtilityMatrixGetLocation"
  894. bl_label = "Get Matrix Location"
  895. bl_icon = "NODE"
  896. initialized : bpy.props.BoolProperty(default = False)
  897. mantis_node_class_name=bl_idname
  898. def init(self, context):
  899. self.inputs.new("MatrixSocket", "Matrix")
  900. self.outputs.new("VectorSocket", "Location")
  901. self.initialized = True
  902. class UtilityTransformationMatrix(Node, MantisUINode):
  903. """Constructs a matrix representing a transformation"""
  904. bl_idname = "UtilityTransformationMatrix"
  905. bl_label = "Transformation Matrix"
  906. bl_icon = "NODE"
  907. initialized : bpy.props.BoolProperty(default = False)
  908. mantis_node_class_name=bl_idname
  909. def init(self, context):
  910. # first input is a transformation type - translation, rotation, or scale
  911. # rotation is an especially annoying feature because it can take multiple types
  912. # so Euler, axis/angle, quaternion, matrix...
  913. # for now I am only going to implement axis-angle
  914. # it should get an axis and a magnitude
  915. # self.inputs.new("MatrixSocket", "Bone Matrix")
  916. self.inputs.new("MatrixTransformOperation", "Operation")
  917. self.inputs.new("VectorSocket", "Vector")
  918. self.inputs.new("FloatSocket", "W")
  919. self.outputs.new("MatrixSocket", "Matrix")
  920. self.initialized = True
  921. def display_update(self, parsed_tree, context):
  922. operation = self.inputs['Operation'].default_value
  923. if self.inputs['Operation'].is_linked:
  924. if context.space_data:
  925. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  926. operation = nc.evaluate_input("Operation")
  927. if operation in ["ROTATE_AXIS_ANGLE", "SCALE"]:
  928. self.inputs["Vector"].hide = False
  929. self.inputs["W"].hide = False
  930. if operation in ["TRANSLATE"]:
  931. self.inputs["Vector"].hide = False
  932. self.inputs["W"].hide = True
  933. # Blender calculates bone roll this way...
  934. # https://projects.blender.org/blender/blender/src/commit/dd209221675ac7b62ce47b7ea42f15cbe34a6035/source/blender/editors/armature/armature_edit.cc#L281
  935. # but this looks like it will be harder to re-implement than to re-use. Unfortunately, it doesn't apply directly to a matrix so I have to call a method
  936. # in the edit bone.
  937. # So instead, we need to avoid calculating the roll for now.
  938. # but I want to make that its own node and add roll-recalc to this node, too.
  939. class UtilitySetBoneMatrixTail(Node, MantisUINode):
  940. """Constructs a matrix representing a transformation"""
  941. bl_idname = "UtilitySetBoneMatrixTail"
  942. bl_label = "Set Bone Matrix Tail"
  943. bl_icon = "NODE"
  944. initialized : bpy.props.BoolProperty(default = False)
  945. mantis_node_class_name=bl_idname
  946. def init(self, context):
  947. self.inputs.new("MatrixSocket", "Matrix")
  948. self.inputs.new("VectorSocket", "Tail Location")
  949. self.outputs.new("MatrixSocket", "Result")
  950. self.initialized = True
  951. class UtilityMatrixFromXForm(Node, MantisUINode):
  952. """Returns the matrix of the given xForm node."""
  953. bl_idname = "UtilityMatrixFromXForm"
  954. bl_label = "Matrix of xForm"
  955. bl_icon = "NODE"
  956. initialized : bpy.props.BoolProperty(default = False)
  957. mantis_node_class_name=bl_idname
  958. def init(self, context):
  959. self.inputs.new("xFormSocket", "xForm")
  960. self.outputs.new("MatrixSocket", "Matrix")
  961. self.initialized = True
  962. class UtilityAxesFromMatrix(Node, MantisUINode):
  963. """Returns the axes of the matrix."""
  964. bl_idname = "UtilityAxesFromMatrix"
  965. bl_label = "Axes of Matrix"
  966. bl_icon = "NODE"
  967. initialized : bpy.props.BoolProperty(default = False)
  968. mantis_node_class_name=bl_idname
  969. def init(self, context):
  970. self.inputs.new("MatrixSocket", "Matrix")
  971. self.outputs.new("VectorSocket", "X Axis")
  972. self.outputs.new("VectorSocket", "Y Axis")
  973. self.outputs.new("VectorSocket", "Z Axis")
  974. self.initialized = True
  975. class UtilityIntToString(Node, MantisUINode):
  976. """Converts a number to a string"""
  977. bl_idname = "UtilityIntToString"
  978. bl_label = "Number String"
  979. bl_icon = "NODE"
  980. initialized : bpy.props.BoolProperty(default = False)
  981. mantis_node_class_name=bl_idname
  982. def init(self, context):
  983. self.inputs.new("IntSocket", "Number")
  984. self.inputs.new("IntSocket", "Zero Padding")
  985. self.outputs.new("StringSocket", "String")
  986. self.initialized = True
  987. class UtilityArrayGet(Node, MantisUINode):
  988. """Gets a value from an array at a specified index."""
  989. bl_idname = "UtilityArrayGet"
  990. bl_label = "Array Get"
  991. bl_icon = "NODE"
  992. initialized : bpy.props.BoolProperty(default = False)
  993. mantis_node_class_name=bl_idname
  994. def init(self, context):
  995. self.inputs.new('EnumArrayGetOptions', 'OoB Behaviour')
  996. self.inputs.new("IntSocket", "Index")
  997. s = self.inputs.new("WildcardSocket", "Array", use_multi_input=True)
  998. s.display_shape = 'SQUARE_DOT'
  999. self.outputs.new("WildcardSocket", "Output")
  1000. self.initialized = True
  1001. def update(self):
  1002. wildcard_color = (0.0,0.0,0.0,0.0)
  1003. if self.inputs['Array'].is_linked == False:
  1004. self.inputs['Array'].color = wildcard_color
  1005. self.outputs['Output'].color = wildcard_color
  1006. def insert_link(self, link):
  1007. super().insert_link(link)
  1008. if link.to_socket.identifier == self.inputs['Array'].identifier:
  1009. from_socket = link.from_socket
  1010. if hasattr(from_socket, "color"):
  1011. self.inputs['Array'].color = from_socket.color
  1012. self.outputs['Output'].color = from_socket.color
  1013. class UtilityArrayLength(Node, MantisUINode):
  1014. """Gets The length of an array."""
  1015. bl_idname = "UtilityArrayLength"
  1016. bl_label = "Array Length"
  1017. bl_icon = "NODE"
  1018. initialized : bpy.props.BoolProperty(default = False)
  1019. mantis_node_class_name=bl_idname
  1020. def init(self, context):
  1021. s = self.inputs.new("WildcardSocket", "Array", use_multi_input=True)
  1022. s.display_shape = 'SQUARE_DOT'
  1023. self.outputs.new("UnsignedIntSocket", "Length")
  1024. self.initialized = True
  1025. def update(self):
  1026. wildcard_color = (0.0,0.0,0.0,0.0)
  1027. if self.inputs['Array'].is_linked == False:
  1028. self.inputs['Array'].color = wildcard_color
  1029. def insert_link(self, link):
  1030. super().insert_link(link)
  1031. if link.to_socket.identifier == self.inputs['Array'].identifier:
  1032. from_socket = link.from_socket
  1033. if hasattr(from_socket, "color"):
  1034. self.inputs['Array'].color = from_socket.color
  1035. class UtilityCompare(Node, MantisUINode):
  1036. """Compares two inputs and produces a boolean output"""
  1037. bl_idname = "UtilityCompare"
  1038. bl_label = "Compare"
  1039. bl_icon = "NODE"
  1040. initialized : bpy.props.BoolProperty(default = False)
  1041. mantis_node_class_name=bl_idname
  1042. def init(self, context):
  1043. self.init_sockets(CompareSockets)
  1044. self.initialized = True
  1045. def update(self):
  1046. wildcard_color = (0.0,0.0,0.0,0.0)
  1047. if self.inputs['A'].is_linked == False:
  1048. self.inputs['A'].color = wildcard_color
  1049. if self.inputs['B'].is_linked == False:
  1050. self.inputs['B'].color = wildcard_color
  1051. def insert_link(self, link):
  1052. super().insert_link(link)
  1053. if link.to_socket.identifier == self.inputs['A'].identifier:
  1054. self.inputs['A'].color = link.from_socket.color_simple
  1055. if hasattr(link.from_socket, "color"):
  1056. self.inputs['A'].color = link.from_socket.color
  1057. if link.to_socket.identifier == self.inputs['B'].identifier:
  1058. self.inputs['B'].color = link.from_socket.color_simple
  1059. if hasattr(link.from_socket, "color"):
  1060. self.inputs['B'].color = link.from_socket.color
  1061. class UtilityChoose(Node, MantisUINode):
  1062. """Chooses an output"""
  1063. bl_idname = "UtilityChoose"
  1064. bl_label = "Choose"
  1065. bl_icon = "NODE"
  1066. initialized : bpy.props.BoolProperty(default = False)
  1067. mantis_node_class_name=bl_idname
  1068. def init(self, context):
  1069. self.inputs.new("BooleanSocket", "Condition")
  1070. self.inputs.new("WildcardSocket", "A")
  1071. self.inputs.new("WildcardSocket", "B")
  1072. self.outputs.new("WildcardSocket", "Result")
  1073. self.initialized = True
  1074. def display_update(self, parsed_tree, context):
  1075. wildcard_color = (0.0,0.0,0.0,0.0)
  1076. if not self.inputs['A'].is_linked:
  1077. self.inputs['A'].color = wildcard_color
  1078. if not self.inputs['B'].is_linked:
  1079. self.inputs['B'].color = wildcard_color
  1080. self.outputs['Result'].color = wildcard_color
  1081. # if both inputs are the same color, then use that color for the result
  1082. if self.inputs['Condition'].is_linked:
  1083. from .base_definitions import get_signature_from_edited_tree
  1084. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  1085. if nc:
  1086. condition = nc.evaluate_input('Condition')
  1087. else:
  1088. condition = self.inputs['Condition'].default_value
  1089. if condition == True:
  1090. self.outputs['Result'].color = self.inputs['B'].color
  1091. else:
  1092. self.outputs['Result'].color = self.inputs['A'].color
  1093. def insert_link(self, link):
  1094. super().insert_link(link)
  1095. if link.to_socket.identifier == self.inputs['A'].identifier:
  1096. self.inputs['A'].color = link.from_socket.color_simple
  1097. if hasattr(link.from_socket, "color"):
  1098. self.inputs['A'].color = link.from_socket.color
  1099. if link.to_socket.identifier == self.inputs['B'].identifier:
  1100. self.inputs['B'].color = link.from_socket.color_simple
  1101. if hasattr(link.from_socket, "color"):
  1102. self.inputs['B'].color = link.from_socket.color
  1103. class UtilityPrint(Node, MantisUINode):
  1104. """A utility used to print arbitrary values."""
  1105. bl_idname = "UtilityPrint"
  1106. bl_label = "Print"
  1107. bl_icon = "NODE"
  1108. initialized : bpy.props.BoolProperty(default = False)
  1109. mantis_node_class_name=bl_idname
  1110. def init(self, context):
  1111. self.inputs.new("WildcardSocket", "Input")
  1112. self.initialized = True
  1113. # Set up the class property that ties the UI classes to the Mantis classes.
  1114. for cls in TellClasses():
  1115. cls.mantis_node_library='.misc_nodes'
  1116. cls.set_mantis_class()