nodes_generic.py 38 KB

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