forked from Spyduck/voxwriter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
68 lines (53 loc) · 1.84 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
bl_info = {
"name": "VoxWriter",
"author": "Spyduck",
"version": (0,2),
"blender": (2,80,0),
"location": "File > Export > MagicaVoxel (.vox)",
"description": "Export to MagicaVoxel .vox",
"category": "Export"}
import bpy
from bpy_extras.io_utils import ExportHelper
from bpy.props import StringProperty, BoolProperty, IntProperty, EnumProperty
from bpy.types import Operator
class ExportSomeData(Operator, ExportHelper):
"""Export the selected object to a MagicaVoxel .vox"""
bl_idname = "export_vox.some_data"
bl_label = "MagicaVoxel (.vox)"
# ExportHelper mixin class uses this
filename_ext = ".vox"
filter_glob: StringProperty(
default="*.vox",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
voxel_detail: IntProperty(
name="Voxel Detail",
description="Voxel Detail",
default=32,
)
use_default_palette: BoolProperty(
name="Use default palette",
description="Use default palette",
default=False,
)
def execute(self, context):
from .writer import voxelize
print("running voxelize...")
voxelize(context.active_object, self.filepath, vox_detail=max(0,min(126,self.voxel_detail)), use_default_palette=self.use_default_palette)
return {'FINISHED'}
# Only needed if you want to add into a dynamic menu
def menu_func_export(self, context):
self.layout.operator(ExportSomeData.bl_idname, text="MagicaVoxel (.vox)")
def register():
bpy.utils.register_class(ExportSomeData)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
def unregister():
bpy.utils.unregister_class(ExportSomeData)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
if __name__ == "__main__":
register()
# test call
bpy.ops.export_vox.some_data('INVOKE_DEFAULT')