forked from REDxEYE/SourceIO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source2_operators.py
164 lines (132 loc) · 6.06 KB
/
source2_operators.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
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
from pathlib import Path
import bpy
from bpy.props import StringProperty, BoolProperty, CollectionProperty, EnumProperty, FloatProperty
from .source2.misc.camera_loader import load_camera
from .source2.resouce_types.valve_model import ValveCompiledModel
from .source2.resouce_types.valve_texture import ValveCompiledTexture
from .source2.resouce_types.valve_material import ValveCompiledMaterial
from .source2.resouce_types.valve_world import ValveCompiledWorld
from .source_shared.content_manager import ContentManager
from .utilities.math_utilities import HAMMER_UNIT_TO_METERS
# noinspection PyUnresolvedReferences
class VMDLImport_OT_operator(bpy.types.Operator):
"""Load Source2 VMDL"""
bl_idname = "source_io.vmdl"
bl_label = "Import Source2 VMDL file"
bl_options = {'UNDO'}
filepath: StringProperty(subtype="FILE_PATH")
invert_uv: BoolProperty(name="invert UV?", default=True)
import_anim: BoolProperty(name="Import animations", default=False)
files: CollectionProperty(name='File paths', type=bpy.types.OperatorFileListElement)
filter_glob: StringProperty(default="*.vmdl_c", options={'HIDDEN'})
def execute(self, context):
if Path(self.filepath).is_file():
directory = Path(self.filepath).parent.absolute()
else:
directory = Path(self.filepath).absolute()
ContentManager().scan_for_content(directory)
for n, file in enumerate(self.files):
print(f"Loading {n + 1}/{len(self.files)}")
model = ValveCompiledModel(str(directory / file.name))
model.load_mesh(self.invert_uv)
model.load_attachments()
if self.import_anim:
model.load_animations()
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
class VWRLDImport_OT_operator(bpy.types.Operator):
"""Load Source2 VWRLD"""
bl_idname = "source_io.vwrld"
bl_label = "Import Source2 VWRLD file"
bl_options = {'UNDO'}
filepath: StringProperty(subtype="FILE_PATH")
files: CollectionProperty(name='File paths', type=bpy.types.OperatorFileListElement)
filter_glob: StringProperty(default="*.vwrld_c", options={'HIDDEN'})
invert_uv: BoolProperty(name="invert UV?", default=True)
scale: FloatProperty(name="World scale", default=HAMMER_UNIT_TO_METERS, precision=6)
def execute(self, context):
if Path(self.filepath).is_file():
directory = Path(self.filepath).parent.absolute()
else:
directory = Path(self.filepath).absolute()
for n, file in enumerate(self.files):
print(f"Loading {n}/{len(self.files)}")
ContentManager().scan_for_content((directory.parent / file.name).with_suffix('.vpk'))
world = ValveCompiledWorld(directory / file.name, invert_uv=self.invert_uv, scale=self.scale)
world.load(file.name)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
# noinspection PyUnresolvedReferences
class VMATImport_OT_operator(bpy.types.Operator):
"""Load Source2 material"""
bl_idname = "source_io.vmat"
bl_label = "Import Source2 VMDL file"
bl_options = {'UNDO'}
filepath: StringProperty(subtype="FILE_PATH")
files: CollectionProperty(name='File paths', type=bpy.types.OperatorFileListElement)
flip: BoolProperty(name="Flip texture", default=True)
split_alpha: BoolProperty(name="Extract alpha texture", default=True)
filter_glob: StringProperty(default="*.vmat_c", options={'HIDDEN'})
def execute(self, context):
if Path(self.filepath).is_file():
directory = Path(self.filepath).parent.absolute()
else:
directory = Path(self.filepath).absolute()
ContentManager().scan_for_content(directory)
for n, file in enumerate(self.files):
print(f"Loading {n + 1}/{len(self.files)}")
material = ValveCompiledMaterial(str(directory / file.name))
material.load()
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
class VTEXImport_OT_operator(bpy.types.Operator):
"""Load Source Engine VTF texture"""
bl_idname = "source_io.vtex"
bl_label = "Import VTEX"
bl_options = {'UNDO'}
filepath: StringProperty(subtype='FILE_PATH', )
flip: BoolProperty(name="Flip texture", default=True)
files: CollectionProperty(name='File paths', type=bpy.types.OperatorFileListElement)
filter_glob: StringProperty(default="*.vtex_c", 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:
texture = ValveCompiledTexture(str(directory / file.name))
texture.load(Path(file.name).stem, self.flip)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
class DMXCameraImport_OT_operator(bpy.types.Operator):
"""Load Valve DMX camera data"""
bl_idname = "source_io.dmx_camera"
bl_label = "Import DMX camera"
bl_options = {'UNDO'}
filepath: StringProperty(subtype='FILE_PATH', )
files: CollectionProperty(name='File paths', type=bpy.types.OperatorFileListElement)
filter_glob: StringProperty(default="*.dmx", 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:
load_camera(directory / file.name)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}