import Signal from "@rbxts/signal"; import { createAnchor } from "Utils/Gui"; import { roundVector } from "Utils/Math"; export class Handles { currentVector: Vector3 = new Vector3(); anchor: Part; valueChanged = new Signal<(newValue: Vector3) => void>(); constructor(model: Folder, startPosition: Vector3 = Vector3.zero, anchor = createAnchor(model, startPosition)) { this.anchor = anchor; const handles = new Instance("Handles"); handles.Adornee = this.anchor; handles.Parent = model; handles.MouseButton1Down.Connect(() => { this.currentVector = this.anchor.Position; }); handles.MouseDrag.Connect((face, distance) => { // Apply the changes to the anchor's position let offset = Vector3.zero; switch (face) { case Enum.NormalId.Right: offset = new Vector3(distance, 0, 0); break; case Enum.NormalId.Left: offset = new Vector3(-distance, 0, 0); break; case Enum.NormalId.Top: offset = new Vector3(0, distance, 0); break; case Enum.NormalId.Bottom: offset = new Vector3(0, -distance, 0); break; case Enum.NormalId.Front: offset = new Vector3(0, 0, -distance); break; case Enum.NormalId.Back: offset = new Vector3(0, 0, distance); break; } this.anchor.Position = roundVector(this.currentVector.add(offset)); }); handles.MouseButton1Up.Connect(() => { const newpos = this.anchor.Position; this.valueChanged.Fire(newpos); }); } }