diff --git a/public/base.glb b/public/base.glb new file mode 100644 index 0000000..5d2d2df Binary files /dev/null and b/public/base.glb differ diff --git a/src/levelDeserializer.ts b/src/levelDeserializer.ts index 1ca44d7..d3b3d73 100644 --- a/src/levelDeserializer.ts +++ b/src/levelDeserializer.ts @@ -28,6 +28,7 @@ import { import { FireProceduralTexture } from "@babylonjs/procedural-textures"; import {createSphereLightmap} from "./sphereLightmap"; import { GameConfig } from "./gameConfig"; +import buildStarBase from "./starBase"; import { MaterialFactory } from "./materialFactory"; import debugLog from './debug'; @@ -60,7 +61,7 @@ export class LevelDeserializer { debugLog('Deserializing level:', this.config.difficulty); // Create entities - const startBase = this.createStartBase(); + const startBase = await this.createStartBase(); const sun = this.createSun(); const planets = this.createPlanets(); const asteroids = await this.createAsteroids(scoreObservable); @@ -76,33 +77,14 @@ export class LevelDeserializer { /** * Create the start base from config */ - private createStartBase(): AbstractMesh { + private async createStartBase(): Promise { const config = this.config.startBase; + const position = this.arrayToVector3(config.position); - const mesh = MeshBuilder.CreateCylinder("startBase", { - diameter: config.diameter, - height: config.height, - tessellation: 72 - }, this.scene); + // Call the buildStarBase function to load and configure the base + const baseMesh = await buildStarBase(position); - mesh.position = this.arrayToVector3(config.position); - - const material = new StandardMaterial("startBaseMaterial", this.scene); - if (config.color) { - material.diffuseColor = new Color3(config.color[0], config.color[1], config.color[2]); - } else { - material.diffuseColor = new Color3(1, 1, 0); // Default yellow - } - mesh.material = material; - - // Only create physics if enabled in config - const gameConfig = GameConfig.getInstance(); - if (gameConfig.physicsEnabled) { - const agg = new PhysicsAggregate(mesh, PhysicsShapeType.CONVEX_HULL, { mass: 0 }, this.scene); - agg.body.setMotionType(PhysicsMotionType.ANIMATED); - } - - return mesh; + return baseMesh; } /** diff --git a/src/starBase.ts b/src/starBase.ts new file mode 100644 index 0000000..92c934a --- /dev/null +++ b/src/starBase.ts @@ -0,0 +1,40 @@ +import { + AbstractMesh, + PhysicsAggregate, + PhysicsMotionType, + PhysicsShapeType, + SceneLoader, + Vector3 +} from "@babylonjs/core"; +import {DefaultScene} from "./defaultScene"; +import {GameConfig} from "./gameConfig"; +import {debug} from "openai/core"; +import debugLog from "./debug"; + +/** + * Create and load the star base mesh + * @param position - Position for the star base + * @returns Promise resolving to the loaded star base mesh + */ +export default async function buildStarBase(position: Vector3): Promise { + const scene = DefaultScene.MainScene; + + // Load the base model + const importMesh = await SceneLoader.ImportMeshAsync(null, "./", "base.glb", scene); + const baseMesh = importMesh.meshes[0].getChildMeshes()[0]; + debugLog('Star base mesh loaded:', baseMesh); + baseMesh.id = "starBase"; + baseMesh.name = "starBase"; + baseMesh.position = position; + debugLog('Ship Bounds radius', baseMesh.getBoundingInfo().boundingSphere.radiusWorld); + // Create physics if enabled + const config = GameConfig.getInstance(); + if (config.physicsEnabled) { + const agg = new PhysicsAggregate(baseMesh, PhysicsShapeType.MESH, { + mass: 0 + }, scene); + agg.body.setMotionType(PhysicsMotionType.STATIC); + } + + return baseMesh; +} \ No newline at end of file