Merge branch 'blender-v4.0-release'
[blender-addons.git] / object_carver / __init__.py
blob642be817387bbf9a85e9a8b7fdaecd8e36d77288
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 import bpy
19 import imp
20 from bpy.props import (
21 BoolProperty,
22 StringProperty,
23 IntProperty
25 from bpy.types import (AddonPreferences, WorkSpaceTool)
26 from bpy.utils.toolsystem import ToolDef
28 from . import carver_utils
29 imp.reload(carver_utils)
30 from . import carver_profils
31 imp.reload(carver_profils)
32 from . import carver_draw
33 imp.reload(carver_draw)
34 from . import carver_operator
35 imp.reload(carver_operator)
37 # TODO : Create an icon for Carver MT
38 # Add an icon in the toolbar
39 # class CarverTool(WorkSpaceTool):
40 # bl_space_type='VIEW_3D'
41 # bl_context_mode='OBJECT'
42 # bl_idname = "carver.operator"
43 # bl_label = "Carver"
44 # bl_description = (
45 # "Multiple tools to carve \n"
46 # "or to create objects"
47 # )
49 # #Icons : \blender-2.80\2.80\datafiles\icons
50 # #Todo: Create a new icon for Carver
51 # bl_icon = "ops.mesh.knife_tool"
52 # bl_widget = None
53 # bl_keymap = (
54 # ("carver.operator", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
55 # )
57 # def draw_settings(context, layout, tool):
58 # layout.prop(tool.operator_properties, "carver")
61 class CarverPreferences(AddonPreferences):
62 bl_idname = __name__
65 Enable_Tab_01: BoolProperty(
66 name="Info",
67 description="Some general information and settings about the add-on",
68 default=False
70 Enable_Tab_02: BoolProperty(
71 name="Hotkeys",
72 description="List of the shortcuts used during carving",
73 default=False
75 Key_Create: StringProperty(
76 name="Object creation",
77 description="Object creation",
78 maxlen=1,
79 default="C"
81 Key_Update: StringProperty(
82 name="Auto Bevel Update",
83 description="Auto Bevel Update",
84 maxlen=1,
85 default="A",
87 Key_Bool: StringProperty(
88 name="Boolean type",
89 description="Boolean operation type",
90 maxlen=1,
91 default="T",
93 Key_Brush: StringProperty(
94 name="Brush Mode",
95 description="Brush Mode",
96 maxlen=1,
97 default="B",
99 Key_Help: StringProperty(
100 name="Help display",
101 description="Help display",
102 maxlen=1,
103 default="H",
105 Key_Instant: StringProperty(
106 name="Instantiate",
107 description="Instantiate object",
108 maxlen=1,
109 default="I",
111 Key_Close: StringProperty(
112 name="Close polygonal shape",
113 description="Close polygonal shape",
114 maxlen=1,
115 default="X",
117 Key_Apply: StringProperty(
118 name="Apply operation",
119 description="Apply operation",
120 maxlen=1,
121 default="Q",
123 Key_Scale: StringProperty(
124 name="Scale object",
125 description="Scale object",
126 maxlen=1,
127 default="S",
129 Key_Gapy: StringProperty(
130 name="Gap rows",
131 description="Scale gap between columns",
132 maxlen=1,
133 default="J",
135 Key_Gapx: StringProperty(
136 name="Gap columns",
137 description="Scale gap between columns",
138 maxlen=1,
139 default="U",
141 Key_Depth: StringProperty(
142 name="Depth",
143 description="Cursor depth or solidify pattern",
144 maxlen=1,
145 default="D",
147 Key_BrushDepth: StringProperty(
148 name="Brush Depth",
149 description="Brush depth",
150 maxlen=1,
151 default="C",
153 Key_Subadd: StringProperty(
154 name="Add subdivision",
155 description="Add subdivision",
156 maxlen=1,
157 default="X",
159 Key_Subrem: StringProperty(
160 name="Remove subdivision",
161 description="Remove subdivision",
162 maxlen=1,
163 default="W",
165 Key_Randrot: StringProperty(
166 name="Random rotation",
167 description="Random rotation",
168 maxlen=1,
169 default="R",
171 ProfilePrefix: StringProperty(
172 name="Profile prefix",
173 description="Prefix to look for profiles with",
174 default="Carver_Profile-",
176 LineWidth: IntProperty(
177 name="Line Width",
178 description="Thickness of the drawing lines",
179 default=1,
181 Key_Snap: StringProperty(
182 name="Grid Snap",
183 description="Grid Snap",
184 maxlen=1,
185 default="G",
188 def draw(self, context):
189 scene = context.scene
190 layout = self.layout
192 icon_1 = "TRIA_RIGHT" if not self.Enable_Tab_01 else "TRIA_DOWN"
193 box = layout.box()
195 box.prop(self, "Enable_Tab_01", text="Info and Settings", emboss=False, icon=icon_1)
196 if self.Enable_Tab_01:
197 box.label(text="Carver Operator:", icon="LAYER_ACTIVE")
198 box.label(text="Select a Mesh Object and press [CTRL]+[SHIFT]+[X] to carve",
199 icon="LAYER_USED")
200 box.label(text="To finish carving press [ESC] or [RIGHT CLICK]",
201 icon="LAYER_USED")
202 box.prop(self, "ProfilePrefix", text="Profile prefix")
203 row = box.row(align=True)
204 row.label(text="Line width:")
205 row.prop(self, "LineWidth", text="")
207 icon_2 = "TRIA_RIGHT" if not self.Enable_Tab_02 else "TRIA_DOWN"
208 box = layout.box()
209 box.prop(self, "Enable_Tab_02", text="Keys", emboss=False, icon=icon_2)
210 if self.Enable_Tab_02:
211 split = box.split(align=True)
212 box = split.box()
213 col = box.column(align=True)
214 col.label(text="Object Creation:")
215 col.prop(self, "Key_Create", text="")
216 col.label(text="Auto bevel update:")
217 col.prop(self, "Key_Update", text="")
218 col.label(text="Boolean operation type:")
219 col.prop(self, "Key_Bool", text="")
220 col.label(text="Brush Depth:")
221 col.prop(self, "Key_BrushDepth", text="")
223 box = split.box()
224 col = box.column(align=True)
225 col.label(text="Brush Mode:")
226 col.prop(self, "Key_Brush", text="")
227 col.label(text="Help display:")
228 col.prop(self, "Key_Help", text="")
229 col.label(text="Instantiate object:")
230 col.prop(self, "Key_Instant", text="")
231 col.label(text="Random rotation:")
232 col.prop(self, "Key_Randrot", text="")
234 box = split.box()
235 col = box.column(align=True)
236 col.label(text="Close polygonal shape:")
237 col.prop(self, "Key_Close", text="")
238 col.label(text="Apply operation:")
239 col.prop(self, "Key_Apply", text="")
240 col.label(text="Scale object:")
241 col.prop(self, "Key_Scale", text="")
242 col.label(text="Subdiv add:")
243 col.prop(self, "Key_Subadd", text="")
245 box = split.box()
246 col = box.column(align=True)
247 col.label(text="Gap rows:")
248 col.prop(self, "Key_Gapy", text="")
249 col.label(text="Gap columns:")
250 col.prop(self, "Key_Gapx", text="")
251 col.label(text="Depth / Solidify:")
252 col.prop(self, "Key_Depth", text="")
253 col.label(text="Subdiv Remove:")
254 col.prop(self, "Key_Subrem", text="")
256 box = split.box()
257 col = box.column(align=True)
258 col.label(text="Grid Snap:")
259 col.prop(self, "Key_Snap", text="")
261 addon_keymaps = []
263 def register():
264 # print("Registered Carver")
266 bpy.utils.register_class(CarverPreferences)
267 # Todo : Add an icon in the toolbat
268 # bpy.utils.register_tool(CarverTool, separator=True, group=True)
269 carver_operator.register()
271 # add keymap entry
272 kcfg = bpy.context.window_manager.keyconfigs.addon
273 if kcfg:
274 km = kcfg.keymaps.new(name='3D View', space_type='VIEW_3D')
275 kmi = km.keymap_items.new("carver.operator", 'X', 'PRESS', shift=True, ctrl=True)
276 addon_keymaps.append((km, kmi))
278 def unregister():
279 # Todo : Add an icon in the toolbat
280 # bpy.utils.unregister_tool(CarverTool)
281 carver_operator.unregister()
282 bpy.utils.unregister_class(CarverPreferences)
284 # print("Unregistered Carver")
286 # remove keymap entry
287 for km, kmi in addon_keymaps:
288 km.keymap_items.remove(kmi)
289 addon_keymaps.clear()
293 if __name__ == "__main__":
294 register()