space-game/src/utils/loadAsset.ts
Michael Mainguy 44c685ac2d Cleanup batch 5: Remove unused exported types
Made 75+ types internal (removed export keyword) across 24 files:
- Analytics event types (kept GameEventMap, GameEventName, GameEventProperties)
- Level config types (QuaternionArray, MaterialConfig, etc.)
- Ship types (SightConfig, InputState, etc.)
- Store state types (AuthState, GameConfigData, etc.)
- Various config interfaces

These types are still used internally but were never imported elsewhere.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:11:40 -06:00

51 lines
1.9 KiB
TypeScript

import {DefaultScene} from "../core/defaultScene";
import {AbstractMesh, AssetContainer, LoadAssetContainerAsync} from "@babylonjs/core";
import debugLog from "../core/debug";
type LoadedAsset = {
container: AssetContainer,
meshes: Map<string, AbstractMesh>,
}
export default async function loadAsset(file: string, theme: string = "default"): Promise<LoadedAsset> {
const assetPath = `/assets/themes/${theme}/models/${file}`;
debugLog(`[loadAsset] Loading: ${assetPath}`);
try {
const container = await LoadAssetContainerAsync(assetPath, DefaultScene.MainScene);
debugLog(`[loadAsset] ✓ Container loaded for ${file}`);
const map: Map<string, AbstractMesh> = new Map();
container.addAllToScene();
debugLog(`[loadAsset] Root nodes count: ${container.rootNodes.length}`);
if (container.rootNodes.length === 0) {
console.error(`[loadAsset] ERROR: No root nodes found in ${file}`);
return {container: container, meshes: map};
}
for (const mesh of container.rootNodes[0].getChildMeshes(false)) {
console.log(mesh.id, mesh);
// Ensure mesh is visible and enabled
mesh.isVisible = true;
mesh.setEnabled(true);
// Fix emissive materials to work without lighting
if (mesh.material) {
const material = mesh.material as any;
// Disable lighting on materials so emissive works without light sources
if (material.disableLighting !== undefined) {
material.disableLighting = true;
}
}
map.set(mesh.id, mesh);
}
debugLog(`[loadAsset] ✓ Loaded ${map.size} meshes from ${file}`);
return {container: container, meshes: map};
} catch (error) {
console.error(`[loadAsset] FAILED to load ${assetPath}:`, error);
throw error;
}
}