misc_nodes_ui.py 39 KB

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