"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultTransform3DVM = exports.Transform3DPM = void 0;
exports.makeTransform3DPM = makeTransform3DPM;
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Transform3D_1 = require("../Entities/Transform3D");
class Transform3DPM extends core_1.AppObjectPM {
    static getForID(appObjID, appObjects) {
        const appObj = appObjects.get(appObjID);
        if (appObj === undefined) {
            return undefined;
        }
        return appObj.getComponent(Transform3DPM.type);
    }
}
exports.Transform3DPM = Transform3DPM;
Transform3DPM.type = "Transform3DPM";
exports.defaultTransform3DVM = {
    position: core_2.Vector3.Zero(),
    rotation: core_2.Quaternion.Identity(),
    scale: core_2.Vector3.One(),
};
function makeTransform3DPM(appObject) {
    return new Transform3DPMImp(appObject);
}
class Transform3DPMImp extends Transform3DPM {
    vmsAreEqual(a, b) {
        if (!core_2.Vector3.Equal(a.position, b.position))
            return false;
        if (!core_2.Vector3.Equal(a.scale, b.scale))
            return false;
        if (!core_2.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_1.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