mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
Merge branch 'main' into ue
This commit is contained in:
commit
5412c479c8
42 files changed
+1044
-934
No files matched your search
@@ -1,15 +1,10 @@
|
||||
import { build } from "esbuild";
|
||||
import { cp, readdir, rm } from "fs/promises";
|
||||
import { argv } from "process";
|
||||
|
||||
const dev = argv.includes("--dev");
|
||||
|
||||
const projectDir = "../..";
|
||||
const srcRoot = `${projectDir}/packages/bot`;
|
||||
const distRoot = `${projectDir}/dist/bot`;
|
||||
const modulesRoot = dev
|
||||
? "../../packages/bot/node_modules"
|
||||
: "../../node_modules";
|
||||
const modulesRoot = "../../node_modules";
|
||||
const workers = await readdir(`${srcRoot}/src/workers`);
|
||||
|
||||
await rm(distRoot, { recursive: true, force: true });
|
||||
@@ -30,9 +25,9 @@ build({
|
||||
},
|
||||
external: ["sharp"],
|
||||
minifyIdentifiers: false, // causes goofy ahh issues
|
||||
minifySyntax: !dev,
|
||||
minifyWhitespace: !dev,
|
||||
sourcemap: !dev,
|
||||
minifySyntax: true,
|
||||
minifyWhitespace: true,
|
||||
sourcemap: true,
|
||||
jsxImportSource: "react",
|
||||
jsx: "automatic",
|
||||
});
|
||||
@@ -44,18 +39,16 @@ for (const module of await readdir(`${modulesRoot}/@resvg`)) {
|
||||
.map((file) =>
|
||||
cp(
|
||||
`${modulesRoot}/@resvg/${module}/${file}`,
|
||||
`${distRoot}/workers/${file}`
|
||||
)
|
||||
)
|
||||
`${distRoot}/workers/${file}`,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (!dev) {
|
||||
await cp(`${projectDir}/prisma`, `${distRoot}/prisma`, { recursive: true });
|
||||
await cp(`${projectDir}/prisma`, `${distRoot}/prisma`, { recursive: true });
|
||||
|
||||
for (const file of await readdir(`${modulesRoot}/prisma`).then((files) =>
|
||||
files.filter((file) => file.endsWith(".node"))
|
||||
)) {
|
||||
cp(`${modulesRoot}/prisma/${file}`, `${distRoot}/prisma/${file}`);
|
||||
}
|
||||
for (const file of await readdir(`${modulesRoot}/prisma`).then((files) =>
|
||||
files.filter((file) => file.endsWith(".node")),
|
||||
)) {
|
||||
cp(`${modulesRoot}/prisma/${file}`, `${distRoot}/prisma/${file}`);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from "@blitzkit/core";
|
||||
import { Accessor, Document, Node, Scene } from "@gltf-transform/core";
|
||||
import { times } from "lodash-es";
|
||||
import { SteamVFS } from "../vfs/vfs";
|
||||
import { SteamVFS } from "../vfs/steam";
|
||||
import {
|
||||
vertexAttributeGLTFName,
|
||||
vertexAttributeGltfVectorSizes,
|
||||
@@ -16,10 +16,10 @@ 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 vfs.file(sc2Path)).buffer as ArrayBuffer
|
||||
(await vfs.file(sc2Path)).buffer as ArrayBuffer,
|
||||
).sc2();
|
||||
const scg = new ScgReadStream(
|
||||
(await vfs.file(scgPath)).buffer as ArrayBuffer
|
||||
(await vfs.file(scgPath)).buffer as ArrayBuffer,
|
||||
).scg();
|
||||
const document = new Document();
|
||||
const scene = document.createScene();
|
||||
@@ -29,7 +29,7 @@ export async function extractArmor(vfs: SteamVFS, 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) => {
|
||||
@@ -43,7 +43,7 @@ export async function extractArmor(vfs: SteamVFS, fileName: string) {
|
||||
|
||||
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(vfs: SteamVFS, fileName: string) {
|
||||
VertexAttribute.TANGENT,
|
||||
attributes
|
||||
.get(VertexAttribute.TANGENT)!
|
||||
.map((tangent) => [...tangent, 1])
|
||||
.map((tangent) => [...tangent, 1]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ export async function extractArmor(vfs: SteamVFS, fileName: string) {
|
||||
|
||||
hardJointIndices.forEach((hardJointIndex) => {
|
||||
const node = document.createNode(
|
||||
`${hierarchy.name}_armor_${hardJointIndex}`
|
||||
`${hierarchy.name}_armor_${hardJointIndex}`,
|
||||
);
|
||||
const mesh = document.createMesh(batch["##name"]);
|
||||
const indicesAccessor = document
|
||||
@@ -104,9 +104,9 @@ export async function extractArmor(vfs: SteamVFS, fileName: string) {
|
||||
new Uint16Array(
|
||||
polygonGroup.indices.filter(
|
||||
(index) =>
|
||||
vertexHardJointIndices.get(index) === hardJointIndex
|
||||
)
|
||||
)
|
||||
vertexHardJointIndices.get(index) === hardJointIndex,
|
||||
),
|
||||
),
|
||||
)
|
||||
.setBuffer(buffer);
|
||||
const primitive = document
|
||||
@@ -127,7 +127,7 @@ export async function extractArmor(vfs: SteamVFS, fileName: string) {
|
||||
|
||||
default:
|
||||
throw new TypeError(
|
||||
`Unhandled component type: ${component["comp.typename"]}`
|
||||
`Unhandled component type: ${component["comp.typename"]}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Document, Material, Node, Scene } from "@gltf-transform/core";
|
||||
import { dedup, prune } from "@gltf-transform/functions";
|
||||
import { times } from "lodash-es";
|
||||
import { dirname } from "path";
|
||||
import { SteamVFS } from "../../vfs/vfs";
|
||||
import { SteamVFS } from "../../vfs/steam";
|
||||
import { readBaseColor } from "../readBaseColor";
|
||||
import { readNormal } from "../readNormal";
|
||||
import { readRoughnessMetallic } from "../readRoughnessMetallic";
|
||||
@@ -29,10 +29,10 @@ 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 vfs.file(sc2Path)).buffer as ArrayBuffer
|
||||
(await vfs.file(sc2Path)).buffer as ArrayBuffer,
|
||||
).sc2();
|
||||
const scg = new ScgReadStream(
|
||||
(await vfs.file(scgPath)).buffer as ArrayBuffer
|
||||
(await vfs.file(scgPath)).buffer as ArrayBuffer,
|
||||
).scg();
|
||||
const document = new Document();
|
||||
const scene = document.createScene();
|
||||
@@ -61,20 +61,17 @@ export async function extractModel(vfs: SteamVFS, path: string) {
|
||||
}
|
||||
|
||||
if (textures) {
|
||||
const { image: baseColor, hasAlpha } = await readBaseColor(
|
||||
`Data/3d/${dirname(path)}/${textures.baseColorMap ?? textures.albedo}`,
|
||||
textures.miscMap
|
||||
? `Data/3d/${dirname(path)}/${textures.miscMap}`
|
||||
: undefined,
|
||||
);
|
||||
material.setBaseColorTexture(
|
||||
document
|
||||
.createTexture(node.materialName)
|
||||
.setMimeType("image/webp")
|
||||
.setImage(
|
||||
await readBaseColor(
|
||||
`Data/3d/${dirname(path)}/${
|
||||
textures.baseColorMap ?? textures.albedo
|
||||
}`,
|
||||
textures.miscMap
|
||||
? `Data/3d/${dirname(path)}/${textures.miscMap}`
|
||||
: undefined
|
||||
)
|
||||
)
|
||||
.setImage(baseColor),
|
||||
);
|
||||
|
||||
if (node.configCount) {
|
||||
@@ -83,15 +80,7 @@ export async function extractModel(vfs: SteamVFS, path: string) {
|
||||
configIndex < node.configCount;
|
||||
configIndex++
|
||||
) {
|
||||
const archive = node[`configArchive_${configIndex}`];
|
||||
|
||||
if (
|
||||
archive.configName !== "Default" ||
|
||||
!archive.enabledPresets?.AlphaTest
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!hasAlpha) continue;
|
||||
material.setAlphaMode("BLEND").setDoubleSided(true);
|
||||
}
|
||||
}
|
||||
@@ -103,9 +92,9 @@ export async function extractModel(vfs: SteamVFS, path: string) {
|
||||
.setMimeType("image/webp")
|
||||
.setImage(
|
||||
await readRoughnessMetallic(
|
||||
`Data/3d/${dirname(path)}/${textures.baseRMMap}`
|
||||
)
|
||||
)
|
||||
`Data/3d/${dirname(path)}/${textures.baseRMMap}`,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -121,9 +110,9 @@ export async function extractModel(vfs: SteamVFS, path: string) {
|
||||
`Data/3d/${dirname(path)}/${
|
||||
textures.baseNormalMap ?? textures.normalmap
|
||||
}`,
|
||||
isBase
|
||||
)
|
||||
)
|
||||
isBase,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -157,7 +146,7 @@ export async function extractModel(vfs: SteamVFS, path: string) {
|
||||
const node = document.createNode(hierarchy.name);
|
||||
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) => {
|
||||
@@ -194,7 +183,7 @@ export async function extractModel(vfs: SteamVFS, path: string) {
|
||||
}
|
||||
if (polygonGroup === undefined) {
|
||||
throw new Error(
|
||||
`Missing polygon group ${batch["rb.datasource"]}`
|
||||
`Missing polygon group ${batch["rb.datasource"]}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -255,7 +244,7 @@ export async function extractModel(vfs: SteamVFS, path: string) {
|
||||
default: {
|
||||
if (ERROR_ON_UNKNOWN_COMPONENT) {
|
||||
throw new Error(
|
||||
`Unhandled component type: ${component["comp.typename"]}`
|
||||
`Unhandled component type: ${component["comp.typename"]}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import sharp from "sharp";
|
||||
import { readTexture } from "./readTexture";
|
||||
|
||||
export async function readBaseColor(path: string, occlusionPath?: string) {
|
||||
let hasAlpha = false;
|
||||
const baseRaw = await readTexture(path);
|
||||
const occlusionRaw = occlusionPath
|
||||
? await readTexture(occlusionPath)
|
||||
@@ -30,10 +31,13 @@ export async function readBaseColor(path: string, occlusionPath?: string) {
|
||||
c = occlusion![occlusionI] / 255;
|
||||
}
|
||||
|
||||
const alpha = base[i * 4 + 3];
|
||||
hasAlpha ||= alpha < 255;
|
||||
|
||||
combined[i * 4 + 0] = Math.round(base[i * 4 + 0] * c);
|
||||
combined[i * 4 + 1] = Math.round(base[i * 4 + 1] * c);
|
||||
combined[i * 4 + 2] = Math.round(base[i * 4 + 2] * c);
|
||||
combined[i * 4 + 3] = base[i * 4 + 3];
|
||||
combined[i * 4 + 3] = alpha;
|
||||
}
|
||||
|
||||
const image = await sharp(combined, {
|
||||
@@ -42,5 +46,5 @@ export async function readBaseColor(path: string, occlusionPath?: string) {
|
||||
.webp()
|
||||
.toBuffer();
|
||||
|
||||
return image;
|
||||
return { hasAlpha, image };
|
||||
}
|
||||
Reference in new issue
Block a user