nodes_generic.py 37 KB

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