Skip to content

Inputs overhaul (CameraControls updated) #7779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 385 commits into from
Jun 20, 2025
Merged

Inputs overhaul (CameraControls updated) #7779

merged 385 commits into from
Jun 20, 2025

Conversation

kpal81xd
Copy link
Contributor

@kpal81xd kpal81xd commented Jun 18, 2025

Input Classes

Input Sources

SingleGestureSource - Single touch or virtual joystick input
DualGestureSource - Split screen touch or virtual joystick input
MultiTouchSource - Multi touch input (includes pinch handling)
KeyboardMouseSource - Keyboard and mouse input
GamepadSource - Game pad input

Input Controllers

FlyController - Applies smoothed free-fly transformations to a Pose
OrbitController - Applies smoothed orbiting transformations to a Pose
FocusController - Applies smoothed focusing transformations to a Pose

Other classes

Pose

  • position, angles, distance fields
  • lerp to interpolate poses
  • look method to construct from position and focus target using look
  • pitchRange and yawRange for angle constraints
  • xRange yRange zRange for position constraints

kpal81xd and others added 30 commits March 11, 2025 15:57
@Maksims
Copy link
Collaborator

Maksims commented Jun 19, 2025

It'll be treeshaken out when using the unbundled build of the engine yes

What about the Editor with classic scripts?

@kpal81xd
Copy link
Contributor Author

It'll be treeshaken out when using the unbundled build of the engine yes

What about the Editor with classic scripts?

If its a UMD or bundled build all extras are bundled in currently. We are working on solutions to split out extras to reduce the overall engine size.

@kpal81xd kpal81xd marked this pull request as ready for review June 19, 2025 17:07
@kpal81xd kpal81xd requested review from a team and Copilot June 19, 2025 17:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR overhauls input-related classes and controllers, updating various input sources (touch, keyboard-mouse, gamepad) and controllers (fly, orbit, focus) as well as updating example code to align with the new camera control API. Key changes include the introduction of a VirtualJoystick class, expanded dual and multi-touch gesture sources, and updated camera control handling in examples.

Reviewed Changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/extras/input/sources/virtual-joystick.js New virtual joystick implementation with basic pointer methods
src/extras/input/sources/single-gesture-source.js Incorporates VirtualJoystick for single-touch inputs
src/extras/input/sources/multi-touch-source.js Supports multi-touch with mid-point and pinch calculations
src/extras/input/sources/keyboard-mouse-source.js Implements keyboard and mouse input handling
src/extras/input/sources/gamepad-source.js Implements gamepad input reporting
src/extras/input/sources/dual-gesture-source.js Supports dual-touch inputs with left/right joystick management
src/extras/input/pose.js Defines 3D pose with interpolation and look methods
src/extras/input/input.js Base input classes and delta aggregation logic
src/extras/input/controllers/orbit-controller.js, focus-controller.js, fly-controller.js New input controllers with smoothing and dampening behaviors
examples/ Updated example modules to accommodate updated controllers and new joystick UI

@Maksims
Copy link
Collaborator

Maksims commented Jun 20, 2025

If its a UMD or bundled build all extras are bundled in currently. We are working on solutions to split out extras to reduce the overall engine size.

As we rely on classical scripts, it would be great to keep the engine as lean as possible.
If large extras are added, it would be nice to highlight the additional Kbs and % of size difference with/without.

@kpal81xd kpal81xd merged commit 5ecf856 into main Jun 20, 2025
7 checks passed
@kpal81xd kpal81xd deleted the inputs branch June 20, 2025 14:03
kpal81xd added a commit that referenced this pull request Jun 23, 2025
* Added in attributes and descriptions

* Updated keyboard input to use codes

* Removed manual update and destroy in example

* Added back arrow keys

* Padded out example for new camera controls with attributes and UI

* Converted gamepad dead zone to vec2

* Ensure enable fly/orbit toggled modes

* Fold init into initialize again

* Fixed ranges to be of the same type

* Replaced old multi camera example with new

* Replaced fly and orbit with new camera controls

* hoisted out reattach and fixed useVirtualGamepad

* removed unsed import

* Added space to keys

* WIP: fps controller update

* Made update controller priv

* WIP: fps controlle rework

* Removed controller for now and embedded directly into controls

* Removed first person controls to merge existing work first

* Removed export for first person model

* Hoisted out clear buttons

* Updated Editor example to use new camera controls

* Replaced old camera controls script with new one

* Fixed typings for events

* Fixed tag ordering

* Added in pointercancel event

* [Refactor] Replace Delta with InputDelta in input handling classes

* [Refactor] Replace mode property with _switchMode method in CameraControls

