mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 11:17:05 +02:00
feat: update all
This commit is contained in:
1 parent
3efe807e35
commit
a0bccc7973
21 files changed
+160
-306
No files matched your search
@@ -2,24 +2,24 @@ import {
|
||||
Hierarchy,
|
||||
Sc2ReadStream,
|
||||
ScgReadStream,
|
||||
SteamVFS,
|
||||
VertexAttribute,
|
||||
} from '@blitzkit/core';
|
||||
import { Accessor, Document, Node, Scene } from '@gltf-transform/core';
|
||||
import { times } from 'lodash-es';
|
||||
} from "@blitzkit/core";
|
||||
import { Accessor, Document, Node, Scene } from "@gltf-transform/core";
|
||||
import { times } from "lodash-es";
|
||||
import {
|
||||
vertexAttributeGLTFName,
|
||||
vertexAttributeGltfVectorSizes,
|
||||
} from './extractModel/constants';
|
||||
import { readDVPLFile } from './readDVPLFile';
|
||||
} from "./extractModel/constants";
|
||||
|
||||
export async function extractArmor(data: string, fileName: string) {
|
||||
const sc2Path = `${data}/3d/Tanks/CollisionMeshes/${fileName}.sc2`;
|
||||
const scgPath = `${data}/3d/Tanks/CollisionMeshes/${fileName}.scg`;
|
||||
export async function extractArmor(vfs: SteamVFS, fileName: string) {
|
||||
const sc2Path = `Data/3d/Tanks/CollisionMeshes/${fileName}.sc2`;
|
||||
const scgPath = `Data/3d/Tanks/CollisionMeshes/${fileName}.scg`;
|
||||
const sc2 = new Sc2ReadStream(
|
||||
(await readDVPLFile(sc2Path)).buffer as ArrayBuffer,
|
||||
(await vfs.file(sc2Path)).buffer as ArrayBuffer
|
||||
).sc2();
|
||||
const scg = new ScgReadStream(
|
||||
(await readDVPLFile(scgPath)).buffer as ArrayBuffer,
|
||||
(await vfs.file(scgPath)).buffer as ArrayBuffer
|
||||
).scg();
|
||||
const document = new Document();
|
||||
const scene = document.createScene();
|
||||
@@ -29,21 +29,21 @@ export async function extractArmor(data: string, fileName: string) {
|
||||
hierarchies.forEach((hierarchy) => {
|
||||
const components = times(
|
||||
hierarchy.components.count,
|
||||
(index) => hierarchy.components[index.toString().padStart(4, '0')],
|
||||
(index) => hierarchy.components[index.toString().padStart(4, "0")]
|
||||
);
|
||||
|
||||
components.forEach((component) => {
|
||||
switch (component['comp.typename']) {
|
||||
case 'TransformComponent':
|
||||
switch (component["comp.typename"]) {
|
||||
case "TransformComponent":
|
||||
break;
|
||||
|
||||
case 'RenderComponent': {
|
||||
const batch = component['rc.renderObj']['ro.batches']['0000'];
|
||||
const polygonGroup = scg.get(batch['rb.datasource']);
|
||||
case "RenderComponent": {
|
||||
const batch = component["rc.renderObj"]["ro.batches"]["0000"];
|
||||
const polygonGroup = scg.get(batch["rb.datasource"]);
|
||||
|
||||
if (!polygonGroup) {
|
||||
console.warn(
|
||||
`Missing polygon group ${batch['rb.datasource']} (${hierarchy.name}); skipping...`,
|
||||
`Missing polygon group ${batch["rb.datasource"]} (${hierarchy.name}); skipping...`
|
||||
);
|
||||
|
||||
break;
|
||||
@@ -73,7 +73,7 @@ export async function extractArmor(data: string, fileName: string) {
|
||||
VertexAttribute.TANGENT,
|
||||
attributes
|
||||
.get(VertexAttribute.TANGENT)!
|
||||
.map((tangent) => [...tangent, 1]),
|
||||
.map((tangent) => [...tangent, 1])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ export async function extractArmor(data: string, fileName: string) {
|
||||
const vertexSize = vertexAttributeGltfVectorSizes[attribute];
|
||||
const accessor = document
|
||||
.createAccessor(name)
|
||||
.setType(vertexSize === 1 ? 'SCALAR' : `VEC${vertexSize}`)
|
||||
.setType(vertexSize === 1 ? "SCALAR" : `VEC${vertexSize}`)
|
||||
.setArray(new Float32Array(value.flat()))
|
||||
.setBuffer(buffer);
|
||||
|
||||
@@ -94,19 +94,19 @@ export async function extractArmor(data: string, fileName: string) {
|
||||
|
||||
hardJointIndices.forEach((hardJointIndex) => {
|
||||
const node = document.createNode(
|
||||
`${hierarchy.name}_armor_${hardJointIndex}`,
|
||||
`${hierarchy.name}_armor_${hardJointIndex}`
|
||||
);
|
||||
const mesh = document.createMesh(batch['##name']);
|
||||
const mesh = document.createMesh(batch["##name"]);
|
||||
const indicesAccessor = document
|
||||
.createAccessor()
|
||||
.setType('SCALAR')
|
||||
.setType("SCALAR")
|
||||
.setArray(
|
||||
new Uint16Array(
|
||||
polygonGroup.indices.filter(
|
||||
(index) =>
|
||||
vertexHardJointIndices.get(index) === hardJointIndex,
|
||||
),
|
||||
),
|
||||
vertexHardJointIndices.get(index) === hardJointIndex
|
||||
)
|
||||
)
|
||||
)
|
||||
.setBuffer(buffer);
|
||||
const primitive = document
|
||||
@@ -127,18 +127,18 @@ export async function extractArmor(data: string, fileName: string) {
|
||||
|
||||
default:
|
||||
throw new TypeError(
|
||||
`Unhandled component type: ${component['comp.typename']}`,
|
||||
`Unhandled component type: ${component["comp.typename"]}`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
if (hierarchy['#hierarchy']) {
|
||||
parseHierarchies(hierarchy['#hierarchy'], parent);
|
||||
if (hierarchy["#hierarchy"]) {
|
||||
parseHierarchies(hierarchy["#hierarchy"], parent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
parseHierarchies(sc2['#hierarchy'], scene);
|
||||
parseHierarchies(sc2["#hierarchy"], scene);
|
||||
|
||||
return document;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
Hierarchy,
|
||||
Sc2ReadStream,
|
||||
ScgReadStream,
|
||||
SteamVFS,
|
||||
Textures,
|
||||
VertexAttribute,
|
||||
} from "@blitzkit/core";
|
||||
@@ -10,7 +11,6 @@ import { dedup, prune } from "@gltf-transform/functions";
|
||||
import { times } from "lodash-es";
|
||||
import { dirname } from "path";
|
||||
import { readBaseColor } from "../readBaseColor";
|
||||
import { readDVPLFile } from "../readDVPLFile";
|
||||
import { readNormal } from "../readNormal";
|
||||
import { readRoughnessMetallic } from "../readRoughnessMetallic";
|
||||
import {
|
||||
@@ -25,14 +25,14 @@ const omitMeshNames = {
|
||||
end: ["_POINT"],
|
||||
};
|
||||
|
||||
export async function extractModel(data: string, path: string) {
|
||||
const sc2Path = `${data}/3d/${path}.sc2`;
|
||||
const scgPath = `${data}/3d/${path}.scg`;
|
||||
export async function extractModel(vfs: SteamVFS, path: string) {
|
||||
const sc2Path = `Data/3d/${path}.sc2`;
|
||||
const scgPath = `Data/3d/${path}.scg`;
|
||||
const sc2 = new Sc2ReadStream(
|
||||
(await readDVPLFile(sc2Path)).buffer as ArrayBuffer
|
||||
(await vfs.file(sc2Path)).buffer as ArrayBuffer
|
||||
).sc2();
|
||||
const scg = new ScgReadStream(
|
||||
(await readDVPLFile(scgPath)).buffer as ArrayBuffer
|
||||
(await vfs.file(scgPath)).buffer as ArrayBuffer
|
||||
).scg();
|
||||
const document = new Document();
|
||||
const scene = document.createScene();
|
||||
@@ -67,11 +67,11 @@ export async function extractModel(data: string, path: string) {
|
||||
.setMimeType("image/webp")
|
||||
.setImage(
|
||||
await readBaseColor(
|
||||
`${data}/3d/${dirname(path)}/${
|
||||
`Data/3d/${dirname(path)}/${
|
||||
textures.baseColorMap ?? textures.albedo
|
||||
}`,
|
||||
textures.miscMap
|
||||
? `${data}/3d/${dirname(path)}/${textures.miscMap}`
|
||||
? `Data/3d/${dirname(path)}/${textures.miscMap}`
|
||||
: undefined
|
||||
)
|
||||
)
|
||||
@@ -103,7 +103,7 @@ export async function extractModel(data: string, path: string) {
|
||||
.setMimeType("image/webp")
|
||||
.setImage(
|
||||
await readRoughnessMetallic(
|
||||
`${data}/3d/${dirname(path)}/${textures.baseRMMap}`
|
||||
`Data/3d/${dirname(path)}/${textures.baseRMMap}`
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -118,7 +118,7 @@ export async function extractModel(data: string, path: string) {
|
||||
.setMimeType("image/webp")
|
||||
.setImage(
|
||||
await readNormal(
|
||||
`${data}/3d/${dirname(path)}/${
|
||||
`Data/3d/${dirname(path)}/${
|
||||
textures.baseNormalMap ?? textures.normalmap
|
||||
}`,
|
||||
isBase
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
import { readDVPLFile } from './readDVPLFile';
|
||||
|
||||
export async function readBase64DVPL(file: string) {
|
||||
const buffer = await readDVPLFile(file);
|
||||
return buffer.toString('base64');
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { readFile } from 'fs/promises';
|
||||
import { DATA_COMPRESSED } from '../../buildAssets/constants';
|
||||
import { readDVPL } from './readDVPL';
|
||||
|
||||
export async function readDVPLFile(file: string) {
|
||||
let path: string;
|
||||
|
||||
if (DATA_COMPRESSED) {
|
||||
path = file.endsWith('.dvpl') ? file : `${file}.dvpl`;
|
||||
} else {
|
||||
path = file.replace('.dvpl', '');
|
||||
}
|
||||
|
||||
const content = await readFile(path);
|
||||
|
||||
if (!DATA_COMPRESSED) return content;
|
||||
|
||||
const dvpl = readDVPL(content);
|
||||
|
||||
return dvpl;
|
||||
}
|
||||
@@ -1,81 +1,17 @@
|
||||
import { DdsReadStream, PvrReadStream } from "@blitzkit/core";
|
||||
import { existsSync } from "fs";
|
||||
import { DATA_COMPRESSED } from "../../../buildAssets/constants";
|
||||
import { readDVPLFile } from "../readDVPLFile";
|
||||
import { vfs } from "../../../buildAssets/constants";
|
||||
|
||||
export async function readTexture(path: string) {
|
||||
const ddsTexturePath = path.replace(".tex", ".dx11.dds");
|
||||
const isDds = existsSync(
|
||||
`${ddsTexturePath}${DATA_COMPRESSED ? ".dvpl" : ""}`
|
||||
);
|
||||
const isDds = vfs.has(ddsTexturePath);
|
||||
const resolvedTexturePath = isDds
|
||||
? ddsTexturePath
|
||||
: ddsTexturePath.replace(".dds", ".pvr");
|
||||
const decompressedDvpl = await readDVPLFile(`${resolvedTexturePath}.dvpl`);
|
||||
const decompressedDvpl = await vfs.file(`${resolvedTexturePath}.dvpl`);
|
||||
|
||||
const raw = isDds
|
||||
? await new DdsReadStream(decompressedDvpl.buffer as ArrayBuffer).dds()
|
||||
: new PvrReadStream(decompressedDvpl.buffer as ArrayBuffer).pvr();
|
||||
|
||||
return raw;
|
||||
|
||||
// switch (mutation) {
|
||||
// case TextureMutation.Normal: {
|
||||
// const bytes = 4 * raw.width * raw.height;
|
||||
// for (let index = 0; index < bytes; index += 4) {
|
||||
// /**
|
||||
// * Red is always 255 and blue is always 0. Only alpha and green contain any
|
||||
// * sort of information.
|
||||
// */
|
||||
// let x = raw.data[index + 3] * (2 / 255) - 1;
|
||||
// let y = raw.data[index + 1] * (2 / 255) - 1;
|
||||
// const underSqrt = 1 - x ** 2 - y ** 2;
|
||||
// let z = underSqrt > 0 ? Math.sqrt(underSqrt) : -Math.sqrt(-underSqrt);
|
||||
|
||||
// raw.data[index] = Math.round((x + 1) * (255 / 2));
|
||||
// raw.data[index + 1] = Math.round((y + 1) * (255 / 2));
|
||||
// raw.data[index + 2] = Math.round((z + 1) * (255 / 2));
|
||||
// raw.data[index + 3] = 255;
|
||||
// }
|
||||
|
||||
// return await sharp(raw.data, { raw }).jpeg().toBuffer();
|
||||
// }
|
||||
|
||||
// case TextureMutation.RoughnessMetallicness: {
|
||||
// const newImage = sharp(Buffer.alloc(raw.width * raw.height), {
|
||||
// raw: { ...raw, channels: 1 },
|
||||
// });
|
||||
// const metallicness = sharp(raw.data, { raw })
|
||||
// .extractChannel("green")
|
||||
// .jpeg()
|
||||
// .toBuffer();
|
||||
// const roughness = sharp(raw.data, { raw })
|
||||
// .extractChannel("alpha")
|
||||
// .jpeg()
|
||||
// .toBuffer();
|
||||
|
||||
// return await newImage
|
||||
// .joinChannel(await Promise.all([roughness, metallicness]))
|
||||
// .jpeg()
|
||||
// .toBuffer();
|
||||
// }
|
||||
|
||||
// case TextureMutation.Miscellaneous: {
|
||||
// /**
|
||||
// * Alpha is ambient occlusion and green is emissive. But very few tanks
|
||||
// * use emissive so I am ignoring it for now.
|
||||
// */
|
||||
// return await sharp(raw.data, { raw })
|
||||
// .extractChannel("alpha")
|
||||
// .jpeg()
|
||||
// .toBuffer();
|
||||
// }
|
||||
|
||||
// case TextureMutation.Albedo: {
|
||||
// return await sharp(raw.data, { raw }).removeAlpha().jpeg().toBuffer();
|
||||
// }
|
||||
|
||||
// default:
|
||||
// return await sharp(raw.data, { raw }).jpeg().toBuffer();
|
||||
// }
|
||||
}
|
||||
Reference in new issue
Block a user