fix: implement types and simplify code

This commit is contained in:
TrèsAbhi committed 2026-04-14 11:31:16 -05:00
1 parent 4d13803b0c
commit 3948af9e39
2 files changed
+22 -12

No files matched your search

+4 -1
View File
@@ -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,14 +76,20 @@ export async function extractModel(vfs: AbstractVFS, path: string) {
.setImage(baseColor), .setImage(baseColor),
); );
const defaultConfigArchive = let defaultConfigArchive: ConfigArchive | undefined = undefined;
typeof node.configCount === "number"
? (times( if (node.configCount) {
node.configCount, const names = times(
(index) => node[`configArchive_${index}`], node.configCount,
).find((archive) => archive.configName === "Default") ?? (index) => node[`configArchive_${index}`],
node.configArchive_0) );
: undefined;
defaultConfigArchive = names.find(
(archive) => archive.configName === "Default",
);
defaultConfigArchive ??= node.configArchive_0;
}
const customCullMode = const customCullMode =
node.customCullMode ?? defaultConfigArchive?.customCullMode; node.customCullMode ?? defaultConfigArchive?.customCullMode;
@@ -204,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,
); );
@@ -317,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;
} }