nodes_generic.py 36 KB

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