forked from cuddlyogre/ExportLDraw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperator_export.py
More file actions
190 lines (151 loc) · 5.56 KB
/
operator_export.py
File metadata and controls
190 lines (151 loc) · 5.56 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import time
import bpy
from bpy_extras.io_utils import ExportHelper
from . import export_options
from . import filesystem
from . import ldraw_colors
from . import ldraw_export
class EXPORT_OT_do_ldraw_export(bpy.types.Operator, ExportHelper):
"""Export an LDraw model File."""
bl_idname = "ldraw_exporter.export_operator"
bl_label = "Export LDraw"
bl_options = {'PRESET'}
filename_ext: bpy.props.EnumProperty(
name='File extension',
description='Choose File Format:',
items=(
('.dat', 'dat', 'Export as part'),
('.ldr', 'ldr', 'Export as model'),
# ('.mpd', 'mpd', 'Export as multi-part document'),
),
default='.dat',
)
filter_glob: bpy.props.StringProperty(
name="Extensions",
options={'HIDDEN'},
default="*.mpd;*.ldr;*.dat",
)
ldraw_path: bpy.props.StringProperty(
name="LDraw path",
description="Full filepath to the LDraw Parts Library (download from http://www.ldraw.org)",
default=filesystem.locate_ldraw(),
)
use_alt_colors: bpy.props.BoolProperty(
name="Use alternate colors",
# options={'HIDDEN'},
description="Use LDCfgalt.ldr",
default=True,
)
selection_only: bpy.props.BoolProperty(
name="Selection only",
description="Export selected objects only",
default=True,
)
recalculate_normals: bpy.props.BoolProperty(
name="Recalculate normals",
description="Recalculate normals",
default=True,
)
triangulate: bpy.props.BoolProperty(
name="Triangulate faces",
description="Triangulate all faces",
default=False,
)
remove_doubles: bpy.props.BoolProperty(
name="Remove doubles",
description="Merge overlapping verices",
default=True,
)
merge_distance: bpy.props.FloatProperty(
name="Merge distance",
description="Maximum distance between elements to merge",
default=0.05,
precision=3,
min=0.0,
)
ngon_handling: bpy.props.EnumProperty(
name="Ngon handling",
description="What to do with ngons",
default="triangulate",
items=[
("skip", "Skip", "Don't export ngons at all"),
("triangulate", "Triangulate", "Triangulate ngons"),
],
)
export_precision: bpy.props.IntProperty(
name="Export precision",
description="Round vertex coordinates to this number of places",
default=2,
min=0,
)
resolution: bpy.props.EnumProperty(
name="Part resolution",
options={'HIDDEN'},
description="Resolution of part primitives, ie. how much geometry they have",
default="Standard",
items=(
("Low", "Low resolution primitives", "Import using low resolution primitives."),
("Standard", "Standard primitives", "Import using standard resolution primitives."),
("High", "High resolution primitives", "Import using high resolution primitives."),
),
)
def execute(self, context):
start = time.monotonic()
filesystem.ldraw_path = self.ldraw_path
filesystem.resolution = self.resolution
ldraw_colors.use_alt_colors = self.use_alt_colors
export_options.selection_only = self.selection_only
export_options.export_precision = self.export_precision
export_options.remove_doubles = self.remove_doubles
export_options.merge_distance = self.merge_distance
export_options.recalculate_normals = self.recalculate_normals
export_options.triangulate = self.triangulate
export_options.ngon_handling = self.ngon_handling
ldraw_export.do_export(bpy.path.abspath(self.filepath))
print("")
print("======Export Complete======")
print(self.filepath)
end = time.monotonic()
elapsed = (end - start)
print(f"elapsed: {elapsed}")
print("===========================")
print("")
return {'FINISHED'}
def draw(self, context):
space_factor = 0.3
layout = self.layout
col = layout.column()
col.prop(self, "ldraw_path")
layout.separator(factor=space_factor)
row = layout.row()
row.label(text="File Format:")
row.prop(self, "filename_ext", expand=True)
layout.separator(factor=space_factor)
col = layout.column()
col.label(text="Export Options")
col.prop(self, "selection_only")
col.prop(self, "use_alt_colors")
col.prop(self, "export_precision")
layout.separator(factor=space_factor)
col = layout.column()
col.label(text="Cleanup Options")
col.prop(self, "remove_doubles")
col.prop(self, "merge_distance")
col.prop(self, "recalculate_normals")
col.prop(self, "triangulate")
col.prop(self, "ngon_handling")
def build_export_menu(self, context):
self.layout.operator(EXPORT_OT_do_ldraw_export.bl_idname, text="LDraw (.mpd/.ldr/.l3b/.dat)")
classesToRegister = [
EXPORT_OT_do_ldraw_export,
]
# https://wiki.blender.org/wiki/Reference/Release_Notes/2.80/Python_API/Addons
registerClasses, unregisterClasses = bpy.utils.register_classes_factory(classesToRegister)
def register():
bpy.utils.register_class(EXPORT_OT_do_ldraw_export)
bpy.types.TOPBAR_MT_file_export.append(build_export_menu)
def unregister():
bpy.utils.unregister_class(EXPORT_OT_do_ldraw_export)
bpy.types.TOPBAR_MT_file_export.remove(build_export_menu)
if __name__ == "__main__":
register()