space-game/bjsEditorPlugin/src/configBuilders/shipBuilder.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

39 lines
1.3 KiB
TypeScript

/**
* Builds ShipConfig from mesh with ShipComponent
*/
import { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh";
import { ShipConfig, Vector3Array } from "../types";
import { getScriptValues } from "../scriptUtils";
export function buildShipConfig(mesh: AbstractMesh | null): ShipConfig {
if (!mesh) {
return { position: [0, 1, 0] };
}
const script = getScriptValues(mesh);
return {
position: toVector3Array(mesh.getAbsolutePosition()),
rotation: mesh.rotation ? toVector3Array(mesh.rotation) : undefined,
linearVelocity: extractVector3OrUndefined(script.linearVelocity),
angularVelocity: extractVector3OrUndefined(script.angularVelocity)
};
}
function toVector3Array(v: { x: number; y: number; z: number }): Vector3Array {
return [v.x, v.y, v.z];
}
function extractVector3OrUndefined(v: unknown): Vector3Array | undefined {
if (!v) return undefined;
if (Array.isArray(v)) {
const arr = v as number[];
if (arr[0] === 0 && arr[1] === 0 && arr[2] === 0) return undefined;
return arr as Vector3Array;
}
const vec = v as { x?: number; y?: number; z?: number };
const arr: Vector3Array = [vec.x ?? 0, vec.y ?? 0, vec.z ?? 0];
if (arr[0] === 0 && arr[1] === 0 && arr[2] === 0) return undefined;
return arr;
}