nodes_generic.py 36 KB

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