* Typedoc ignore WIP extras for now

* Exposed input devices and controllers with alpha typedoc flag

* Refactored Controller name to Transformer to better describe classes

* Refactor CameraControls: rename controller variables to transformer for clarity

* Alphabetized imports in camera-controls

* Clarify damping descriptions in CameraControls documentation to specify range and effects

* Clarify damping descriptions in FlyTransformer and OrbitTransformer to specify range and default values

* Clarify pitch and yaw range descriptions to specify the range and their application in fly and orbit modes

* Enhance documentation for InputDelta and InputDevice classes with category and alpha annotations

* Add a blank line for improved readability in KeyboardMouseInputDevice class

* Refactor input device classes and add new input sources for enhanced control

* Reorganised inputs

* renamed joystick to virtual joystick

* Replaced joystick touch with dual touch

* Removed joystick touch refe

* Refactor input handling: remove DoubleJoystick, update to DualTouch, and enhance type management

* Refactor DualTouch input handling: update layout management and simplify joystick type usage

* Rename Joystick class to VirtualJoystick and update event firing references

* Refactor input handling: update mobile input layout references and replace Joystick with VirtualJoystick

* Update category annotations for input controllers and sources

* Refactor input sources: rename classes and update imports for consistency

* Update documentation for DualTouchSource layout and fix delta handling

* Add SingleTouchSource input source implementation and update exports

* Remove unused _camera property from detach method in DualTouchSource and GamepadSource

* Add layout documentation for CameraControls and remove redundant layout comment from DualTouchSource

* Update category annotations for InputDelta, InputSource, and InputController

* Refactor DualTouchSource and SingleTouchSource constructors to remove layout parameter and update default layout values

* Rename DualTouchSource to DualGuestureSource and add SingleGuestureSource implementation

* Fix typos in gesture source names and add SingleGestureSource implementation

* Fix: Correct dual gesture source layout and enhance constructor flexibility

* Fix: Correct input order in desktop controls for better navigation

* Fix: Correct zoom property to return the current zoom distance

* Refactor: Rename lerpRate function to damp for clarity

* Enhance camera controls: integrate orbit controller with camera and simplify update logic

* Refactor: Rename mobile input properties for clarity in DualGestureSource

* Refactor: Update input handling to use InputDelta for movement and rotation in camera controllers

* Refactor: Simplify movement scaling in CameraControls and improve input handling

* Refactor: Streamline mobile input handling and consolidate input accumulation logic

* Refactor: Restrict joystick event handling to fly mode and streamline input accumulation logic

* Refactor: Replace length calculation with Math.sqrt for improved clarity in OrbitController

* Refactor: Enhance clarity and organization in CameraControls class structure

* Refactor: Replace drag input handling with rotate input in CameraControls and OrbitController

* Refactor: Simplify input handling in OrbitController and CameraControls by consolidating zoom and move logic

* Fixed pan

* Refactor: Adjust rotate input handling in CameraControls to improve consistency and clarity

* Refactor: Consolidate dead zone logic for gamepad input in CameraControls

* Refactor: Streamline input handling for orbit and fly modes in CameraControls

* Refactor: Consolidate look, pan, and zoom logic in FlyController and OrbitController for improved clarity and maintainability

* Refactor: Introduce Pose class and update input controllers to use Pose for position and rotation management

* Refactor: Update FlyController to use local rotation for movement calculations and return pose

* Refactor: Update pose handling in FlyController and OrbitController to use angles instead of rotation

* Refactor: Enhance Pose class with pitch and yaw range management, and implement move and rotate methods

* Fix: Ensure detach is called in InputController destroy method

* Refactor: Update FlyController to use Pose for target position and angles management

* Refactor: Update pan condition in CameraControls to depend on orbit mode

* Refactor: Replace angle clamping with rotation and movement methods in FlyController

* Refactor: Simplify angle handling in Pose class and update FlyController to utilize new methods

* Refactor: Optimize angle setting in Pose class to handle zero rotation case

* Refactor: Remove redundant pitch and yaw range properties in FlyController and utilize targetPose for range management

* Refactor: Update OrbitController to use focusPoint instead of point and streamline pose management

* Refactor: Simplify pitch and yaw range handling in OrbitController and streamline zoom management

* Refactor: Introduce distance method in Pose class and simplify focus delta calculation in OrbitController

* Refactor: Adjust damping values in FlyController for improved movement responsiveness

* Fixed typo in lerp

* Refactor: Use rotateDamping for rotation dampening in FlyController update method

* Refactor: Improve focus interrupt logic in OrbitController by using separate length calculations for move and rotate inputs

* Refactor: Simplify position update logic in OrbitController by using move method for target pose

