nodes_generic.py 37 KB

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