-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathblender_import_mesh.py
More file actions
64 lines (53 loc) · 2.36 KB
/
Copy pathblender_import_mesh.py
File metadata and controls
64 lines (53 loc) · 2.36 KB
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
# import bpy
import sys
from pathlib import Path
cur_path = Path(__file__).parent
sys.path.append(cur_path)
from ProjectDecima.archive.archive_manager import ArchiveManager
from ProjectDecima.core.entry_reference import EntryReference
from . import *
from ProjectDecima.core.stream_reference import StreamReference
import numpy as np
vertex_dtype = np.dtype([('pos', np.float32, (3,)), ('bone_ids', np.uint8, (8,)), ('weights', np.uint8, (8,))])
def handle_model(model: RegularSkinnedMeshResource, ar_set: ArchiveManager):
mesh_stream = model.mesh_stream.stream_reader
def pad_offset(block_size):
mesh_stream.seek(mesh_stream.tell() + (block_size - (mesh_stream.tell() % block_size)))
# for mesh_info_ref in model.mesh_info_ref:
# mesh_info: MeshInfo = mesh_info_ref.ref
mesh_info: MeshInfo = model.mesh_info_ref[0].ref
indices_info: IndicesInfo = mesh_info.indices_info.ref
vertex_info: Vectices = mesh_info.vertex_info.ref
vertex_count = vertex_info.vertex_count
indices_count = indices_info.indices_count
vertex_data = np.frombuffer(mesh_stream.read_bytes(vertex_dtype.itemsize * vertex_count), dtype=vertex_dtype)
pad_offset(256)
mesh_stream.skip(8 * vertex_count)
pad_offset(256)
uv = np.frombuffer(mesh_stream.read_bytes(4 * vertex_count), dtype=np.float16)
uv.reshape((2, -1))
mesh_stream.skip(12 * vertex_count)
pad_offset(256)
indices = np.frombuffer(mesh_stream.read_bytes(2 * indices_count), dtype=np.uint16)
indices.reshape((3, -1))
pad_offset(256)
pass
archive_dir = Path(input('Folder with archives: ') or r'F:\SteamLibrary\steamapps\common\Death Stranding\data')
print(f'Loading archives from "{archive_dir}"')
dump_dir = Path(input('Output path: ') or r'F:\SteamLibrary\steamapps\common\Death Stranding\dump')
print(f'Dumping files to "{archive_dir}"')
ar_set = ArchiveManager(archive_dir)
ar_set.parse_all()
mesh_path = input("Mesh path:")
core_file = ar_set.queue_file(mesh_path, True)
StreamReference.resolve(ar_set)
EntryReference.resolve(ar_set)
model_entries = core_file.get_entries_by_type(LodMeshResource)
for model_entry in model_entries:
model_entry: LodMeshResource
unk_model_entry: MultiMeshResource = model_entry.parts[0].ref
models = model_entry.parts[1:]
models.extend(unk_model_entry.parts)
for model in models:
handle_model(model.ref, ar_set)
pass