"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScaleSceneRootWithRay = void 0;
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const SceneRootEntity_1 = require("../Entities/SceneRootEntity");
class ScaleSceneRootWithRay extends core_1.AppObjectUC {
    constructor(appObject) {
        super(appObject, ScaleSceneRootWithRay.type);
        this.sensitivity = 10;
        this.pickPoint = core_2.Vector3.Zero();
        this.lastDistance = 0;
        this.doScale = (pickRay, rayStart) => {
            if (!this.sceneRoot)
                return;
            const newDistance = core_2.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 = (0, Babylon_1.sceneRayPick)(pickRay, this.appObjects);
            this.pickPoint = pick?.worldPickPoint ?? core_2.Vector3.Zero();
            this.lastDistance = core_2.Vector3.Subtract(rayStart, this.pickPoint).magnitude;
        };
        this.sceneRoot = appObject.getComponent(SceneRootEntity_1.SceneRootEntity.type);
        if (!this.sceneRoot) {
            this.warn("ScaleSceneRootWithRay added to an app object that does not have a SceneRootEntity");
        }
    }
}
exports.ScaleSceneRootWithRay = ScaleSceneRootWithRay;
ScaleSceneRootWithRay.type = "ScaleSceneRootWithRay";
//# sourceMappingURL=ScaleSceneRootWithRay.js.map