misc_nodes_ui.py 45 KB

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