-
Notifications
You must be signed in to change notification settings - Fork 55
/
__init__.py
97 lines (80 loc) · 3.66 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
# This script is Free software. Please share and reuse.
# ♡2010-2022 Adam Dominec <[email protected]>
bl_info = {
"name": "Export Paper Model",
"author": "Addam Dominec",
"version": (1, 3),
"blender": (3, 0, 0),
"location": "File > Export > Paper Model",
"warning": "",
"description": "Export printable net of the active mesh",
"doc_url": "{BLENDER_MANUAL_URL}/addons/import_export/paper_model.html",
"category": "Import-Export",
}
# TODO:
# QuickSweepline is very much broken -- it throws GeometryError for all nets > ~15 faces
# check conflicts in island naming and either:
# * append a number to the conflicting names or
# * enumerate faces uniquely within all islands of the same name (requires a check that both label and abbr. equals)
import bpy
from . import operator
def factory_update_addon_category(cls, prop):
def func(self, context):
if hasattr(bpy.types, cls.__name__):
bpy.utils.unregister_class(cls)
cls.bl_category = self[prop]
bpy.utils.register_class(cls)
return func
class PaperAddonPreferences(bpy.types.AddonPreferences):
bl_idname = __name__
unfold_category: bpy.props.StringProperty(
name="Unfold Panel Category", description="Category in 3D View Toolbox where the Unfold panel is displayed",
default="Paper", update=factory_update_addon_category(operator.VIEW3D_PT_paper_model_tools, 'unfold_category'))
export_category: bpy.props.StringProperty(
name="Export Panel Category", description="Category in 3D View Toolbox where the Export panel is displayed",
default="Paper", update=factory_update_addon_category(operator.VIEW3D_PT_paper_model_settings, 'export_category'))
def draw(self, context):
sub = self.layout.column(align=True)
sub.use_property_split = True
sub.label(text="3D View Panel Category:")
sub.prop(self, "unfold_category", text="Unfold Panel:")
sub.prop(self, "export_category", text="Export Panel:")
module_classes = (
operator.Unfold,
operator.ExportPaperModel,
operator.ClearAllSeams,
operator.SelectIsland,
operator.FaceList,
operator.IslandList,
operator.PaperModelSettings,
operator.DATA_PT_paper_model_islands,
operator.VIEW3D_PT_paper_model_tools,
operator.VIEW3D_PT_paper_model_settings,
PaperAddonPreferences,
)
def register():
for cls in module_classes:
bpy.utils.register_class(cls)
bpy.types.Scene.paper_model = bpy.props.PointerProperty(
name="Paper Model", description="Settings of the Export Paper Model script",
type=operator.PaperModelSettings, options={'SKIP_SAVE'})
bpy.types.Mesh.paper_island_list = bpy.props.CollectionProperty(
name="Island List", type=operator.IslandList)
bpy.types.Mesh.paper_island_index = bpy.props.IntProperty(
name="Island List Index",
default=-1, min=-1, max=100, options={'SKIP_SAVE'}, update=operator.island_index_changed)
bpy.types.TOPBAR_MT_file_export.append(operator.menu_func_export)
bpy.types.VIEW3D_MT_edit_mesh.prepend(operator.menu_func_unfold)
# Force an update on the panel category properties
prefs = bpy.context.preferences.addons[__name__].preferences
prefs.unfold_category = prefs.unfold_category
prefs.export_category = prefs.export_category
def unregister():
bpy.types.TOPBAR_MT_file_export.remove(operator.menu_func_export)
bpy.types.VIEW3D_MT_edit_mesh.remove(operator.menu_func_unfold)
del bpy.types.Scene.paper_model
del bpy.types.Mesh.paper_island_list
del bpy.types.Mesh.paper_island_index
for cls in reversed(module_classes):
bpy.utils.unregister_class(cls)