misc_nodes_ui.py 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  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. UtilityMatrixInvert,
  57. UtilityMatrixCompose,
  58. UtilityTransformationMatrix,
  59. UtilitySetBoneMatrixTail,
  60. UtilityIntToString,
  61. UtilityArrayGet,
  62. UtilityArrayLength,
  63. #
  64. UtilityCompare,
  65. UtilityChoose,
  66. # for testing
  67. UtilityPrint,
  68. ]
  69. def default_traverse(self,socket):
  70. return None
  71. class InputFloatNode(Node, MantisUINode):
  72. '''A node representing inheritance'''
  73. bl_idname = 'InputFloatNode'
  74. bl_label = "Float"
  75. bl_icon = 'NODE'
  76. initialized : bpy.props.BoolProperty(default = False)
  77. mantis_node_class_name=bl_idname[:-4]
  78. def init(self, context):
  79. self.outputs.new('FloatSocket', "Float Input").input = True
  80. self.initialized = True
  81. class InputIntNode(Node, MantisUINode):
  82. '''A node representing inheritance'''
  83. bl_idname = 'InputIntNode'
  84. bl_label = "Integer"
  85. bl_icon = 'NODE'
  86. initialized : bpy.props.BoolProperty(default = False)
  87. mantis_node_class_name=bl_idname
  88. def init(self, context):
  89. self.outputs.new('IntSocket', "Integer").input = True
  90. self.initialized = True
  91. class InputVectorNode(Node, MantisUINode):
  92. '''A node representing inheritance'''
  93. bl_idname = 'InputVectorNode'
  94. bl_label = "Vector"
  95. bl_icon = 'NODE'
  96. initialized : bpy.props.BoolProperty(default = False)
  97. mantis_node_class_name=bl_idname[:-4]
  98. def init(self, context):
  99. self.outputs.new('VectorSocket', "").input = True
  100. self.initialized = True
  101. class InputBooleanNode(Node, MantisUINode):
  102. '''A node representing inheritance'''
  103. bl_idname = 'InputBooleanNode'
  104. bl_label = "Boolean"
  105. bl_icon = 'NODE'
  106. initialized : bpy.props.BoolProperty(default = False)
  107. mantis_node_class_name=bl_idname[:-4]
  108. def init(self, context):
  109. self.outputs.new('BooleanSocket', "").input = True
  110. self.initialized = True
  111. class InputBooleanThreeTupleNode(Node, MantisUINode):
  112. '''A node representing inheritance'''
  113. bl_idname = 'InputBooleanThreeTupleNode'
  114. bl_label = "Boolean Vector"
  115. bl_icon = 'NODE'
  116. initialized : bpy.props.BoolProperty(default = False)
  117. mantis_node_class_name=bl_idname[:-4]
  118. def init(self, context):
  119. self.outputs.new('BooleanThreeTupleSocket', "")
  120. self.initialized = True
  121. class InputRotationOrderNode(Node, MantisUINode):
  122. '''A node representing inheritance'''
  123. bl_idname = 'InputRotationOrderNode'
  124. bl_label = "Rotation Order"
  125. bl_icon = 'NODE'
  126. initialized : bpy.props.BoolProperty(default = False)
  127. mantis_node_class_name=bl_idname[:-4]
  128. def init(self, context):
  129. self.outputs.new('RotationOrderSocket', "").input = True
  130. self.initialized = True
  131. class InputTransformSpaceNode(Node, MantisUINode):
  132. '''A node representing inheritance'''
  133. bl_idname = 'InputTransformSpaceNode'
  134. bl_label = "Transform Space"
  135. bl_icon = 'NODE'
  136. initialized : bpy.props.BoolProperty(default = False)
  137. mantis_node_class_name=bl_idname[:-4]
  138. def init(self, context):
  139. self.outputs.new('TransformSpaceSocket', "").input = True
  140. self.initialized = True
  141. class InputStringNode(Node, MantisUINode):
  142. '''A node representing inheritance'''
  143. bl_idname = 'InputStringNode'
  144. bl_label = "String"
  145. bl_icon = 'NODE'
  146. initialized : bpy.props.BoolProperty(default = False)
  147. mantis_node_class_name=bl_idname[:-4]
  148. def init(self, context):
  149. self.outputs.new('StringSocket', "").input = True
  150. self.initialized = True
  151. class InputMatrixNode(Node, MantisUINode):
  152. '''A node representing inheritance'''
  153. bl_idname = 'InputMatrixNode'
  154. bl_label = "Matrix"
  155. bl_icon = 'NODE'
  156. first_row : bpy.props.FloatVectorProperty(name="", size=4, default = (1.0, 0.0, 0.0, 0.0,))
  157. second_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 1.0, 0.0, 0.0,))
  158. third_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 1.0, 0.0,))
  159. fourth_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 0.0, 1.0,))
  160. initialized : bpy.props.BoolProperty(default = False)
  161. mantis_node_class_name=bl_idname[:-4]
  162. def set_matrix(self):
  163. return (self.first_row[ 0], self.first_row[ 1], self.first_row[ 2], self.first_row[ 3],
  164. self.second_row[0], self.second_row[1], self.second_row[2], self.second_row[3],
  165. self.third_row[ 0], self.third_row[ 1], self.third_row[ 2], self.third_row[ 3],
  166. self.fourth_row[0], self.fourth_row[1], self.fourth_row[2], self.fourth_row[3],)
  167. def init(self, context):
  168. self.outputs.new('MatrixSocket', "Matrix")
  169. self.initialized = True
  170. def draw_buttons(self, context, layout):
  171. # return
  172. layout.prop(self, "first_row")
  173. layout.prop(self, "second_row")
  174. layout.prop(self, "third_row")
  175. layout.prop(self, "fourth_row")
  176. def update(self):
  177. mat_sock = self.outputs[0]
  178. mat_sock.default_value = self.set_matrix()
  179. class ScaleBoneLengthNode(Node, MantisUINode):
  180. '''Scale Bone Length'''
  181. bl_idname = 'ScaleBoneLength'
  182. bl_label = "Scale Bone Length"
  183. bl_icon = 'NODE'
  184. initialized : bpy.props.BoolProperty(default = False)
  185. # === Optional Functions ===
  186. def init(self, context):
  187. self.inputs.new('MatrixSocket', "In Matrix")
  188. self.inputs.new('FloatSocket', "Factor")
  189. self.outputs.new('MatrixSocket', "Out Matrix")
  190. self.initialized = True
  191. class MetaRigMatrixNode(Node, MantisUINode):
  192. # Identical to the above, except
  193. '''A node representing a bone's matrix'''
  194. bl_idname = 'MetaRigMatrixNode'
  195. bl_label = "Matrix"
  196. bl_icon = 'NODE'
  197. first_row : bpy.props.FloatVectorProperty(name="", size=4, default = (1.0, 0.0, 0.0, 0.0,))
  198. second_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 1.0, 0.0, 0.0,))
  199. third_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 1.0, 0.0,))
  200. fourth_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 0.0, 1.0,))
  201. initialized : bpy.props.BoolProperty(default = False)
  202. mantis_node_class_name="UtilityMetaRig"
  203. def set_matrix(self):
  204. return (self.first_row[ 0], self.first_row[ 1], self.first_row[ 2], self.first_row[ 3],
  205. self.second_row[0], self.second_row[1], self.second_row[2], self.second_row[3],
  206. self.third_row[ 0], self.third_row[ 1], self.third_row[ 2], self.third_row[ 3],
  207. self.fourth_row[0], self.fourth_row[1], self.fourth_row[2], self.fourth_row[3],)
  208. def init(self, context):
  209. self.outputs.new('MatrixSocket', "Matrix")
  210. self.initialized = True
  211. def update(self):
  212. mat_sock = self.outputs[0]
  213. mat_sock.default_value = self.set_matrix()
  214. class UtilityMatrixFromCurve(Node, MantisUINode):
  215. """Gets a matrix from a curve."""
  216. bl_idname = "UtilityMatrixFromCurve"
  217. bl_label = "Matrix from Curve"
  218. bl_icon = "NODE"
  219. initialized : bpy.props.BoolProperty(default = False)
  220. mantis_node_class_name=bl_idname
  221. def init(self, context):
  222. curv = self.inputs.new("EnumCurveSocket", "Curve")
  223. self.inputs.new('IntSocket', 'Total Divisions')
  224. self.inputs.new('IntSocket', 'Matrix Index')
  225. self.outputs.new("MatrixSocket", "Matrix")
  226. self.initialized = True
  227. class UtilityPointFromCurve(Node, MantisUINode):
  228. """Gets a point from a curve."""
  229. bl_idname = "UtilityPointFromCurve"
  230. bl_label = "Point from Curve"
  231. bl_icon = "NODE"
  232. initialized : bpy.props.BoolProperty(default = False)
  233. mantis_node_class_name=bl_idname
  234. def init(self, context):
  235. curv = self.inputs.new("EnumCurveSocket", "Curve")
  236. self.inputs.new('FloatFactorSocket', 'Factor')
  237. self.outputs.new("VectorSocket", "Point")
  238. self.initialized = True
  239. class UtilityNumberOfCurveSegments(Node, MantisUINode):
  240. """Tells the number of segments in a curve."""
  241. bl_idname = "UtilityNumberOfCurveSegments"
  242. bl_label = "Number of Curve Segments"
  243. bl_icon = "NODE"
  244. initialized : bpy.props.BoolProperty(default = False)
  245. mantis_node_class_name=bl_idname
  246. def init(self, context):
  247. self.inputs.new("EnumCurveSocket", "Curve")
  248. self.inputs.new('UnsignedIntSocket', 'Spline Index')
  249. self.outputs.new("UnsignedIntSocket", "Number of Segments")
  250. self.initialized = True
  251. class UtilityMatrixFromCurveSegment(Node, MantisUINode):
  252. """Gets a matrix from a curve segment."""
  253. bl_idname = "UtilityMatrixFromCurveSegment"
  254. bl_label = "Matrix from Curve Segment"
  255. bl_icon = "NODE"
  256. initialized : bpy.props.BoolProperty(default = False)
  257. mantis_node_class_name=bl_idname
  258. def init(self, context):
  259. self.inputs.new("EnumCurveSocket", "Curve")
  260. self.inputs.new('UnsignedIntSocket', 'Spline Index')
  261. self.inputs.new('UnsignedIntSocket', 'Segment Index')
  262. self.outputs.new("MatrixSocket", "Matrix")
  263. self.initialized = True
  264. class UtilityGetCurvePoint(Node, MantisUINode):
  265. bl_idname = 'UtilityGetCurvePoint'
  266. bl_label = "Get Curve Point"
  267. bl_icon = 'NODE'
  268. initialized : bpy.props.BoolProperty(default = False)
  269. mantis_node_class_name=bl_idname
  270. def init(self, context):
  271. self.init_sockets(GetCurvePointSockets)
  272. self.initialized = True
  273. def display_update(self, parsed_tree, context):
  274. self.outputs["Point"].hide=False
  275. self.outputs["Left Handle"].hide=True
  276. self.outputs["Right Handle"].hide=True
  277. spline_index = self.inputs['Spline Index'].default_value
  278. index = self.inputs['Index'].default_value
  279. curve = self.inputs['Curve'].default_value
  280. if self.inputs['Spline Index'].is_linked or self.inputs['Index'].is_linked \
  281. or self.inputs['Curve'].is_linked:
  282. mantis_node = parsed_tree.get(get_signature_from_edited_tree(self, context))
  283. spline_index = mantis_node.evaluate_input("Spline Index")
  284. index = mantis_node.evaluate_input("Index")
  285. curve = mantis_node.evaluate_input("Curve")
  286. if curve := bpy.data.objects.get(curve):
  287. if curve.type != "CURVE":
  288. self.outputs["Point"].hide=True
  289. spline = curve.data.splines[spline_index]
  290. if spline.type == 'BEZIER':
  291. self.outputs["Left Handle"].hide=False
  292. self.outputs["Right Handle"].hide=False
  293. class UtilityMatricesFromCurve(Node, MantisUINode):
  294. """Gets a matrix from a curve."""
  295. bl_idname = "UtilityMatricesFromCurve"
  296. bl_label = "Matrices from Curve"
  297. bl_icon = "NODE"
  298. initialized : bpy.props.BoolProperty(default = False)
  299. mantis_node_class_name=bl_idname
  300. def init(self, context):
  301. curv = self.inputs.new("EnumCurveSocket", "Curve")
  302. curv.icon = "OUTLINER_OB_CURVE"
  303. self.inputs.new('IntSocket', 'Total Divisions')
  304. o = self.outputs.new("MatrixSocket", "Matrices")
  305. o.display_shape = 'SQUARE_DOT'
  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 UtilityMatrixSetLocation(Node, MantisUINode):
  778. """Sets a matrix's location."""
  779. bl_idname = "UtilityMatrixSetLocation"
  780. bl_label = "Set Matrix Location"
  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.inputs.new("MatrixSocket", "Matrix")
  786. self.inputs.new("VectorSocket", "Location")
  787. self.outputs.new("MatrixSocket", "Matrix")
  788. self.initialized = True
  789. class UtilityMatrixGetLocation(Node, MantisUINode):
  790. """Gets a matrix's location."""
  791. bl_idname = "UtilityMatrixGetLocation"
  792. bl_label = "Get Matrix Location"
  793. bl_icon = "NODE"
  794. initialized : bpy.props.BoolProperty(default = False)
  795. mantis_node_class_name=bl_idname
  796. def init(self, context):
  797. self.inputs.new("MatrixSocket", "Matrix")
  798. self.outputs.new("VectorSocket", "Location")
  799. self.initialized = True
  800. class UtilityTransformationMatrix(Node, MantisUINode):
  801. """Constructs a matrix representing a transformation"""
  802. bl_idname = "UtilityTransformationMatrix"
  803. bl_label = "Transformation Matrix"
  804. bl_icon = "NODE"
  805. initialized : bpy.props.BoolProperty(default = False)
  806. mantis_node_class_name=bl_idname
  807. def init(self, context):
  808. # first input is a transformation type - translation, rotation, or scale
  809. # rotation is an especially annoying feature because it can take multiple types
  810. # so Euler, axis/angle, quaternion, matrix...
  811. # for now I am only going to implement axis-angle
  812. # it should get an axis and a magnitude
  813. # self.inputs.new("MatrixSocket", "Bone Matrix")
  814. self.inputs.new("MatrixTransformOperation", "Operation")
  815. self.inputs.new("VectorSocket", "Vector")
  816. self.inputs.new("FloatSocket", "W")
  817. self.outputs.new("MatrixSocket", "Matrix")
  818. self.initialized = True
  819. def display_update(self, parsed_tree, context):
  820. operation = self.inputs['Operation'].default_value
  821. if self.inputs['Operation'].is_linked:
  822. if context.space_data:
  823. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  824. operation = nc.evaluate_input("Operation")
  825. if operation in ["ROTATE_AXIS_ANGLE", "SCALE"]:
  826. self.inputs["Vector"].hide = False
  827. self.inputs["W"].hide = False
  828. if operation in ["TRANSLATE"]:
  829. self.inputs["Vector"].hide = False
  830. self.inputs["W"].hide = True
  831. # Blender calculates bone roll this way...
  832. # https://projects.blender.org/blender/blender/src/commit/dd209221675ac7b62ce47b7ea42f15cbe34a6035/source/blender/editors/armature/armature_edit.cc#L281
  833. # 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
  834. # in the edit bone.
  835. # So instead, we need to avoid calculating the roll for now.
  836. # but I want to make that its own node and add roll-recalc to this node, too.
  837. class UtilitySetBoneMatrixTail(Node, MantisUINode):
  838. """Constructs a matrix representing a transformation"""
  839. bl_idname = "UtilitySetBoneMatrixTail"
  840. bl_label = "Set Bone Matrix Tail"
  841. bl_icon = "NODE"
  842. initialized : bpy.props.BoolProperty(default = False)
  843. mantis_node_class_name=bl_idname
  844. def init(self, context):
  845. self.inputs.new("MatrixSocket", "Matrix")
  846. self.inputs.new("VectorSocket", "Tail Location")
  847. self.outputs.new("MatrixSocket", "Result")
  848. self.initialized = True
  849. class UtilityMatrixFromXForm(Node, MantisUINode):
  850. """Returns the matrix of the given xForm node."""
  851. bl_idname = "UtilityMatrixFromXForm"
  852. bl_label = "Matrix of xForm"
  853. bl_icon = "NODE"
  854. initialized : bpy.props.BoolProperty(default = False)
  855. mantis_node_class_name=bl_idname
  856. def init(self, context):
  857. self.inputs.new("xFormSocket", "xForm")
  858. self.outputs.new("MatrixSocket", "Matrix")
  859. self.initialized = True
  860. class UtilityAxesFromMatrix(Node, MantisUINode):
  861. """Returns the axes of the matrix."""
  862. bl_idname = "UtilityAxesFromMatrix"
  863. bl_label = "Axes of Matrix"
  864. bl_icon = "NODE"
  865. initialized : bpy.props.BoolProperty(default = False)
  866. mantis_node_class_name=bl_idname
  867. def init(self, context):
  868. self.inputs.new("MatrixSocket", "Matrix")
  869. self.outputs.new("VectorSocket", "X Axis")
  870. self.outputs.new("VectorSocket", "Y Axis")
  871. self.outputs.new("VectorSocket", "Z Axis")
  872. self.initialized = True
  873. class UtilityIntToString(Node, MantisUINode):
  874. """Converts a number to a string"""
  875. bl_idname = "UtilityIntToString"
  876. bl_label = "Number String"
  877. bl_icon = "NODE"
  878. initialized : bpy.props.BoolProperty(default = False)
  879. mantis_node_class_name=bl_idname
  880. def init(self, context):
  881. self.inputs.new("IntSocket", "Number")
  882. self.inputs.new("IntSocket", "Zero Padding")
  883. self.outputs.new("StringSocket", "String")
  884. self.initialized = True
  885. class UtilityArrayGet(Node, MantisUINode):
  886. """Gets a value from an array at a specified index."""
  887. bl_idname = "UtilityArrayGet"
  888. bl_label = "Array Get"
  889. bl_icon = "NODE"
  890. initialized : bpy.props.BoolProperty(default = False)
  891. mantis_node_class_name=bl_idname
  892. def init(self, context):
  893. self.inputs.new('EnumArrayGetOptions', 'OoB Behaviour')
  894. self.inputs.new("IntSocket", "Index")
  895. s = self.inputs.new("WildcardSocket", "Array", use_multi_input=True)
  896. s.display_shape = 'SQUARE_DOT'
  897. self.outputs.new("WildcardSocket", "Output")
  898. self.initialized = True
  899. def update(self):
  900. wildcard_color = (0.0,0.0,0.0,0.0)
  901. if self.inputs['Array'].is_linked == False:
  902. self.inputs['Array'].color = wildcard_color
  903. self.outputs['Output'].color = wildcard_color
  904. def insert_link(self, link):
  905. super().insert_link(link)
  906. if link.to_socket.identifier == self.inputs['Array'].identifier:
  907. from_socket = link.from_socket
  908. if hasattr(from_socket, "color"):
  909. self.inputs['Array'].color = from_socket.color
  910. self.outputs['Output'].color = from_socket.color
  911. class UtilityArrayLength(Node, MantisUINode):
  912. """Gets The length of an array."""
  913. bl_idname = "UtilityArrayLength"
  914. bl_label = "Array Length"
  915. bl_icon = "NODE"
  916. initialized : bpy.props.BoolProperty(default = False)
  917. mantis_node_class_name=bl_idname
  918. def init(self, context):
  919. s = self.inputs.new("WildcardSocket", "Array", use_multi_input=True)
  920. s.display_shape = 'SQUARE_DOT'
  921. self.outputs.new("UnsignedIntSocket", "Length")
  922. self.initialized = True
  923. def update(self):
  924. wildcard_color = (0.0,0.0,0.0,0.0)
  925. if self.inputs['Array'].is_linked == False:
  926. self.inputs['Array'].color = wildcard_color
  927. def insert_link(self, link):
  928. super().insert_link(link)
  929. if link.to_socket.identifier == self.inputs['Array'].identifier:
  930. from_socket = link.from_socket
  931. if hasattr(from_socket, "color"):
  932. self.inputs['Array'].color = from_socket.color
  933. class UtilityCompare(Node, MantisUINode):
  934. """Compares two inputs and produces a boolean output"""
  935. bl_idname = "UtilityCompare"
  936. bl_label = "Compare"
  937. bl_icon = "NODE"
  938. initialized : bpy.props.BoolProperty(default = False)
  939. mantis_node_class_name=bl_idname
  940. def init(self, context):
  941. self.init_sockets(CompareSockets)
  942. self.initialized = True
  943. def update(self):
  944. wildcard_color = (0.0,0.0,0.0,0.0)
  945. if self.inputs['A'].is_linked == False:
  946. self.inputs['A'].color = wildcard_color
  947. if self.inputs['B'].is_linked == False:
  948. self.inputs['B'].color = wildcard_color
  949. def insert_link(self, link):
  950. super().insert_link(link)
  951. if link.to_socket.identifier == self.inputs['A'].identifier:
  952. self.inputs['A'].color = link.from_socket.color_simple
  953. if hasattr(link.from_socket, "color"):
  954. self.inputs['A'].color = link.from_socket.color
  955. if link.to_socket.identifier == self.inputs['B'].identifier:
  956. self.inputs['B'].color = link.from_socket.color_simple
  957. if hasattr(link.from_socket, "color"):
  958. self.inputs['B'].color = link.from_socket.color
  959. class UtilityChoose(Node, MantisUINode):
  960. """Chooses an output"""
  961. bl_idname = "UtilityChoose"
  962. bl_label = "Choose"
  963. bl_icon = "NODE"
  964. initialized : bpy.props.BoolProperty(default = False)
  965. mantis_node_class_name=bl_idname
  966. def init(self, context):
  967. self.inputs.new("BooleanSocket", "Condition")
  968. self.inputs.new("WildcardSocket", "A")
  969. self.inputs.new("WildcardSocket", "B")
  970. self.outputs.new("WildcardSocket", "Result")
  971. self.initialized = True
  972. def display_update(self, parsed_tree, context):
  973. wildcard_color = (0.0,0.0,0.0,0.0)
  974. if not self.inputs['A'].is_linked:
  975. self.inputs['A'].color = wildcard_color
  976. if not self.inputs['B'].is_linked:
  977. self.inputs['B'].color = wildcard_color
  978. self.outputs['Result'].color = wildcard_color
  979. # if both inputs are the same color, then use that color for the result
  980. if self.inputs['Condition'].is_linked:
  981. from .base_definitions import get_signature_from_edited_tree
  982. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  983. if nc:
  984. condition = nc.evaluate_input('Condition')
  985. else:
  986. condition = self.inputs['Condition'].default_value
  987. if condition == True:
  988. self.outputs['Result'].color = self.inputs['B'].color
  989. else:
  990. self.outputs['Result'].color = self.inputs['A'].color
  991. def insert_link(self, link):
  992. super().insert_link(link)
  993. if link.to_socket.identifier == self.inputs['A'].identifier:
  994. self.inputs['A'].color = link.from_socket.color_simple
  995. if hasattr(link.from_socket, "color"):
  996. self.inputs['A'].color = link.from_socket.color
  997. if link.to_socket.identifier == self.inputs['B'].identifier:
  998. self.inputs['B'].color = link.from_socket.color_simple
  999. if hasattr(link.from_socket, "color"):
  1000. self.inputs['B'].color = link.from_socket.color
  1001. class UtilityPrint(Node, MantisUINode):
  1002. """A utility used to print arbitrary values."""
  1003. bl_idname = "UtilityPrint"
  1004. bl_label = "Print"
  1005. bl_icon = "NODE"
  1006. initialized : bpy.props.BoolProperty(default = False)
  1007. mantis_node_class_name=bl_idname
  1008. def init(self, context):
  1009. self.inputs.new("WildcardSocket", "Input")
  1010. self.initialized = True
  1011. # Set up the class property that ties the UI classes to the Mantis classes.
  1012. for cls in TellClasses():
  1013. cls.mantis_node_library='.misc_nodes'
  1014. cls.set_mantis_class()