mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
Merge pull request #239 from karelpak1/fix-alphatest-culling
This commit is contained in:
2 files changed
+50
-7
No files matched your search
@@ -15,6 +15,9 @@ type DataNode = {
|
|||||||
qualityGroup?: string;
|
qualityGroup?: string;
|
||||||
fxName?: string;
|
fxName?: string;
|
||||||
textures?: Textures;
|
textures?: Textures;
|
||||||
|
customCullMode?: number;
|
||||||
|
enabledPresets?: EnabledPresets;
|
||||||
|
properties?: Properties;
|
||||||
} & (
|
} & (
|
||||||
| ({
|
| ({
|
||||||
configCount: number;
|
configCount: number;
|
||||||
@@ -24,7 +27,7 @@ type DataNode = {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
interface ConfigArchive {
|
export interface ConfigArchive {
|
||||||
configName: string;
|
configName: string;
|
||||||
fxName: string;
|
fxName: string;
|
||||||
properties: Properties;
|
properties: Properties;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
bufferToBigInt,
|
bufferToBigInt,
|
||||||
|
ConfigArchive,
|
||||||
Hierarchy,
|
Hierarchy,
|
||||||
Sc2ReadStream,
|
Sc2ReadStream,
|
||||||
ScgReadStream,
|
ScgReadStream,
|
||||||
@@ -75,6 +76,42 @@ export async function extractModel(vfs: AbstractVFS, path: string) {
|
|||||||
.setImage(baseColor),
|
.setImage(baseColor),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let defaultConfigArchive: ConfigArchive | undefined = undefined;
|
||||||
|
|
||||||
|
if (node.configCount) {
|
||||||
|
const names = times(
|
||||||
|
node.configCount,
|
||||||
|
(index) => node[`configArchive_${index}`],
|
||||||
|
);
|
||||||
|
|
||||||
|
defaultConfigArchive = names.find(
|
||||||
|
(archive) => archive.configName === "Default",
|
||||||
|
);
|
||||||
|
defaultConfigArchive ??= node.configArchive_0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const customCullMode =
|
||||||
|
node.customCullMode ?? defaultConfigArchive?.customCullMode;
|
||||||
|
|
||||||
|
if (customCullMode === 0) {
|
||||||
|
material.setDoubleSided(true);
|
||||||
|
} else if (customCullMode !== undefined) {
|
||||||
|
material.setDoubleSided(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
node.enabledPresets?.AlphaTest &&
|
||||||
|
node.properties?.alphatestThreshold
|
||||||
|
) {
|
||||||
|
const view = new DataView(node.properties.alphatestThreshold);
|
||||||
|
const alphaCutoff =
|
||||||
|
view.byteLength < 4
|
||||||
|
? 0.5
|
||||||
|
: view.getFloat32(view.byteLength - 4, true);
|
||||||
|
|
||||||
|
material.setAlphaMode("MASK").setAlphaCutoff(alphaCutoff);
|
||||||
|
}
|
||||||
|
|
||||||
if (node.configCount) {
|
if (node.configCount) {
|
||||||
for (
|
for (
|
||||||
let configIndex = 0;
|
let configIndex = 0;
|
||||||
@@ -85,14 +122,17 @@ export async function extractModel(vfs: AbstractVFS, path: string) {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
archive.configName !== "Default" ||
|
archive.configName !== "Default" ||
|
||||||
!archive.enabledPresets?.AlphaTest
|
!archive.enabledPresets?.AlphaTest ||
|
||||||
|
!archive.properties?.alphatestThreshold
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const view = new DataView(archive.properties.alphatestThreshold);
|
const view = new DataView(archive.properties.alphatestThreshold);
|
||||||
const _ = view.getUint8(0); // only god knows what these flags are
|
const alphaCutoff =
|
||||||
const alphaCutoff = view.getFloat32(1, true);
|
view.byteLength < 4
|
||||||
|
? 0.5
|
||||||
|
: view.getFloat32(view.byteLength - 4, true);
|
||||||
|
|
||||||
material.setAlphaMode("MASK").setAlphaCutoff(alphaCutoff);
|
material.setAlphaMode("MASK").setAlphaCutoff(alphaCutoff);
|
||||||
}
|
}
|
||||||
@@ -171,8 +211,8 @@ export async function extractModel(vfs: AbstractVFS, path: string) {
|
|||||||
|
|
||||||
case "TransformComponent": {
|
case "TransformComponent": {
|
||||||
const localTranslation = component["tc.localTranslation"];
|
const localTranslation = component["tc.localTranslation"];
|
||||||
// The game resets top-level node translation to [0, 0, 0] on load.
|
// The game resets top-level node translation to [0, 0, 0] on load.
|
||||||
// Child nodes must keep their authored local offsets.
|
// Child nodes must keep their authored local offsets.
|
||||||
node.setTranslation(
|
node.setTranslation(
|
||||||
parent instanceof Scene ? [0, 0, 0] : localTranslation,
|
parent instanceof Scene ? [0, 0, 0] : localTranslation,
|
||||||
);
|
);
|
||||||
@@ -284,4 +324,4 @@ export async function extractModel(vfs: AbstractVFS, path: string) {
|
|||||||
await document.transform(prune({ keepAttributes: true }), dedup());
|
await document.transform(prune({ keepAttributes: true }), dedup());
|
||||||
|
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user