* Refactor: Enhance focus end check in OrbitController by separating movement and zoom distance calculations

* Refactor: Add _pan method to OrbitController for improved rotation input handling

* Refactor: Replace _position getter with _getPosition method in OrbitController for improved position calculation

* Refactor: Update _getPosition method in OrbitController to improve position calculation clarity

* Refactor: Update attach method in FlyController to improve pose handling and add look method in Pose for direction setting

* Refactor: Simplify attach method in FlyController for improved clarity and efficiency

* Refactor: Simplify attach method in FlyController and enhance look method in Pose for improved direction handling

* Fix: Correct elevation calculation in look method for accurate pose direction

* Refactored look method

* Refactor: Update look method to improve direction handling and clarify parameter requirements

* Refactor: Remove unused temporary variables in Pose class for improved clarity

* Refactor: Add distance and zoomRange properties to Pose class and update related methods for enhanced functionality

* Refactor: Simplify zoom handling by integrating zoom logic into targetPose and removing unused variables

* Refactor: Replace _zoomDist with direct access to rootPose.distance for improved clarity and consistency in zoom handling

* Refactor: Remove unused math import in orbit-controller for improved clarity

* Refactor: Rename focusPoint getter to focus and update focus method to reset for improved clarity and consistency in orbit controls

* Refactor: Rename _targetPose to _targetRootPose and _targetChildPose for improved clarity; update related methods to enhance pose handling

* Refactor: Remove unused variables and implement pose multiplication method for improved clarity and functionality in pose handling

* Refactor: Simplify controller attachment by removing unnecessary zero parameter in pose initialization for improved clarity

* Refactor: Simplify move and zoom multipliers for improved readability and maintainability

* Refactor: Update mode switching logic to default to orbit mode and streamline controller attachment for improved clarity and functionality

* Refactor: Update input controller to include focus parameter in attach method and adjust related logic for improved functionality

* Refactor: Add TypeScript ignore comments for camera, controller, and mode properties to suppress type checking errors

* Refactor: Rename mode switching method from _switchMode to _setMode for improved clarity and consistency

* Refactor: Update mode initialization to default to orbit mode for improved clarity

* Refactor: Update attach methods in input controllers to use position instead of pose for improved clarity and consistency

* Refactor: Update parameter names in attach and reset methods for improved clarity

* Refactor: Clarify comment for switchToFly condition to specify movement keys

* Refactor: Update parameters in attach method for improved clarity

* Refactor: Remove unused temporary Pose variable for improved clarity

* Refactor: Update variable names in reset method for improved clarity

* Added header for pose class

* Refactor: Update orbit controller comment and set zoom range defaults

* Refactor: Remove old controller detachment logic for improved clarity

* Refactor: Simplify pitch, yaw, and zoom range setters for improved clarity

* Moved pan from rotate to move input

* Refactor: Enhance mobile and gamepad input sensitivity calculations for improved control

* Refactor: Update pan method to normalize deltas and improve perspective calculations

* Refactor: Update _pan method to include zoom delta and improve perspective calculations

* Refactor: Update camera properties handling in OrbitController for improved perspective calculations

* Refactor: Enhance perspective calculations in OrbitController and CameraControls for improved zoom and pan handling

* Refactor: Simplify movement and rotation handling in OrbitController for improved clarity

* Refactor: Remove unused pan input delta from update method in OrbitController

* Refactor: Update view frustum size calculation and streamline controller update in CameraControls

* Refactor: Streamline input handling in CameraControls by consolidating input methods and removing unused frame properties

* Refactor: Remove unused variable tmpV2 from OrbitController

* Refactor: Replace new InputDelta instances with InputDelta.alloc for improved memory management

* Refactor: Update _screenToWorld method to use this.app for accessing graphicsDevice

* Refactor: Simplify input handling in CameraControls and enhance InputDelta methods for improved chaining

* Removed unused sub and flush methods on input delta class

* Refactored input delta add

* Refactor: Consolidate input delta handling in CameraControls for improved clarity and maintainability

* Refactor: Replace InputDelta.alloc with new InputDelta for improved clarity and consistency

* Added new InputFrame class for managing multiple input deltas

* Refactor: Replace frame methods with flush in input sources for consistency and clarity

* Add InputConsumer class and update exports for input handling

* Refactor: Reorganize InputConsumer class definition and update exports for clarity

* Refactor: Remove unused camera property from OrbitController for clarity

* Refactor: Clarify comment on controller update in CameraControls class

* Refactor: Rename input delta methods for consistency and clarity

* Add static parse method to InputFrame for processing raw input values

* Refactor: Rename orbitMove to flyMove for clarity in movement calculations

