misc_nodes_ui.py 51 KB

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