misc_nodes_ui.py 46 KB

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