blob: 418d1b921c6d6612446c8ad49cf96805a3dddbed (
plain)
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
|
import struct
from collections import OrderedDict
from gameobjects.matrix44 import *
from gameobjects.vector3 import *
class Node:
pass
nodes = OrderedDict()
BaseNode = Node()
BaseNode.mtx = Matrix44()
BaseNode.brres_key = '3D00'
BaseNode.model_name = 'WorldBase'
BaseNode.lm_type = 0
nodes['Base'] = BaseNode
# todo: string table optimisation
header = struct.pack('>4sI', b'MScn', len(nodes))
entrydata = b''
stringtable = b''
stringoffsets = {}
currentoffset = 8 + (0x40 * len(nodes))
for key,node in nodes.items():
#nodekey, brreskey, lmtype, nameoffset, matrix
enc_name = node.model_name.encode('Shift-JIS')
if enc_name not in stringoffsets:
stringoffsets[enc_name] = currentoffset
stringtable += enc_name + b'\0'
currentoffset += len(enc_name) + 1
nameoffs = stringoffsets[enc_name]
entrydata += struct.pack('>4s4sII', key.encode('Shift-JIS'), node.brres_key.encode('Shift-JIS'), node.lm_type, stringoffsets[enc_name])
for f in list(node.mtx.transposed_components())[0:12]:
entrydata += struct.pack('>f', f)
open('scenedata.bin', 'wb').write(header + entrydata + stringtable)
|