Class AbstractTransform

java.lang.Object
com.j3d.engine.interact.cmd.base.Command
com.j3d.engine.interact.cmd.args.Subcommand
com.j3d.engine.interact.cmd.commands.transform.AbstractTransform
All Implemented Interfaces:
Argument, KeyedStatefulCommand, SemiStatefulCommand, StatefulCommand<Void>, EventListener
Direct Known Subclasses:
RotateSelection, ScaleSelection, TranslateSelection

public abstract class AbstractTransform extends Subcommand implements KeyedStatefulCommand, EventListener
An abstract base class that provides the core framework for all stateful transformation commands (Translate, Rotate, Scale).

This class implements the KeyedStatefulCommand interface and handles the complex, shared logic required to enter a "transform mode." This includes:

  • Collecting the selected objects (references) to be transformed.
  • Storing their original positions for undo/cancel functionality.
  • Spawning and managing the 3D interactive handles (gizmos).
  • Registering and unregistering temporary keybindings (arrow keys, gear key).
  • Drawing the UI overlay with command-specific information.
  • Handling the final commit (Enter) or cancellation (Escape) of the transformation.
Subclasses like TranslateSelection extend this class to define the specific actions that happen when the user interacts with the handles or presses the arrow keys.

Any command implementing this will inherit the need to take in a single optional ArgSet called mode ("f", "t", "v", "p", "thing). By default, is set to face-mode ("f" or "t"). The difference being within face-mode, the command will filter the selection only for GTri and take the points of each triangle as the points to transform. meaning if you had selected only a single point who is parented to some triangle, all the points in the triangle are part of the transformation selection as they share the same triangle up to hierarchy. To avoid this, use point-mode ("p", "v"). Otherwise, if you had selected the "thing" option the command will filter the selection only for that Thing and take all the points of each thing as the points to transform.

Author:
Lehlogonolo Poole
See Also:
  • Field Details

    • overlapId

      protected UUID overlapId
      A unique ID for the UI overlay drawn by the sceneManager during the transform state.
    • mouseOwner

      private final TransformMouseOwner mouseOwner
      The mouse owner responsible for handling direct interaction with the 3D handles.
    • keys

      protected ArrayList<J3Key> keys
      A list of temporary keybindings (e.g., arrow keys) active during this state.
    • originalPointPos

      protected ArrayList<Vector3> originalPointPos
      A snapshot of the original positions of all points being transformed, for undo purposes.
    • references

      protected ArrayList<GPoint> references
      The list of actual GPoint objects that are being manipulated.
    • center

      protected Vector3 center
      The calculated center of the current selection.
    • argSet

      protected ArgSet argSet
      The argument set for choosing between point/face selection mode.
    • eventName

      protected String eventName
      The name of the event associated with this stateful command.
    • faceMode

      protected FaceMode faceMode
      A flag indicating if the transformation should operate on whole faces (tris) or individual points or whole things.
    • gearTrain

      protected double[] gearTrain
      An array of step sizes (e.g., 1, 5, 20) that the user can cycle through.
    • currentIndex

      protected int currentIndex
      The index of the currently active step size in the gearTrain.
    • gear

      protected J3Key gear
      The keybinding used to cycle through the gearTrain step sizes.
    • label

      protected SafeJLabel label
      The label used for providing feedback to the user.
    • centreIsSelectionPivot

      private boolean centreIsSelectionPivot
    • selectionPivot

      private GPoint selectionPivot
    • label1

      private String label1
  • Constructor Details

    • AbstractTransform

      public AbstractTransform(String commandName, String commandDesc, String eventName, TransformMouseOwner mouseOwner, double[] gearTrain)
      Constructs the abstract base for a transformation command.
      Parameters:
      commandName - The primary name of the command (e.g., "translate").
      commandDesc - A user-friendly description of the command.
      eventName - The name of the stateful event to run.
      mouseOwner - The specific mouse owner that will handle handle interaction.
      gearTrain - An array of step sizes for the command's "gear" system.
  • Method Details

    • onEvent

      public <K> void onEvent(EventType event, EventPayload<K> properties)
      Description copied from interface: EventListener
      onEvent is called by EventEmitter via EventEmitter.broadcast(EventType, EventPayload). Allowing the emitter to call any other object that implements this.
      Specified by:
      onEvent in interface EventListener
      Type Parameters:
      K - The type of the emitter of this event
      Parameters:
      event - The type of event
      properties - The given event payload
    • getCurrentStepSize

      public double getCurrentStepSize()
      Gets the currently active step size from the gear train.
      Returns:
      The current step size.
    • run

      public void run(Invoker invoker, SafeJLabel logLabel, String aliasUsed, Object[] args, ArrayList<TaggedArgValue<?>> taggedArgs)
      The main entry point for the command. It gathers the selected objects and initiates the stateful transformation mode.
      Overrides:
      run in class Command
      Parameters:
      invoker - The invoker of this command
      logLabel - The JLabel to display log messages.
      aliasUsed - The alias of the command that was used to invoke it.
      args - The arguments passed to the command.
      taggedArgs - Tagged arguments passed to the command.
    • onStart

      public void onStart(Void object, SafeJLabel label)
      Called when the transformation state begins. This method sets up the interactive environment.
      Specified by:
      onStart in interface StatefulCommand<Void>
      Parameters:
      object - The object that the command operates on.
      label - The SafeJLabel instance.
    • calculateCentre

      private Vector3 calculateCentre()
    • finished

      public void finished(boolean success, SafeJLabel lbl)
      Description copied from interface: KeyedStatefulCommand
      Method which clears all state related to this which can be
      • keys
      • ghost previews
      • temporary listeners
      • ...
      Specified by:
      finished in interface KeyedStatefulCommand
      Parameters:
      success - Whether the command finished successfully or not. if the user had clicked escape or an error occurred that counts as an unsuccessful invocation
      lbl - The label.
    • onEnter

      public void onEnter(Void object, SafeJLabel label)
      Called when the user presses Enter, committing the transformation.
      Specified by:
      onEnter in interface StatefulCommand<Void>
      Parameters:
      object - The object that the command operates on.
      label - The SafeJLabel instance.
    • toggleSaved

      private void toggleSaved()
    • onEsc

      public void onEsc(Void object, SafeJLabel label)
      Called when the user presses Escape, canceling the transformation and reverting all changes.
      Specified by:
      onEsc in interface StatefulCommand<Void>
      Parameters:
      object - The object that the command operates on.
      label - The SafeJLabel instance.
    • getKeys

      public ArrayList<J3Key> getKeys()
      Description copied from interface: KeyedStatefulCommand
      Gets the list of temporary J3Keys that are active during this command's state.
      Specified by:
      getKeys in interface KeyedStatefulCommand
      Returns:
      An ArrayList of active keys.
    • selfName

      public String selfName()
      Description copied from interface: KeyedStatefulCommand
      Returns the name of the specific command instance, used for creating unique key IDs.
      Specified by:
      selfName in interface KeyedStatefulCommand
      Returns:
      The name of the command.
    • getOriginalPointPositions

      public ArrayList<Vector3> getOriginalPointPositions()
      Retrieves the initial positions of all points being transformed. This is crucial for undoing the operation if the user cancels.
      Returns:
      An ArrayList of the original Vector3 positions.
    • getReferences

      public ArrayList<GPoint> getReferences()
      Retrieves the actual GPoint objects that are being manipulated.
      Returns:
      An ArrayList of the point references.
    • getGearTrain

      public double[] getGearTrain()
      Description copied from interface: KeyedStatefulCommand
      Gets the array of available step sizes for the transformation (the "gear train").
      Specified by:
      getGearTrain in interface KeyedStatefulCommand
      Returns:
      An array of doubles representing different step magnitudes.
    • getGearIndex

      public int getGearIndex()
      Description copied from interface: KeyedStatefulCommand
      Gets the index of the currently active step size in the gear train.
      Specified by:
      getGearIndex in interface KeyedStatefulCommand
      Returns:
      The current gear index.
    • setGearIndex

      public void setGearIndex(int index)
      Description copied from interface: KeyedStatefulCommand
      Sets the current gear index, allowing the command to cycle through step sizes.
      Specified by:
      setGearIndex in interface KeyedStatefulCommand
      Parameters:
      index - The new gear index.