From a55b72a6a9b8522a555183bb797cb220c3e82773 Mon Sep 17 00:00:00 2001 From: Eirfire Date: Fri, 27 May 2022 09:17:45 +1000 Subject: [PATCH] Update 0.0.4 new things added and bug fixes --- Sago Zip/__init__.py | 211 ++++++++++++++++++++++++++++++---------- Sago Zip/changelogs.txt | 35 +++++++ Sago Zip/hello_world.py | 23 ----- Sago Zip/operators.py | 85 +++++++++------- Sago Zip/ui_menus.py | 35 ++++--- Sago Zip/ui_panels.py | 19 +--- 6 files changed, 273 insertions(+), 135 deletions(-) create mode 100644 Sago Zip/changelogs.txt delete mode 100644 Sago Zip/hello_world.py diff --git a/Sago Zip/__init__.py b/Sago Zip/__init__.py index 751d096..393f662 100644 --- a/Sago Zip/__init__.py +++ b/Sago Zip/__init__.py @@ -18,22 +18,20 @@ bl_info = { "name": "Sago", - "description": "Extra render settings STILL IN EARLY STAGES OF DEVOLMENT", + "description": "Extra render settings and quick acces tool", "author": "Jacob Samorowksi", - "version": (0, 0, 3), + "version": (0, 0, 4), "blender": (2, 83, 0), "location": "3d View > Tool shelf", - "warning": "make sure that all your files are saved before clicking shutdown computer otherwise you will lose files i take no responsibility for the lose of files and make sure that the blend file is saved before rendering as it will not work", + "warning": "Make sure other files on computer are saved", "doc_url": "https://github.com/Eirfire/Blender-addon/wiki", "tracker_url": "https://github.com/Eirfire/Blender-addon/issues", "support": "COMMUNITY", - "category": "Generic" + "category": "Generic", } #import blender python modules -from cProfile import label -from unicodedata import name import bpy import bmesh from bpy.props import (StringProperty, BoolProperty, IntProperty, FloatProperty, FloatVectorProperty, EnumProperty, PointerProperty,) @@ -46,14 +44,15 @@ from math import * #import classes from files -from . hello_world import ( - hello_world, -) from . operators import( MESH_OT_MONKEY_grid, camera_settings, - NODE_OT_customgroup, SAGO_OT_add_displace, + sago_mod_subsurf, + sago_mod_displace, + sago_mod_array, + sago_mod_wireframe, + toggle_face_orientation, ) from . ui_panels import( @@ -64,7 +63,8 @@ ) from . ui_menus import( - WM_MT_pie_menu, + SAGO_MT_pie_menu, + ) @@ -72,31 +72,6 @@ #------------------------------------------------------------------------------------------ #Custom Properties #------------------------------------------------------------------------------------------ -class sago_addon_properties(AddonPreferences): - bl_idname = __name__ - - - - def draw(self, context): - layout = self.layout - wm = context.window_manager - box = layout.box() - row = box.row() - col = row.column() - - box.label(text='Test box') - box.label(text='in the addon there are many different operators and menus:\n') - box.label(text='locations of items:') - box.label(text='1. Pie menu- Hotkey = Mouse button 4') - box.label(text='2. side panel - 3D view > toolshelf > sago') - - box.label(text='IMPORTANT!!! This addon is still in early devolment and there will be bugs so sorrybut please let me know if youand i try and fix them ASAP') - - box.label(text='Thank Jacob') - - col.operator("wm.url_open", text="Resport Issues").url = "https://github.com/Eirfire/Sago-Extra-Render-Addon/issues" - - class SagoProperties(PropertyGroup): @@ -132,25 +107,170 @@ class SagoProperties(PropertyGroup): default=0.5, min=0, soft_max=1, ) + +#prefence that go in the addon aera in prefences for the addon +class sago_addon_properties(AddonPreferences): + bl_idname = __name__ + tabs: EnumProperty( + name="Tabs", + items=[ + ("GENERAL", "General", ""), + ("INFO", "Info", ""), + ("KEYMAP", "Keymap", ""), + ], + default="GENERAL", + ) + #main drawing panel with the tabs + def draw(self, context): + layout = self.layout + + column = layout.column(align=True) + row = column.row() + row.prop(self, "tabs", expand=True) + + box = layout.box() + + if self.tabs == "GENERAL": + self.draw_general(box) + elif self.tabs == "INFO": + self.draw_info(box) + elif self.tabs == "KEYMAP": + self.draw_keymap(box) + + #what is shown if the tab is set to general + def draw_general(self, box): + layout = self.layout + wm = bpy.context.window_manager + box = layout.box() + row = box.row() + col = row.column() + + box.label(text='version ' + str(bl_info["version"])) + box.label(text='Panel- 3D view > toolshelf > sago') + box.label(text='Pie menu - hotkey mouse button 4') + box.label(text='hotkeys can be change in the hotkeys tab') + + #what is shown if the tab is set to info + def draw_info(self, box): + layout = self.layout + wm = bpy.context.window_manager + box = layout.box() + row = box.row() + col = row.column() + + box.label(text='Test box') + box.label(text='in the addon there are many different operators and menus:\n') + box.label(text='locations of items:') + box.label(text='1. Pie menu- Hotkey = Mouse button 4') + box.label(text='2. side panel - 3D view > toolshelf > sago') + + box.label(text='IMPORTANT!!! This addon is still in early devolment and there will be bugs so sorrybut please let me know if youand i try and fix them ASAP') + + box.label(text='Thank Jacob') + + box.operator("wm.url_open", text="Resport Issues").url = "https://github.com/Eirfire/Sago-Extra-Render-Addon/issues" + + #what is shown if the tab is set to keymap + def draw_keymap(self, box): + layout = self.layout + wm = bpy.context.window_manager + box = layout.box() + row = box.row() + col = row.column() + + col.label(text='Pie menu hot key:') + wm = bpy.context.window_manager + kc = wm.keyconfigs.user + km = kc.keymaps['3D View Generic'] + kmi = get_hotkey_entry_item(km, 'wm.call_menu_pie', f'{str(pie_menu_name)}') + if kmi: + col.context_pointer_set('keymap', km) + rna_keymap_ui.draw_kmi([], kc, km, kmi, col, 0) + else: + col.label(text='No hotkey found', icon='ERROR') + col.operator('add_hotkey.sago', text='Add hotkey') + + + + + + + + +#add hotkey/ hotkeys to blender addon_keymaps = [] +pie_menu_name = SAGO_MT_pie_menu.bl_idname + +#find the hotkey in blenders keymap +def get_hotkey_entry_item(km, kmi_name, kmi_value): + + for i, km_item in enumerate(km.keymap_items): + if km.keymap_items.keys()[i] == kmi_name: + if km.keymap_items[i].properties.name == kmi_value: + return km_item + return None + +#adds the hotkey to blenders keymap +def add_hotkey(): + + addon_prefs = bpy.context.preferences.addons[__name__].preferences + + kc = bpy.context.window_manager.keyconfigs.addon + if kc: + km = kc.keymaps.new(name='3D View Generic', space_type='VIEW_3D', region_type='WINDOW') + kmi = km.keymap_items.new('wm.call_menu_pie', type='BUTTON4MOUSE', value='PRESS', ctrl=False, shift=False, alt=False) + kmi.properties.name = f'{str(pie_menu_name)}' + kmi.active = True + addon_keymaps.append((km, kmi)) + +#removes the hotkey from blenders keymap +def remove_hotkey(): + + for km, kmi in addon_keymaps: + km.keymap_items.remove(kmi) + + addon_keymaps.clear() + +#if get_hotkey_entry_item can't find a hotkey this will be called in the pannel +class USERPREF_OT_change_hotkey(Operator): + '''Add hotkey''' + bl_idname = "add_hotkey.sago" + bl_label = "Add Hotkey" + bl_options = {'REGISTER', 'INTERNAL'} + + def execute(self, context): + add_hotkey() + return {'FINISHED'} + + + + + + +#add all classes to be registered classes = ( #panels VEIW3D_PT_Main_Panel, VEIW3D_PT_ExtraRender, NODE_PT_customPanel, #menus - WM_MT_pie_menu, + SAGO_MT_pie_menu, #properties SagoProperties, sago_addon_properties, + USERPREF_OT_change_hotkey, #operators MESH_OT_MONKEY_grid, - NODE_OT_customgroup, camera_settings, SAGO_OT_add_displace, + sago_mod_subsurf, + sago_mod_displace, + sago_mod_array, + sago_mod_wireframe, + toggle_face_orientation, ) # Register @@ -174,14 +294,8 @@ def register(): for cls in classes: bpy.utils.register_class(cls) - #add a keymap for pie menu - wm = bpy.context.window_manager - kc = wm.keyconfigs.addon - if kc: - km = kc.keymaps.new(name='3D View', space_type='VIEW_3D') - kmi = km.keymap_items.new("wm.call_menu_pie", type='BUTTON4MOUSE', value='PRESS') - kmi.properties.name = "WM_MT_pie_menu" - addon_keymaps.append((km,kmi)) + #add hotkey/ hotkeys + add_hotkey() #register custom properties bpy.types.Scene.sago = PointerProperty(type=SagoProperties) @@ -193,11 +307,10 @@ def unregister(): for cls in classes: bpy.utils.unregister_class(cls) #unregister keymaps - for km,kmi in addon_keymaps: - km.keymap_items.remove(kmi) - addon_keymaps.clear() + remove_hotkey() #unregister properties del bpy.types.Scene.sago +#makes the file an executable file and reduces errors in code if __name__ == "__main__": register() \ No newline at end of file diff --git a/Sago Zip/changelogs.txt b/Sago Zip/changelogs.txt new file mode 100644 index 0000000..dce3e16 --- /dev/null +++ b/Sago Zip/changelogs.txt @@ -0,0 +1,35 @@ +welcome to the change logs for Sago + +creidt to the poeple below for the use of their addons for refence for my own code: +Addon: Bagapie > by: Antoine Bagattini +Addon: ND-v1.27.0 > by: HugeMenace + + + + + + +V 0.0.4 +Overall changes: +- Bug fixes +- General improvements +- made things look nicer with newer Formats + +Operators: + new operators: + > face orientation- shows normals of a faces + > add modifiers - modifers: displace, subsurf, array, wireframe + + +Panels: +- made things look nicer +- added it so you can save images + + +Menus: +- made the pie menu look nicer and added more things to it like modifiers and new Operators + + +Addon preferences: +- made it look nicer and easier to use +- added support to change hotkey for the pie menu diff --git a/Sago Zip/hello_world.py b/Sago Zip/hello_world.py deleted file mode 100644 index 605234b..0000000 --- a/Sago Zip/hello_world.py +++ /dev/null @@ -1,23 +0,0 @@ -#import blender python modules -from unicodedata import name -import bpy -import bmesh -from bpy.props import (StringProperty, BoolProperty, IntProperty, FloatProperty, FloatVectorProperty, EnumProperty, PointerProperty,) -from bpy.types import (Panel, Menu, Operator, PropertyGroup, AddonPreferences) -import rna_keymap_ui -#import other python modules -import os -import time -import math -from math import * - - -class hello_world(Operator): - bl_idname = "sago.hello_world" - bl_label = "says hello world" - bl_options = {"REGISTER", "UNDO"} - - def execute(self, context): - self.report({'INFO'}, "Hello World") - - return {'FINISHED'} \ No newline at end of file diff --git a/Sago Zip/operators.py b/Sago Zip/operators.py index dd71ddf..82baf45 100644 --- a/Sago Zip/operators.py +++ b/Sago Zip/operators.py @@ -1,22 +1,17 @@ #import blender python modules -from unicodedata import name import bpy +from . import bl_info import bmesh from bpy.props import (StringProperty, BoolProperty, IntProperty, FloatProperty, FloatVectorProperty, EnumProperty, PointerProperty,) from bpy.types import (Panel, Menu, Operator, PropertyGroup, AddonPreferences) -import rna_keymap_ui #import other python modules import os import time import math -from math import * +from math import* + + -class File_browse(Operator): - bl_idname = 'sago.files_browse' - bl_label = 'File Browse' - - def execute(self, context): - bpy.ops.buttons.file_browse() class MESH_OT_MONKEY_grid(bpy.types.Operator): """The Tool Tip""" @@ -207,36 +202,8 @@ def execute(self, context): return {'FINISHED'} -class NODE_OT_customgroup(Operator): - """Tooltip""" - bl_idname = "node.simple_operator" - bl_label = "sago.geoScatter" - bl_options = {'REGISTER', 'UNDO'} - - @classmethod - def poll(cls, context): - space = context.space_data - return space.type == 'NODE_EDITOR' - def execute(self, context): - - - mod = bpy.context.active_object - - for mod in mod.modifiers: - if mod.type == 'NODES': - Scatter(1) - - else: - self.report({'INFO'}, "Object needs geometry nodes") - - - - - - return {"FINISHED"} - class SAGO_OT_add_displace(Operator): bl_idname = "sago.add_displacement" bl_label = "Displace" @@ -440,3 +407,47 @@ def invoke(self, context, event): return wm.invoke_props_dialog(self) +#modifiers for pie menu +class sago_mod_subsurf(Operator): + bl_idname = "sago.modifier_subsurf" + bl_label = "Adds a subsurf modifier" + + def execute(self, context): + bpy.context.active_object.modifiers.new("Sago Subdiv", 'SUBSURF') + return {'FINISHED'} + +class sago_mod_displace(Operator): + bl_idname = "sago.modifier_displace" + bl_label = "Adds a Displacement modifier" + + def execute(self, context): + bpy.context.active_object.modifiers.new("Sago Dsiplace", 'DISPLACE') + return {'FINISHED'} + +class sago_mod_array(Operator): + bl_idname = "sago.modifier_array" + bl_label = "Adds an Array modifier" + + def execute(self, context): + bpy.context.active_object.modifiers.new("Sago array", 'ARRAY') + return {'FINISHED'} + +class sago_mod_wireframe(Operator): + bl_idname = "sago.modifier_wireframe" + bl_label = "Adds a wireframe modifier" + + def execute(self, context): + bpy.context.active_object.modifiers.new("Sago Wireframe", 'WIREFRAME') + return {'FINISHED'} + + +class toggle_face_orientation(bpy.types.Operator): + bl_idname = "sago.toggle_face_orientation" + bl_label = "Face Orientation" + bl_description = "Toggle face orientation" + + + def execute(self, context): + bpy.context.space_data.overlay.show_face_orientation = not bpy.context.space_data.overlay.show_face_orientation + + return {'FINISHED'} \ No newline at end of file diff --git a/Sago Zip/ui_menus.py b/Sago Zip/ui_menus.py index db92ce3..cb6b3c6 100644 --- a/Sago Zip/ui_menus.py +++ b/Sago Zip/ui_menus.py @@ -1,6 +1,7 @@ #import blender python modules -from unicodedata import name +from cgitb import text import bpy +from . import bl_info import bmesh from bpy.props import (StringProperty, BoolProperty, IntProperty, FloatProperty, FloatVectorProperty, EnumProperty, PointerProperty,) from bpy.types import (Panel, Menu, Operator, PropertyGroup, AddonPreferences) @@ -11,21 +12,19 @@ import math from math import * - -class WM_MT_pie_menu(Menu): +class SAGO_MT_pie_menu(Menu): # label is displayed at the center of the pie menu. - bl_label = "Select Mode" - bl_idname = "WM_MT_pie_menu" - bl_options = {"REGISTER", "UNDO"} + bl_label = "Sago" + #id label + bl_idname = "SAGO_MT_pie_menu" def draw(self, context): layout = self.layout - pie = layout.menu_pie() mode = bpy.context.object.mode if mode == "EDIT": - #Edit mode only + #only visable in edit mode only col = pie.column(align=True) col.scale_y = 1.2 col.label(text = "Mesh Operators", icon = "MESH_GRID") @@ -34,17 +33,31 @@ def draw(self, context): col.operator("mesh.select_random", icon="MOD_ARRAY") if mode == "OBJECT": + #Only visable in object mode only col = pie.column(align=True) col.scale_y = 1.2 col.label(text = "Displacement", icon = "MOD_DISPLACE") col.scale_y = 1.2 col.scale_x = 1.4 col.operator("sago.add_displacement", icon="MOD_DISPLACE") - #Any Mode + #can be scene in any Mode + #modifers + col = pie.column(align=True) + col.scale_y = 1.2 + col.label(text = "Modifers", icon = 'MODIFIER_ON') + col.scale_y = 1.2 + col.scale_x = 1.4 + col.operator("sago.modifier_displace", text = "Displace modifier", icon="MOD_DISPLACE") + col.operator("sago.modifier_subsurf",text="Subsurf modifier", icon="MOD_SUBSURF") + col.operator("sago.modifier_array",text="Array modifier", icon="MOD_ARRAY") + col.operator("sago.modifier_wireframe",text="Wireframe modifier", icon="MOD_WIREFRAME") + + #other operators like camera settings and monkey grid col = pie.column(align=True) col.scale_y = 1.2 - col.label(text = "Object", icon = "META_CUBE") + col.label(text = "Objects", icon = "META_CUBE") col.scale_y = 1.2 col.scale_x = 1.4 col.operator("sago.camera_settings", icon="VIEW_CAMERA") - col.operator("mesh.monkey_grid", icon="MONKEY") \ No newline at end of file + col.operator("mesh.monkey_grid", icon="MONKEY") + col.operator("sago.toggle_face_orientation",text="toggle face orientation", icon="NORMALS_FACE") \ No newline at end of file diff --git a/Sago Zip/ui_panels.py b/Sago Zip/ui_panels.py index 8c2bb2d..eeb749e 100644 --- a/Sago Zip/ui_panels.py +++ b/Sago Zip/ui_panels.py @@ -1,6 +1,6 @@ #import blender python modules -from unicodedata import name import bpy +from . import bl_info import bmesh from bpy.props import (StringProperty, BoolProperty, IntProperty, FloatProperty, FloatVectorProperty, EnumProperty, PointerProperty,) from bpy.types import (Panel, Menu, Operator, PropertyGroup, AddonPreferences) @@ -31,6 +31,7 @@ def draw(self, context): row.operator("mesh.primitive_uv_sphere_add", icon="MESH_UVSPHERE") row = layout.row() row.operator("mesh.monkey_grid", icon="MONKEY") + layout.operator('sago.add_displacement') layout.separator() row.operator("mesh.subdivide", icon="MESH_GRID") @@ -54,6 +55,7 @@ def draw(self, context): #change camera resolution col.prop(rd, "resolution_x", text="Resolution X") col.prop(rd, "resolution_y", text="Resolution Y") + col.operator("sago.camera_settings", text='camera settings') #add a render button props1 = col.operator("render.render", text="Render Image",icon='RENDER_STILL') props1.use_viewport = True @@ -93,6 +95,7 @@ def draw(self, context): + def some_other_function(self, dummy): sago = bpy.context.scene.sago print("Render complete") @@ -115,19 +118,6 @@ def sago_image_save(self, context): img.save_render(filepath) bpy.context.scene.save_image = False - - -class VEIW3D_PT_quick_effects(Panel): - bl_idname = "OBJECT_PT_quick_effects" - bl_label = "Quick Effects" - bl_space_type = "VIEW_3D" - bl_region_type = "UI" - bl_category = "Sago" - - def draw(self, context): - print("") - - #node editor panels class NODE_PT_customPanel(Panel): bl_label = "Custom Geo Group" @@ -141,4 +131,3 @@ def draw(self, context): col = layout.column(align=True) col.label(text='There might be something here in the future') - col.operator("sago.geoScatter", text="Geo Scatter")