var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { Vector3 } from "three";
import { serializable } from "../engine/engine_serialization_decorator.js";
import * as utils from "./../engine/engine_three_utils.js";
import { Behaviour, GameObject } from "./Component.js";
/**
 * The [AlignmentConstraint](https://engine.needle.tools/docs/api/AlignmentConstraint) positions and scales this GameObject to span between two target objects.
 * The object is rotated to face `to` and scaled along Z to match the distance.
 *
 * **Use cases:**
 * - Dynamic beams or laser effects between objects
 * - Stretchy connectors or ropes
 * - Visual links between UI elements
 * - Debug lines between transforms
 *
 * **How it works:**
 * - Position: Centered between `from` and `to` (or at `from` if not centered)
 * - Rotation: Looks at `to` from `from`
 * - Scale: Z-axis scales to match distance, X/Y use `width`
 *
 * @example Create a beam between two objects
 * ```ts
 * const beam = beamMesh.addComponent(AlignmentConstraint);
 * // Set targets via serialized properties in editor
 * // or via code if properties are exposed
 * ```
 *
 * @summary Aligns and scales object between two targets
 * @category Constraints
 * @group Components
 * @see {@link LookAtConstraint} for rotation-only constraints
 * @see {@link SmoothFollow} for following with smoothing
 **/
export class AlignmentConstraint extends Behaviour {
    from;
    to;
    width = 0;
    centered = true;
    _centerPos;
    awake() {
        this._centerPos = new Vector3();
    }
    update() {
        if (!this.from || !this.to)
            return;
        const fromWorldPos = utils.getWorldPosition(this.from).clone();
        const toWorldPos = utils.getWorldPosition(this.to).clone();
        const dist = fromWorldPos.distanceTo(toWorldPos);
        this._centerPos.copy(fromWorldPos);
        this._centerPos.add(toWorldPos);
        this._centerPos.multiplyScalar(0.5);
        utils.setWorldPosition(this.gameObject, this.centered ? this._centerPos : fromWorldPos);
        this.gameObject.lookAt(utils.getWorldPosition(this.to).clone());
        this.gameObject.scale.set(this.width, this.width, dist);
    }
}
__decorate([
    serializable(GameObject)
], AlignmentConstraint.prototype, "from", void 0);
__decorate([
    serializable(GameObject)
], AlignmentConstraint.prototype, "to", void 0);
//# sourceMappingURL=AlignmentConstraint.js.map