misc_nodes_ui.py 45 KB

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