import { AppObjectPM } from "@vived/core";
import { Quaternion, Vector3 } from "@vived/core";
import { Transform3D } from "../Entities/Transform3D";
export class Transform3DPM extends AppObjectPM {
    static getForID(appObjID, appObjects) {
        const appObj = appObjects.get(appObjID);
        if (appObj === undefined) {
            return undefined;
        }
        return appObj.getComponent(Transform3DPM.type);
    }
}
Transform3DPM.type = "Transform3DPM";
export const defaultTransform3DVM = {
    position: Vector3.Zero(),
    rotation: Quaternion.Identity(),
    scale: Vector3.One(),
};
export function makeTransform3DPM(appObject) {
    return new Transform3DPMImp(appObject);
}
class Transform3DPMImp extends Transform3DPM {
    vmsAreEqual(a, b) {
        if (!Vector3.Equal(a.position, b.position))
            return false;
        if (!Vector3.Equal(a.scale, b.scale))
            return false;
        if (!Quaternion.Equal(a.rotation, b.rotation))
            return false;
        return true;
    }
    constructor(appObject) {
        super(appObject, Transform3DPM.type);
        this.onTransformChange = () => {
            if (!this.transform)
                return;
            const vm = {
                position: this.transform.localPosition,
                rotation: this.transform.localRotation,
                scale: this.transform.localScale,
            };
            this.doUpdateView(vm);
        };
        this.dispose = () => {
            super.dispose();
            this.transform?.removeChangeObserver(this.onTransformChange);
            this.transform?.removeOnDisposeObserver(this.dispose);
        };
        this.transform = Transform3D.get(appObject);
        if (!this.transform) {
            this.warn("Unable to find Transform3D Entity");
            return;
        }
        else {
            this.transform.addChangeObserver(this.onTransformChange);
            this.transform.addOnDisposeObserver(this.dispose);
            this.onTransformChange();
        }
    }
}
//# sourceMappingURL=Transform3DPM.js.map