space-game/bjsEditorPlugin/src/configBuilders/planetBuilder.ts
Michael Mainguy 96bc3df51e
All checks were successful
Build / build (push) Successful in 2m0s
Fix position export and add target physics improvements
- Use getAbsolutePosition() in all config builders for correct world coords
- Add TargetComponent case to meshCollector for target export
- Add shared target body cache in RockFactory (asteroids can share targets)
- Add debug logging throughout export and physics pipelines
- Pass targetId to RockFactory for proper target body sharing

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-09 12:33:31 -06:00

32 lines
1.0 KiB
TypeScript

/**
* Builds PlanetConfig[] from meshes with PlanetComponent
*/
import { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh";
import { PlanetConfig, Vector3Array } from "../types";
import { getScriptValues } from "../scriptUtils";
export function buildPlanetConfigs(meshes: AbstractMesh[]): PlanetConfig[] {
return meshes.map(buildSinglePlanet);
}
function buildSinglePlanet(mesh: AbstractMesh): PlanetConfig {
const script = getScriptValues(mesh);
return {
name: mesh.name || "planet",
position: toVector3Array(mesh.getAbsolutePosition()),
diameter: (script.diameter as number) ?? 100,
texturePath: (script.texturePath as string) || "planet_texture.jpg",
rotation: hasRotation(mesh) ? toVector3Array(mesh.rotation) : undefined
};
}
function toVector3Array(v: { x: number; y: number; z: number }): Vector3Array {
return [v.x, v.y, v.z];
}
function hasRotation(mesh: AbstractMesh): boolean {
const r = mesh.rotation;
return r.x !== 0 || r.y !== 0 || r.z !== 0;
}