nodes_generic.py 36 KB

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