Fix add-ons with Python 3.12 by replacing "imp" with "importlib"
[blender-addons.git] / object_carver / __init__.py
blobc91d1558624e7bf7708835882aaf6621144e58d5
1 # SPDX-FileCopyrightText: 2019-2023 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 bl_info = {
6 "name": "Carver",
7 "author": "Pixivore, Cedric LEPILLER, Ted Milker, Clarkx",
8 "description": "Multiple tools to carve or to create objects",
9 "version": (1, 2, 2),
10 "blender": (3, 4, 0),
11 "location": "3D View > Ctrl/Shift/x",
12 "warning": "",
13 "doc_url": "{BLENDER_MANUAL_URL}/addons/object/carver.html",
14 "support": 'COMMUNITY',
15 "category": "Object"
18 if "bpy" in locals():
19 import importlib
21 importlib.reload(carver_utils)
22 importlib.reload(carver_profils)
23 importlib.reload(carver_draw)
24 importlib.reload(carver_operator)
26 import bpy
28 from bpy.props import (
29 BoolProperty,
30 StringProperty,
31 IntProperty
33 from bpy.types import (AddonPreferences, WorkSpaceTool)
34 from bpy.utils.toolsystem import ToolDef
36 from . import (
37 carver_utils,
38 carver_profils,
39 carver_draw,
40 carver_operator,
43 # TODO : Create an icon for Carver MT
44 # Add an icon in the toolbar
45 # class CarverTool(WorkSpaceTool):
46 # bl_space_type='VIEW_3D'
47 # bl_context_mode='OBJECT'
48 # bl_idname = "carver.operator"
49 # bl_label = "Carver"
50 # bl_description = (
51 # "Multiple tools to carve \n"
52 # "or to create objects"
53 # )
55 # #Icons : \blender-2.80\2.80\datafiles\icons
56 # #Todo: Create a new icon for Carver
57 # bl_icon = "ops.mesh.knife_tool"
58 # bl_widget = None
59 # bl_keymap = (
60 # ("carver.operator", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
61 # )
63 # def draw_settings(context, layout, tool):
64 # layout.prop(tool.operator_properties, "carver")
67 class CarverPreferences(AddonPreferences):
68 bl_idname = __name__
71 Enable_Tab_01: BoolProperty(
72 name="Info",
73 description="Some general information and settings about the add-on",
74 default=False
76 Enable_Tab_02: BoolProperty(
77 name="Hotkeys",
78 description="List of the shortcuts used during carving",
79 default=False
81 Key_Create: StringProperty(
82 name="Object creation",
83 description="Object creation",
84 maxlen=1,
85 default="C"
87 Key_Update: StringProperty(
88 name="Auto Bevel Update",
89 description="Auto Bevel Update",
90 maxlen=1,
91 default="A",
93 Key_Bool: StringProperty(
94 name="Boolean type",
95 description="Boolean operation type",
96 maxlen=1,
97 default="T",
99 Key_Brush: StringProperty(
100 name="Brush Mode",
101 description="Brush Mode",
102 maxlen=1,
103 default="B",
105 Key_Help: StringProperty(
106 name="Help display",
107 description="Help display",
108 maxlen=1,
109 default="H",
111 Key_Instant: StringProperty(
112 name="Instantiate",
113 description="Instantiate object",
114 maxlen=1,
115 default="I",
117 Key_Close: StringProperty(
118 name="Close polygonal shape",
119 description="Close polygonal shape",
120 maxlen=1,
121 default="X",
123 Key_Apply: StringProperty(
124 name="Apply operation",
125 description="Apply operation",
126 maxlen=1,
127 default="Q",
129 Key_Scale: StringProperty(
130 name="Scale object",
131 description="Scale object",
132 maxlen=1,
133 default="S",
135 Key_Gapy: StringProperty(
136 name="Gap rows",
137 description="Scale gap between columns",
138 maxlen=1,
139 default="J",
141 Key_Gapx: StringProperty(
142 name="Gap columns",
143 description="Scale gap between columns",
144 maxlen=1,
145 default="U",
147 Key_Depth: StringProperty(
148 name="Depth",
149 description="Cursor depth or solidify pattern",
150 maxlen=1,
151 default="D",
153 Key_BrushDepth: StringProperty(
154 name="Brush Depth",
155 description="Brush depth",
156 maxlen=1,
157 default="C",
159 Key_Subadd: StringProperty(
160 name="Add subdivision",
161 description="Add subdivision",
162 maxlen=1,
163 default="X",
165 Key_Subrem: StringProperty(
166 name="Remove subdivision",
167 description="Remove subdivision",
168 maxlen=1,
169 default="W",
171 Key_Randrot: StringProperty(
172 name="Random rotation",
173 description="Random rotation",
174 maxlen=1,
175 default="R",
177 ProfilePrefix: StringProperty(
178 name="Profile prefix",
179 description="Prefix to look for profiles with",
180 default="Carver_Profile-",
182 LineWidth: IntProperty(
183 name="Line Width",
184 description="Thickness of the drawing lines",
185 default=1,
187 Key_Snap: StringProperty(
188 name="Grid Snap",
189 description="Grid Snap",
190 maxlen=1,
191 default="G",
194 def draw(self, context):
195 scene = context.scene
196 layout = self.layout
198 icon_1 = "TRIA_RIGHT" if not self.Enable_Tab_01 else "TRIA_DOWN"
199 box = layout.box()
201 box.prop(self, "Enable_Tab_01", text="Info and Settings", emboss=False, icon=icon_1)
202 if self.Enable_Tab_01:
203 box.label(text="Carver Operator:", icon="LAYER_ACTIVE")
204 box.label(text="Select a Mesh Object and press [CTRL]+[SHIFT]+[X] to carve",
205 icon="LAYER_USED")
206 box.label(text="To finish carving press [ESC] or [RIGHT CLICK]",
207 icon="LAYER_USED")
208 box.prop(self, "ProfilePrefix", text="Profile prefix")
209 row = box.row(align=True)
210 row.label(text="Line width:")
211 row.prop(self, "LineWidth", text="")
213 icon_2 = "TRIA_RIGHT" if not self.Enable_Tab_02 else "TRIA_DOWN"
214 box = layout.box()
215 box.prop(self, "Enable_Tab_02", text="Keys", emboss=False, icon=icon_2)
216 if self.Enable_Tab_02:
217 split = box.split(align=True)
218 box = split.box()
219 col = box.column(align=True)
220 col.label(text="Object Creation:")
221 col.prop(self, "Key_Create", text="")
222 col.label(text="Auto bevel update:")
223 col.prop(self, "Key_Update", text="")
224 col.label(text="Boolean operation type:")
225 col.prop(self, "Key_Bool", text="")
226 col.label(text="Brush Depth:")
227 col.prop(self, "Key_BrushDepth", text="")
229 box = split.box()
230 col = box.column(align=True)
231 col.label(text="Brush Mode:")
232 col.prop(self, "Key_Brush", text="")
233 col.label(text="Help display:")
234 col.prop(self, "Key_Help", text="")
235 col.label(text="Instantiate object:")
236 col.prop(self, "Key_Instant", text="")
237 col.label(text="Random rotation:")
238 col.prop(self, "Key_Randrot", text="")
240 box = split.box()
241 col = box.column(align=True)
242 col.label(text="Close polygonal shape:")
243 col.prop(self, "Key_Close", text="")
244 col.label(text="Apply operation:")
245 col.prop(self, "Key_Apply", text="")
246 col.label(text="Scale object:")
247 col.prop(self, "Key_Scale", text="")
248 col.label(text="Subdiv add:")
249 col.prop(self, "Key_Subadd", text="")
251 box = split.box()
252 col = box.column(align=True)
253 col.label(text="Gap rows:")
254 col.prop(self, "Key_Gapy", text="")
255 col.label(text="Gap columns:")
256 col.prop(self, "Key_Gapx", text="")
257 col.label(text="Depth / Solidify:")
258 col.prop(self, "Key_Depth", text="")
259 col.label(text="Subdiv Remove:")
260 col.prop(self, "Key_Subrem", text="")
262 box = split.box()
263 col = box.column(align=True)
264 col.label(text="Grid Snap:")
265 col.prop(self, "Key_Snap", text="")
267 addon_keymaps = []
269 def register():
270 # print("Registered Carver")
272 bpy.utils.register_class(CarverPreferences)
273 # Todo : Add an icon in the toolbat
274 # bpy.utils.register_tool(CarverTool, separator=True, group=True)
275 carver_operator.register()
277 # add keymap entry
278 kcfg = bpy.context.window_manager.keyconfigs.addon
279 if kcfg:
280 km = kcfg.keymaps.new(name='3D View', space_type='VIEW_3D')
281 kmi = km.keymap_items.new("carver.operator", 'X', 'PRESS', shift=True, ctrl=True)
282 addon_keymaps.append((km, kmi))
284 def unregister():
285 # Todo : Add an icon in the toolbat
286 # bpy.utils.unregister_tool(CarverTool)
287 carver_operator.unregister()
288 bpy.utils.unregister_class(CarverPreferences)
290 # print("Unregistered Carver")
292 # remove keymap entry
293 for km, kmi in addon_keymaps:
294 km.keymap_items.remove(kmi)
295 addon_keymaps.clear()
299 if __name__ == "__main__":
300 register()