nodes_generic.py 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  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.inputs.new("eFCrvExtrapolationMode", "Extrapolation Mode")
  382. self.outputs.new("FCurveSocket", "fCurve")
  383. self.initialized = True
  384. def draw_buttons(self, context, layout):
  385. layout.operator( 'mantis.fcurve_node_add_kf' )
  386. if (len(self.inputs) > 1):
  387. layout.operator( 'mantis.fcurve_node_remove_kf' )
  388. class UtilityDriverNode(Node, MantisNode):
  389. """Represents a Driver relationship"""
  390. bl_idname = "UtilityDriver"
  391. bl_label = "Driver"
  392. bl_icon = "NODE"
  393. initialized : bpy.props.BoolProperty(default = False)
  394. def init(self, context):
  395. self.inputs.new("EnumDriverType", "Driver Type")
  396. self.inputs.new("FCurveSocket", "fCurve")
  397. self.inputs.new("StringSocket", "Expression")
  398. self.outputs.new("DriverSocket", "Driver")
  399. self.initialized = True
  400. def display_update(self, parsed_tree, context):
  401. if not self.inputs["Driver Type"].is_linked:
  402. dType = self.inputs["Driver Type"].default_value
  403. from .base_definitions import get_signature_from_edited_tree
  404. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  405. if nc:
  406. dType = nc.evaluate_input("Driver Type")
  407. if dType == 'SCRIPTED':
  408. self.inputs["Expression"].hide = False
  409. else:
  410. self.inputs["Expression"].hide = True
  411. def draw_buttons(self, context, layout):
  412. # return
  413. layout.operator( 'mantis.driver_node_add_variable' )
  414. if (len(self.inputs) > 3):
  415. layout.operator( 'mantis.driver_node_remove_variable' )
  416. class UtilitySwitchNode(Node, MantisNode):
  417. """Represents a switch relationship between one driver property and one or more driven properties."""
  418. bl_idname = "UtilitySwitch"
  419. bl_label = "Switch"
  420. bl_icon = "NODE"
  421. initialized : bpy.props.BoolProperty(default = False)
  422. def init(self, context):
  423. # self.inputs.new("xFormSocket", "xForm")
  424. self.inputs.new("ParameterStringSocket", "Parameter")
  425. self.inputs.new("IntSocket", "Parameter Index")
  426. self.inputs.new("BooleanSocket", "Invert Switch")
  427. self.outputs.new("DriverSocket", "Driver")
  428. self.initialized = True
  429. class UtilityCombineThreeBoolNode(Node, MantisNode):
  430. """Combines three booleans into a three-bool."""
  431. bl_idname = "UtilityCombineThreeBool"
  432. bl_label = "CombineThreeBool"
  433. bl_icon = "NODE"
  434. initialized : bpy.props.BoolProperty(default = False)
  435. def init(self, context):
  436. self.inputs.new("BooleanSocket", "X")
  437. self.inputs.new("BooleanSocket", "Y")
  438. self.inputs.new("BooleanSocket", "Z")
  439. self.outputs.new("BooleanThreeTupleSocket", "Three-Bool")
  440. self.initialized = True
  441. class UtilityCombineVectorNode(Node, MantisNode):
  442. """Combines three floats into a vector."""
  443. bl_idname = "UtilityCombineVector"
  444. bl_label = "CombineVector"
  445. bl_icon = "NODE"
  446. initialized : bpy.props.BoolProperty(default = False)
  447. def init(self, context):
  448. self.inputs.new("FloatSocket", "X")
  449. self.inputs.new("FloatSocket", "Y")
  450. self.inputs.new("FloatSocket", "Z")
  451. self.outputs.new("VectorSocket", "Vector")
  452. self.initialized = True
  453. class UtilitySeparateVector(Node, MantisNode):
  454. """Separates a vector into three floats"""
  455. bl_idname = "UtilitySeparateVector"
  456. bl_label = "Separate Vector"
  457. bl_icon = "NODE"
  458. initialized : bpy.props.BoolProperty(default = False)
  459. def init(self, context):
  460. self.inputs.new("VectorSocket", "Vector")
  461. self.outputs.new("FloatSocket", "X")
  462. self.outputs.new("FloatSocket", "Y")
  463. self.outputs.new("FloatSocket", "Z")
  464. self.initialized = True
  465. class UtilityCatStringsNode(Node, MantisNode):
  466. """Adds a suffix to a string"""
  467. bl_idname = "UtilityCatStrings"
  468. bl_label = "Concatenate Strings"
  469. bl_icon = "NODE"
  470. initialized : bpy.props.BoolProperty(default = False)
  471. def init(self, context):
  472. self.inputs.new("StringSocket", "String_1")
  473. self.inputs.new("StringSocket", "String_2")
  474. self.outputs.new("StringSocket", "OutputString")
  475. self.initialized = True
  476. class InputLayerMaskNode(Node, MantisNode):
  477. """Represents a layer mask for a bone."""
  478. bl_idname = "InputLayerMaskNode"
  479. bl_label = "Layer Mask"
  480. bl_icon = "NODE"
  481. initialized : bpy.props.BoolProperty(default = False)
  482. def init(self, context):
  483. self.outputs.new("LayerMaskInputSocket", "Layer Mask")
  484. self.initialized = True
  485. class InputExistingGeometryObjectNode(Node, MantisNode):
  486. """Represents an existing geometry object from within the scene."""
  487. bl_idname = "InputExistingGeometryObject"
  488. bl_label = "Existing Object"
  489. bl_icon = "NODE"
  490. initialized : bpy.props.BoolProperty(default = False)
  491. # We want Mantis to import widgets and stuff, so we hold a reference to the object
  492. object_reference : bpy.props.PointerProperty(type=bpy.types.Object,)
  493. def init(self, context):
  494. self.inputs.new("StringSocket", "Name")
  495. self.outputs.new("xFormSocket", "Object")
  496. self.initialized = True
  497. def display_update(self, parsed_tree, context):
  498. from .base_definitions import get_signature_from_edited_tree
  499. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  500. if nc: # this is done here so I don't have to define yet another custom socket.
  501. self.object_reference = bpy.data.objects.get(nc.evaluate_input("Name"))
  502. # TODO: maybe I should hold a data reference here, too.
  503. # but it is complicated by the fact that Mantis does not distinguish b/tw geo types
  504. class InputExistingGeometryDataNode(Node, MantisNode):
  505. """Represents a mesh or curve datablock from the scene."""
  506. bl_idname = "InputExistingGeometryData"
  507. bl_label = "Existing Geometry"
  508. bl_icon = "NODE"
  509. initialized : bpy.props.BoolProperty(default = False)
  510. def init(self, context):
  511. self.inputs.new("StringSocket", "Name")
  512. self.outputs.new("GeometrySocket", "Geometry")
  513. self.initialized = True
  514. class UtilityGeometryOfXForm(Node, MantisNode):
  515. """Retrieves a mesh or curve datablock from an xForm."""
  516. bl_idname = "UtilityGeometryOfXForm"
  517. bl_label = "Geometry of xForm"
  518. bl_icon = "NODE"
  519. initialized : bpy.props.BoolProperty(default = False)
  520. def init(self, context):
  521. self.inputs.new("xFormSocket", "xForm")
  522. self.outputs.new("GeometrySocket", "Geometry")
  523. self.initialized = True
  524. class UtilityNameOfXForm(Node, MantisNode):
  525. """Retrieves the name of a xForm."""
  526. bl_idname = "UtilityNameOfXForm"
  527. bl_label = "Name of xForm"
  528. bl_icon = "NODE"
  529. initialized : bpy.props.BoolProperty(default = False)
  530. def init(self, context):
  531. self.inputs.new("xFormSocket", "xForm")
  532. self.outputs.new("StringSocket", "Name")
  533. self.initialized = True
  534. class UtilityGetBoneLength(Node, MantisNode):
  535. """Returns the length of the bone from its matrix."""
  536. bl_idname = "UtilityGetBoneLength"
  537. bl_label = "Get Bone Length"
  538. bl_icon = "NODE"
  539. initialized : bpy.props.BoolProperty(default = False)
  540. def init(self, context):
  541. self.inputs.new("MatrixSocket", "Bone Matrix")
  542. self.outputs.new("FloatSocket", "Bone Length")
  543. self.initialized = True
  544. # TODO: make it work with BBones!
  545. class UtilityPointFromBoneMatrix(Node, MantisNode):
  546. """Returns a point representing the location along a bone, given a matrix representing that bone's shape."""
  547. bl_idname = "UtilityPointFromBoneMatrix"
  548. bl_label = "Point from Bone Matrix"
  549. bl_icon = "NODE"
  550. initialized : bpy.props.BoolProperty(default = False)
  551. def init(self, context):
  552. self.inputs.new("MatrixSocket", "Bone Matrix")
  553. self.inputs.new("FloatFactorSocket", "Head/Tail")
  554. self.outputs.new("VectorSocket", "Point")
  555. self.initialized = True
  556. class UtilitySetBoneLength(Node, MantisNode):
  557. """Sets the length of a bone matrix."""
  558. bl_idname = "UtilitySetBoneLength"
  559. bl_label = "Set Bone Matrix Length"
  560. bl_icon = "NODE"
  561. initialized : bpy.props.BoolProperty(default = False)
  562. def init(self, context):
  563. self.inputs.new("MatrixSocket", "Bone Matrix")
  564. self.inputs.new("FloatSocket", "Length")
  565. self.outputs.new("MatrixSocket", "Bone Matrix")
  566. self.initialized = True
  567. # TODO: more keyframe types should be supported in the future.
  568. # Some of the code that can do this is commented out here until I can implement it properly.
  569. class UtilityKeyframe(Node, MantisNode):
  570. """A keyframe for a FCurve"""
  571. bl_idname = "UtilityKeyframe"
  572. bl_label = "KeyFrame"
  573. bl_icon = "NODE"
  574. initialized : bpy.props.BoolProperty(default = False)
  575. def init(self, context):
  576. # x and y
  577. # output is keyframe
  578. # self.inputs.new("EnumKeyframeInterpolationTypeSocket", "Interpolation")
  579. # self.inputs.new("EnumKeyframeBezierHandleType", "Left Handle Type")
  580. # self.inputs.new("EnumKeyframeBezierHandleType", "Right Handle Type")
  581. # self.inputs.new("FloatSocket", "Left Handle Distance")
  582. # self.inputs.new("FloatSocket", "Left Handle Value")
  583. # self.inputs.new("FloatSocket", "Right Handle Frame")
  584. # self.inputs.new("FloatSocket", "Right Handle Value")
  585. self.inputs.new("FloatSocket", "Frame")
  586. self.inputs.new("FloatSocket", "Value")
  587. self.outputs.new("KeyframeSocket", "Keyframe")
  588. # there will eventually be inputs for e.g. key type, key handles, etc.
  589. # right now I am gonna hardcode LINEAR keyframes so I don't have to deal with anything else
  590. # TODO TODO TODO
  591. # def display_update(self, parsed_tree, context):
  592. # if context.space_data:
  593. # nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  594. # if nc.evaluate_input("Interpolation") in ["CONSTANT", "LINEAR"]:
  595. # for inp in self.inputs[1:6]:
  596. # inp.hide = True
  597. # else:
  598. # if nc.evaluate_input("Left Handle Type") in ["FREE", "ALIGNED"]:
  599. # for inp in self.inputs[1:6]:
  600. # inp.hide = False
  601. self.initialized = True
  602. class UtilityBoneMatrixHeadTailFlip(Node, MantisNode):
  603. """Flips a bone matrix so that the head is where the tail was and visa versa."""
  604. bl_idname = "UtilityBoneMatrixHeadTailFlip"
  605. bl_label = "Flip Head/Tail"
  606. bl_icon = "NODE"
  607. initialized : bpy.props.BoolProperty(default = False)
  608. def init(self, context):
  609. self.inputs.new("MatrixSocket", "Bone Matrix")
  610. self.outputs.new("MatrixSocket", "Bone Matrix")
  611. self.initialized = True
  612. class UtilityMatrixTransform(Node, MantisNode):
  613. """Transforms a matrix by another."""
  614. bl_idname = "UtilityMatrixTransform"
  615. bl_label = "Matrix Transform"
  616. bl_icon = "NODE"
  617. initialized : bpy.props.BoolProperty(default = False)
  618. def init(self, context):
  619. self.inputs.new("MatrixSocket", "Matrix 1")
  620. self.inputs.new("MatrixSocket", "Matrix 2")
  621. self.outputs.new("MatrixSocket", "Out Matrix")
  622. self.initialized = True
  623. class UtilityMatrixSetLocation(Node, MantisNode):
  624. """Sets a matrix's location."""
  625. bl_idname = "UtilityMatrixSetLocation"
  626. bl_label = "Set Matrix Location"
  627. bl_icon = "NODE"
  628. initialized : bpy.props.BoolProperty(default = False)
  629. def init(self, context):
  630. self.inputs.new("MatrixSocket", "Matrix")
  631. self.inputs.new("VectorSocket", "Location")
  632. self.outputs.new("MatrixSocket", "Matrix")
  633. self.initialized = True
  634. class UtilityMatrixGetLocation(Node, MantisNode):
  635. """Gets a matrix's location."""
  636. bl_idname = "UtilityMatrixGetLocation"
  637. bl_label = "Get Matrix Location"
  638. bl_icon = "NODE"
  639. initialized : bpy.props.BoolProperty(default = False)
  640. def init(self, context):
  641. self.inputs.new("MatrixSocket", "Matrix")
  642. self.outputs.new("VectorSocket", "Location")
  643. self.initialized = True
  644. class UtilityTransformationMatrix(Node, MantisNode):
  645. """Constructs a matrix representing a transformation"""
  646. bl_idname = "UtilityTransformationMatrix"
  647. bl_label = "Transformation Matrix"
  648. bl_icon = "NODE"
  649. initialized : bpy.props.BoolProperty(default = False)
  650. def init(self, context):
  651. # first input is a transformation type - translation, rotation, or scale
  652. # rotation is an especially annoying feature because it can take multiple types
  653. # so Euler, axis/angle, quaternion, matrix...
  654. # for now I am only going to implement axis-angle
  655. # it should get an axis and a magnitude
  656. # self.inputs.new("MatrixSocket", "Bone Matrix")
  657. self.inputs.new("MatrixTransformOperation", "Operation")
  658. self.inputs.new("VectorSocket", "Vector")
  659. self.inputs.new("FloatSocket", "W")
  660. self.outputs.new("MatrixSocket", "Matrix")
  661. self.initialized = True
  662. def display_update(self, parsed_tree, context):
  663. from .base_definitions import get_signature_from_edited_tree
  664. operation = self.inputs['Operation'].default_value
  665. if self.inputs['Operation'].is_linked:
  666. if context.space_data:
  667. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  668. operation = nc.evaluate_input("Operation")
  669. if operation in ["ROTATE_AXIS_ANGLE", "SCALE"]:
  670. self.inputs["Vector"].hide = False
  671. self.inputs["W"].hide = False
  672. if operation in ["TRANSLATE"]:
  673. self.inputs["Vector"].hide = False
  674. self.inputs["W"].hide = True
  675. # Blender calculates bone roll this way...
  676. # https://projects.blender.org/blender/blender/src/commit/dd209221675ac7b62ce47b7ea42f15cbe34a6035/source/blender/editors/armature/armature_edit.cc#L281
  677. # 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
  678. # in the edit bone.
  679. # So instead, we need to avoid calculating the roll for now.
  680. # but I want to make that its own node and add roll-recalc to this node, too.
  681. class UtilitySetBoneMatrixTail(Node, MantisNode):
  682. """Constructs a matrix representing a transformation"""
  683. bl_idname = "UtilitySetBoneMatrixTail"
  684. bl_label = "Set Bone Matrix Tail"
  685. bl_icon = "NODE"
  686. initialized : bpy.props.BoolProperty(default = False)
  687. def init(self, context):
  688. self.inputs.new("MatrixSocket", "Matrix")
  689. self.inputs.new("VectorSocket", "Tail Location")
  690. self.outputs.new("MatrixSocket", "Result")
  691. self.initialized = True
  692. class UtilityMatrixFromXForm(Node, MantisNode):
  693. """Returns the matrix of the given xForm node."""
  694. bl_idname = "UtilityMatrixFromXForm"
  695. bl_label = "Matrix of xForm"
  696. bl_icon = "NODE"
  697. initialized : bpy.props.BoolProperty(default = False)
  698. def init(self, context):
  699. self.inputs.new("xFormSocket", "xForm")
  700. self.outputs.new("MatrixSocket", "Matrix")
  701. self.initialized = True
  702. class UtilityAxesFromMatrix(Node, MantisNode):
  703. """Returns the axes of the matrix."""
  704. bl_idname = "UtilityAxesFromMatrix"
  705. bl_label = "Axes of Matrix"
  706. bl_icon = "NODE"
  707. initialized : bpy.props.BoolProperty(default = False)
  708. def init(self, context):
  709. self.inputs.new("MatrixSocket", "Matrix")
  710. self.outputs.new("VectorSocket", "X Axis")
  711. self.outputs.new("VectorSocket", "Y Axis")
  712. self.outputs.new("VectorSocket", "Z Axis")
  713. self.initialized = True
  714. class UtilityIntToString(Node, MantisNode):
  715. """Converts a number to a string"""
  716. bl_idname = "UtilityIntToString"
  717. bl_label = "Number String"
  718. bl_icon = "NODE"
  719. initialized : bpy.props.BoolProperty(default = False)
  720. def init(self, context):
  721. self.inputs.new("IntSocket", "Number")
  722. self.inputs.new("IntSocket", "Zero Padding")
  723. self.outputs.new("StringSocket", "String")
  724. self.initialized = True
  725. class UtilityArrayGet(Node, MantisNode):
  726. """Gets a value from an array at a specified index."""
  727. bl_idname = "UtilityArrayGet"
  728. bl_label = "Array Get"
  729. bl_icon = "NODE"
  730. initialized : bpy.props.BoolProperty(default = False)
  731. def init(self, context):
  732. self.inputs.new('EnumArrayGetOptions', 'OoB Behaviour')
  733. self.inputs.new("IntSocket", "Index")
  734. s = self.inputs.new("WildcardSocket", "Array", use_multi_input=True)
  735. s.display_shape = 'SQUARE_DOT'
  736. self.outputs.new("WildcardSocket", "Output")
  737. self.initialized = True
  738. def update(self):
  739. wildcard_color = (0.0,0.0,0.0,0.0)
  740. if self.inputs['Array'].is_linked == False:
  741. self.inputs['Array'].color = wildcard_color
  742. self.outputs['Output'].color = wildcard_color
  743. def insert_link(self, link):
  744. prGreen(link.from_node.name, link.from_socket.identifier, link.to_node.name, link.to_socket.identifier)
  745. if link.to_socket.identifier == self.inputs['Array'].identifier:
  746. from_socket = link.from_socket
  747. print (from_socket.color)
  748. if hasattr(from_socket, "color"):
  749. self.inputs['Array'].color = from_socket.color
  750. self.outputs['Output'].color = from_socket.color
  751. class UtilityCompare(Node, MantisNode):
  752. """Compares two inputs and produces a boolean output"""
  753. bl_idname = "UtilityCompare"
  754. bl_label = "Compare"
  755. bl_icon = "NODE"
  756. initialized : bpy.props.BoolProperty(default = False)
  757. def init(self, context):
  758. self.inputs.new("WildcardSocket", "A")
  759. self.inputs.new("WildcardSocket", "B")
  760. self.outputs.new("BooleanSocket", "Result")
  761. self.initialized = True
  762. def update(self):
  763. wildcard_color = (0.0,0.0,0.0,0.0)
  764. if self.inputs['A'].is_linked == False:
  765. self.inputs['A'].color = wildcard_color
  766. if self.inputs['B'].is_linked == False:
  767. self.inputs['B'].color = wildcard_color
  768. def insert_link(self, link):
  769. if link.to_socket.identifier == self.inputs['A'].identifier:
  770. self.inputs['A'].color = link.from_socket.color_simple
  771. if hasattr(link.from_socket, "color"):
  772. self.inputs['A'].color = link.from_socket.color
  773. if link.to_socket.identifier == self.inputs['B'].identifier:
  774. self.inputs['B'].color = link.from_socket.color_simple
  775. if hasattr(link.from_socket, "color"):
  776. self.inputs['B'].color = link.from_socket.color
  777. class UtilityChoose(Node, MantisNode):
  778. """Chooses an output"""
  779. bl_idname = "UtilityChoose"
  780. bl_label = "Choose"
  781. bl_icon = "NODE"
  782. initialized : bpy.props.BoolProperty(default = False)
  783. def init(self, context):
  784. self.inputs.new("BooleanSocket", "Condition")
  785. self.inputs.new("WildcardSocket", "A")
  786. self.inputs.new("WildcardSocket", "B")
  787. self.outputs.new("WildcardSocket", "Result")
  788. self.initialized = True
  789. def update(self):
  790. wildcard_color = (0.0,0.0,0.0,0.0)
  791. if self.inputs['A'].is_linked == False:
  792. self.inputs['A'].color = wildcard_color
  793. self.outputs['Result'].color = (1.0,0.0,0.0,0.0) # red for Error
  794. if self.inputs['B'].is_linked == False:
  795. self.inputs['B'].color = wildcard_color
  796. self.outputs['Result'].color = (1.0,0.0,0.0,0.0)
  797. # if both inputs are the same color, then use that color for the result
  798. if self.inputs['A'].is_linked and self.inputs['A'].color == self.inputs['B'].color:
  799. self.outputs['Result'].color = self.inputs['A'].color
  800. #
  801. if ((self.inputs['A'].is_linked and self.inputs['B'].is_linked) and
  802. (self.inputs['A'].links[0].from_socket.bl_idname != self.inputs['B'].links[0].from_socket.bl_idname)):
  803. self.inputs['A'].color = (1.0,0.0,0.0,0.0)
  804. self.inputs['B'].color = (1.0,0.0,0.0,0.0)
  805. self.outputs['Result'].color = (1.0,0.0,0.0,0.0)
  806. def insert_link(self, link):
  807. if link.to_socket.identifier == self.inputs['A'].identifier:
  808. self.inputs['A'].color = from_socket.color_simple
  809. if hasattr(from_socket, "color"):
  810. self.inputs['A'].color = from_socket.color
  811. if link.to_socket.identifier == self.inputs['B'].identifier:
  812. self.inputs['B'].color = from_socket.color_simple
  813. if hasattr(from_socket, "color"):
  814. self.inputs['B'].color = from_socket.color
  815. class UtilityPrint(Node, MantisNode):
  816. """A utility used to print arbitrary values."""
  817. bl_idname = "UtilityPrint"
  818. bl_label = "Print"
  819. bl_icon = "NODE"
  820. initialized : bpy.props.BoolProperty(default = False)
  821. def init(self, context):
  822. self.inputs.new("WildcardSocket", "Input")
  823. self.initialized = True