-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
89 lines (63 loc) · 2.43 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
import os
import sys
from pathlib import Path
bl_info = {
"name": "Pragma Engine model(.wmd)",
"author": "RED_EYE, Silverlan",
"version": (0, 0, 5),
"blender": (2, 80, 0),
"location": "File > Import-Export > Import Pragma WMD file",
"description": "Import/Export Pragma models",
"category": "Import-Export"
}
import bpy
from bpy.props import StringProperty, BoolProperty, CollectionProperty, EnumProperty
from .model_import import import_model
from . import wmd_nodes
class PyWMDPreferences(bpy.types.AddonPreferences):
bl_idname = __package__
sfm_path: StringProperty(default='', name='SFM path')
def draw(self, context):
layout = self.layout
# layout.label(text='Enter SFM install path:')
# row = layout.row()
# row.prop(self, 'sfm_path')
# noinspection PyUnresolvedReferences
class WMD_import_OT_operator(bpy.types.Operator):
"""Load Pragma Engine WMD models"""
bl_idname = "py_wmd.wmd"
bl_label = "Import Pragma WMD file"
bl_options = {'UNDO'}
filepath: StringProperty(subtype="FILE_PATH")
files: CollectionProperty(name='File paths', type=bpy.types.OperatorFileListElement)
import_textures: BoolProperty(name="Load textures", default=False, subtype='UNSIGNED')
filter_glob: StringProperty(default="*.wmd", options={'HIDDEN'})
def execute(self, context):
if Path(self.filepath).is_file():
directory = Path(self.filepath).parent.absolute()
else:
directory = Path(self.filepath).absolute()
for file in self.files:
import_model(str(directory / file.name))
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
class CUSTOM_objectCollection(bpy.types.PropertyGroup):
# name: StringProperty() -> Instantiated by default
pass
classes = (PyWMDPreferences, WMD_import_OT_operator, CUSTOM_objectCollection)
register_, unregister_ = bpy.utils.register_classes_factory(classes)
def menu_import(self, context):
self.layout.operator(WMD_import_OT_operator.bl_idname, text="Pragma model (.wmd)")
def register():
register_()
wmd_nodes.register_nodes()
bpy.types.TOPBAR_MT_file_import.append(menu_import)
def unregister():
bpy.types.TOPBAR_MT_file_import.remove(menu_import)
wmd_nodes.unregister_nodes()
unregister_()
if __name__ == "__main__":
register()