-
Notifications
You must be signed in to change notification settings - Fork 14
/
in_out_mvr.py
125 lines (92 loc) · 3.62 KB
/
in_out_mvr.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
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
import bpy
import os
from .logging import DMX_Log
from bpy_extras.io_utils import ImportHelper, ExportHelper
if bpy.app.version >= (4, 2):
from bpy_extras.io_utils import poll_file_object_drop
from bpy.props import (
StringProperty,
CollectionProperty,
)
from bpy.types import Operator
from threading import Timer
def createDMXcollection():
dmx = bpy.context.scene.dmx
if not dmx.collection:
bpy.context.scene.dmx.new()
class DMX_OT_Import_MVR(Operator, ImportHelper):
"""Import My Virtual Rig"""
bl_idname = "dmx.import_mvr_into_scene"
bl_label = "Import MVR (.mvr)"
bl_options = {"PRESET", "UNDO"}
filename_ext = ".mvr"
filter_glob: StringProperty(default="*.mvr", options={"HIDDEN"})
files: CollectionProperty(type=bpy.types.OperatorFileListElement, options={"HIDDEN", "SKIP_SAVE"})
directory: StringProperty(subtype="DIR_PATH")
def draw(self, context):
dmx = context.scene.dmx
if not dmx.collection:
Timer(0.5, createDMXcollection, ()).start()
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
def execute(self, context):
dmx = context.scene.dmx
for file in self.files:
if not file.name:
continue
file_path = os.path.join(self.directory, file.name)
print("INFO", f"Processing MVR file: {file_path}")
dmx.addMVR(file_path)
return {"FINISHED"}
class DMX_OT_Export_MVR(Operator, ExportHelper):
"""Export My Virtual Rig"""
bl_idname = "dmx.export_mvr_from_scene"
bl_label = "Export MVR (.mvr)"
bl_options = {"PRESET", "UNDO"}
filename_ext = ".mvr"
def draw(self, context):
dmx = context.scene.dmx
if not dmx.collection:
Timer(0.5, createDMXcollection, ()).start()
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
def execute(self, context):
dmx = context.scene.dmx
DMX_Log.log.info(self.filepath)
result = dmx.export_mvr(self.filepath)
if result.ok:
self.report({"INFO"}, "Data exported to: {}".format(self.filepath))
else:
self.report({"ERROR"}, result.error)
return {"FINISHED"}
if bpy.app.version >= (4, 1):
class DMX_IO_FH_MVR(bpy.types.FileHandler):
bl_idname = "IO_FH_mvr"
bl_label = "MVR"
bl_import_operator = "dmx.import_mvr_into_scene"
bl_export_operator = "dmx.export_mvr_from_scene"
bl_file_extensions = ".mvr"
@classmethod
def poll_drop(cls, context):
if bpy.app.version >= (4, 2):
return poll_file_object_drop(context)
def menu_func_export(self, context):
self.layout.operator(DMX_OT_Export_MVR.bl_idname, text="My Virtual Rig (.mvr) from BlenderDMX")
def menu_func_import(self, context):
self.layout.operator(DMX_OT_Import_MVR.bl_idname, text="My Virtual Rig (.mvr) into BlenderDMX")
def register():
bpy.utils.register_class(DMX_OT_Import_MVR)
bpy.utils.register_class(DMX_OT_Export_MVR)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
if bpy.app.version >= (4, 1):
bpy.utils.register_class(DMX_IO_FH_MVR)
def unregister():
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
if bpy.app.version >= (4, 1):
bpy.utils.unregister_class(DMX_IO_FH_MVR)
bpy.utils.unregister_class(DMX_OT_Import_MVR)
bpy.utils.unregister_class(DMX_OT_Export_MVR)