import { Memory } from 'thyseus';
import { Vec3 } from "@houseki-engine/core";
import { Transform } from "@houseki-engine/scene";
import { Entity, EntityCommands, type f32, struct, type u64 } from "thyseus";
export class TargetTransform extends Transform {
}
export class PrevTargetTransform extends Transform {
}
export class Velocity extends Vec3 {
}
export class BoxCollider {
    static readonly size = 24;
    static readonly alignment = 8;
    __$$b = 0;
    deserialize() { this.size.__$$b = this.__$$b; this.size.deserialize(); }
    serialize() { this.size.__$$b = this.__$$b; this.size.serialize(); }
    size: Vec3;
    constructor(size: Readonly<[
        number,
        number,
        number
    ]> = [1, 1, 1]) {
        this.size = new Vec3(...size);
    }
}
export class SphereCollider {
    static readonly size = 4;
    static readonly alignment = 4;
    __$$b = 0;
    deserialize() { this.radius = Memory.f32[this.__$$b >> 2]; }
    serialize() { Memory.f32[this.__$$b >> 2] = this.radius; }
    radius: f32;
    constructor(radius = 0.5) {
        this.radius = radius;
    }
}
export class CapsuleCollider {
    static readonly size = 8;
    static readonly alignment = 4;
    __$$b = 0;
    deserialize() { this.radius = Memory.f32[this.__$$b >> 2]; this.height = Memory.f32[(this.__$$b + 4) >> 2]; }
    serialize() { Memory.f32[this.__$$b >> 2] = this.radius; Memory.f32[(this.__$$b + 4) >> 2] = this.height; }
    radius: f32;
    height: f32;
    constructor(radius = 0.5, height = 1) {
        this.radius = radius;
        this.height = height;
    }
}
export class CylinderCollider {
    static readonly size = 8;
    static readonly alignment = 4;
    __$$b = 0;
    deserialize() { this.radius = Memory.f32[this.__$$b >> 2]; this.height = Memory.f32[(this.__$$b + 4) >> 2]; }
    serialize() { Memory.f32[this.__$$b >> 2] = this.radius; Memory.f32[(this.__$$b + 4) >> 2] = this.height; }
    radius: f32;
    height: f32;
    constructor(radius = 0.5, height = 1) {
        this.radius = radius;
        this.height = height;
    }
}
export class HullCollider {
    static readonly size = 8;
    static readonly alignment = 8;
    __$$b = 0;
    deserialize() { this.meshId = Memory.u64[this.__$$b >> 3]; }
    serialize() { Memory.u64[this.__$$b >> 3] = this.meshId; }
    meshId: u64;
    constructor(mesh?: Entity | EntityCommands) {
        this.meshId = mesh?.id ?? 0n;
    }
}
export class MeshCollider {
    static readonly size = 8;
    static readonly alignment = 8;
    __$$b = 0;
    deserialize() { this.meshId = Memory.u64[this.__$$b >> 3]; }
    serialize() { Memory.u64[this.__$$b >> 3] = this.meshId; }
    meshId: u64;
    constructor(mesh?: Entity | EntityCommands) {
        this.meshId = mesh?.id ?? 0n;
    }
}
export class StaticBody {
    static readonly size = 0;
    static readonly alignment = 1;
    __$$b = 0;
    deserialize() { }
    serialize() { }
}
export class KinematicBody {
    static readonly size = 56;
    static readonly alignment = 8;
    __$$b = 0;
    deserialize() { this.linearVelocity.__$$b = this.__$$b; this.linearVelocity.deserialize(); this.angularVelocity.__$$b = this.__$$b + 24; this.angularVelocity.deserialize(); this.mass = Memory.f32[(this.__$$b + 48) >> 2]; }
    serialize() { this.linearVelocity.__$$b = this.__$$b; this.linearVelocity.serialize(); this.angularVelocity.__$$b = this.__$$b + 24; this.angularVelocity.serialize(); Memory.f32[(this.__$$b + 48) >> 2] = this.mass; }
    mass: f32;
    linearVelocity: Vec3 = new Vec3();
    angularVelocity: Vec3 = new Vec3();
    constructor(mass = 1) {
        this.mass = mass;
    }
}
export class DynamicBody {
    static readonly size = 56;
    static readonly alignment = 8;
    __$$b = 0;
    deserialize() { this.linearVelocity.__$$b = this.__$$b; this.linearVelocity.deserialize(); this.angularVelocity.__$$b = this.__$$b + 24; this.angularVelocity.deserialize(); this.mass = Memory.f32[(this.__$$b + 48) >> 2]; }
    serialize() { this.linearVelocity.__$$b = this.__$$b; this.linearVelocity.serialize(); this.angularVelocity.__$$b = this.__$$b + 24; this.angularVelocity.serialize(); Memory.f32[(this.__$$b + 48) >> 2] = this.mass; }
    mass: f32 = 0;
    linearVelocity: Vec3 = new Vec3();
    angularVelocity: Vec3 = new Vec3();
    constructor(mass = 1) {
        this.mass = mass;
    }
}
export class CharacterController {
    static readonly size = 32;
    static readonly alignment = 4;
    __$$b = 0;
    deserialize() { this.offset = Memory.f32[this.__$$b >> 2]; this.maxSlopeClimbAngle = Memory.f32[(this.__$$b + 4) >> 2]; this.minSlopeSlideAngle = Memory.f32[(this.__$$b + 8) >> 2]; this.maxStepHeight = Memory.f32[(this.__$$b + 12) >> 2]; this.minStepWidth = Memory.f32[(this.__$$b + 16) >> 2]; this.snapToGroundDistance = Memory.f32[(this.__$$b + 20) >> 2]; this.enableAutostep = Boolean(Memory.u8[this.__$$b + 24]); this.stepOnDynamicBodies = Boolean(Memory.u8[this.__$$b + 25]); this.enableSnapToGround = Boolean(Memory.u8[this.__$$b + 26]); this.applyImpulsesToDynamicBodies = Boolean(Memory.u8[this.__$$b + 27]); this.isGrounded = Boolean(Memory.u8[this.__$$b + 28]); }
    serialize() { Memory.f32[this.__$$b >> 2] = this.offset; Memory.f32[(this.__$$b + 4) >> 2] = this.maxSlopeClimbAngle; Memory.f32[(this.__$$b + 8) >> 2] = this.minSlopeSlideAngle; Memory.f32[(this.__$$b + 12) >> 2] = this.maxStepHeight; Memory.f32[(this.__$$b + 16) >> 2] = this.minStepWidth; Memory.f32[(this.__$$b + 20) >> 2] = this.snapToGroundDistance; Memory.u8[this.__$$b + 24] = Number(this.enableAutostep); Memory.u8[this.__$$b + 25] = Number(this.stepOnDynamicBodies); Memory.u8[this.__$$b + 26] = Number(this.enableSnapToGround); Memory.u8[this.__$$b + 27] = Number(this.applyImpulsesToDynamicBodies); Memory.u8[this.__$$b + 28] = Number(this.isGrounded); }
    offset: f32;
    maxSlopeClimbAngle: f32;
    minSlopeSlideAngle: f32;
    enableAutostep: boolean;
    maxStepHeight: f32;
    minStepWidth: f32;
    stepOnDynamicBodies: boolean;
    enableSnapToGround: boolean;
    snapToGroundDistance: f32;
    applyImpulsesToDynamicBodies: boolean;
    isGrounded: boolean;
    constructor(offset = 0.02) {
        this.offset = offset;
        this.maxSlopeClimbAngle = (60 * Math.PI) / 180;
        this.minSlopeSlideAngle = (50 * Math.PI) / 180;
        this.enableAutostep = true;
        this.maxStepHeight = 0.3;
        this.minStepWidth = 0.2;
        this.stepOnDynamicBodies = false;
        this.enableSnapToGround = true;
        this.snapToGroundDistance = 0.2;
        this.applyImpulsesToDynamicBodies = true;
        this.isGrounded = false;
    }
}
/**
 * @see https://rapier.rs/docs/user_guides/javascript/scene_queries/#ray-casting
 */
