misc_nodes_ui.py 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. import bpy
  2. from bpy.types import Node
  3. from .base_definitions import MantisUINode
  4. from .utilities import (prRed, prGreen, prPurple, prWhite,
  5. prOrange,
  6. wrapRed, wrapGreen, wrapPurple, wrapWhite,
  7. wrapOrange,)
  8. def TellClasses():
  9. return [ InputFloatNode,
  10. InputIntNode,
  11. InputVectorNode,
  12. InputBooleanNode,
  13. InputBooleanThreeTupleNode,
  14. InputRotationOrderNode,
  15. InputTransformSpaceNode,
  16. InputStringNode,
  17. InputMatrixNode,
  18. # InputGeometryNode,
  19. InputExistingGeometryObjectNode,
  20. InputExistingGeometryDataNode,
  21. UtilityGeometryOfXForm,
  22. UtilityNameOfXForm,
  23. # ComposeMatrixNode,
  24. MetaRigMatrixNode,
  25. UtilityMatrixFromCurve,
  26. UtilityPointFromCurve,
  27. UtilityMatricesFromCurve,
  28. # ScaleBoneLengthNode,
  29. UtilityMetaRigNode,
  30. UtilityBonePropertiesNode,
  31. UtilityDriverVariableNode,
  32. UtilityFCurveNode,
  33. UtilityDriverNode,
  34. UtilitySwitchNode,
  35. UtilityKeyframe,
  36. UtilityCombineThreeBoolNode,
  37. UtilityCombineVectorNode,
  38. UtilitySeparateVector,
  39. UtilityCatStringsNode,
  40. UtilityGetBoneLength,
  41. UtilityPointFromBoneMatrix,
  42. UtilitySetBoneLength,
  43. UtilityMatrixSetLocation,
  44. UtilityMatrixGetLocation,
  45. UtilityMatrixFromXForm,
  46. UtilityAxesFromMatrix,
  47. UtilityBoneMatrixHeadTailFlip,
  48. UtilityMatrixTransform,
  49. UtilityTransformationMatrix,
  50. UtilitySetBoneMatrixTail,
  51. UtilityIntToString,
  52. UtilityArrayGet,
  53. #
  54. UtilityCompare,
  55. UtilityChoose,
  56. # for testing
  57. UtilityPrint,
  58. ]
  59. def default_traverse(self,socket):
  60. return None
  61. class InputFloatNode(Node, MantisUINode):
  62. '''A node representing inheritance'''
  63. bl_idname = 'InputFloatNode'
  64. bl_label = "Float"
  65. bl_icon = 'NODE'
  66. initialized : bpy.props.BoolProperty(default = False)
  67. mantis_node_class_name=bl_idname[:-4]
  68. def init(self, context):
  69. self.outputs.new('FloatSocket', "Float Input").input = True
  70. self.initialized = True
  71. class InputIntNode(Node, MantisUINode):
  72. '''A node representing inheritance'''
  73. bl_idname = 'InputIntNode'
  74. bl_label = "Integer"
  75. bl_icon = 'NODE'
  76. initialized : bpy.props.BoolProperty(default = False)
  77. mantis_node_class_name=bl_idname
  78. def init(self, context):
  79. self.outputs.new('IntSocket', "Integer").input = True
  80. self.initialized = True
  81. class InputVectorNode(Node, MantisUINode):
  82. '''A node representing inheritance'''
  83. bl_idname = 'InputVectorNode'
  84. bl_label = "Vector"
  85. bl_icon = 'NODE'
  86. initialized : bpy.props.BoolProperty(default = False)
  87. mantis_node_class_name=bl_idname[:-4]
  88. def init(self, context):
  89. self.outputs.new('VectorSocket', "").input = True
  90. self.initialized = True
  91. class InputBooleanNode(Node, MantisUINode):
  92. '''A node representing inheritance'''
  93. bl_idname = 'InputBooleanNode'
  94. bl_label = "Boolean"
  95. bl_icon = 'NODE'
  96. initialized : bpy.props.BoolProperty(default = False)
  97. mantis_node_class_name=bl_idname[:-4]
  98. def init(self, context):
  99. self.outputs.new('BooleanSocket', "").input = True
  100. self.initialized = True
  101. class InputBooleanThreeTupleNode(Node, MantisUINode):
  102. '''A node representing inheritance'''
  103. bl_idname = 'InputBooleanThreeTupleNode'
  104. bl_label = "Boolean Vector"
  105. bl_icon = 'NODE'
  106. initialized : bpy.props.BoolProperty(default = False)
  107. mantis_node_class_name=bl_idname[:-4]
  108. def init(self, context):
  109. self.outputs.new('BooleanThreeTupleSocket', "")
  110. self.initialized = True
  111. class InputRotationOrderNode(Node, MantisUINode):
  112. '''A node representing inheritance'''
  113. bl_idname = 'InputRotationOrderNode'
  114. bl_label = "Rotation Order"
  115. bl_icon = 'NODE'
  116. initialized : bpy.props.BoolProperty(default = False)
  117. mantis_node_class_name=bl_idname[:-4]
  118. def init(self, context):
  119. self.outputs.new('RotationOrderSocket', "").input = True
  120. self.initialized = True
  121. class InputTransformSpaceNode(Node, MantisUINode):
  122. '''A node representing inheritance'''
  123. bl_idname = 'InputTransformSpaceNode'
  124. bl_label = "Transform Space"
  125. bl_icon = 'NODE'
  126. initialized : bpy.props.BoolProperty(default = False)
  127. mantis_node_class_name=bl_idname[:-4]
  128. def init(self, context):
  129. self.outputs.new('TransformSpaceSocket', "").input = True
  130. self.initialized = True
  131. class InputStringNode(Node, MantisUINode):
  132. '''A node representing inheritance'''
  133. bl_idname = 'InputStringNode'
  134. bl_label = "String"
  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('StringSocket', "").input = True
  140. self.initialized = True
  141. class InputMatrixNode(Node, MantisUINode):
  142. '''A node representing inheritance'''
  143. bl_idname = 'InputMatrixNode'
  144. bl_label = "Matrix"
  145. bl_icon = 'NODE'
  146. first_row : bpy.props.FloatVectorProperty(name="", size=4, default = (1.0, 0.0, 0.0, 0.0,))
  147. second_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 1.0, 0.0, 0.0,))
  148. third_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 1.0, 0.0,))
  149. fourth_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 0.0, 1.0,))
  150. initialized : bpy.props.BoolProperty(default = False)
  151. mantis_node_class_name=bl_idname[:-4]
  152. def set_matrix(self):
  153. return (self.first_row[ 0], self.first_row[ 1], self.first_row[ 2], self.first_row[ 3],
  154. self.second_row[0], self.second_row[1], self.second_row[2], self.second_row[3],
  155. self.third_row[ 0], self.third_row[ 1], self.third_row[ 2], self.third_row[ 3],
  156. self.fourth_row[0], self.fourth_row[1], self.fourth_row[2], self.fourth_row[3],)
  157. def init(self, context):
  158. self.outputs.new('MatrixSocket', "Matrix")
  159. self.initialized = True
  160. def draw_buttons(self, context, layout):
  161. # return
  162. layout.prop(self, "first_row")
  163. layout.prop(self, "second_row")
  164. layout.prop(self, "third_row")
  165. layout.prop(self, "fourth_row")
  166. def update(self):
  167. mat_sock = self.outputs[0]
  168. mat_sock.default_value = self.set_matrix()
  169. class ScaleBoneLengthNode(Node, MantisUINode):
  170. '''Scale Bone Length'''
  171. bl_idname = 'ScaleBoneLength'
  172. bl_label = "Scale Bone Length"
  173. bl_icon = 'NODE'
  174. initialized : bpy.props.BoolProperty(default = False)
  175. # === Optional Functions ===
  176. def init(self, context):
  177. self.inputs.new('MatrixSocket', "In Matrix")
  178. self.inputs.new('FloatSocket', "Factor")
  179. self.outputs.new('MatrixSocket', "Out Matrix")
  180. self.initialized = True
  181. class MetaRigMatrixNode(Node, MantisUINode):
  182. # Identical to the above, except
  183. '''A node representing a bone's matrix'''
  184. bl_idname = 'MetaRigMatrixNode'
  185. bl_label = "Matrix"
  186. bl_icon = 'NODE'
  187. first_row : bpy.props.FloatVectorProperty(name="", size=4, default = (1.0, 0.0, 0.0, 0.0,))
  188. second_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 1.0, 0.0, 0.0,))
  189. third_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 1.0, 0.0,))
  190. fourth_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 0.0, 1.0,))
  191. initialized : bpy.props.BoolProperty(default = False)
  192. mantis_node_class_name="UtilityMetaRig"
  193. def set_matrix(self):
  194. return (self.first_row[ 0], self.first_row[ 1], self.first_row[ 2], self.first_row[ 3],
  195. self.second_row[0], self.second_row[1], self.second_row[2], self.second_row[3],
  196. self.third_row[ 0], self.third_row[ 1], self.third_row[ 2], self.third_row[ 3],
  197. self.fourth_row[0], self.fourth_row[1], self.fourth_row[2], self.fourth_row[3],)
  198. def init(self, context):
  199. self.outputs.new('MatrixSocket', "Matrix")
  200. self.initialized = True
  201. def update(self):
  202. mat_sock = self.outputs[0]
  203. mat_sock.default_value = self.set_matrix()
  204. class UtilityMatrixFromCurve(Node, MantisUINode):
  205. """Gets a matrix from a curve."""
  206. bl_idname = "UtilityMatrixFromCurve"
  207. bl_label = "Matrix from Curve"
  208. bl_icon = "NODE"
  209. initialized : bpy.props.BoolProperty(default = False)
  210. mantis_node_class_name=bl_idname
  211. def init(self, context):
  212. curv = self.inputs.new("EnumCurveSocket", "Curve")
  213. self.inputs.new('IntSocket', 'Total Divisions')
  214. self.inputs.new('IntSocket', 'Matrix Index')
  215. self.outputs.new("MatrixSocket", "Matrix")
  216. self.initialized = True
  217. class UtilityPointFromCurve(Node, MantisUINode):
  218. """Gets a point from a curve."""
  219. bl_idname = "UtilityPointFromCurve"
  220. bl_label = "Point from Curve"
  221. bl_icon = "NODE"
  222. initialized : bpy.props.BoolProperty(default = False)
  223. mantis_node_class_name=bl_idname
  224. def init(self, context):
  225. curv = self.inputs.new("EnumCurveSocket", "Curve")
  226. self.inputs.new('FloatFactorSocket', 'Factor')
  227. self.outputs.new("VectorSocket", "Point")
  228. self.initialized = True
  229. class UtilityMatricesFromCurve(Node, MantisUINode):
  230. """Gets a matrix from a curve."""
  231. bl_idname = "UtilityMatricesFromCurve"
  232. bl_label = "Matrices from Curve"
  233. bl_icon = "NODE"
  234. initialized : bpy.props.BoolProperty(default = False)
  235. mantis_node_class_name=bl_idname
  236. def init(self, context):
  237. curv = self.inputs.new("EnumCurveSocket", "Curve")
  238. curv.icon = "OUTLINER_OB_CURVE"
  239. self.inputs.new('IntSocket', 'Total Divisions')
  240. o = self.outputs.new("MatrixSocket", "Matrices")
  241. o.display_shape = 'SQUARE_DOT'
  242. self.initialized = True
  243. class UtilityMetaRigNode(Node, MantisUINode):
  244. """Gets a matrix from a meta-rig bone."""
  245. bl_idname = "UtilityMetaRig"
  246. bl_label = "Meta-Rig"
  247. bl_icon = "NODE"
  248. armature:bpy.props.StringProperty()
  249. pose_bone:bpy.props.StringProperty()
  250. initialized : bpy.props.BoolProperty(default = False)
  251. mantis_node_class_name=bl_idname
  252. def init(self, context):
  253. armt = self.inputs.new("EnumMetaRigSocket", "Meta-Armature")
  254. bone = self.inputs.new("EnumMetaBoneSocket", "Meta-Bone")
  255. bone.hide=True
  256. self.outputs.new("MatrixSocket", "Matrix")
  257. self.initialized = True
  258. def display_update(self, parsed_tree, context):
  259. from .base_definitions import get_signature_from_edited_tree
  260. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  261. if nc:
  262. self.armature= nc.evaluate_input("Meta-Armature")
  263. self.pose_bone= nc.evaluate_input("Meta-Bone")
  264. if not self.armature:
  265. self.inputs["Meta-Bone"].hide=True
  266. else:
  267. self.inputs["Meta-Bone"].hide=False
  268. if self.inputs["Meta-Armature"].is_linked:
  269. self.inputs["Meta-Armature"].search_prop = None
  270. if self.inputs["Meta-Bone"].is_linked:
  271. self.inputs["Meta-Bone"].search_prop = None
  272. class UtilityBonePropertiesNode(Node, MantisUINode):
  273. """Provides as sockets strings identifying bone transform properties."""
  274. bl_idname = "UtilityBoneProperties"
  275. bl_label = "Bone Properties"
  276. bl_icon = "NODE"
  277. #bl_width_default = 250
  278. initialized : bpy.props.BoolProperty(default = False)
  279. mantis_node_class_name=bl_idname
  280. def init(self, context):
  281. self.outputs.new("StringSocket", "matrix")
  282. self.outputs.new("StringSocket", "matrix_local")
  283. self.outputs.new("StringSocket", "matrix_basis")
  284. self.outputs.new("StringSocket", "head")
  285. self.outputs.new("StringSocket", "tail")
  286. self.outputs.new("StringSocket", "length")
  287. self.outputs.new("StringSocket", "rotation")
  288. self.outputs.new("StringSocket", "location")
  289. self.outputs.new("StringSocket", "scale")
  290. self.initialized = True
  291. class UtilityDriverVariableNode(Node, MantisUINode):
  292. """Creates a variable for use in a driver."""
  293. bl_idname = "UtilityDriverVariable"
  294. bl_label = "Driver Variable"
  295. bl_icon = "NODE"
  296. initialized : bpy.props.BoolProperty(default = False)
  297. mantis_node_class_name=bl_idname
  298. def init(self, context):
  299. self.inputs.new("EnumDriverVariableType", "Variable Type") # 0
  300. self.inputs.new("ParameterStringSocket", "Property") # 1
  301. self.inputs.new("IntSocket", "Property Index") # 2
  302. self.inputs.new("EnumDriverVariableEvaluationSpace", "Evaluation Space") # 3
  303. self.inputs.new("EnumDriverRotationMode", "Rotation Mode") # 4
  304. self.inputs.new("xFormSocket", "xForm 1") # 5
  305. self.inputs.new("xFormSocket", "xForm 2") # 6
  306. self.outputs.new("DriverVariableSocket", "Driver Variable")
  307. self.inputs[3].hide = True
  308. self.initialized = True
  309. def display_update(self, parsed_tree, context):
  310. from .base_definitions import get_signature_from_edited_tree
  311. if self.inputs["Variable Type"].is_linked:
  312. if context.space_data:
  313. node_tree = context.space_data.path[0].node_tree
  314. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  315. if nc:
  316. driver_type = nc.evaluate_input("Variable Type")
  317. else:
  318. driver_type = self.inputs[0].default_value
  319. if driver_type == 'SINGLE_PROP':
  320. self.inputs[1].hide = False
  321. self.inputs[2].hide = False
  322. self.inputs[3].hide = False
  323. self.inputs[4].hide = False
  324. self.inputs[5].hide = False
  325. self.inputs[6].hide = True
  326. elif driver_type == 'LOC_DIFF':
  327. self.inputs[1].hide = True
  328. self.inputs[2].hide = True
  329. self.inputs[3].hide = True
  330. self.inputs[4].hide = True
  331. self.inputs[5].hide = False
  332. self.inputs[6].hide = False
  333. elif driver_type == 'ROTATION_DIFF':
  334. self.inputs[1].hide = True
  335. self.inputs[2].hide = True
  336. self.inputs[3].hide = True
  337. self.inputs[4].hide = False
  338. self.inputs[5].hide = False
  339. self.inputs[6].hide = False
  340. elif driver_type == 'TRANSFORMS':
  341. self.inputs[1].hide = True
  342. self.inputs[2].hide = True
  343. self.inputs[3].hide = False
  344. self.inputs[4].hide = False
  345. self.inputs[5].hide = False
  346. self.inputs[6].hide = True
  347. # TODO: make a way to edit the fCurve directly.
  348. # I had a working version of this in the past, but it required doing sinful things like
  349. # keeping track of the RAM address of the window.
  350. class UtilityFCurveNode(Node, MantisUINode):
  351. """Creates an fCurve for use with a driver."""
  352. bl_idname = "UtilityFCurve"
  353. bl_label = "fCurve"
  354. bl_icon = "NODE"
  355. use_kf_nodes : bpy.props.BoolProperty(default=True)
  356. initialized : bpy.props.BoolProperty(default = False)
  357. mantis_node_class_name=bl_idname
  358. def init(self, context):
  359. self.inputs.new("eFCrvExtrapolationMode", "Extrapolation Mode")
  360. self.outputs.new("FCurveSocket", "fCurve")
  361. self.initialized = True
  362. def draw_buttons(self, context, layout):
  363. layout.operator( 'mantis.fcurve_node_add_kf' )
  364. if (len(self.inputs) > 1):
  365. layout.operator( 'mantis.fcurve_node_remove_kf' )
  366. class UtilityDriverNode(Node, MantisUINode):
  367. """Represents a Driver relationship"""
  368. bl_idname = "UtilityDriver"
  369. bl_label = "Driver"
  370. bl_icon = "NODE"
  371. initialized : bpy.props.BoolProperty(default = False)
  372. mantis_node_class_name=bl_idname
  373. def init(self, context):
  374. self.inputs.new("EnumDriverType", "Driver Type")
  375. self.inputs.new("FCurveSocket", "fCurve")
  376. self.inputs.new("StringSocket", "Expression")
  377. self.outputs.new("DriverSocket", "Driver")
  378. self.initialized = True
  379. def display_update(self, parsed_tree, context):
  380. if not self.inputs["Driver Type"].is_linked:
  381. dType = self.inputs["Driver Type"].default_value
  382. from .base_definitions import get_signature_from_edited_tree
  383. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  384. if nc:
  385. dType = nc.evaluate_input("Driver Type")
  386. if dType == 'SCRIPTED':
  387. self.inputs["Expression"].hide = False
  388. else:
  389. self.inputs["Expression"].hide = True
  390. def draw_buttons(self, context, layout):
  391. # return
  392. layout.operator( 'mantis.driver_node_add_variable' )
  393. if (len(self.inputs) > 3):
  394. layout.operator( 'mantis.driver_node_remove_variable' )
  395. class UtilitySwitchNode(Node, MantisUINode):
  396. """Represents a switch relationship between one driver property and one or more driven properties."""
  397. bl_idname = "UtilitySwitch"
  398. bl_label = "Switch"
  399. bl_icon = "NODE"
  400. initialized : bpy.props.BoolProperty(default = False)
  401. mantis_node_class_name=bl_idname
  402. def init(self, context):
  403. # self.inputs.new("xFormSocket", "xForm")
  404. self.inputs.new("ParameterStringSocket", "Parameter")
  405. self.inputs.new("IntSocket", "Parameter Index")
  406. self.inputs.new("BooleanSocket", "Invert Switch")
  407. self.outputs.new("DriverSocket", "Driver")
  408. self.initialized = True
  409. class UtilityCombineThreeBoolNode(Node, MantisUINode):
  410. """Combines three booleans into a three-bool."""
  411. bl_idname = "UtilityCombineThreeBool"
  412. bl_label = "CombineThreeBool"
  413. bl_icon = "NODE"
  414. initialized : bpy.props.BoolProperty(default = False)
  415. mantis_node_class_name=bl_idname
  416. def init(self, context):
  417. self.inputs.new("BooleanSocket", "X")
  418. self.inputs.new("BooleanSocket", "Y")
  419. self.inputs.new("BooleanSocket", "Z")
  420. self.outputs.new("BooleanThreeTupleSocket", "Three-Bool")
  421. self.initialized = True
  422. class UtilityCombineVectorNode(Node, MantisUINode):
  423. """Combines three floats into a vector."""
  424. bl_idname = "UtilityCombineVector"
  425. bl_label = "CombineVector"
  426. bl_icon = "NODE"
  427. initialized : bpy.props.BoolProperty(default = False)
  428. mantis_node_class_name=bl_idname
  429. def init(self, context):
  430. self.inputs.new("FloatSocket", "X")
  431. self.inputs.new("FloatSocket", "Y")
  432. self.inputs.new("FloatSocket", "Z")
  433. self.outputs.new("VectorSocket", "Vector")
  434. self.initialized = True
  435. class UtilitySeparateVector(Node, MantisUINode):
  436. """Separates a vector into three floats"""
  437. bl_idname = "UtilitySeparateVector"
  438. bl_label = "Separate Vector"
  439. bl_icon = "NODE"
  440. initialized : bpy.props.BoolProperty(default = False)
  441. mantis_node_class_name=bl_idname
  442. def init(self, context):
  443. self.inputs.new("VectorSocket", "Vector")
  444. self.outputs.new("FloatSocket", "X")
  445. self.outputs.new("FloatSocket", "Y")
  446. self.outputs.new("FloatSocket", "Z")
  447. self.initialized = True
  448. class UtilityCatStringsNode(Node, MantisUINode):
  449. """Adds a suffix to a string"""
  450. bl_idname = "UtilityCatStrings"
  451. bl_label = "Concatenate Strings"
  452. bl_icon = "NODE"
  453. initialized : bpy.props.BoolProperty(default = False)
  454. mantis_node_class_name=bl_idname
  455. def init(self, context):
  456. self.inputs.new("StringSocket", "String_1")
  457. self.inputs.new("StringSocket", "String_2")
  458. self.outputs.new("StringSocket", "OutputString")
  459. self.initialized = True
  460. def draw_label(self): # this will prefer a user-set label, or return the evaluated name
  461. if self.label:
  462. return self.label
  463. if self.outputs['OutputString'].display_text:
  464. return self.outputs['OutputString'].display_text
  465. return self.name
  466. def display_update(self, parsed_tree, context):
  467. from .base_definitions import get_signature_from_edited_tree
  468. if context.space_data:
  469. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  470. self.inputs['String_1'].display_text = ""
  471. self.inputs['String_2'].display_text = ""
  472. self.outputs['OutputString'].display_text = ""
  473. if nc:
  474. try:
  475. self.inputs['String_1'].display_text = a = nc.evaluate_input("String_1")
  476. self.inputs['String_2'].display_text = b = nc.evaluate_input("String_2")
  477. # cat the strings here, since the node may not have run yet.
  478. self.outputs['OutputString'].display_text = a+b
  479. except KeyError:
  480. return # the tree isn't ready yet.
  481. class InputLayerMaskNode(Node, MantisUINode):
  482. """Represents a layer mask for a bone."""
  483. bl_idname = "InputLayerMaskNode"
  484. bl_label = "Layer Mask"
  485. bl_icon = "NODE"
  486. initialized : bpy.props.BoolProperty(default = False)
  487. mantis_node_class_name=bl_idname
  488. def init(self, context):
  489. self.outputs.new("LayerMaskInputSocket", "Layer Mask")
  490. self.initialized = True
  491. class InputExistingGeometryObjectNode(Node, MantisUINode):
  492. """Represents an existing geometry object from within the scene."""
  493. bl_idname = "InputExistingGeometryObject"
  494. bl_label = "Existing Object"
  495. bl_icon = "NODE"
  496. initialized : bpy.props.BoolProperty(default = False)
  497. mantis_node_class_name=bl_idname
  498. # We want Mantis to import widgets and stuff, so we hold a reference to the object
  499. object_reference : bpy.props.PointerProperty(type=bpy.types.Object,)
  500. def init(self, context):
  501. self.inputs.new("StringSocket", "Name")
  502. self.outputs.new("xFormSocket", "Object")
  503. self.initialized = True
  504. def display_update(self, parsed_tree, context):
  505. from .base_definitions import get_signature_from_edited_tree
  506. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  507. if nc: # this is done here so I don't have to define yet another custom socket.
  508. self.object_reference = bpy.data.objects.get(nc.evaluate_input("Name"))
  509. # TODO: maybe I should hold a data reference here, too.
  510. # but it is complicated by the fact that Mantis does not distinguish b/tw geo types
  511. class InputExistingGeometryDataNode(Node, MantisUINode):
  512. """Represents a mesh or curve datablock from the scene."""
  513. bl_idname = "InputExistingGeometryData"
  514. bl_label = "Existing Geometry"
  515. bl_icon = "NODE"
  516. initialized : bpy.props.BoolProperty(default = False)
  517. mantis_node_class_name=bl_idname
  518. def init(self, context):
  519. self.inputs.new("StringSocket", "Name")
  520. self.outputs.new("GeometrySocket", "Geometry")
  521. self.initialized = True
  522. class UtilityGeometryOfXForm(Node, MantisUINode):
  523. """Retrieves a mesh or curve datablock from an xForm."""
  524. bl_idname = "UtilityGeometryOfXForm"
  525. bl_label = "Geometry of xForm"
  526. bl_icon = "NODE"
  527. initialized : bpy.props.BoolProperty(default = False)
  528. mantis_node_class_name=bl_idname
  529. def init(self, context):
  530. self.inputs.new("xFormSocket", "xForm")
  531. self.outputs.new("GeometrySocket", "Geometry")
  532. self.initialized = True
  533. class UtilityNameOfXForm(Node, MantisUINode):
  534. """Retrieves the name of a xForm."""
  535. bl_idname = "UtilityNameOfXForm"
  536. bl_label = "Name of xForm"
  537. bl_icon = "NODE"
  538. initialized : bpy.props.BoolProperty(default = False)
  539. mantis_node_class_name=bl_idname
  540. def init(self, context):
  541. self.inputs.new("xFormSocket", "xForm")
  542. self.outputs.new("StringSocket", "Name")
  543. self.initialized = True
  544. class UtilityGetBoneLength(Node, MantisUINode):
  545. """Returns the length of the bone from its matrix."""
  546. bl_idname = "UtilityGetBoneLength"
  547. bl_label = "Get Bone Length"
  548. bl_icon = "NODE"
  549. initialized : bpy.props.BoolProperty(default = False)
  550. mantis_node_class_name=bl_idname
  551. def init(self, context):
  552. self.inputs.new("MatrixSocket", "Bone Matrix")
  553. self.outputs.new("FloatSocket", "Bone Length")
  554. self.initialized = True
  555. # TODO: make it work with BBones!
  556. class UtilityPointFromBoneMatrix(Node, MantisUINode):
  557. """Returns a point representing the location along a bone, given a matrix representing that bone's shape."""
  558. bl_idname = "UtilityPointFromBoneMatrix"
  559. bl_label = "Point from Bone Matrix"
  560. bl_icon = "NODE"
  561. initialized : bpy.props.BoolProperty(default = False)
  562. mantis_node_class_name=bl_idname
  563. def init(self, context):
  564. self.inputs.new("MatrixSocket", "Bone Matrix")
  565. self.inputs.new("FloatFactorSocket", "Head/Tail")
  566. self.outputs.new("VectorSocket", "Point")
  567. self.initialized = True
  568. class UtilitySetBoneLength(Node, MantisUINode):
  569. """Sets the length of a bone matrix."""
  570. bl_idname = "UtilitySetBoneLength"
  571. bl_label = "Set Bone Matrix Length"
  572. bl_icon = "NODE"
  573. initialized : bpy.props.BoolProperty(default = False)
  574. mantis_node_class_name=bl_idname
  575. def init(self, context):
  576. self.inputs.new("MatrixSocket", "Bone Matrix")
  577. self.inputs.new("FloatSocket", "Length")
  578. self.outputs.new("MatrixSocket", "Bone Matrix")
  579. self.initialized = True
  580. # TODO: more keyframe types should be supported in the future.
  581. # Some of the code that can do this is commented out here until I can implement it properly.
  582. class UtilityKeyframe(Node, MantisUINode):
  583. """A keyframe for a FCurve"""
  584. bl_idname = "UtilityKeyframe"
  585. bl_label = "KeyFrame"
  586. bl_icon = "NODE"
  587. initialized : bpy.props.BoolProperty(default = False)
  588. mantis_node_class_name=bl_idname
  589. def init(self, context):
  590. # x and y
  591. # output is keyframe
  592. # self.inputs.new("EnumKeyframeInterpolationTypeSocket", "Interpolation")
  593. # self.inputs.new("EnumKeyframeBezierHandleType", "Left Handle Type")
  594. # self.inputs.new("EnumKeyframeBezierHandleType", "Right Handle Type")
  595. # self.inputs.new("FloatSocket", "Left Handle Distance")
  596. # self.inputs.new("FloatSocket", "Left Handle Value")
  597. # self.inputs.new("FloatSocket", "Right Handle Frame")
  598. # self.inputs.new("FloatSocket", "Right Handle Value")
  599. self.inputs.new("FloatSocket", "Frame")
  600. self.inputs.new("FloatSocket", "Value")
  601. self.outputs.new("KeyframeSocket", "Keyframe")
  602. # there will eventually be inputs for e.g. key type, key handles, etc.
  603. # right now I am gonna hardcode LINEAR keyframes so I don't have to deal with anything else
  604. # TODO TODO TODO
  605. # def display_update(self, parsed_tree, context):
  606. # if context.space_data:
  607. # nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  608. # if nc.evaluate_input("Interpolation") in ["CONSTANT", "LINEAR"]:
  609. # for inp in self.inputs[1:6]:
  610. # inp.hide = True
  611. # else:
  612. # if nc.evaluate_input("Left Handle Type") in ["FREE", "ALIGNED"]:
  613. # for inp in self.inputs[1:6]:
  614. # inp.hide = False
  615. self.initialized = True
  616. class UtilityBoneMatrixHeadTailFlip(Node, MantisUINode):
  617. """Flips a bone matrix so that the head is where the tail was and visa versa."""
  618. bl_idname = "UtilityBoneMatrixHeadTailFlip"
  619. bl_label = "Flip Head/Tail"
  620. bl_icon = "NODE"
  621. initialized : bpy.props.BoolProperty(default = False)
  622. mantis_node_class_name=bl_idname
  623. def init(self, context):
  624. self.inputs.new("MatrixSocket", "Bone Matrix")
  625. self.outputs.new("MatrixSocket", "Bone Matrix")
  626. self.initialized = True
  627. class UtilityMatrixTransform(Node, MantisUINode):
  628. """Transforms a matrix by another."""
  629. bl_idname = "UtilityMatrixTransform"
  630. bl_label = "Matrix Transform"
  631. bl_icon = "NODE"
  632. initialized : bpy.props.BoolProperty(default = False)
  633. mantis_node_class_name=bl_idname
  634. def init(self, context):
  635. self.inputs.new("MatrixSocket", "Matrix 1")
  636. self.inputs.new("MatrixSocket", "Matrix 2")
  637. self.outputs.new("MatrixSocket", "Out Matrix")
  638. self.initialized = True
  639. class UtilityMatrixSetLocation(Node, MantisUINode):
  640. """Sets a matrix's location."""
  641. bl_idname = "UtilityMatrixSetLocation"
  642. bl_label = "Set Matrix Location"
  643. bl_icon = "NODE"
  644. initialized : bpy.props.BoolProperty(default = False)
  645. mantis_node_class_name=bl_idname
  646. def init(self, context):
  647. self.inputs.new("MatrixSocket", "Matrix")
  648. self.inputs.new("VectorSocket", "Location")
  649. self.outputs.new("MatrixSocket", "Matrix")
  650. self.initialized = True
  651. class UtilityMatrixGetLocation(Node, MantisUINode):
  652. """Gets a matrix's location."""
  653. bl_idname = "UtilityMatrixGetLocation"
  654. bl_label = "Get Matrix Location"
  655. bl_icon = "NODE"
  656. initialized : bpy.props.BoolProperty(default = False)
  657. mantis_node_class_name=bl_idname
  658. def init(self, context):
  659. self.inputs.new("MatrixSocket", "Matrix")
  660. self.outputs.new("VectorSocket", "Location")
  661. self.initialized = True
  662. class UtilityTransformationMatrix(Node, MantisUINode):
  663. """Constructs a matrix representing a transformation"""
  664. bl_idname = "UtilityTransformationMatrix"
  665. bl_label = "Transformation Matrix"
  666. bl_icon = "NODE"
  667. initialized : bpy.props.BoolProperty(default = False)
  668. mantis_node_class_name=bl_idname
  669. def init(self, context):
  670. # first input is a transformation type - translation, rotation, or scale
  671. # rotation is an especially annoying feature because it can take multiple types
  672. # so Euler, axis/angle, quaternion, matrix...
  673. # for now I am only going to implement axis-angle
  674. # it should get an axis and a magnitude
  675. # self.inputs.new("MatrixSocket", "Bone Matrix")
  676. self.inputs.new("MatrixTransformOperation", "Operation")
  677. self.inputs.new("VectorSocket", "Vector")
  678. self.inputs.new("FloatSocket", "W")
  679. self.outputs.new("MatrixSocket", "Matrix")
  680. self.initialized = True
  681. def display_update(self, parsed_tree, context):
  682. from .base_definitions import get_signature_from_edited_tree
  683. operation = self.inputs['Operation'].default_value
  684. if self.inputs['Operation'].is_linked:
  685. if context.space_data:
  686. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  687. operation = nc.evaluate_input("Operation")
  688. if operation in ["ROTATE_AXIS_ANGLE", "SCALE"]:
  689. self.inputs["Vector"].hide = False
  690. self.inputs["W"].hide = False
  691. if operation in ["TRANSLATE"]:
  692. self.inputs["Vector"].hide = False
  693. self.inputs["W"].hide = True
  694. # Blender calculates bone roll this way...
  695. # https://projects.blender.org/blender/blender/src/commit/dd209221675ac7b62ce47b7ea42f15cbe34a6035/source/blender/editors/armature/armature_edit.cc#L281
  696. # 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
  697. # in the edit bone.
  698. # So instead, we need to avoid calculating the roll for now.
  699. # but I want to make that its own node and add roll-recalc to this node, too.
  700. class UtilitySetBoneMatrixTail(Node, MantisUINode):
  701. """Constructs a matrix representing a transformation"""
  702. bl_idname = "UtilitySetBoneMatrixTail"
  703. bl_label = "Set Bone Matrix Tail"
  704. bl_icon = "NODE"
  705. initialized : bpy.props.BoolProperty(default = False)
  706. mantis_node_class_name=bl_idname
  707. def init(self, context):
  708. self.inputs.new("MatrixSocket", "Matrix")
  709. self.inputs.new("VectorSocket", "Tail Location")
  710. self.outputs.new("MatrixSocket", "Result")
  711. self.initialized = True
  712. class UtilityMatrixFromXForm(Node, MantisUINode):
  713. """Returns the matrix of the given xForm node."""
  714. bl_idname = "UtilityMatrixFromXForm"
  715. bl_label = "Matrix of xForm"
  716. bl_icon = "NODE"
  717. initialized : bpy.props.BoolProperty(default = False)
  718. mantis_node_class_name=bl_idname
  719. def init(self, context):
  720. self.inputs.new("xFormSocket", "xForm")
  721. self.outputs.new("MatrixSocket", "Matrix")
  722. self.initialized = True
  723. class UtilityAxesFromMatrix(Node, MantisUINode):
  724. """Returns the axes of the matrix."""
  725. bl_idname = "UtilityAxesFromMatrix"
  726. bl_label = "Axes of Matrix"
  727. bl_icon = "NODE"
  728. initialized : bpy.props.BoolProperty(default = False)
  729. mantis_node_class_name=bl_idname
  730. def init(self, context):
  731. self.inputs.new("MatrixSocket", "Matrix")
  732. self.outputs.new("VectorSocket", "X Axis")
  733. self.outputs.new("VectorSocket", "Y Axis")
  734. self.outputs.new("VectorSocket", "Z Axis")
  735. self.initialized = True
  736. class UtilityIntToString(Node, MantisUINode):
  737. """Converts a number to a string"""
  738. bl_idname = "UtilityIntToString"
  739. bl_label = "Number String"
  740. bl_icon = "NODE"
  741. initialized : bpy.props.BoolProperty(default = False)
  742. mantis_node_class_name=bl_idname
  743. def init(self, context):
  744. self.inputs.new("IntSocket", "Number")
  745. self.inputs.new("IntSocket", "Zero Padding")
  746. self.outputs.new("StringSocket", "String")
  747. self.initialized = True
  748. class UtilityArrayGet(Node, MantisUINode):
  749. """Gets a value from an array at a specified index."""
  750. bl_idname = "UtilityArrayGet"
  751. bl_label = "Array Get"
  752. bl_icon = "NODE"
  753. initialized : bpy.props.BoolProperty(default = False)
  754. mantis_node_class_name=bl_idname
  755. def init(self, context):
  756. self.inputs.new('EnumArrayGetOptions', 'OoB Behaviour')
  757. self.inputs.new("IntSocket", "Index")
  758. s = self.inputs.new("WildcardSocket", "Array", use_multi_input=True)
  759. s.display_shape = 'SQUARE_DOT'
  760. self.outputs.new("WildcardSocket", "Output")
  761. self.initialized = True
  762. def update(self):
  763. wildcard_color = (0.0,0.0,0.0,0.0)
  764. if self.inputs['Array'].is_linked == False:
  765. self.inputs['Array'].color = wildcard_color
  766. self.outputs['Output'].color = wildcard_color
  767. def insert_link(self, link):
  768. super().insert_link(link)
  769. prGreen(link.from_node.name, link.from_socket.identifier, link.to_node.name, link.to_socket.identifier)
  770. if link.to_socket.identifier == self.inputs['Array'].identifier:
  771. from_socket = link.from_socket
  772. print (from_socket.color)
  773. if hasattr(from_socket, "color"):
  774. self.inputs['Array'].color = from_socket.color
  775. self.outputs['Output'].color = from_socket.color
  776. class UtilityCompare(Node, MantisUINode):
  777. """Compares two inputs and produces a boolean output"""
  778. bl_idname = "UtilityCompare"
  779. bl_label = "Compare"
  780. bl_icon = "NODE"
  781. initialized : bpy.props.BoolProperty(default = False)
  782. mantis_node_class_name=bl_idname
  783. def init(self, context):
  784. self.inputs.new("WildcardSocket", "A")
  785. self.inputs.new("WildcardSocket", "B")
  786. self.outputs.new("BooleanSocket", "Result")
  787. self.initialized = True
  788. def update(self):
  789. wildcard_color = (0.0,0.0,0.0,0.0)
  790. if self.inputs['A'].is_linked == False:
  791. self.inputs['A'].color = wildcard_color
  792. if self.inputs['B'].is_linked == False:
  793. self.inputs['B'].color = wildcard_color
  794. def insert_link(self, link):
  795. super().insert_link(link)
  796. if link.to_socket.identifier == self.inputs['A'].identifier:
  797. self.inputs['A'].color = link.from_socket.color_simple
  798. if hasattr(link.from_socket, "color"):
  799. self.inputs['A'].color = link.from_socket.color
  800. if link.to_socket.identifier == self.inputs['B'].identifier:
  801. self.inputs['B'].color = link.from_socket.color_simple
  802. if hasattr(link.from_socket, "color"):
  803. self.inputs['B'].color = link.from_socket.color
  804. class UtilityChoose(Node, MantisUINode):
  805. """Chooses an output"""
  806. bl_idname = "UtilityChoose"
  807. bl_label = "Choose"
  808. bl_icon = "NODE"
  809. initialized : bpy.props.BoolProperty(default = False)
  810. mantis_node_class_name=bl_idname
  811. def init(self, context):
  812. self.inputs.new("BooleanSocket", "Condition")
  813. self.inputs.new("WildcardSocket", "A")
  814. self.inputs.new("WildcardSocket", "B")
  815. self.outputs.new("WildcardSocket", "Result")
  816. self.initialized = True
  817. def display_update(self, parsed_tree, context):
  818. wildcard_color = (0.0,0.0,0.0,0.0)
  819. if not self.inputs['A'].is_linked:
  820. self.inputs['A'].color = wildcard_color
  821. if not self.inputs['B'].is_linked:
  822. self.inputs['B'].color = wildcard_color
  823. self.outputs['Result'].color = wildcard_color
  824. # if both inputs are the same color, then use that color for the result
  825. if self.inputs['Condition'].is_linked:
  826. from .base_definitions import get_signature_from_edited_tree
  827. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  828. if nc:
  829. condition = nc.evaluate_input('Condition')
  830. else:
  831. condition = self.inputs['Condition'].default_value
  832. if condition == True:
  833. self.outputs['Result'].color = self.inputs['B'].color
  834. else:
  835. self.outputs['Result'].color = self.inputs['A'].color
  836. def insert_link(self, link):
  837. super().insert_link(link)
  838. if link.to_socket.identifier == self.inputs['A'].identifier:
  839. self.inputs['A'].color = link.from_socket.color_simple
  840. if hasattr(link.from_socket, "color"):
  841. self.inputs['A'].color = link.from_socket.color
  842. if link.to_socket.identifier == self.inputs['B'].identifier:
  843. self.inputs['B'].color = link.from_socket.color_simple
  844. if hasattr(link.from_socket, "color"):
  845. self.inputs['B'].color = link.from_socket.color
  846. class UtilityPrint(Node, MantisUINode):
  847. """A utility used to print arbitrary values."""
  848. bl_idname = "UtilityPrint"
  849. bl_label = "Print"
  850. bl_icon = "NODE"
  851. initialized : bpy.props.BoolProperty(default = False)
  852. mantis_node_class_name=bl_idname
  853. def init(self, context):
  854. self.inputs.new("WildcardSocket", "Input")
  855. self.initialized = True
  856. # Set up the class property that ties the UI classes to the Mantis classes.
  857. for cls in TellClasses():
  858. cls.mantis_node_library='.misc_nodes'
  859. cls.set_mantis_class()