-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswr_import.py
74 lines (56 loc) · 2.45 KB
/
swr_import.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
# Copyright (C) 2021-2024
# Created by LightningPirate
# This file is part of SWE1R Import/Export.
# SWE1R Import/Export is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <https://www.gnu.org
# /licenses>.
import bpy
from .modelblock import Model
from .splineblock import Spline
from .spline_map import spline_map
from .block import Block
# for material in bpy.data.materials:
# material.user_clear()
# bpy.data.materials.remove(material)
# for obj in bpy.data.objects:
# bpy.data.objects.remove(obj)
# for col in bpy.data.collections:
# bpy.data.collections.remove(col)
# for img in bpy.data.images:
# bpy.data.images.remove(img)
scale = 0.01
def import_model(file_path, selector=None):
for image in bpy.data.images:
bpy.data.images.remove(image)
for mat in bpy.data.materials:
bpy.data.materials.remove(mat)
modelblock = Block(file_path + 'out_modelblock.bin', [[], []]).read()
textureblock = Block(file_path + 'out_textureblock.bin', [[], []]).read()
splineblock = Block(file_path + 'out_splineblock.bin', [[]]).read()
modelblock.textureblock = textureblock
modelblock.splineblock = splineblock
if selector is None:
selector = range(324)
for model_id in selector:
model_buffer = modelblock.fetch(model_id)[1]
model = Model(model_id).read(model_buffer)
if model is None:
print("There was an error while parsing the model")
return
model.modelblock = modelblock
collection = model.make()
if model_id in spline_map:
spline_id = spline_map[model_id]
spline_buffer = splineblock.fetch(spline_id)[0]
spline = Spline(spline_id).read(spline_buffer)
collection.objects.link(spline.make(model.scale))
print(f'Successfully unpacked {len(selector)} models')