export class Raycast {
    static readonly size = 128;
    static readonly alignment = 8;
    __$$b = 0;
    deserialize() { this.origin.__$$b = this.__$$b; this.origin.deserialize(); this.direction.__$$b = this.__$$b + 24; this.direction.deserialize(); this.
    /**
     * Entity ID of a rigid body that should be excluded from the ray cast.
     */
    excludeRigidBodyId = Memory.u64[(this.__$$b + 48) >> 3]; this.hitEntityId = Memory.u64[(this.__$$b + 56) >> 3]; this.hitPosition.__$$b = this.__$$b + 64; this.hitPosition.deserialize(); this.hitNormal.__$$b = this.__$$b + 88; this.hitNormal.deserialize(); this.maxToi = Memory.f32[(this.__$$b + 112) >> 2]; this.hitToi = Memory.f32[(this.__$$b + 116) >> 2]; this.solid = Boolean(Memory.u8[this.__$$b + 120]); this.hit = Boolean(Memory.u8[this.__$$b + 121]); }
    serialize() { this.origin.__$$b = this.__$$b; this.origin.serialize(); this.direction.__$$b = this.__$$b + 24; this.direction.serialize(); Memory.u64[(this.__$$b + 48) >> 3] = this.
    /**
     * Entity ID of a rigid body that should be excluded from the ray cast.
     */
    excludeRigidBodyId; Memory.u64[(this.__$$b + 56) >> 3] = this.hitEntityId; this.hitPosition.__$$b = this.__$$b + 64; this.hitPosition.serialize(); this.hitNormal.__$$b = this.__$$b + 88; this.hitNormal.serialize(); Memory.f32[(this.__$$b + 112) >> 2] = this.maxToi; Memory.f32[(this.__$$b + 116) >> 2] = this.hitToi; Memory.u8[this.__$$b + 120] = Number(this.solid); Memory.u8[this.__$$b + 121] = Number(this.hit); }
    origin: Vec3 = new Vec3();
    direction: Vec3 = new Vec3();
    maxToi: f32;
    solid: boolean;
    /**
     * Entity ID of a rigid body that should be excluded from the ray cast.
     */
    excludeRigidBodyId: u64 = 0n;
    hit: boolean = false;
    hitToi: f32 = 0;
    hitEntityId: u64 = 0n;
    hitPosition: Vec3 = new Vec3();
    hitNormal: Vec3 = new Vec3();
    constructor(origin: Readonly<[
        number,
        number,
        number
    ]> = [0, 0, 0], direction: Readonly<[
        number,
        number,
        number
    ]> = [0, 0, 0], maxToi = 1000, solid = false) {
        this.origin = new Vec3(...origin);
        this.direction = new Vec3(...direction);
        this.maxToi = maxToi;
        this.solid = solid;
    }
}
