fix: transparency checks and depth writing

This commit is contained in:
TrèsAbhi committed 2026-02-18 18:20:37 -06:00
1 parent bae7ca2720
commit d5269e763b
3 files changed
+22 -25

No files matched your search

@@ -61,20 +61,17 @@ export async function extractModel(vfs: SteamVFS, path: string) {
} }
if (textures) { 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( material.setBaseColorTexture(
document document
.createTexture(node.materialName) .createTexture(node.materialName)
.setMimeType("image/webp") .setMimeType("image/webp")
.setImage( .setImage(baseColor),
await readBaseColor(
`Data/3d/${dirname(path)}/${
textures.baseColorMap ?? textures.albedo
}`,
textures.miscMap
? `Data/3d/${dirname(path)}/${textures.miscMap}`
: undefined,
),
),
); );
if (node.configCount) { if (node.configCount) {
@@ -83,15 +80,7 @@ export async function extractModel(vfs: SteamVFS, path: string) {
configIndex < node.configCount; configIndex < node.configCount;
configIndex++ configIndex++
) { ) {
const archive = node[`configArchive_${configIndex}`]; if (!hasAlpha) continue;
if (
archive.configName !== "Default" ||
!archive.enabledPresets?.AlphaTest
) {
continue;
}
material.setAlphaMode("BLEND").setDoubleSided(true); material.setAlphaMode("BLEND").setDoubleSided(true);
} }
} }
@@ -2,6 +2,7 @@ import sharp from "sharp";
import { readTexture } from "./readTexture"; import { readTexture } from "./readTexture";
export async function readBaseColor(path: string, occlusionPath?: string) { export async function readBaseColor(path: string, occlusionPath?: string) {
let hasAlpha = false;
const baseRaw = await readTexture(path); const baseRaw = await readTexture(path);
const occlusionRaw = occlusionPath const occlusionRaw = occlusionPath
? await readTexture(occlusionPath) ? await readTexture(occlusionPath)
@@ -30,10 +31,13 @@ export async function readBaseColor(path: string, occlusionPath?: string) {
c = occlusion![occlusionI] / 255; 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 + 0] = Math.round(base[i * 4 + 0] * c);
combined[i * 4 + 1] = Math.round(base[i * 4 + 1] * 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 + 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, { const image = await sharp(combined, {
@@ -42,5 +46,5 @@ export async function readBaseColor(path: string, occlusionPath?: string) {
.webp() .webp()
.toBuffer(); .toBuffer();
return image; return { hasAlpha, image };
} }
@@ -1,5 +1,5 @@
import type { ComponentProps, ReactNode } from "react"; import type { ComponentProps, ReactNode } from "react";
import { Mesh, Object3D } from "three"; import { Mesh, MeshStandardMaterial, Object3D } from "three";
export function jsxTree( export function jsxTree(
node: Object3D, node: Object3D,
@@ -7,14 +7,14 @@ export function jsxTree(
mesh?: ( mesh?: (
mesh: Mesh, mesh: Mesh,
props: ComponentProps<"mesh">, props: ComponentProps<"mesh">,
key: string key: string,
) => ReactNode; ) => ReactNode;
group?: ( group?: (
object3d: Object3D, object3d: Object3D,
props: ComponentProps<"group">, props: ComponentProps<"group">,
key: string key: string,
) => ReactNode; ) => ReactNode;
} },
): ReactNode { ): ReactNode {
if (node instanceof Mesh) { if (node instanceof Mesh) {
const props = { const props = {
@@ -25,6 +25,10 @@ export function jsxTree(
scale: node.scale, scale: node.scale,
}; };
if (props.material instanceof MeshStandardMaterial) {
props.material.depthWrite = true;
}
return mergers?.mesh ? ( return mergers?.mesh ? (
mergers.mesh(node, props, node.uuid) mergers.mesh(node, props, node.uuid)
) : ( ) : (