import { interpolatePosition } from "./ScenePhysicsBridge.js";
export class ECSPhysicsBridge {
    bindings = new Map();
    bind(binding) {
        if (this.bindings.has(binding.bodyId)) {
            throw new Error(`Body ${binding.bodyId} is already bound to an ECS transform.`);
        }
        this.bindings.set(binding.bodyId, binding);
    }
    unbind(bodyId) {
        this.bindings.delete(bodyId);
    }
    pushKinematic(world) {
        for (const binding of this.bindings.values()) {
            if (binding.mode !== "kinematic") {
                continue;
            }
            world.getBody(binding.bodyId)?.setPosition(binding.transform.position);
        }
    }
    pullDynamic(world, alpha = 1) {
        for (const binding of this.bindings.values()) {
            if (binding.mode === "kinematic") {
                continue;
            }
            const body = world.getBody(binding.bodyId);
            if (!body) {
                continue;
            }
            const interpolated = interpolatePosition(body.previousPosition, body.position, alpha);
            binding.transform.position[0] = interpolated[0];
            binding.transform.position[1] = interpolated[1];
            binding.transform.position[2] = interpolated[2];
        }
    }
}
//# sourceMappingURL=ECSPhysicsBridge.js.map