misc_nodes_ui.py 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. import bpy
  2. from bpy.types import Node
  3. from .base_definitions import MantisUINode
  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. InputMatrixNode,
  18. # InputGeometryNode,
  19. InputExistingGeometryObjectNode,
  20. InputExistingGeometryDataNode,
  21. UtilityGeometryOfXForm,
  22. UtilityNameOfXForm,
  23. # ComposeMatrixNode,
  24. MetaRigMatrixNode,
  25. UtilityPointFromCurve,
  26. UtilityMatrixFromCurve,
  27. UtilityMatricesFromCurve,
  28. UtilityNumberOfCurveSegments,
  29. UtilityMatrixFromCurveSegment,
  30. # ScaleBoneLengthNode,
  31. UtilityMetaRigNode,
  32. UtilityBonePropertiesNode,
  33. UtilityDriverVariableNode,
  34. UtilityFCurveNode,
  35. UtilityDriverNode,
  36. UtilitySwitchNode,
  37. UtilityKeyframe,
  38. UtilityCombineThreeBoolNode,
  39. UtilityCombineVectorNode,
  40. UtilitySeparateVector,
  41. UtilityCatStringsNode,
  42. UtilityGetBoneLength,
  43. UtilityPointFromBoneMatrix,
  44. UtilitySetBoneLength,
  45. UtilityMatrixSetLocation,
  46. UtilityMatrixGetLocation,
  47. UtilityMatrixFromXForm,
  48. UtilityAxesFromMatrix,
  49. UtilityBoneMatrixHeadTailFlip,
  50. UtilityMatrixTransform,
  51. UtilityTransformationMatrix,
  52. UtilitySetBoneMatrixTail,
  53. UtilityIntToString,
  54. UtilityArrayGet,
  55. #
  56. UtilityCompare,
  57. UtilityChoose,
  58. # for testing
  59. UtilityPrint,
  60. ]
  61. def default_traverse(self,socket):
  62. return None
  63. class InputFloatNode(Node, MantisUINode):
  64. '''A node representing inheritance'''
  65. bl_idname = 'InputFloatNode'
  66. bl_label = "Float"
  67. bl_icon = 'NODE'
  68. initialized : bpy.props.BoolProperty(default = False)
  69. mantis_node_class_name=bl_idname[:-4]
  70. def init(self, context):
  71. self.outputs.new('FloatSocket', "Float Input").input = True
  72. self.initialized = True
  73. class InputIntNode(Node, MantisUINode):
  74. '''A node representing inheritance'''
  75. bl_idname = 'InputIntNode'
  76. bl_label = "Integer"
  77. bl_icon = 'NODE'
  78. initialized : bpy.props.BoolProperty(default = False)
  79. mantis_node_class_name=bl_idname
  80. def init(self, context):
  81. self.outputs.new('IntSocket', "Integer").input = True
  82. self.initialized = True
  83. class InputVectorNode(Node, MantisUINode):
  84. '''A node representing inheritance'''
  85. bl_idname = 'InputVectorNode'
  86. bl_label = "Vector"
  87. bl_icon = 'NODE'
  88. initialized : bpy.props.BoolProperty(default = False)
  89. mantis_node_class_name=bl_idname[:-4]
  90. def init(self, context):
  91. self.outputs.new('VectorSocket', "").input = True
  92. self.initialized = True
  93. class InputBooleanNode(Node, MantisUINode):
  94. '''A node representing inheritance'''
  95. bl_idname = 'InputBooleanNode'
  96. bl_label = "Boolean"
  97. bl_icon = 'NODE'
  98. initialized : bpy.props.BoolProperty(default = False)
  99. mantis_node_class_name=bl_idname[:-4]
  100. def init(self, context):
  101. self.outputs.new('BooleanSocket', "").input = True
  102. self.initialized = True
  103. class InputBooleanThreeTupleNode(Node, MantisUINode):
  104. '''A node representing inheritance'''
  105. bl_idname = 'InputBooleanThreeTupleNode'
  106. bl_label = "Boolean Vector"
  107. bl_icon = 'NODE'
  108. initialized : bpy.props.BoolProperty(default = False)
  109. mantis_node_class_name=bl_idname[:-4]
  110. def init(self, context):
  111. self.outputs.new('BooleanThreeTupleSocket', "")
  112. self.initialized = True
  113. class InputRotationOrderNode(Node, MantisUINode):
  114. '''A node representing inheritance'''
  115. bl_idname = 'InputRotationOrderNode'
  116. bl_label = "Rotation Order"
  117. bl_icon = 'NODE'
  118. initialized : bpy.props.BoolProperty(default = False)
  119. mantis_node_class_name=bl_idname[:-4]
  120. def init(self, context):
  121. self.outputs.new('RotationOrderSocket', "").input = True
  122. self.initialized = True
  123. class InputTransformSpaceNode(Node, MantisUINode):
  124. '''A node representing inheritance'''
  125. bl_idname = 'InputTransformSpaceNode'
  126. bl_label = "Transform Space"
  127. bl_icon = 'NODE'
  128. initialized : bpy.props.BoolProperty(default = False)
  129. mantis_node_class_name=bl_idname[:-4]
  130. def init(self, context):
  131. self.outputs.new('TransformSpaceSocket', "").input = True
  132. self.initialized = True
  133. class InputStringNode(Node, MantisUINode):
  134. '''A node representing inheritance'''
  135. bl_idname = 'InputStringNode'
  136. bl_label = "String"
  137. bl_icon = 'NODE'
  138. initialized : bpy.props.BoolProperty(default = False)
  139. mantis_node_class_name=bl_idname[:-4]
  140. def init(self, context):
  141. self.outputs.new('StringSocket', "").input = True
  142. self.initialized = True
  143. class InputMatrixNode(Node, MantisUINode):
  144. '''A node representing inheritance'''
  145. bl_idname = 'InputMatrixNode'
  146. bl_label = "Matrix"
  147. bl_icon = 'NODE'
  148. first_row : bpy.props.FloatVectorProperty(name="", size=4, default = (1.0, 0.0, 0.0, 0.0,))
  149. second_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 1.0, 0.0, 0.0,))
  150. third_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 1.0, 0.0,))
  151. fourth_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 0.0, 1.0,))
  152. initialized : bpy.props.BoolProperty(default = False)
  153. mantis_node_class_name=bl_idname[:-4]
  154. def set_matrix(self):
  155. return (self.first_row[ 0], self.first_row[ 1], self.first_row[ 2], self.first_row[ 3],
  156. self.second_row[0], self.second_row[1], self.second_row[2], self.second_row[3],
  157. self.third_row[ 0], self.third_row[ 1], self.third_row[ 2], self.third_row[ 3],
  158. self.fourth_row[0], self.fourth_row[1], self.fourth_row[2], self.fourth_row[3],)
  159. def init(self, context):
  160. self.outputs.new('MatrixSocket', "Matrix")
  161. self.initialized = True
  162. def draw_buttons(self, context, layout):
  163. # return
  164. layout.prop(self, "first_row")
  165. layout.prop(self, "second_row")
  166. layout.prop(self, "third_row")
  167. layout.prop(self, "fourth_row")
  168. def update(self):
  169. mat_sock = self.outputs[0]
  170. mat_sock.default_value = self.set_matrix()
  171. class ScaleBoneLengthNode(Node, MantisUINode):
  172. '''Scale Bone Length'''
  173. bl_idname = 'ScaleBoneLength'
  174. bl_label = "Scale Bone Length"
  175. bl_icon = 'NODE'
  176. initialized : bpy.props.BoolProperty(default = False)
  177. # === Optional Functions ===
  178. def init(self, context):
  179. self.inputs.new('MatrixSocket', "In Matrix")
  180. self.inputs.new('FloatSocket', "Factor")
  181. self.outputs.new('MatrixSocket', "Out Matrix")
  182. self.initialized = True
  183. class MetaRigMatrixNode(Node, MantisUINode):
  184. # Identical to the above, except
  185. '''A node representing a bone's matrix'''
  186. bl_idname = 'MetaRigMatrixNode'
  187. bl_label = "Matrix"
  188. bl_icon = 'NODE'
  189. first_row : bpy.props.FloatVectorProperty(name="", size=4, default = (1.0, 0.0, 0.0, 0.0,))
  190. second_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 1.0, 0.0, 0.0,))
  191. third_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 1.0, 0.0,))
  192. fourth_row : bpy.props.FloatVectorProperty(name="", size=4, default = (0.0, 0.0, 0.0, 1.0,))
  193. initialized : bpy.props.BoolProperty(default = False)
  194. mantis_node_class_name="UtilityMetaRig"
  195. def set_matrix(self):
  196. return (self.first_row[ 0], self.first_row[ 1], self.first_row[ 2], self.first_row[ 3],
  197. self.second_row[0], self.second_row[1], self.second_row[2], self.second_row[3],
  198. self.third_row[ 0], self.third_row[ 1], self.third_row[ 2], self.third_row[ 3],
  199. self.fourth_row[0], self.fourth_row[1], self.fourth_row[2], self.fourth_row[3],)
  200. def init(self, context):
  201. self.outputs.new('MatrixSocket', "Matrix")
  202. self.initialized = True
  203. def update(self):
  204. mat_sock = self.outputs[0]
  205. mat_sock.default_value = self.set_matrix()
  206. class UtilityMatrixFromCurve(Node, MantisUINode):
  207. """Gets a matrix from a curve."""
  208. bl_idname = "UtilityMatrixFromCurve"
  209. bl_label = "Matrix from Curve"
  210. bl_icon = "NODE"
  211. initialized : bpy.props.BoolProperty(default = False)
  212. mantis_node_class_name=bl_idname
  213. def init(self, context):
  214. curv = self.inputs.new("EnumCurveSocket", "Curve")
  215. self.inputs.new('IntSocket', 'Total Divisions')
  216. self.inputs.new('IntSocket', 'Matrix Index')
  217. self.outputs.new("MatrixSocket", "Matrix")
  218. self.initialized = True
  219. class UtilityPointFromCurve(Node, MantisUINode):
  220. """Gets a point from a curve."""
  221. bl_idname = "UtilityPointFromCurve"
  222. bl_label = "Point from Curve"
  223. bl_icon = "NODE"
  224. initialized : bpy.props.BoolProperty(default = False)
  225. mantis_node_class_name=bl_idname
  226. def init(self, context):
  227. curv = self.inputs.new("EnumCurveSocket", "Curve")
  228. self.inputs.new('FloatFactorSocket', 'Factor')
  229. self.outputs.new("VectorSocket", "Point")
  230. self.initialized = True
  231. class UtilityNumberOfCurveSegments(Node, MantisUINode):
  232. """Tells the number of segments in a curve."""
  233. bl_idname = "UtilityNumberOfCurveSegments"
  234. bl_label = "Number of Curve Segments"
  235. bl_icon = "NODE"
  236. initialized : bpy.props.BoolProperty(default = False)
  237. mantis_node_class_name=bl_idname
  238. def init(self, context):
  239. self.inputs.new("EnumCurveSocket", "Curve")
  240. self.inputs.new('UnsignedIntSocket', 'Spline Index')
  241. self.outputs.new("UnsignedIntSocket", "Number of Segments")
  242. self.initialized = True
  243. class UtilityMatrixFromCurveSegment(Node, MantisUINode):
  244. """Gets a matrix from a curve segment."""
  245. bl_idname = "UtilityMatrixFromCurveSegment"
  246. bl_label = "Matrix from Curve Segment"
  247. bl_icon = "NODE"
  248. initialized : bpy.props.BoolProperty(default = False)
  249. mantis_node_class_name=bl_idname
  250. def init(self, context):
  251. self.inputs.new("EnumCurveSocket", "Curve")
  252. self.inputs.new('UnsignedIntSocket', 'Spline Index')
  253. self.inputs.new('UnsignedIntSocket', 'Segment Index')
  254. self.outputs.new("MatrixSocket", "Matrix")
  255. self.initialized = True
  256. class UtilityMatricesFromCurve(Node, MantisUINode):
  257. """Gets a matrix from a curve."""
  258. bl_idname = "UtilityMatricesFromCurve"
  259. bl_label = "Matrices from Curve"
  260. bl_icon = "NODE"
  261. initialized : bpy.props.BoolProperty(default = False)
  262. mantis_node_class_name=bl_idname
  263. def init(self, context):
  264. curv = self.inputs.new("EnumCurveSocket", "Curve")
  265. curv.icon = "OUTLINER_OB_CURVE"
  266. self.inputs.new('IntSocket', 'Total Divisions')
  267. o = self.outputs.new("MatrixSocket", "Matrices")
  268. o.display_shape = 'SQUARE_DOT'
  269. self.initialized = True
  270. class UtilityMetaRigNode(Node, MantisUINode):
  271. """Gets a matrix from a meta-rig bone."""
  272. bl_idname = "UtilityMetaRig"
  273. bl_label = "Meta-Rig"
  274. bl_icon = "NODE"
  275. armature:bpy.props.StringProperty()
  276. pose_bone:bpy.props.StringProperty()
  277. initialized : bpy.props.BoolProperty(default = False)
  278. mantis_node_class_name=bl_idname
  279. def init(self, context):
  280. armt = self.inputs.new("EnumMetaRigSocket", "Meta-Armature")
  281. bone = self.inputs.new("EnumMetaBoneSocket", "Meta-Bone")
  282. bone.hide=True
  283. self.outputs.new("MatrixSocket", "Matrix")
  284. self.initialized = True
  285. def display_update(self, parsed_tree, context):
  286. from .base_definitions import get_signature_from_edited_tree
  287. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  288. if nc:
  289. self.armature= nc.evaluate_input("Meta-Armature")
  290. self.pose_bone= nc.evaluate_input("Meta-Bone")
  291. if not self.armature:
  292. self.inputs["Meta-Bone"].hide=True
  293. else:
  294. self.inputs["Meta-Bone"].hide=False
  295. if self.inputs["Meta-Armature"].is_linked:
  296. self.inputs["Meta-Armature"].search_prop = None
  297. if self.inputs["Meta-Bone"].is_linked:
  298. self.inputs["Meta-Bone"].search_prop = None
  299. class UtilityBonePropertiesNode(Node, MantisUINode):
  300. """Provides as sockets strings identifying bone transform properties."""
  301. bl_idname = "UtilityBoneProperties"
  302. bl_label = "Bone Properties"
  303. bl_icon = "NODE"
  304. #bl_width_default = 250
  305. initialized : bpy.props.BoolProperty(default = False)
  306. mantis_node_class_name=bl_idname
  307. def init(self, context):
  308. self.outputs.new("StringSocket", "matrix")
  309. self.outputs.new("StringSocket", "matrix_local")
  310. self.outputs.new("StringSocket", "matrix_basis")
  311. self.outputs.new("StringSocket", "head")
  312. self.outputs.new("StringSocket", "tail")
  313. self.outputs.new("StringSocket", "length")
  314. self.outputs.new("StringSocket", "rotation")
  315. self.outputs.new("StringSocket", "location")
  316. self.outputs.new("StringSocket", "scale")
  317. self.initialized = True
  318. class UtilityDriverVariableNode(Node, MantisUINode):
  319. """Creates a variable for use in a driver."""
  320. bl_idname = "UtilityDriverVariable"
  321. bl_label = "Driver Variable"
  322. bl_icon = "NODE"
  323. initialized : bpy.props.BoolProperty(default = False)
  324. mantis_node_class_name=bl_idname
  325. def init(self, context):
  326. self.inputs.new("EnumDriverVariableType", "Variable Type") # 0
  327. self.inputs.new("ParameterStringSocket", "Property") # 1
  328. self.inputs.new("IntSocket", "Property Index") # 2
  329. self.inputs.new("EnumDriverVariableEvaluationSpace", "Evaluation Space") # 3
  330. self.inputs.new("EnumDriverRotationMode", "Rotation Mode") # 4
  331. self.inputs.new("xFormSocket", "xForm 1") # 5
  332. self.inputs.new("xFormSocket", "xForm 2") # 6
  333. self.outputs.new("DriverVariableSocket", "Driver Variable")
  334. self.inputs[3].hide = True
  335. self.initialized = True
  336. def display_update(self, parsed_tree, context):
  337. from .base_definitions import get_signature_from_edited_tree
  338. if self.inputs["Variable Type"].is_linked:
  339. if context.space_data:
  340. node_tree = context.space_data.path[0].node_tree
  341. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  342. if nc:
  343. driver_type = nc.evaluate_input("Variable Type")
  344. else:
  345. driver_type = self.inputs[0].default_value
  346. if driver_type == 'SINGLE_PROP':
  347. self.inputs[1].hide = False
  348. self.inputs[2].hide = False
  349. self.inputs[3].hide = False
  350. self.inputs[4].hide = False
  351. self.inputs[5].hide = False
  352. self.inputs[6].hide = True
  353. elif driver_type == 'LOC_DIFF':
  354. self.inputs[1].hide = True
  355. self.inputs[2].hide = True
  356. self.inputs[3].hide = True
  357. self.inputs[4].hide = True
  358. self.inputs[5].hide = False
  359. self.inputs[6].hide = False
  360. elif driver_type == 'ROTATION_DIFF':
  361. self.inputs[1].hide = True
  362. self.inputs[2].hide = True
  363. self.inputs[3].hide = True
  364. self.inputs[4].hide = False
  365. self.inputs[5].hide = False
  366. self.inputs[6].hide = False
  367. elif driver_type == 'TRANSFORMS':
  368. self.inputs[1].hide = True
  369. self.inputs[2].hide = True
  370. self.inputs[3].hide = False
  371. self.inputs[4].hide = False
  372. self.inputs[5].hide = False
  373. self.inputs[6].hide = True
  374. # TODO: make a way to edit the fCurve directly.
  375. # I had a working version of this in the past, but it required doing sinful things like
  376. # keeping track of the RAM address of the window.
  377. class UtilityFCurveNode(Node, MantisUINode):
  378. """Creates an fCurve for use with a driver."""
  379. bl_idname = "UtilityFCurve"
  380. bl_label = "fCurve"
  381. bl_icon = "NODE"
  382. use_kf_nodes : bpy.props.BoolProperty(default=True)
  383. initialized : bpy.props.BoolProperty(default = False)
  384. mantis_node_class_name=bl_idname
  385. def init(self, context):
  386. self.inputs.new("eFCrvExtrapolationMode", "Extrapolation Mode")
  387. self.outputs.new("FCurveSocket", "fCurve")
  388. self.initialized = True
  389. def draw_buttons(self, context, layout):
  390. layout.operator( 'mantis.fcurve_node_add_kf' )
  391. if (len(self.inputs) > 1):
  392. layout.operator( 'mantis.fcurve_node_remove_kf' )
  393. class UtilityDriverNode(Node, MantisUINode):
  394. """Represents a Driver relationship"""
  395. bl_idname = "UtilityDriver"
  396. bl_label = "Driver"
  397. bl_icon = "NODE"
  398. initialized : bpy.props.BoolProperty(default = False)
  399. mantis_node_class_name=bl_idname
  400. def init(self, context):
  401. self.inputs.new("EnumDriverType", "Driver Type")
  402. self.inputs.new("FCurveSocket", "fCurve")
  403. self.inputs.new("StringSocket", "Expression")
  404. self.outputs.new("DriverSocket", "Driver")
  405. self.initialized = True
  406. def display_update(self, parsed_tree, context):
  407. if not self.inputs["Driver Type"].is_linked:
  408. dType = self.inputs["Driver Type"].default_value
  409. from .base_definitions import get_signature_from_edited_tree
  410. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  411. if nc:
  412. dType = nc.evaluate_input("Driver Type")
  413. if dType == 'SCRIPTED':
  414. self.inputs["Expression"].hide = False
  415. else:
  416. self.inputs["Expression"].hide = True
  417. def draw_buttons(self, context, layout):
  418. # return
  419. layout.operator( 'mantis.driver_node_add_variable' )
  420. if (len(self.inputs) > 3):
  421. layout.operator( 'mantis.driver_node_remove_variable' )
  422. class UtilitySwitchNode(Node, MantisUINode):
  423. """Represents a switch relationship between one driver property and one or more driven properties."""
  424. bl_idname = "UtilitySwitch"
  425. bl_label = "Switch"
  426. bl_icon = "NODE"
  427. initialized : bpy.props.BoolProperty(default = False)
  428. mantis_node_class_name=bl_idname
  429. def init(self, context):
  430. # self.inputs.new("xFormSocket", "xForm")
  431. self.inputs.new("ParameterStringSocket", "Parameter")
  432. self.inputs.new("IntSocket", "Parameter Index")
  433. self.inputs.new("BooleanSocket", "Invert Switch")
  434. self.outputs.new("DriverSocket", "Driver")
  435. self.initialized = True
  436. class UtilityCombineThreeBoolNode(Node, MantisUINode):
  437. """Combines three booleans into a three-bool."""
  438. bl_idname = "UtilityCombineThreeBool"
  439. bl_label = "CombineThreeBool"
  440. bl_icon = "NODE"
  441. initialized : bpy.props.BoolProperty(default = False)
  442. mantis_node_class_name=bl_idname
  443. def init(self, context):
  444. self.inputs.new("BooleanSocket", "X")
  445. self.inputs.new("BooleanSocket", "Y")
  446. self.inputs.new("BooleanSocket", "Z")
  447. self.outputs.new("BooleanThreeTupleSocket", "Three-Bool")
  448. self.initialized = True
  449. class UtilityCombineVectorNode(Node, MantisUINode):
  450. """Combines three floats into a vector."""
  451. bl_idname = "UtilityCombineVector"
  452. bl_label = "CombineVector"
  453. bl_icon = "NODE"
  454. initialized : bpy.props.BoolProperty(default = False)
  455. mantis_node_class_name=bl_idname
  456. def init(self, context):
  457. self.inputs.new("FloatSocket", "X")
  458. self.inputs.new("FloatSocket", "Y")
  459. self.inputs.new("FloatSocket", "Z")
  460. self.outputs.new("VectorSocket", "Vector")
  461. self.initialized = True
  462. class UtilitySeparateVector(Node, MantisUINode):
  463. """Separates a vector into three floats"""
  464. bl_idname = "UtilitySeparateVector"
  465. bl_label = "Separate Vector"
  466. bl_icon = "NODE"
  467. initialized : bpy.props.BoolProperty(default = False)
  468. mantis_node_class_name=bl_idname
  469. def init(self, context):
  470. self.inputs.new("VectorSocket", "Vector")
  471. self.outputs.new("FloatSocket", "X")
  472. self.outputs.new("FloatSocket", "Y")
  473. self.outputs.new("FloatSocket", "Z")
  474. self.initialized = True
  475. class UtilityCatStringsNode(Node, MantisUINode):
  476. """Adds a suffix to a string"""
  477. bl_idname = "UtilityCatStrings"
  478. bl_label = "Concatenate Strings"
  479. bl_icon = "NODE"
  480. initialized : bpy.props.BoolProperty(default = False)
  481. mantis_node_class_name=bl_idname
  482. def init(self, context):
  483. self.inputs.new("StringSocket", "String_1")
  484. self.inputs.new("StringSocket", "String_2")
  485. self.outputs.new("StringSocket", "OutputString")
  486. self.initialized = True
  487. def draw_label(self): # this will prefer a user-set label, or return the evaluated name
  488. if self.label:
  489. return self.label
  490. if self.outputs['OutputString'].display_text:
  491. return self.outputs['OutputString'].display_text
  492. return self.name
  493. def display_update(self, parsed_tree, context):
  494. from .base_definitions import get_signature_from_edited_tree
  495. if context.space_data:
  496. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  497. self.inputs['String_1'].display_text = ""
  498. self.inputs['String_2'].display_text = ""
  499. self.outputs['OutputString'].display_text = ""
  500. if nc:
  501. try:
  502. self.inputs['String_1'].display_text = a = nc.evaluate_input("String_1")
  503. self.inputs['String_2'].display_text = b = nc.evaluate_input("String_2")
  504. # cat the strings here, since the node may not have run yet.
  505. self.outputs['OutputString'].display_text = a+b
  506. except KeyError:
  507. return # the tree isn't ready yet.
  508. class InputLayerMaskNode(Node, MantisUINode):
  509. """Represents a layer mask for a bone."""
  510. bl_idname = "InputLayerMaskNode"
  511. bl_label = "Layer Mask"
  512. bl_icon = "NODE"
  513. initialized : bpy.props.BoolProperty(default = False)
  514. mantis_node_class_name=bl_idname
  515. def init(self, context):
  516. self.outputs.new("LayerMaskInputSocket", "Layer Mask")
  517. self.initialized = True
  518. class InputExistingGeometryObjectNode(Node, MantisUINode):
  519. """Represents an existing geometry object from within the scene."""
  520. bl_idname = "InputExistingGeometryObject"
  521. bl_label = "Existing Object"
  522. bl_icon = "NODE"
  523. initialized : bpy.props.BoolProperty(default = False)
  524. mantis_node_class_name=bl_idname
  525. # We want Mantis to import widgets and stuff, so we hold a reference to the object
  526. object_reference : bpy.props.PointerProperty(type=bpy.types.Object,)
  527. def init(self, context):
  528. self.inputs.new("StringSocket", "Name")
  529. self.outputs.new("xFormSocket", "Object")
  530. self.initialized = True
  531. def display_update(self, parsed_tree, context):
  532. from .base_definitions import get_signature_from_edited_tree
  533. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  534. if nc: # this is done here so I don't have to define yet another custom socket.
  535. self.object_reference = bpy.data.objects.get(nc.evaluate_input("Name"))
  536. # TODO: maybe I should hold a data reference here, too.
  537. # but it is complicated by the fact that Mantis does not distinguish b/tw geo types
  538. class InputExistingGeometryDataNode(Node, MantisUINode):
  539. """Represents a mesh or curve datablock from the scene."""
  540. bl_idname = "InputExistingGeometryData"
  541. bl_label = "Existing Geometry"
  542. bl_icon = "NODE"
  543. initialized : bpy.props.BoolProperty(default = False)
  544. mantis_node_class_name=bl_idname
  545. def init(self, context):
  546. self.inputs.new("StringSocket", "Name")
  547. self.outputs.new("GeometrySocket", "Geometry")
  548. self.initialized = True
  549. class UtilityGeometryOfXForm(Node, MantisUINode):
  550. """Retrieves a mesh or curve datablock from an xForm."""
  551. bl_idname = "UtilityGeometryOfXForm"
  552. bl_label = "Geometry of xForm"
  553. bl_icon = "NODE"
  554. initialized : bpy.props.BoolProperty(default = False)
  555. mantis_node_class_name=bl_idname
  556. def init(self, context):
  557. self.inputs.new("xFormSocket", "xForm")
  558. self.outputs.new("GeometrySocket", "Geometry")
  559. self.initialized = True
  560. class UtilityNameOfXForm(Node, MantisUINode):
  561. """Retrieves the name of a xForm."""
  562. bl_idname = "UtilityNameOfXForm"
  563. bl_label = "Name of xForm"
  564. bl_icon = "NODE"
  565. initialized : bpy.props.BoolProperty(default = False)
  566. mantis_node_class_name=bl_idname
  567. def init(self, context):
  568. self.inputs.new("xFormSocket", "xForm")
  569. self.outputs.new("StringSocket", "Name")
  570. self.initialized = True
  571. class UtilityGetBoneLength(Node, MantisUINode):
  572. """Returns the length of the bone from its matrix."""
  573. bl_idname = "UtilityGetBoneLength"
  574. bl_label = "Get Bone Length"
  575. bl_icon = "NODE"
  576. initialized : bpy.props.BoolProperty(default = False)
  577. mantis_node_class_name=bl_idname
  578. def init(self, context):
  579. self.inputs.new("MatrixSocket", "Bone Matrix")
  580. self.outputs.new("FloatSocket", "Bone Length")
  581. self.initialized = True
  582. # TODO: make it work with BBones!
  583. class UtilityPointFromBoneMatrix(Node, MantisUINode):
  584. """Returns a point representing the location along a bone, given a matrix representing that bone's shape."""
  585. bl_idname = "UtilityPointFromBoneMatrix"
  586. bl_label = "Point from Bone Matrix"
  587. bl_icon = "NODE"
  588. initialized : bpy.props.BoolProperty(default = False)
  589. mantis_node_class_name=bl_idname
  590. def init(self, context):
  591. self.inputs.new("MatrixSocket", "Bone Matrix")
  592. self.inputs.new("FloatFactorSocket", "Head/Tail")
  593. self.outputs.new("VectorSocket", "Point")
  594. self.initialized = True
  595. class UtilitySetBoneLength(Node, MantisUINode):
  596. """Sets the length of a bone matrix."""
  597. bl_idname = "UtilitySetBoneLength"
  598. bl_label = "Set Bone Matrix Length"
  599. bl_icon = "NODE"
  600. initialized : bpy.props.BoolProperty(default = False)
  601. mantis_node_class_name=bl_idname
  602. def init(self, context):
  603. self.inputs.new("MatrixSocket", "Bone Matrix")
  604. self.inputs.new("FloatSocket", "Length")
  605. self.outputs.new("MatrixSocket", "Bone Matrix")
  606. self.initialized = True
  607. # TODO: more keyframe types should be supported in the future.
  608. # Some of the code that can do this is commented out here until I can implement it properly.
  609. class UtilityKeyframe(Node, MantisUINode):
  610. """A keyframe for a FCurve"""
  611. bl_idname = "UtilityKeyframe"
  612. bl_label = "KeyFrame"
  613. bl_icon = "NODE"
  614. initialized : bpy.props.BoolProperty(default = False)
  615. mantis_node_class_name=bl_idname
  616. def init(self, context):
  617. # x and y
  618. # output is keyframe
  619. # self.inputs.new("EnumKeyframeInterpolationTypeSocket", "Interpolation")
  620. # self.inputs.new("EnumKeyframeBezierHandleType", "Left Handle Type")
  621. # self.inputs.new("EnumKeyframeBezierHandleType", "Right Handle Type")
  622. # self.inputs.new("FloatSocket", "Left Handle Distance")
  623. # self.inputs.new("FloatSocket", "Left Handle Value")
  624. # self.inputs.new("FloatSocket", "Right Handle Frame")
  625. # self.inputs.new("FloatSocket", "Right Handle Value")
  626. self.inputs.new("FloatSocket", "Frame")
  627. self.inputs.new("FloatSocket", "Value")
  628. self.outputs.new("KeyframeSocket", "Keyframe")
  629. # there will eventually be inputs for e.g. key type, key handles, etc.
  630. # right now I am gonna hardcode LINEAR keyframes so I don't have to deal with anything else
  631. # TODO TODO TODO
  632. # def display_update(self, parsed_tree, context):
  633. # if context.space_data:
  634. # nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  635. # if nc.evaluate_input("Interpolation") in ["CONSTANT", "LINEAR"]:
  636. # for inp in self.inputs[1:6]:
  637. # inp.hide = True
  638. # else:
  639. # if nc.evaluate_input("Left Handle Type") in ["FREE", "ALIGNED"]:
  640. # for inp in self.inputs[1:6]:
  641. # inp.hide = False
  642. self.initialized = True
  643. class UtilityBoneMatrixHeadTailFlip(Node, MantisUINode):
  644. """Flips a bone matrix so that the head is where the tail was and visa versa."""
  645. bl_idname = "UtilityBoneMatrixHeadTailFlip"
  646. bl_label = "Flip Head/Tail"
  647. bl_icon = "NODE"
  648. initialized : bpy.props.BoolProperty(default = False)
  649. mantis_node_class_name=bl_idname
  650. def init(self, context):
  651. self.inputs.new("MatrixSocket", "Bone Matrix")
  652. self.outputs.new("MatrixSocket", "Bone Matrix")
  653. self.initialized = True
  654. class UtilityMatrixTransform(Node, MantisUINode):
  655. """Transforms a matrix by another."""
  656. bl_idname = "UtilityMatrixTransform"
  657. bl_label = "Matrix Transform"
  658. bl_icon = "NODE"
  659. initialized : bpy.props.BoolProperty(default = False)
  660. mantis_node_class_name=bl_idname
  661. def init(self, context):
  662. self.inputs.new("MatrixSocket", "Matrix 1")
  663. self.inputs.new("MatrixSocket", "Matrix 2")
  664. self.outputs.new("MatrixSocket", "Out Matrix")
  665. self.initialized = True
  666. class UtilityMatrixSetLocation(Node, MantisUINode):
  667. """Sets a matrix's location."""
  668. bl_idname = "UtilityMatrixSetLocation"
  669. bl_label = "Set Matrix Location"
  670. bl_icon = "NODE"
  671. initialized : bpy.props.BoolProperty(default = False)
  672. mantis_node_class_name=bl_idname
  673. def init(self, context):
  674. self.inputs.new("MatrixSocket", "Matrix")
  675. self.inputs.new("VectorSocket", "Location")
  676. self.outputs.new("MatrixSocket", "Matrix")
  677. self.initialized = True
  678. class UtilityMatrixGetLocation(Node, MantisUINode):
  679. """Gets a matrix's location."""
  680. bl_idname = "UtilityMatrixGetLocation"
  681. bl_label = "Get Matrix Location"
  682. bl_icon = "NODE"
  683. initialized : bpy.props.BoolProperty(default = False)
  684. mantis_node_class_name=bl_idname
  685. def init(self, context):
  686. self.inputs.new("MatrixSocket", "Matrix")
  687. self.outputs.new("VectorSocket", "Location")
  688. self.initialized = True
  689. class UtilityTransformationMatrix(Node, MantisUINode):
  690. """Constructs a matrix representing a transformation"""
  691. bl_idname = "UtilityTransformationMatrix"
  692. bl_label = "Transformation Matrix"
  693. bl_icon = "NODE"
  694. initialized : bpy.props.BoolProperty(default = False)
  695. mantis_node_class_name=bl_idname
  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. def display_update(self, parsed_tree, context):
  709. from .base_definitions import get_signature_from_edited_tree
  710. operation = self.inputs['Operation'].default_value
  711. if self.inputs['Operation'].is_linked:
  712. if context.space_data:
  713. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  714. operation = nc.evaluate_input("Operation")
  715. if operation in ["ROTATE_AXIS_ANGLE", "SCALE"]:
  716. self.inputs["Vector"].hide = False
  717. self.inputs["W"].hide = False
  718. if operation in ["TRANSLATE"]:
  719. self.inputs["Vector"].hide = False
  720. self.inputs["W"].hide = True
  721. # Blender calculates bone roll this way...
  722. # https://projects.blender.org/blender/blender/src/commit/dd209221675ac7b62ce47b7ea42f15cbe34a6035/source/blender/editors/armature/armature_edit.cc#L281
  723. # 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
  724. # in the edit bone.
  725. # So instead, we need to avoid calculating the roll for now.
  726. # but I want to make that its own node and add roll-recalc to this node, too.
  727. class UtilitySetBoneMatrixTail(Node, MantisUINode):
  728. """Constructs a matrix representing a transformation"""
  729. bl_idname = "UtilitySetBoneMatrixTail"
  730. bl_label = "Set Bone Matrix Tail"
  731. bl_icon = "NODE"
  732. initialized : bpy.props.BoolProperty(default = False)
  733. mantis_node_class_name=bl_idname
  734. def init(self, context):
  735. self.inputs.new("MatrixSocket", "Matrix")
  736. self.inputs.new("VectorSocket", "Tail Location")
  737. self.outputs.new("MatrixSocket", "Result")
  738. self.initialized = True
  739. class UtilityMatrixFromXForm(Node, MantisUINode):
  740. """Returns the matrix of the given xForm node."""
  741. bl_idname = "UtilityMatrixFromXForm"
  742. bl_label = "Matrix of xForm"
  743. bl_icon = "NODE"
  744. initialized : bpy.props.BoolProperty(default = False)
  745. mantis_node_class_name=bl_idname
  746. def init(self, context):
  747. self.inputs.new("xFormSocket", "xForm")
  748. self.outputs.new("MatrixSocket", "Matrix")
  749. self.initialized = True
  750. class UtilityAxesFromMatrix(Node, MantisUINode):
  751. """Returns the axes of the matrix."""
  752. bl_idname = "UtilityAxesFromMatrix"
  753. bl_label = "Axes of Matrix"
  754. bl_icon = "NODE"
  755. initialized : bpy.props.BoolProperty(default = False)
  756. mantis_node_class_name=bl_idname
  757. def init(self, context):
  758. self.inputs.new("MatrixSocket", "Matrix")
  759. self.outputs.new("VectorSocket", "X Axis")
  760. self.outputs.new("VectorSocket", "Y Axis")
  761. self.outputs.new("VectorSocket", "Z Axis")
  762. self.initialized = True
  763. class UtilityIntToString(Node, MantisUINode):
  764. """Converts a number to a string"""
  765. bl_idname = "UtilityIntToString"
  766. bl_label = "Number String"
  767. bl_icon = "NODE"
  768. initialized : bpy.props.BoolProperty(default = False)
  769. mantis_node_class_name=bl_idname
  770. def init(self, context):
  771. self.inputs.new("IntSocket", "Number")
  772. self.inputs.new("IntSocket", "Zero Padding")
  773. self.outputs.new("StringSocket", "String")
  774. self.initialized = True
  775. class UtilityArrayGet(Node, MantisUINode):
  776. """Gets a value from an array at a specified index."""
  777. bl_idname = "UtilityArrayGet"
  778. bl_label = "Array Get"
  779. bl_icon = "NODE"
  780. initialized : bpy.props.BoolProperty(default = False)
  781. mantis_node_class_name=bl_idname
  782. def init(self, context):
  783. self.inputs.new('EnumArrayGetOptions', 'OoB Behaviour')
  784. self.inputs.new("IntSocket", "Index")
  785. s = self.inputs.new("WildcardSocket", "Array", use_multi_input=True)
  786. s.display_shape = 'SQUARE_DOT'
  787. self.outputs.new("WildcardSocket", "Output")
  788. self.initialized = True
  789. def update(self):
  790. wildcard_color = (0.0,0.0,0.0,0.0)
  791. if self.inputs['Array'].is_linked == False:
  792. self.inputs['Array'].color = wildcard_color
  793. self.outputs['Output'].color = wildcard_color
  794. def insert_link(self, link):
  795. super().insert_link(link)
  796. prGreen(link.from_node.name, link.from_socket.identifier, link.to_node.name, link.to_socket.identifier)
  797. if link.to_socket.identifier == self.inputs['Array'].identifier:
  798. from_socket = link.from_socket
  799. print (from_socket.color)
  800. if hasattr(from_socket, "color"):
  801. self.inputs['Array'].color = from_socket.color
  802. self.outputs['Output'].color = from_socket.color
  803. class UtilityCompare(Node, MantisUINode):
  804. """Compares two inputs and produces a boolean output"""
  805. bl_idname = "UtilityCompare"
  806. bl_label = "Compare"
  807. bl_icon = "NODE"
  808. initialized : bpy.props.BoolProperty(default = False)
  809. mantis_node_class_name=bl_idname
  810. def init(self, context):
  811. self.inputs.new("WildcardSocket", "A")
  812. self.inputs.new("WildcardSocket", "B")
  813. self.outputs.new("BooleanSocket", "Result")
  814. self.initialized = True
  815. def update(self):
  816. wildcard_color = (0.0,0.0,0.0,0.0)
  817. if self.inputs['A'].is_linked == False:
  818. self.inputs['A'].color = wildcard_color
  819. if self.inputs['B'].is_linked == False:
  820. self.inputs['B'].color = wildcard_color
  821. def insert_link(self, link):
  822. super().insert_link(link)
  823. if link.to_socket.identifier == self.inputs['A'].identifier:
  824. self.inputs['A'].color = link.from_socket.color_simple
  825. if hasattr(link.from_socket, "color"):
  826. self.inputs['A'].color = link.from_socket.color
  827. if link.to_socket.identifier == self.inputs['B'].identifier:
  828. self.inputs['B'].color = link.from_socket.color_simple
  829. if hasattr(link.from_socket, "color"):
  830. self.inputs['B'].color = link.from_socket.color
  831. class UtilityChoose(Node, MantisUINode):
  832. """Chooses an output"""
  833. bl_idname = "UtilityChoose"
  834. bl_label = "Choose"
  835. bl_icon = "NODE"
  836. initialized : bpy.props.BoolProperty(default = False)
  837. mantis_node_class_name=bl_idname
  838. def init(self, context):
  839. self.inputs.new("BooleanSocket", "Condition")
  840. self.inputs.new("WildcardSocket", "A")
  841. self.inputs.new("WildcardSocket", "B")
  842. self.outputs.new("WildcardSocket", "Result")
  843. self.initialized = True
  844. def display_update(self, parsed_tree, context):
  845. wildcard_color = (0.0,0.0,0.0,0.0)
  846. if not self.inputs['A'].is_linked:
  847. self.inputs['A'].color = wildcard_color
  848. if not self.inputs['B'].is_linked:
  849. self.inputs['B'].color = wildcard_color
  850. self.outputs['Result'].color = wildcard_color
  851. # if both inputs are the same color, then use that color for the result
  852. if self.inputs['Condition'].is_linked:
  853. from .base_definitions import get_signature_from_edited_tree
  854. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  855. if nc:
  856. condition = nc.evaluate_input('Condition')
  857. else:
  858. condition = self.inputs['Condition'].default_value
  859. if condition == True:
  860. self.outputs['Result'].color = self.inputs['B'].color
  861. else:
  862. self.outputs['Result'].color = self.inputs['A'].color
  863. def insert_link(self, link):
  864. super().insert_link(link)
  865. if link.to_socket.identifier == self.inputs['A'].identifier:
  866. self.inputs['A'].color = link.from_socket.color_simple
  867. if hasattr(link.from_socket, "color"):
  868. self.inputs['A'].color = link.from_socket.color
  869. if link.to_socket.identifier == self.inputs['B'].identifier:
  870. self.inputs['B'].color = link.from_socket.color_simple
  871. if hasattr(link.from_socket, "color"):
  872. self.inputs['B'].color = link.from_socket.color
  873. class UtilityPrint(Node, MantisUINode):
  874. """A utility used to print arbitrary values."""
  875. bl_idname = "UtilityPrint"
  876. bl_label = "Print"
  877. bl_icon = "NODE"
  878. initialized : bpy.props.BoolProperty(default = False)
  879. mantis_node_class_name=bl_idname
  880. def init(self, context):
  881. self.inputs.new("WildcardSocket", "Input")
  882. self.initialized = True
  883. # Set up the class property that ties the UI classes to the Mantis classes.
  884. for cls in TellClasses():
  885. cls.mantis_node_library='.misc_nodes'
  886. cls.set_mantis_class()