misc_nodes_ui.py 50 KB

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