__init__.py 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. from . import ( ops_nodegroup,
  2. base_definitions,
  3. socket_definitions,
  4. link_definitions,
  5. xForm_definitions,
  6. nodes_generic,
  7. primitives_definitions,
  8. deformer_definitions,
  9. math_definitions,
  10. i_o,
  11. schema_definitions,
  12. )
  13. from .ops_generate_tree import GenerateMantisTree
  14. from bpy.types import NodeSocket
  15. from .utilities import prRed
  16. classLists = [module.TellClasses() for module in [
  17. link_definitions,
  18. xForm_definitions,
  19. base_definitions,
  20. nodes_generic,
  21. socket_definitions,
  22. ops_nodegroup,
  23. primitives_definitions,
  24. deformer_definitions,
  25. math_definitions,
  26. i_o,
  27. schema_definitions,
  28. ]]
  29. # lol
  30. classLists.append( [GenerateMantisTree] )
  31. #
  32. classes = []
  33. while (classLists):
  34. classes.extend(classLists.pop())
  35. interface_classes = []
  36. from bpy import app
  37. # if app.version[0] == 3:
  38. # for cls in [cls for cls in socket_definitions.TellClasses() if issubclass(cls, NodeSocket)]:
  39. # name = cls.__name__+"Interface"
  40. # from bpy.types import NodeSocketInterface
  41. # def default_draw_color(self, context,):
  42. # return self.color
  43. # def default_draw(self, context, layout):
  44. # return
  45. # interface = type(
  46. # name,
  47. # (NodeSocketInterface,),
  48. # {
  49. # "color" : cls.color,
  50. # "draw_color" : default_draw_color,
  51. # "draw" : default_draw,
  52. # "bl_idname" : name,
  53. # "bl_socket_idname" : cls.__name__,
  54. # },
  55. # )
  56. # interface_classes.append(interface)
  57. # classes.extend(interface_classes)
  58. import nodeitems_utils
  59. from nodeitems_utils import NodeCategory, NodeItem
  60. class MantisNodeCategory(NodeCategory):
  61. @classmethod
  62. def poll(cls, context):
  63. return (context.space_data.tree_type in ['MantisTree', 'SchemaTree'])
  64. class SchemaNodeCategory(NodeCategory):
  65. @classmethod
  66. def poll(cls, context):
  67. # doesn't seem to work tho
  68. try:
  69. return (context.space_data.path[len(path)-1].node_tree.bl_idname == 'SchemaTree')
  70. except:
  71. return True
  72. input_category=[
  73. NodeItem("InputFloatNode"),
  74. NodeItem("InputVectorNode"),
  75. NodeItem("InputBooleanNode"),
  76. # NodeItem("InputBooleanThreeTupleNode"),
  77. # NodeItem("InputRotationOrderNode"),
  78. # NodeItem("InputTransformSpaceNode"),
  79. NodeItem("InputStringNode"),
  80. NodeItem("InputIntNode"),
  81. # NodeItem("InputQuaternionNode"),
  82. # NodeItem("InputQuaternionNodeAA"),
  83. NodeItem("InputMatrixNode"),
  84. NodeItem("InputLayerMaskNode"),
  85. NodeItem("InputExistingGeometryObject"),
  86. NodeItem("InputExistingGeometryData"),
  87. ]
  88. link_transform_category = [
  89. NodeItem("LinkCopyLocation"),
  90. NodeItem("LinkCopyRotation"),
  91. NodeItem("LinkCopyScale"),
  92. NodeItem("LinkCopyTransforms"),
  93. NodeItem("LinkLimitLocation"),
  94. NodeItem("LinkLimitScale"),
  95. NodeItem("LinkLimitRotation"),
  96. NodeItem("LinkLimitDistance"),
  97. NodeItem("LinkTransformation"),
  98. ]
  99. link_tracking_category = [
  100. NodeItem("LinkInverseKinematics"),
  101. NodeItem("LinkSplineIK"),
  102. NodeItem("LinkStretchTo"),
  103. NodeItem("LinkDampedTrack"),
  104. NodeItem("LinkLockedTrack"),
  105. NodeItem("LinkTrackTo"),
  106. ]
  107. link_relationship_category = [
  108. NodeItem("linkInherit"),
  109. NodeItem("LinkInheritConstraint"),
  110. NodeItem("LinkArmature"),
  111. ]
  112. deformer_category=[NodeItem(cls.bl_idname) for cls in deformer_definitions.TellClasses()]
  113. xForm_category = [
  114. NodeItem("xFormGeometryObject"),
  115. # NodeItem("xFormNullNode"),
  116. NodeItem("xFormBoneNode"),
  117. NodeItem("xFormRootNode"),
  118. NodeItem("xFormArmatureNode"),
  119. ]
  120. driver_category = [
  121. NodeItem("LinkDrivenParameter"),
  122. NodeItem("UtilityFCurve"),
  123. NodeItem("UtilityBoneProperties"),
  124. NodeItem("UtilityDriverVariable"),
  125. NodeItem("UtilitySwitch"),
  126. NodeItem("UtilityDriver"),
  127. NodeItem("UtilityKeyframe"),
  128. ]
  129. geometry_category = [
  130. NodeItem("GeometryCirclePrimitive"),
  131. ]
  132. utility_category = [
  133. NodeItem("MathStaticInt"),
  134. NodeItem("MathStaticFloat"),
  135. NodeItem("MathStaticVector"),
  136. NodeItem("UtilityCatStrings"),
  137. NodeItem("UtilityCombineThreeBool"),
  138. NodeItem("UtilityCombineVector"),
  139. NodeItem("UtilityIntToString"),
  140. NodeItem("UtilityArrayGet"),
  141. NodeItem("UtilityChoose"),
  142. NodeItem("UtilityCompare"),
  143. NodeItem("UtilityPrint"),
  144. ]
  145. matrix_category = [
  146. NodeItem("UtilityMetaRig"),
  147. NodeItem("UtilityMatrixFromCurve"),
  148. NodeItem("UtilityMatricesFromCurve"),
  149. NodeItem("UtilityPointFromBoneMatrix"),
  150. NodeItem("UtilitySetBoneLength"),
  151. NodeItem("UtilityGetBoneLength"),
  152. NodeItem("UtilityBoneMatrixHeadTailFlip"),
  153. NodeItem("UtilityMatrixSetLocation"),
  154. NodeItem("UtilityMatrixGetLocation"),
  155. NodeItem("UtilityMatrixFromXForm"),
  156. NodeItem("UtilityAxesFromMatrix"),
  157. NodeItem("UtilityMatrixTransform"),
  158. NodeItem("UtilityTransformationMatrix"),
  159. ]
  160. groups_category = [
  161. NodeItem("MantisNodeGroup"),
  162. NodeItem("MantisSchemaGroup"),
  163. ]
  164. # THIS is stupid, should be filled out automatically
  165. node_categories = [
  166. # identifier, label, items list
  167. MantisNodeCategory('INPUT', "Input", items=input_category),
  168. # MantisNodeCategory('LINK', "Link", items=[]),
  169. # MantisNodeCategory('LINK_TRACKING', "Link", items=[]),
  170. MantisNodeCategory('LINK_TRANSFORM', "Link (Transform)", items=link_transform_category),
  171. MantisNodeCategory('LINK_TRACKING', "Link (Tracking)", items=link_tracking_category),
  172. MantisNodeCategory('LINK_RELATIONSHIP', "Link (Inheritance)", items=link_relationship_category),
  173. MantisNodeCategory('DEFORMER', "Deformer", items=deformer_category),
  174. MantisNodeCategory('XFORM', "Transform", items=xForm_category),
  175. MantisNodeCategory('DRIVER', "Driver", items=driver_category),
  176. MantisNodeCategory('GEOMETRY', "Geometry", items =geometry_category),
  177. MantisNodeCategory('UTILITIES', "Utility", items=utility_category),
  178. MantisNodeCategory('MATRIX', "Matrix", items=matrix_category),
  179. MantisNodeCategory('GROUPS', "Groups", items=groups_category),
  180. ]
  181. schema_category=[NodeItem(cls.bl_idname) for cls in schema_definitions.TellClasses()]
  182. schema_categories = [
  183. SchemaNodeCategory('SCHEMA_SCHEMA', "Schema", items=schema_category),
  184. ]
  185. import bpy
  186. def init_keymaps():
  187. kc = bpy.context.window_manager.keyconfigs.addon
  188. km = kc.keymaps.new(name="Node Generic", space_type='NODE_EDITOR')
  189. kmi = [
  190. # Normal operation
  191. km.keymap_items.new("mantis.group_nodes", 'G', 'PRESS', ctrl=True),
  192. km.keymap_items.new("mantis.edit_group", 'TAB', 'PRESS'),
  193. km.keymap_items.new("mantis.execute_node_tree", 'E', 'PRESS'),
  194. km.keymap_items.new("mantis.mute_node", 'M', 'PRESS'),
  195. km.keymap_items.new("mantis.nodes_cleanup", "C", 'PRESS', shift=True,),
  196. # Testing
  197. km.keymap_items.new("mantis.query_sockets", 'Q', 'PRESS'),
  198. km.keymap_items.new("mantis.test_operator", 'T', 'PRESS'),
  199. km.keymap_items.new("mantis.visualize_output", 'V', 'PRESS'),
  200. # Saving, Loading, Reloading, etc.
  201. km.keymap_items.new("mantis.export_save_choose", "S", 'PRESS', alt=True,),
  202. km.keymap_items.new("mantis.export_save_as", "S", 'PRESS', alt=True, shift=True),
  203. km.keymap_items.new("mantis.reload_tree", "R", 'PRESS', alt=True,),
  204. km.keymap_items.new("mantis.import_tree", "O", 'PRESS', ctrl=True,),
  205. ]
  206. return km, kmi
  207. addon_keymaps = []
  208. def register():
  209. from bpy.utils import register_class
  210. for cls in classes:
  211. try:
  212. register_class(cls)
  213. except RuntimeError as e:
  214. prRed(cls.__name__)
  215. raise e
  216. nodeitems_utils.register_node_categories('MantisNodeCategories', node_categories)
  217. nodeitems_utils.register_node_categories('SchemaNodeCategories', schema_categories)
  218. if (not bpy.app.background):
  219. km, kmi = init_keymaps()
  220. for k in kmi:
  221. k.active = True
  222. addon_keymaps.append((km, k))
  223. def unregister():
  224. nodeitems_utils.unregister_node_categories('MantisNodeCategories')
  225. nodeitems_utils.unregister_node_categories('SchemaNodeCategories')
  226. from bpy.utils import unregister_class
  227. for cls in reversed(classes):
  228. unregister_class(cls)
  229. for km, kmi in addon_keymaps:
  230. km.keymap_items.remove(kmi)
  231. addon_keymaps.clear()