-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.js
166 lines (146 loc) · 3.46 KB
/
index.js
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
165
166
import r from 'restructure';
import Chunk from '../chunked/chunk';
import Chunked from '../chunked';
import SkipChunk from '../chunked/skip-chunk';
import PaddedStrings from '../chunked/padded-strings';
import { Quat, Vec3Float, float32array3 } from '../types';
const MOHD = Chunk({
textureCount: r.uint32le,
groupCount: r.uint32le,
portalCount: r.uint32le,
lightCount: r.uint32le,
modelCount: r.uint32le,
doodadCount: r.uint32le,
doodadSetCount: r.uint32le,
baseColor: new r.Struct({
r: r.uint8,
g: r.uint8,
b: r.uint8,
a: r.uint8,
}),
wmoID: r.uint32le,
minBoundingBox: Vec3Float,
maxBoundingBox: Vec3Float,
flags: r.uint32le,
skipBaseColor: function () {
return (this.flags & 0x02) !== 0;
},
});
const MOTX = Chunk({
filenames: new PaddedStrings('size', 'bytes'),
});
const MOMT = Chunk({
materials: new r.Array(new r.Struct({
flags: r.uint32le,
shader: r.uint32le,
blendMode: r.uint32le,
textures: new r.Array(new r.Struct({
offset: r.uint32le,
color: new r.Struct({
r: r.uint8,
g: r.uint8,
b: r.uint8,
a: r.uint8,
}),
flags: r.uint32le,
}), 3),
unknowns: new r.Reserved(r.uint32le, 4),
}), 'size', 'bytes'),
});
const MOGN = Chunk({
names: new r.Array(new r.String(null), 'size', 'bytes'),
});
const MOGI = Chunk({
groups: new r.Array(new r.Struct({
flags: r.uint32le,
minBoundingBox: Vec3Float,
maxBoundingBox: Vec3Float,
nameOffset: r.int32le,
indoor: function () {
return (this.flags & 0x2000) !== 0 && (this.flags & 0x8) === 0;
},
}), 'size', 'bytes'),
});
const MOSB = Chunk({
skybox: new r.String('size'),
});
const MODS = Chunk({
sets: new r.Array(new r.Struct({
name: new r.String(20),
startIndex: r.uint32le,
doodadCount: r.uint32le,
unused: new r.Reserved(r.uint32le),
}), 'size', 'bytes'),
});
const MODN = Chunk({
filenames: new PaddedStrings('size', 'bytes'),
});
const MODD = Chunk({
doodads: new r.Array(new r.Struct({
filenameOffset: r.uint24le,
filename: function () {
return this.parent.parent.MODN.filenames[this.filenameOffset];
},
flags: r.uint8,
position: Vec3Float,
rotation: Quat,
scale: r.floatle,
color: r.uint32le,
}), 'size', 'bytes'),
});
const MFOG = Chunk({
fogs: new r.Array(new r.Struct({
flags: r.uint32le,
position: Vec3Float,
smallerRadius: r.floatle,
largerRadius: r.floatle,
fogEnd: r.floatle,
fogStartMultiplier: r.floatle,
color: r.uint32le,
unknowns: new r.Reserved(r.floatle, 2),
color2: r.uint32le,
}), 'size', 'bytes'),
});
const MOPV = Chunk({
vertices: new r.Array(float32array3, 'size', 'bytes'),
});
const MOPT = Chunk({
portals: new r.Array(new r.Struct({
vertexOffset: r.uint16le,
vertexCount: r.uint16le,
plane: new r.Struct({
normal: float32array3,
constant: r.floatle,
}),
}), 'size', 'bytes'),
});
const MOPR = Chunk({
references: new r.Array(new r.Struct({
portalIndex: r.uint16le,
groupIndex: r.uint16le,
side: r.int16le,
unknown1: r.uint16le,
}), 'size', 'bytes'),
});
export default Chunked({
MOHD: MOHD,
MOTX: MOTX,
MOMT: MOMT,
MOGN: MOGN,
MOGI: MOGI,
MOSB: MOSB,
MOPV: MOPV,
MOPT: MOPT,
MOPR: MOPR,
MOVV: SkipChunk,
MOVB: SkipChunk,
MOLT: SkipChunk,
MODS: MODS,
MODN: MODN,
MODD: MODD,
MFOG: MFOG,
// TODO: Optional MCVP chunk
flags: function () {
return this.MOHD.flags;
},
});