fix: alpha clipping

This commit is contained in:
tresabhi committed 2026-03-11 16:50:18 -05:00
1 parent 427b189a34
commit f14e73d811
5 files changed
+35 -15

No files matched your search

@@ -6,13 +6,13 @@ import {
} from "@blitzkit/core";
import { Accessor, Document, Node, Scene } from "@gltf-transform/core";
import { times } from "lodash-es";
import { SteamVFS } from "../vfs/steam";
import { AbstractVFS } from "../vfs/abstract";
import {
vertexAttributeGLTFName,
vertexAttributeGltfVectorSizes,
} from "./extractModel/constants";
export async function extractArmor(vfs: SteamVFS, fileName: string) {
export async function extractArmor(vfs: AbstractVFS, fileName: string) {
const sc2Path = `Data/3d/Tanks/CollisionMeshes/${fileName}.sc2`;
const scgPath = `Data/3d/Tanks/CollisionMeshes/${fileName}.scg`;
const sc2 = new Sc2ReadStream(
@@ -141,4 +141,4 @@ export async function extractArmor(vfs: SteamVFS, fileName: string) {
parseHierarchies(sc2["#hierarchy"], scene);
return document;
}
}
@@ -1,4 +1,5 @@
import {
bufferToBigInt,
Hierarchy,
Sc2ReadStream,
ScgReadStream,
@@ -9,7 +10,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/steam";
import { AbstractVFS } from "../../vfs/abstract";
import { readBaseColor } from "../readBaseColor";
import { readNormal } from "../readNormal";
import { readRoughnessMetallic } from "../readRoughnessMetallic";
@@ -25,7 +26,7 @@ const omitMeshNames = {
end: ["_POINT"],
};
export async function extractModel(vfs: SteamVFS, path: string) {
export async function extractModel(vfs: AbstractVFS, path: string) {
const sc2Path = `Data/3d/${path}.sc2`;
const scgPath = `Data/3d/${path}.scg`;
const sc2 = new Sc2ReadStream(
@@ -40,7 +41,7 @@ export async function extractModel(vfs: SteamVFS, path: string) {
const materials = new Map<bigint, Material | bigint | undefined>();
for (const node of sc2["#dataNodes"]) {
const id = new DataView(node["#id"]).getBigUint64(0, true);
const id = bufferToBigInt(node["#id"]);
if (node.parentMaterialKey !== undefined) {
/**
@@ -80,8 +81,20 @@ export async function extractModel(vfs: SteamVFS, path: string) {
configIndex < node.configCount;
configIndex++
) {
if (!hasAlpha) continue;
material.setAlphaMode("BLEND").setDoubleSided(true);
const archive = node[`configArchive_${configIndex}`];
if (
archive.configName !== "Default" ||
!archive.enabledPresets?.AlphaTest
) {
continue;
}
const view = new DataView(archive.properties.alphatestThreshold);
const _ = view.getUint8(0); // only god knows what these flags are
const alphaCutoff = view.getFloat32(1, true);
material.setAlphaMode("MASK").setAlphaCutoff(alphaCutoff);
}
}
@@ -116,7 +129,7 @@ export async function extractModel(vfs: SteamVFS, path: string) {
);
}
materials.set(new DataView(node["#id"]).getBigUint64(0, true), material);
materials.set(id, material);
}
}
@@ -266,4 +279,4 @@ export async function extractModel(vfs: SteamVFS, path: string) {
await document.transform(prune({ keepAttributes: true }), dedup());
return document;
}
}