misc_nodes_ui.py 50 KB

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