misc_nodes_ui.py 45 KB

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