nodes_generic.py 39 KB

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