import { Matrix4Compat, QuaternionCompat, Vector3Compat } from "../math/index.js";
let nextObjectId = 1;
export class Object3DCompat {
    id = nextObjectId++;
    uuid;
    name = "";
    type = "Object3D";
    parent = null;
    children = [];
    position = new Vector3Compat();
    rotation = new Vector3Compat();
    quaternion = new QuaternionCompat();
    scale = new Vector3Compat(1, 1, 1);
    matrix = new Matrix4Compat();
    matrixWorld = new Matrix4Compat();
    visible = true;
    userData = {};
    constructor() {
        this.uuid = `a3d-three-compat-${this.id}`;
    }
    add(...objects) {
        for (const object of objects) {
            if (object.parent)
                object.parent.remove(object);
            object.parent = this;
            this.children.push(object);
        }
        return this;
    }
    remove(...objects) {
        for (const object of objects) {
            const index = this.children.indexOf(object);
            if (index >= 0) {
                this.children.splice(index, 1);
                object.parent = null;
            }
        }
        return this;
    }
    traverse(callback) {
        callback(this);
        for (const child of this.children)
            child.traverse(callback);
    }
    updateMatrixWorld() {
        this.matrixWorld.identity();
        for (const child of this.children)
            child.updateMatrixWorld();
    }
}
export class GroupCompat extends Object3DCompat {
    type = "Group";
}
export class MeshCompat extends Object3DCompat {
    geometry;
    material;
    type = "Mesh";
    constructor(geometry = null, material = null) {
        super();
        this.geometry = geometry;
        this.material = material;
    }
}
export class LineSegmentsCompat extends Object3DCompat {
    geometry;
    material;
    type = "LineSegments";
    constructor(geometry = null, material = null) {
        super();
        this.geometry = geometry;
        this.material = material;
    }
}
export class PointsCompat extends Object3DCompat {
    geometry;
    material;
    type = "Points";
    constructor(geometry = null, material = null) {
        super();
        this.geometry = geometry;
        this.material = material;
    }
}
export class SpriteCompat extends Object3DCompat {
    material;
    type = "Sprite";
    constructor(material = null) {
        super();
        this.material = material;
    }
}
export class SpriteBatchCompat extends Object3DCompat {
    type = "SpriteBatch";
    sprites = [];
    billboardMode = "screen-aligned";
    addSprite(sprite) {
        this.add(sprite);
        this.sprites.push(sprite);
        return this;
    }
    buildInstanceData() {
        return this.sprites.filter((sprite) => sprite.visible).map((sprite) => ({
            sprite,
            position: [sprite.position.x, sprite.position.y, sprite.position.z],
            scale: [sprite.scale.x, sprite.scale.y],
            rotation: typeof sprite.material?.rotation === "number"
                ? sprite.material.rotation
                : 0
        }));
    }
}
//# sourceMappingURL=Object3DCompat.js.map