feat: more accurate models

This commit is contained in:
TrèsAbhi committed 2024-02-18 16:17:00 -06:00
1 parent bc85b354a0
commit 60a115b7d8
9 files changed
+39 -38

No files matched your search

+2 -2
View File
@@ -16,8 +16,8 @@ Buffer.prototype.toJSON = function () {
export async function extractArmor(data: string, fileName: string) {
const sc2Path = `${data}/3d/Tanks/CollisionMeshes/${fileName}.sc2.dvpl`;
const scgPath = `${data}/3d/Tanks/CollisionMeshes/${fileName}.scg.dvpl`;
const sc2 = new Sc2ReadStream(await readDVPLFile(sc2Path)).sc2();
const scg = new ScgReadStream(await readDVPLFile(scgPath)).scg();
const sc2 = new Sc2ReadStream((await readDVPLFile(sc2Path)).buffer).sc2();
const scg = new ScgReadStream((await readDVPLFile(scgPath)).buffer).scg();
const document = new Document();
const scene = document.createScene();
const buffer = document.createBuffer();
+4 -4
View File
@@ -48,8 +48,8 @@ export async function extractModel(
) {
const sc2Path = `${data}/3d/${path}.sc2.dvpl`;
const scgPath = `${data}/3d/${path}.scg.dvpl`;
const sc2 = new Sc2ReadStream(await readDVPLFile(sc2Path)).sc2();
const scg = new ScgReadStream(await readDVPLFile(scgPath)).scg();
const sc2 = new Sc2ReadStream((await readDVPLFile(sc2Path)).buffer).sc2();
const scg = new ScgReadStream((await readDVPLFile(scgPath)).buffer).scg();
const document = new Document();
const scene = document.createScene();
const buffer = document.createBuffer();
@@ -58,7 +58,7 @@ export async function extractModel(
// create materials
await Promise.all(
sc2['#dataNodes'].map(async (node) => {
const id = node['#id'].readBigUInt64LE();
const id = new DataView(node['#id']).getBigUint64(0, true);
if (node.parentMaterialKey !== undefined) {
/**
@@ -140,7 +140,7 @@ export async function extractModel(
}
}
materials.set(node['#id'].readBigUInt64LE(), material);
materials.set(new DataView(node['#id']).getBigUint64(0, true), material);
}),
);
@@ -25,5 +25,3 @@ export interface EquipmentDefinitions {
export const equipmentDefinitions = fetchCdonLz4<EquipmentDefinitions>(
asset('definitions/equipment.cdon.lz4'),
);
equipmentDefinitions.then(console.log);
+5 -5
View File
@@ -36,8 +36,8 @@ export async function readTexture(path: string, options?: ReadTextureOptions) {
const decompressedDvpl = await readDVPLFile(resolvedTexturePath);
const raw = isDds
? await new DdsReadStream(decompressedDvpl).dds()
: new PvrReadStream(decompressedDvpl).pvr();
? await new DdsReadStream(decompressedDvpl.buffer).dds()
: new PvrReadStream(decompressedDvpl.buffer).pvr();
const channels = 4 * raw.width * raw.height;
switch (options?.mutation) {
@@ -81,11 +81,11 @@ export async function readTexture(path: string, options?: ReadTextureOptions) {
case TextureMutation.Miscellaneous: {
for (let index = 0; index < channels; index += 4) {
/**
* Green is ambient occlusion and alpha is emissive. But very few tanks
* Alpha is ambient occlusion and green is emissive. But very few tanks
* use emissive so I am ignoring it for now.
*/
const occlusion = raw.data[index + 1];
// const emissive = raw.data[index + 3];
// const emissive = raw.data[index + 1];
const occlusion = raw.data[index + 3];
raw.data[index] = occlusion;
raw.data[index + 1] = 0;
+10 -10
View File
@@ -9,7 +9,7 @@ export interface SC2 {
type DataNode = {
'##name': 'NMaterial';
'#id': Buffer;
'#id': ArrayBuffer;
materialName: string;
parentMaterialKey?: bigint;
qualityGroup?: string;
@@ -46,15 +46,15 @@ interface Flags {
}
interface Properties {
alphatestThreshold: Buffer;
attenuationBoxHalfSize: Buffer;
attenuationBoxSmoothness: Buffer;
baseColorFactor?: Buffer;
decalTileCoordScale?: Buffer;
inGlossiness: Buffer;
inSpecularity: Buffer;
metalFresnelReflectance: Buffer;
metallicRoughnessFactor?: Buffer;
alphatestThreshold: ArrayBuffer;
attenuationBoxHalfSize: ArrayBuffer;
attenuationBoxSmoothness: ArrayBuffer;
baseColorFactor?: ArrayBuffer;
decalTileCoordScale?: ArrayBuffer;
inGlossiness: ArrayBuffer;
inSpecularity: ArrayBuffer;
metalFresnelReflectance: ArrayBuffer;
metallicRoughnessFactor?: ArrayBuffer;
}
interface TextureSampleStates {
+10 -7
View File
@@ -2,18 +2,18 @@ import { ScpgReadStream, VertexAttribute } from './scpg';
interface PolygonGroupRaw {
'##name': 'PolygonGroup';
'#id': Buffer;
'#id': ArrayBuffer;
cubeTextureCoordCount: number;
indexCount: number;
indexFormat: 0 | 1;
indices: Buffer;
indices: ArrayBuffer;
packing: 0 | 1;
primitiveCount: number;
rhi_primitiveType: 1 | 2 | 10;
textureCoordCount: number;
vertexCount: number;
vertexFormat: number;
vertices: Buffer;
vertices: ArrayBuffer;
}
type BlitzkriegVertex = { attribute: VertexAttribute; value: number[] }[];
@@ -104,10 +104,13 @@ export class ScgReadStream extends ScpgReadStream {
}));
}
polygonGroups.set(polygonGroupRaw['#id'].readBigUInt64LE(), {
vertices,
indices,
});
polygonGroups.set(
new DataView(polygonGroupRaw['#id']).getBigUint64(0, true),
{
vertices,
indices,
},
);
});
return polygonGroups;