misc_nodes_ui.py 48 KB

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