nodes_generic.py 37 KB

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