misc_nodes_ui.py 53 KB

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