* Refactor: Rename joystick event names for clarity and consistency

* Refactor: Simplify joystick UI show/hide logic and remove unused move calls

* Refactor: Consolidate joystick event handling into a single event for improved clarity and efficiency

* Refactor: Rename slice variable to halfSlice for clarity in view frustum calculations

* Refactor: Update InputFrame and related classes to use arrays for move and rotate properties for improved flexibility

* Refactor: Remove unused getter for current delta value in InputDelta class

* Refactor: Rename _instance to _value in InputDelta class for clarity

* Refactor: Rename flush methods to read for consistency in input handling

* Refactor: Rename reset methods to attach for consistency in controller handling and add smooth transition option

* Refactor: Replace new Array() with Array() for consistency in array initialization

* Refactor: Update _screenToWorld method to use system.app.graphicsDevice.clientRect for improved device coordinate handling

* Refactor: Update attach and look methods for improved pose handling and consistency

* Refactor: Improve distance calculations in OrbitController and Pose classes for better focus handling

* Refactor: Update attach method in FlyController to copy position for improved pose handling

* Refactor: Update look method in Pose class to improve parameter naming for clarity

* Refactor: Update Pose class constructor and methods to include distance parameter for improved pose handling

* Use pose for attach

* Refactor: Optimize vector calculations in FlyController for improved performance

* Refactor: Replace temporary variables with class properties in OrbitController for improved clarity

* Refactor: Replace manual distance calculations with utility functions for improved readability in OrbitController

* Refactor: Simplify movement and rotation input handling in CameraControls for improved readability

* Refactor: Move screenToWorld function outside of CameraControls class for improved modularity and clarity

* Refactor: Consolidate state reset logic in CameraControls for improved clarity and maintainability

* Refactor: Replace temporary variable with new instance of Vec3 for improved clarity in CameraControls

* Refactor: Inline movement and zoom multipliers in CameraControls for improved clarity and maintainability

* Refactor: Replace orbit controller zoom with pose distance for improved consistency in CameraControls

* Refactor: Add spacing for improved readability in CameraControls class

* Refactor: Remove redundant state reset logic in CameraControls for improved clarity and maintainability

* Refactor: Optimize layout setter in gesture sources to prevent unnecessary updates and improve performance

* Refactor: Simplify mobile input layout assignment in CameraControls for improved clarity

* Refactor: Clarify documentation for angles in Pose class to specify calculation from forward vector

* Refactor: Remove unused rotation2 variable in OrbitController for improved clarity

* Refactor: Introduce getFocus method in Pose class for improved clarity and encapsulation of focus point calculation

* Refactor: Rename offset variable to position in OrbitController for improved clarity and consistency

* Refactor: Move set method to the end of the Pose class for improved organization and readability

* Refactor: Update lerp method in Pose class to include distance interpolation for improved functionality

* Refactor: Update pose calculation in CameraControls for improved focus handling and clarity

* Refactor: Enhance focus handling in OrbitController and add length method to InputDelta for improved functionality

* Refactor: Move damp function to math.js for improved organization and reuse in controllers

* Refactor: Replace static mode constants in CameraControls with string literals for improved clarity and simplicity

* Refactor: Replace almostEqualPose function with equalsApprox method for improved clarity and performance

* Refactor: Simplify focus handling in CameraControls and OrbitController for improved clarity and functionality

* WIP: added focus controller

* Refactor: Enhance CameraControls to support 'focus' mode and streamline controller management

* Refactor: Simplify focusPoint setter in CameraControls by removing unnecessary mode switch

* Refactor: Remove unused _prevMode property from CameraControls and set default mode to 'orbit'

* Refactor: Add clone method to Pose class for creating a new instance with the same properties

* Refactor: Rename position variable to offset in OrbitController for clarity

* Moved all scaling inside camera controls

* Refactor: Discard frame by default in InputConsumer and call super in InputController update method

* Added enum for keycode ids in the input delta for key

* Refactor: Simplify pointer event handling in DualGestureSource

* Refactor: Simplify pointer event handling in SingleGestureSource

* Refactor: Optimize pointer event handling in MultiTouchSource

* Refactor: Improve pointer event handling by using target property in DualGestureSource and SingleGestureSource

* feat: Add event handling capabilities to InputSource class

* Refactor: Update VirtualJoystick to use _base and _stick for position tracking

* refactor: Simplify joystick event handling and improve code readability

* refactor: Eliminate unnecessary Vec2 instance and streamline move method logic

* fix: Handle cases with fewer than two pointer events in mid point and pinch distance calculations

* Snap internal pose when setting focusPoint

* refactor: Optimize move method by reusing Vec2 instance for calculations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants