nodes_generic.py 39 KB

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