import { AppObjectUC } from "@vived/core";
import { Vector3 } from "@vived/core";
import { sceneRayPick } from "../../Babylon";
import { SceneRootEntity } from "../Entities/SceneRootEntity";
export class ScaleSceneRootWithRay extends AppObjectUC {
    constructor(appObject) {
        super(appObject, ScaleSceneRootWithRay.type);
        this.sensitivity = 10;
        this.pickPoint = Vector3.Zero();
        this.lastDistance = 0;
        this.doScale = (pickRay, rayStart) => {
            if (!this.sceneRoot)
                return;
            const newDistance = Vector3.Subtract(rayStart, this.pickPoint).magnitude;
            const distanceChange = newDistance - this.lastDistance;
            const currentScale = this.sceneRoot.scale;
            const scaleDelta = distanceChange * this.sensitivity * currentScale;
            this.sceneRoot.bumpScaleAboutPoint(scaleDelta, this.pickPoint);
            this.lastDistance = newDistance;
        };
        this.initializeScale = (pickRay, rayStart) => {
            const pick = sceneRayPick(pickRay, this.appObjects);
            this.pickPoint = pick?.worldPickPoint ?? Vector3.Zero();
            this.lastDistance = Vector3.Subtract(rayStart, this.pickPoint).magnitude;
        };
        this.sceneRoot = appObject.getComponent(SceneRootEntity.type);
        if (!this.sceneRoot) {
            this.warn("ScaleSceneRootWithRay added to an app object that does not have a SceneRootEntity");
        }
    }
}
ScaleSceneRootWithRay.type = "ScaleSceneRootWithRay";
//# sourceMappingURL=ScaleSceneRootWithRay.js.map