nodes_generic.py 39 KB

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