nodes_generic.py 38 KB

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