misc_nodes_ui.py 51 KB

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