rw-parser-ng 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/lib/index.d.ts +0 -6
- package/lib/index.js +0 -26
- package/lib/renderware/RwFile.d.ts +0 -10
- package/lib/renderware/RwFile.js +0 -33
- package/lib/renderware/RwSections.d.ts +0 -20
- package/lib/renderware/RwSections.js +0 -29
- package/lib/renderware/dff/DffModelType.d.ts +0 -5
- package/lib/renderware/dff/DffModelType.js +0 -9
- package/lib/renderware/dff/DffParser.d.ts +0 -155
- package/lib/renderware/dff/DffParser.js +0 -418
- package/lib/renderware/errors/RwParseError.d.ts +0 -6
- package/lib/renderware/errors/RwParseError.js +0 -34
- package/lib/renderware/txd/TxdParser.d.ts +0 -38
- package/lib/renderware/txd/TxdParser.js +0 -185
- package/lib/renderware/utils/ImageDecoder.d.ts +0 -23
- package/lib/renderware/utils/ImageDecoder.js +0 -512
- package/lib/renderware/utils/ImageFormatEnums.d.ts +0 -25
- package/lib/renderware/utils/ImageFormatEnums.js +0 -32
- package/lib/renderware/utils/RwVersion.d.ts +0 -7
- package/lib/renderware/utils/RwVersion.js +0 -30
- package/lib/utils/ByteStream.d.ts +0 -16
- package/lib/utils/ByteStream.js +0 -60
|
@@ -1,418 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.DffParser = void 0;
|
|
22
|
-
var RwFile_1 = require("../RwFile");
|
|
23
|
-
var RwSections_1 = require("../RwSections");
|
|
24
|
-
var RwParseError_1 = require("../errors/RwParseError");
|
|
25
|
-
var RwVersion_1 = __importDefault(require("../utils/RwVersion"));
|
|
26
|
-
var DffModelType_1 = require("./DffModelType");
|
|
27
|
-
var DffParser = /** @class */ (function (_super) {
|
|
28
|
-
__extends(DffParser, _super);
|
|
29
|
-
function DffParser(buffer) {
|
|
30
|
-
return _super.call(this, buffer) || this;
|
|
31
|
-
}
|
|
32
|
-
DffParser.prototype.parse = function () {
|
|
33
|
-
var version;
|
|
34
|
-
var versionNumber;
|
|
35
|
-
var atomics = [];
|
|
36
|
-
var dummies = [];
|
|
37
|
-
var animNodes = [];
|
|
38
|
-
var geometryList = null;
|
|
39
|
-
var frameList = null;
|
|
40
|
-
while (this.getPosition() < this.getSize()) {
|
|
41
|
-
var header = this.readSectionHeader();
|
|
42
|
-
if (header.sectionType === 0) {
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
if (header.sectionSize == 0) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
switch (header.sectionType) {
|
|
49
|
-
case RwSections_1.RwSections.RwClump:
|
|
50
|
-
// Multiple clumps are used in SA player models, so we should eventually support it
|
|
51
|
-
versionNumber = RwVersion_1.default.unpackVersion(header.versionNumber);
|
|
52
|
-
version = RwVersion_1.default.versions[versionNumber];
|
|
53
|
-
break;
|
|
54
|
-
case RwSections_1.RwSections.RwFrameList:
|
|
55
|
-
frameList = this.readFrameList();
|
|
56
|
-
break;
|
|
57
|
-
case RwSections_1.RwSections.RwExtension:
|
|
58
|
-
var extensionHeader = this.readSectionHeader();
|
|
59
|
-
switch (extensionHeader.sectionType) {
|
|
60
|
-
case RwSections_1.RwSections.RwNodeName:
|
|
61
|
-
dummies.push(this.readString(extensionHeader.sectionSize));
|
|
62
|
-
break;
|
|
63
|
-
case RwSections_1.RwSections.RwAnim:
|
|
64
|
-
animNodes.push(this.readAnimNode());
|
|
65
|
-
break;
|
|
66
|
-
default:
|
|
67
|
-
console.debug("Extension type ".concat(extensionHeader.sectionType, " (").concat(extensionHeader.sectionType.toString(16), ") not found at offset (").concat(this.getPosition().toString(16), "). Skipping ").concat(extensionHeader.sectionSize, " bytes."));
|
|
68
|
-
this.skip(extensionHeader.sectionSize);
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
case RwSections_1.RwSections.RwGeometryList:
|
|
73
|
-
geometryList = this.readGeometryList();
|
|
74
|
-
break;
|
|
75
|
-
case RwSections_1.RwSections.RwAtomic:
|
|
76
|
-
var atomic = this.readAtomic();
|
|
77
|
-
atomics[atomic.geometryIndex] = atomic.frameIndex;
|
|
78
|
-
break;
|
|
79
|
-
case RwSections_1.RwSections.RwNodeName:
|
|
80
|
-
// For some reason, this frame is outside RwExtension.
|
|
81
|
-
dummies.push(this.readString(header.sectionSize));
|
|
82
|
-
break;
|
|
83
|
-
case RwSections_1.RwSections.RwAnim:
|
|
84
|
-
// For III / VC models
|
|
85
|
-
animNodes.push(this.readAnimNode());
|
|
86
|
-
break;
|
|
87
|
-
default:
|
|
88
|
-
console.debug("Section type ".concat(header.sectionType, " (").concat(header.sectionType.toString(16), ") not found at offset (").concat(this.getPosition().toString(16), "). Skipping ").concat(header.sectionSize, " bytes."));
|
|
89
|
-
this.skip(header.sectionSize);
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (!version || !versionNumber) {
|
|
94
|
-
throw new RwParseError_1.RwParseStructureNotFoundError('version');
|
|
95
|
-
}
|
|
96
|
-
var modelType = DffModelType_1.DffModelType.GENERIC;
|
|
97
|
-
if (geometryList === null || geometryList === void 0 ? void 0 : geometryList.geometries.some(function (g) { return g.skin; })) {
|
|
98
|
-
modelType = DffModelType_1.DffModelType.SKIN;
|
|
99
|
-
}
|
|
100
|
-
else if (dummies.some(function (d) { return d.toLowerCase().includes('wheel') || d.toLowerCase().includes('chassis'); })) {
|
|
101
|
-
modelType = DffModelType_1.DffModelType.VEHICLE;
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
modelType: modelType,
|
|
105
|
-
version: version,
|
|
106
|
-
versionNumber: versionNumber,
|
|
107
|
-
geometryList: geometryList,
|
|
108
|
-
frameList: frameList,
|
|
109
|
-
atomics: atomics,
|
|
110
|
-
dummies: dummies,
|
|
111
|
-
animNodes: animNodes,
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
DffParser.prototype.readClump = function () {
|
|
115
|
-
var versionNumber = this.readSectionHeader().versionNumber;
|
|
116
|
-
var atomicCount = this.readUint32();
|
|
117
|
-
var lightCount;
|
|
118
|
-
var cameraCount;
|
|
119
|
-
if (versionNumber > 0x33000) {
|
|
120
|
-
lightCount = this.readUint32();
|
|
121
|
-
cameraCount = this.readUint32();
|
|
122
|
-
}
|
|
123
|
-
return { atomicCount: atomicCount, lightCount: lightCount, cameraCount: cameraCount };
|
|
124
|
-
};
|
|
125
|
-
DffParser.prototype.readFrameList = function () {
|
|
126
|
-
this.readSectionHeader();
|
|
127
|
-
var frameCount = this.readUint32();
|
|
128
|
-
var frames = [];
|
|
129
|
-
for (var i = 0; i < frameCount; i++) {
|
|
130
|
-
// All these could probably be moved to readFrameData()
|
|
131
|
-
var rotationMatrix = {
|
|
132
|
-
right: { x: this.readFloat(), y: this.readFloat(), z: this.readFloat() },
|
|
133
|
-
up: { x: this.readFloat(), y: this.readFloat(), z: this.readFloat() },
|
|
134
|
-
at: { x: this.readFloat(), y: this.readFloat(), z: this.readFloat() },
|
|
135
|
-
};
|
|
136
|
-
var coordinatesOffset = { x: this.readFloat(), y: this.readFloat(), z: this.readFloat() };
|
|
137
|
-
var parentFrame = this.readInt32();
|
|
138
|
-
// Skip matrix creation internal flags
|
|
139
|
-
// They are read by the game but are not used
|
|
140
|
-
this.skip(4);
|
|
141
|
-
frames.push({ rotationMatrix: rotationMatrix, coordinatesOffset: coordinatesOffset, parentFrame: parentFrame });
|
|
142
|
-
}
|
|
143
|
-
return { frameCount: frameCount, frames: frames };
|
|
144
|
-
};
|
|
145
|
-
DffParser.prototype.readGeometryList = function () {
|
|
146
|
-
var header = this.readSectionHeader();
|
|
147
|
-
var geometricObjectCount = this.readUint32();
|
|
148
|
-
var geometries = [];
|
|
149
|
-
for (var i = 0; i < geometricObjectCount; i++) {
|
|
150
|
-
this.readSectionHeader();
|
|
151
|
-
this.readSectionHeader();
|
|
152
|
-
var versionNumber = RwVersion_1.default.unpackVersion(header.versionNumber);
|
|
153
|
-
var geometryData = this.readGeometry(versionNumber);
|
|
154
|
-
geometries.push(geometryData);
|
|
155
|
-
}
|
|
156
|
-
return { geometricObjectCount: geometricObjectCount, geometries: geometries };
|
|
157
|
-
};
|
|
158
|
-
DffParser.prototype.readGeometry = function (versionNumber) {
|
|
159
|
-
var flags = this.readUint16();
|
|
160
|
-
var textureCoordinatesCount = this.readUint8();
|
|
161
|
-
var _nativeGeometryFlags = this.readUint8();
|
|
162
|
-
var triangleCount = this.readUint32();
|
|
163
|
-
var vertexCount = this.readUint32();
|
|
164
|
-
var _morphTargetCount = this.readUint32();
|
|
165
|
-
// Surface properties
|
|
166
|
-
var _ambient;
|
|
167
|
-
var _specular;
|
|
168
|
-
var _diffuse;
|
|
169
|
-
if (versionNumber < 0x34000) {
|
|
170
|
-
_ambient = this.readFloat();
|
|
171
|
-
_specular = this.readFloat();
|
|
172
|
-
_diffuse = this.readFloat();
|
|
173
|
-
}
|
|
174
|
-
var _isTriangleStrip = (flags & (1 << 0)) !== 0;
|
|
175
|
-
var _vertexTranslation = (flags & (1 << 1)) !== 0;
|
|
176
|
-
var isTexturedUV1 = (flags & (1 << 2)) !== 0;
|
|
177
|
-
var isGeometryPrelit = (flags & (1 << 3)) !== 0;
|
|
178
|
-
var _hasNormals = (flags & (1 << 4)) !== 0;
|
|
179
|
-
var _isGeometryLit = (flags & (1 << 5)) !== 0;
|
|
180
|
-
var _shouldModulateMaterialColor = (flags & (1 << 6)) !== 0;
|
|
181
|
-
var isTexturedUV2 = (flags & (1 << 7)) !== 0;
|
|
182
|
-
var vertexColorInformation = [];
|
|
183
|
-
var textureMappingInformation = [];
|
|
184
|
-
var triangleInformation = [];
|
|
185
|
-
// Geometry is marked as prelit
|
|
186
|
-
if (isGeometryPrelit) {
|
|
187
|
-
for (var i = 0; i < vertexCount; i++) {
|
|
188
|
-
vertexColorInformation[i] = { r: this.readUint8(), g: this.readUint8(), b: this.readUint8(), a: this.readUint8() };
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
// Geometry either has first or second texture
|
|
192
|
-
if (isTexturedUV1 || isTexturedUV2) {
|
|
193
|
-
for (var textureCoordinateIndex = 0; textureCoordinateIndex < textureCoordinatesCount; textureCoordinateIndex++) {
|
|
194
|
-
textureMappingInformation[textureCoordinateIndex] = [];
|
|
195
|
-
for (var vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
|
|
196
|
-
textureMappingInformation[textureCoordinateIndex][vertexIndex] = { u: this.readFloat(), v: this.readFloat() };
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
for (var i = 0; i < triangleCount; i++) {
|
|
201
|
-
// Information is written in this order
|
|
202
|
-
var vertex2 = this.readUint16();
|
|
203
|
-
var vertex1 = this.readUint16();
|
|
204
|
-
var materialId = this.readUint16();
|
|
205
|
-
var vertex3 = this.readUint16();
|
|
206
|
-
triangleInformation[i] = { vector: { x: vertex1, y: vertex2, z: vertex3 }, materialId: materialId };
|
|
207
|
-
}
|
|
208
|
-
// We are sure that there's only one morph target, but if
|
|
209
|
-
// we are wrong, we have to loop these through morphTargetCount
|
|
210
|
-
var boundingSphere = {
|
|
211
|
-
vector: { x: this.readFloat(), y: this.readFloat(), z: this.readFloat() },
|
|
212
|
-
radius: this.readFloat(),
|
|
213
|
-
};
|
|
214
|
-
var hasVertices = !!this.readUint32();
|
|
215
|
-
var hasNormals = !!this.readUint32();
|
|
216
|
-
var vertexInformation = [];
|
|
217
|
-
if (hasVertices) {
|
|
218
|
-
for (var i = 0; i < vertexCount; i++) {
|
|
219
|
-
vertexInformation[i] = { x: this.readFloat(), y: this.readFloat(), z: this.readFloat() };
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
var normalInformation = [];
|
|
223
|
-
if (hasNormals) {
|
|
224
|
-
for (var i = 0; i < vertexCount; i++) {
|
|
225
|
-
normalInformation[i] = { x: this.readFloat(), y: this.readFloat(), z: this.readFloat() };
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
var materialList = this.readMaterialList();
|
|
229
|
-
var sectionSize = this.readSectionHeader().sectionSize;
|
|
230
|
-
var position = this.getPosition();
|
|
231
|
-
var binMesh = this.readBinMesh();
|
|
232
|
-
var skin = undefined;
|
|
233
|
-
if (this.readSectionHeader().sectionType == RwSections_1.RwSections.RwSkin) {
|
|
234
|
-
skin = this.readSkin(vertexCount);
|
|
235
|
-
}
|
|
236
|
-
this.setPosition(position + sectionSize);
|
|
237
|
-
return {
|
|
238
|
-
textureCoordinatesCount: textureCoordinatesCount,
|
|
239
|
-
textureMappingInformation: textureMappingInformation,
|
|
240
|
-
boundingSphere: boundingSphere,
|
|
241
|
-
hasVertices: hasVertices,
|
|
242
|
-
hasNormals: hasNormals,
|
|
243
|
-
vertexColorInformation: vertexColorInformation,
|
|
244
|
-
vertexInformation: vertexInformation,
|
|
245
|
-
normalInformation: normalInformation,
|
|
246
|
-
triangleInformation: triangleInformation,
|
|
247
|
-
materialList: materialList,
|
|
248
|
-
binMesh: binMesh,
|
|
249
|
-
skin: skin,
|
|
250
|
-
};
|
|
251
|
-
};
|
|
252
|
-
DffParser.prototype.readBinMesh = function () {
|
|
253
|
-
this.readSectionHeader();
|
|
254
|
-
// Flags (0: triangle list, 1: triangle strip)
|
|
255
|
-
this.skip(4);
|
|
256
|
-
var meshCount = this.readUint32();
|
|
257
|
-
// Total number of indices
|
|
258
|
-
this.skip(4);
|
|
259
|
-
var meshes = [];
|
|
260
|
-
for (var i = 0; i < meshCount; i++) {
|
|
261
|
-
meshes.push(this.readMesh());
|
|
262
|
-
}
|
|
263
|
-
return {
|
|
264
|
-
meshCount: meshCount,
|
|
265
|
-
meshes: meshes
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
DffParser.prototype.readSkin = function (vertexCount) {
|
|
269
|
-
var boneCount = this.readUint8();
|
|
270
|
-
var usedBoneCount = this.readUint8();
|
|
271
|
-
var maxWeightsPerVertex = this.readUint8();
|
|
272
|
-
this.skip(1); // Padding
|
|
273
|
-
this.skip(usedBoneCount); // Skipping special indices
|
|
274
|
-
var boneVertexIndices = [];
|
|
275
|
-
var vertexWeights = [];
|
|
276
|
-
var inverseBoneMatrices = [];
|
|
277
|
-
for (var i = 0; i < vertexCount; i++) {
|
|
278
|
-
var indices = [];
|
|
279
|
-
for (var j = 0; j < 4; j++) {
|
|
280
|
-
indices.push(this.readUint8());
|
|
281
|
-
}
|
|
282
|
-
boneVertexIndices.push(indices);
|
|
283
|
-
}
|
|
284
|
-
for (var i = 0; i < vertexCount; i++) {
|
|
285
|
-
var weights = [];
|
|
286
|
-
for (var j = 0; j < 4; j++) {
|
|
287
|
-
weights.push(this.readFloat());
|
|
288
|
-
}
|
|
289
|
-
vertexWeights.push(weights);
|
|
290
|
-
}
|
|
291
|
-
for (var i = 0; i < boneCount; i++) {
|
|
292
|
-
var matrix4x4 = {
|
|
293
|
-
right: { x: this.readFloat(), y: this.readFloat(), z: this.readFloat(), t: this.readFloat() },
|
|
294
|
-
up: { x: this.readFloat(), y: this.readFloat(), z: this.readFloat(), t: this.readFloat() },
|
|
295
|
-
at: { x: this.readFloat(), y: this.readFloat(), z: this.readFloat(), t: this.readFloat() },
|
|
296
|
-
transform: { x: this.readFloat(), y: this.readFloat(), z: this.readFloat(), t: this.readFloat() },
|
|
297
|
-
};
|
|
298
|
-
inverseBoneMatrices.push(matrix4x4);
|
|
299
|
-
}
|
|
300
|
-
return {
|
|
301
|
-
boneCount: boneCount,
|
|
302
|
-
usedBoneCount: usedBoneCount,
|
|
303
|
-
maxWeightsPerVertex: maxWeightsPerVertex,
|
|
304
|
-
boneVertexIndices: boneVertexIndices,
|
|
305
|
-
vertexWeights: vertexWeights,
|
|
306
|
-
inverseBoneMatrices: inverseBoneMatrices,
|
|
307
|
-
};
|
|
308
|
-
};
|
|
309
|
-
DffParser.prototype.readAnimNode = function () {
|
|
310
|
-
this.skip(4); // Skipping AnimVersion property (0x100)
|
|
311
|
-
var boneId = this.readInt32();
|
|
312
|
-
var boneCount = this.readInt32();
|
|
313
|
-
var bones = [];
|
|
314
|
-
if (boneId == 0) {
|
|
315
|
-
this.skip(8); // Skipping flags and keyFrameSize properties
|
|
316
|
-
}
|
|
317
|
-
if (boneCount > 0) {
|
|
318
|
-
for (var i = 0; i < boneCount; i++) {
|
|
319
|
-
bones.push({
|
|
320
|
-
boneId: this.readInt32(),
|
|
321
|
-
boneIndex: this.readInt32(),
|
|
322
|
-
flags: this.readInt32()
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return {
|
|
327
|
-
boneId: boneId,
|
|
328
|
-
bonesCount: boneCount,
|
|
329
|
-
bones: bones
|
|
330
|
-
};
|
|
331
|
-
};
|
|
332
|
-
DffParser.prototype.readMesh = function () {
|
|
333
|
-
var indexCount = this.readUint32();
|
|
334
|
-
var materialIndex = this.readUint32();
|
|
335
|
-
var indices = [];
|
|
336
|
-
for (var i = 0; i < indexCount; i++) {
|
|
337
|
-
indices.push(this.readUint32());
|
|
338
|
-
}
|
|
339
|
-
return {
|
|
340
|
-
indexCount: indexCount,
|
|
341
|
-
materialIndex: materialIndex,
|
|
342
|
-
indices: indices
|
|
343
|
-
};
|
|
344
|
-
};
|
|
345
|
-
DffParser.prototype.readMaterialList = function () {
|
|
346
|
-
this.readSectionHeader();
|
|
347
|
-
this.readSectionHeader();
|
|
348
|
-
var materialInstanceCount = this.readUint32();
|
|
349
|
-
var materialIndices = [];
|
|
350
|
-
for (var i = 0; i < materialInstanceCount; i++) {
|
|
351
|
-
var materialIndex = this.readInt32();
|
|
352
|
-
materialIndices.push(materialIndex);
|
|
353
|
-
}
|
|
354
|
-
var materialData = [];
|
|
355
|
-
for (var i = 0; i < materialInstanceCount; i++) {
|
|
356
|
-
var materialIndex = materialIndices[i];
|
|
357
|
-
if (materialIndex == -1) {
|
|
358
|
-
materialData.push(this.readMaterial());
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
materialData.push(materialData[materialIndex]);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
return { materialInstanceCount: materialInstanceCount, materialData: materialData };
|
|
365
|
-
};
|
|
366
|
-
DffParser.prototype.readMaterial = function () {
|
|
367
|
-
this.readSectionHeader();
|
|
368
|
-
var header = this.readSectionHeader();
|
|
369
|
-
// Flags - not used
|
|
370
|
-
this.skip(4);
|
|
371
|
-
var color = { r: this.readUint8(), g: this.readUint8(), b: this.readUint8(), a: this.readUint8() };
|
|
372
|
-
// Unknown - not used
|
|
373
|
-
this.skip(4);
|
|
374
|
-
var isTextured = this.readUint32() > 0;
|
|
375
|
-
// Surface properties
|
|
376
|
-
var ambient;
|
|
377
|
-
var specular;
|
|
378
|
-
var diffuse;
|
|
379
|
-
if (header.versionNumber > 0x30400) {
|
|
380
|
-
ambient = this.readFloat();
|
|
381
|
-
specular = this.readFloat();
|
|
382
|
-
diffuse = this.readFloat();
|
|
383
|
-
}
|
|
384
|
-
var texture;
|
|
385
|
-
if (isTextured) {
|
|
386
|
-
texture = this.readTexture();
|
|
387
|
-
}
|
|
388
|
-
// Skip various unused extensions
|
|
389
|
-
this.skip(this.readSectionHeader().sectionSize);
|
|
390
|
-
return { color: color, isTextured: isTextured, ambient: ambient, specular: specular, diffuse: diffuse, texture: texture };
|
|
391
|
-
};
|
|
392
|
-
DffParser.prototype.readTexture = function () {
|
|
393
|
-
this.readSectionHeader();
|
|
394
|
-
this.readSectionHeader();
|
|
395
|
-
var textureData = this.readUint32();
|
|
396
|
-
var textureFiltering = (textureData & 0xFF);
|
|
397
|
-
var uAddressing = (textureData & 0xF00) >> 8;
|
|
398
|
-
var vAddressing = (textureData & 0xF000) >> 12;
|
|
399
|
-
var usesMipLevels = (textureData & (1 << 16)) !== 0;
|
|
400
|
-
var textureNameSize = this.readSectionHeader().sectionSize;
|
|
401
|
-
var textureName = this.readString(textureNameSize);
|
|
402
|
-
// Skip various unused extensions
|
|
403
|
-
this.skip(this.readSectionHeader().sectionSize);
|
|
404
|
-
this.skip(this.readSectionHeader().sectionSize);
|
|
405
|
-
return { textureFiltering: textureFiltering, uAddressing: uAddressing, vAddressing: vAddressing, usesMipLevels: usesMipLevels, textureName: textureName };
|
|
406
|
-
};
|
|
407
|
-
DffParser.prototype.readAtomic = function () {
|
|
408
|
-
this.readSectionHeader();
|
|
409
|
-
var frameIndex = this.readUint32();
|
|
410
|
-
var geometryIndex = this.readUint32();
|
|
411
|
-
var flags = this.readUint32();
|
|
412
|
-
// Skip unused bytes
|
|
413
|
-
this.skip(4);
|
|
414
|
-
return { frameIndex: frameIndex, geometryIndex: geometryIndex, flags: flags };
|
|
415
|
-
};
|
|
416
|
-
return DffParser;
|
|
417
|
-
}(RwFile_1.RwFile));
|
|
418
|
-
exports.DffParser = DffParser;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.RwParseStructureNotFoundError = exports.RwParseError = void 0;
|
|
19
|
-
var RwParseError = /** @class */ (function (_super) {
|
|
20
|
-
__extends(RwParseError, _super);
|
|
21
|
-
function RwParseError(message) {
|
|
22
|
-
return _super.call(this, message) || this;
|
|
23
|
-
}
|
|
24
|
-
return RwParseError;
|
|
25
|
-
}(Error));
|
|
26
|
-
exports.RwParseError = RwParseError;
|
|
27
|
-
var RwParseStructureNotFoundError = /** @class */ (function (_super) {
|
|
28
|
-
__extends(RwParseStructureNotFoundError, _super);
|
|
29
|
-
function RwParseStructureNotFoundError(structureName) {
|
|
30
|
-
return _super.call(this, "Structure ".concat(structureName, " not found.")) || this;
|
|
31
|
-
}
|
|
32
|
-
return RwParseStructureNotFoundError;
|
|
33
|
-
}(RwParseError));
|
|
34
|
-
exports.RwParseStructureNotFoundError = RwParseStructureNotFoundError;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { RwFile } from '../RwFile';
|
|
2
|
-
export interface RwTxd {
|
|
3
|
-
textureDictionary: RwTextureDictionary;
|
|
4
|
-
}
|
|
5
|
-
export interface RwTextureDictionary {
|
|
6
|
-
textureCount: number;
|
|
7
|
-
textureNatives: RwTextureNative[];
|
|
8
|
-
}
|
|
9
|
-
export interface RwTextureNative {
|
|
10
|
-
platformId: number;
|
|
11
|
-
filterMode: number;
|
|
12
|
-
uAddressing: number;
|
|
13
|
-
vAddressing: number;
|
|
14
|
-
textureName: string;
|
|
15
|
-
maskName: string;
|
|
16
|
-
rasterFormat: number;
|
|
17
|
-
d3dFormat: string;
|
|
18
|
-
width: number;
|
|
19
|
-
height: number;
|
|
20
|
-
depth: number;
|
|
21
|
-
mipmapCount: number;
|
|
22
|
-
rasterType: number;
|
|
23
|
-
alpha: boolean;
|
|
24
|
-
cubeTexture: boolean;
|
|
25
|
-
autoMipMaps: boolean;
|
|
26
|
-
compressed: boolean;
|
|
27
|
-
mipmaps: number[][];
|
|
28
|
-
}
|
|
29
|
-
export declare class TxdParser extends RwFile {
|
|
30
|
-
constructor(stream: Buffer);
|
|
31
|
-
parse(): RwTxd;
|
|
32
|
-
readTextureDictionary(): RwTextureDictionary;
|
|
33
|
-
readTextureNative(): RwTextureNative;
|
|
34
|
-
readPalette(paletteType: number, depth: number): Uint8Array;
|
|
35
|
-
getBitmapWithPalette(paletteType: number, depth: number, hasAlpha: boolean, raster: Uint8Array, palette: Uint8Array, width: number, height: number): Uint8Array;
|
|
36
|
-
getBitmapWithDXT(dxtType: string, raster: Uint8Array, width: number, height: number): Uint8Array;
|
|
37
|
-
getBitmapWithRasterFormat(rasterFormat: number, raster: Uint8Array, width: number, height: number): Uint8Array;
|
|
38
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.TxdParser = void 0;
|
|
19
|
-
var RwFile_1 = require("../RwFile");
|
|
20
|
-
var ImageDecoder_1 = require("../utils/ImageDecoder");
|
|
21
|
-
var ImageFormatEnums_1 = require("../utils/ImageFormatEnums");
|
|
22
|
-
var TxdParser = /** @class */ (function (_super) {
|
|
23
|
-
__extends(TxdParser, _super);
|
|
24
|
-
function TxdParser(stream) {
|
|
25
|
-
return _super.call(this, stream) || this;
|
|
26
|
-
}
|
|
27
|
-
TxdParser.prototype.parse = function () {
|
|
28
|
-
return {
|
|
29
|
-
textureDictionary: this.readTextureDictionary(),
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
TxdParser.prototype.readTextureDictionary = function () {
|
|
33
|
-
this.readSectionHeader();
|
|
34
|
-
this.readSectionHeader();
|
|
35
|
-
var textureCount = this.readUint16();
|
|
36
|
-
this.skip(2);
|
|
37
|
-
var textureNatives = [];
|
|
38
|
-
for (var i = 0; i < textureCount; i++) {
|
|
39
|
-
var textureNative = this.readTextureNative();
|
|
40
|
-
textureNatives.push(textureNative);
|
|
41
|
-
}
|
|
42
|
-
// Skip unused extension
|
|
43
|
-
this.skip(this.readSectionHeader().sectionSize);
|
|
44
|
-
return { textureCount: textureCount, textureNatives: textureNatives };
|
|
45
|
-
};
|
|
46
|
-
TxdParser.prototype.readTextureNative = function () {
|
|
47
|
-
this.readSectionHeader();
|
|
48
|
-
this.readSectionHeader();
|
|
49
|
-
// TODO: Structure this part better
|
|
50
|
-
// Texture format
|
|
51
|
-
var platformId = this.readUint32();
|
|
52
|
-
var flags = this.readUint32();
|
|
53
|
-
var filterMode = (flags & 0xFF);
|
|
54
|
-
var uAddressing = (flags & 0xF00) >> 8;
|
|
55
|
-
var vAddressing = (flags & 0xF000) >> 12;
|
|
56
|
-
var textureName = this.readString(32);
|
|
57
|
-
var maskName = this.readString(32);
|
|
58
|
-
// Raster format
|
|
59
|
-
var rasterFormat = this.readUint32();
|
|
60
|
-
var d3dFormat = this.readString(4);
|
|
61
|
-
var width = this.readUint16();
|
|
62
|
-
var height = this.readUint16();
|
|
63
|
-
var depth = this.readUint8();
|
|
64
|
-
var mipmapCount = this.readUint8();
|
|
65
|
-
var rasterType = this.readUint8();
|
|
66
|
-
var compressionFlags = this.readUint8(); // Is "dxtType" for III/VC
|
|
67
|
-
// SA
|
|
68
|
-
var alpha = (compressionFlags & (1 << 0)) !== 0;
|
|
69
|
-
var cubeTexture = (compressionFlags & (1 << 1)) !== 0;
|
|
70
|
-
var autoMipMaps = (compressionFlags & (1 << 2)) !== 0;
|
|
71
|
-
var compressed = (compressionFlags & (1 << 3)) !== 0;
|
|
72
|
-
var paletteType = (rasterFormat >> 13) & 3;
|
|
73
|
-
var mipWidth = width;
|
|
74
|
-
var mipHeight = height;
|
|
75
|
-
var mipmaps = [];
|
|
76
|
-
var palette = (paletteType !== ImageFormatEnums_1.PaletteType.PALETTE_NONE ? this.readPalette(paletteType, depth) : new Uint8Array(0));
|
|
77
|
-
for (var i = 0; i < mipmapCount; i++) {
|
|
78
|
-
var rasterSize = this.readUint32();
|
|
79
|
-
var raster = this.read(rasterSize);
|
|
80
|
-
if (i == 0) {
|
|
81
|
-
// Raw RGBA presentation
|
|
82
|
-
var bitmap = void 0;
|
|
83
|
-
if (palette.length !== 0) {
|
|
84
|
-
var rasterFormatsWithoutAlpha = [
|
|
85
|
-
ImageFormatEnums_1.RasterFormat.RASTER_565,
|
|
86
|
-
ImageFormatEnums_1.RasterFormat.RASTER_LUM,
|
|
87
|
-
ImageFormatEnums_1.RasterFormat.RASTER_888,
|
|
88
|
-
ImageFormatEnums_1.RasterFormat.RASTER_555
|
|
89
|
-
];
|
|
90
|
-
var hasAlpha = ((platformId === ImageFormatEnums_1.PlatformType.D3D9 && alpha) || (platformId == ImageFormatEnums_1.PlatformType.D3D8 && !rasterFormatsWithoutAlpha.includes(rasterFormat)));
|
|
91
|
-
bitmap = Array.from(this.getBitmapWithPalette(paletteType, depth, hasAlpha, raster, palette, width, height));
|
|
92
|
-
}
|
|
93
|
-
else if (platformId === ImageFormatEnums_1.PlatformType.D3D8 && compressionFlags !== 0) {
|
|
94
|
-
bitmap = Array.from(this.getBitmapWithDXT('DXT' + compressionFlags, raster, width, height));
|
|
95
|
-
}
|
|
96
|
-
else if (platformId === ImageFormatEnums_1.PlatformType.D3D9 && compressed) {
|
|
97
|
-
bitmap = Array.from(this.getBitmapWithDXT(d3dFormat, raster, width, height));
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
bitmap = Array.from(this.getBitmapWithRasterFormat(rasterFormat, raster, width, height));
|
|
101
|
-
}
|
|
102
|
-
mipmaps.push(bitmap);
|
|
103
|
-
}
|
|
104
|
-
mipWidth /= 2;
|
|
105
|
-
mipHeight /= 2;
|
|
106
|
-
}
|
|
107
|
-
// Skip extension
|
|
108
|
-
this.skip(this.readSectionHeader().sectionSize);
|
|
109
|
-
return {
|
|
110
|
-
platformId: platformId,
|
|
111
|
-
filterMode: filterMode,
|
|
112
|
-
uAddressing: uAddressing,
|
|
113
|
-
vAddressing: vAddressing,
|
|
114
|
-
textureName: textureName,
|
|
115
|
-
maskName: maskName,
|
|
116
|
-
rasterFormat: rasterFormat,
|
|
117
|
-
d3dFormat: d3dFormat,
|
|
118
|
-
width: width,
|
|
119
|
-
height: height,
|
|
120
|
-
depth: depth,
|
|
121
|
-
mipmapCount: mipmapCount,
|
|
122
|
-
rasterType: rasterType,
|
|
123
|
-
alpha: alpha,
|
|
124
|
-
cubeTexture: cubeTexture,
|
|
125
|
-
autoMipMaps: autoMipMaps,
|
|
126
|
-
compressed: compressed,
|
|
127
|
-
mipmaps: mipmaps,
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
TxdParser.prototype.readPalette = function (paletteType, depth) {
|
|
131
|
-
var size = (paletteType === ImageFormatEnums_1.PaletteType.PALETTE_8 ? 1024 : (depth === 4 ? 64 : 128));
|
|
132
|
-
return this.read(size);
|
|
133
|
-
};
|
|
134
|
-
TxdParser.prototype.getBitmapWithPalette = function (paletteType, depth, hasAlpha, raster, palette, width, height) {
|
|
135
|
-
if (paletteType !== ImageFormatEnums_1.PaletteType.PALETTE_8 && depth == 4) {
|
|
136
|
-
return (hasAlpha
|
|
137
|
-
? ImageDecoder_1.ImageDecoder.pal4(raster, palette, width, height)
|
|
138
|
-
: ImageDecoder_1.ImageDecoder.pal4NoAlpha(raster, palette, width, height));
|
|
139
|
-
}
|
|
140
|
-
return (hasAlpha
|
|
141
|
-
? ImageDecoder_1.ImageDecoder.pal8(raster, palette, width, height)
|
|
142
|
-
: ImageDecoder_1.ImageDecoder.pal8NoAlpha(raster, palette, width, height));
|
|
143
|
-
};
|
|
144
|
-
TxdParser.prototype.getBitmapWithDXT = function (dxtType, raster, width, height) {
|
|
145
|
-
switch (dxtType) {
|
|
146
|
-
case ImageFormatEnums_1.D3DFormat.D3D_DXT1:
|
|
147
|
-
return ImageDecoder_1.ImageDecoder.bc1(raster, width, height);
|
|
148
|
-
case ImageFormatEnums_1.D3DFormat.D3D_DXT2:
|
|
149
|
-
return ImageDecoder_1.ImageDecoder.bc2(raster, width, height, true);
|
|
150
|
-
case ImageFormatEnums_1.D3DFormat.D3D_DXT3:
|
|
151
|
-
return ImageDecoder_1.ImageDecoder.bc2(raster, width, height, false);
|
|
152
|
-
case ImageFormatEnums_1.D3DFormat.D3D_DXT4:
|
|
153
|
-
return ImageDecoder_1.ImageDecoder.bc3(raster, width, height, true);
|
|
154
|
-
case ImageFormatEnums_1.D3DFormat.D3D_DXT5:
|
|
155
|
-
return ImageDecoder_1.ImageDecoder.bc3(raster, width, height, false);
|
|
156
|
-
// LUM8_A8 has compressed flag
|
|
157
|
-
case ImageFormatEnums_1.D3DFormat.D3DFMT_A8L8:
|
|
158
|
-
return ImageDecoder_1.ImageDecoder.lum8a8(raster, width, height);
|
|
159
|
-
default:
|
|
160
|
-
return new Uint8Array(0);
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
TxdParser.prototype.getBitmapWithRasterFormat = function (rasterFormat, raster, width, height) {
|
|
164
|
-
switch (rasterFormat) {
|
|
165
|
-
case ImageFormatEnums_1.RasterFormat.RASTER_1555:
|
|
166
|
-
return ImageDecoder_1.ImageDecoder.bgra1555(raster, width, height);
|
|
167
|
-
case ImageFormatEnums_1.RasterFormat.RASTER_565:
|
|
168
|
-
return ImageDecoder_1.ImageDecoder.bgra565(raster, width, height);
|
|
169
|
-
case ImageFormatEnums_1.RasterFormat.RASTER_4444:
|
|
170
|
-
return ImageDecoder_1.ImageDecoder.bgra4444(raster, width, height);
|
|
171
|
-
case ImageFormatEnums_1.RasterFormat.RASTER_LUM:
|
|
172
|
-
return ImageDecoder_1.ImageDecoder.lum8(raster, width, height);
|
|
173
|
-
case ImageFormatEnums_1.RasterFormat.RASTER_8888:
|
|
174
|
-
return ImageDecoder_1.ImageDecoder.bgra8888(raster, width, height);
|
|
175
|
-
case ImageFormatEnums_1.RasterFormat.RASTER_888:
|
|
176
|
-
return ImageDecoder_1.ImageDecoder.bgra888(raster, width, height);
|
|
177
|
-
case ImageFormatEnums_1.RasterFormat.RASTER_555:
|
|
178
|
-
return ImageDecoder_1.ImageDecoder.bgra555(raster, width, height);
|
|
179
|
-
default:
|
|
180
|
-
return new Uint8Array(0);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
return TxdParser;
|
|
184
|
-
}(RwFile_1.RwFile));
|
|
185
|
-
exports.TxdParser = TxdParser;
|