misc_nodes_ui.py 45 KB

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