module Controls3D
- type TransformModfier: Record<TransformType, number>
No description.
- type KeyboardModifier<Axes extends string>: Record<Axes, Array<string[]>>
No description.
class Controls3D
- Controls3D(eventTarget?: EventTarget,): Controls3D
config?: Partial<Controls3DConfig> Parameters
-
eventTarget
: The DOM Element to receive the pointer, wheel and touch events. If left unspecified, usechangeTarget
. -
config
: A subset of the possible configuration options.
-
- hasGamepad: boolean
No description.
- touchIsActive: boolean
If true, a touch action is currently underway.
No description.
- readonly target: EventTarget
No description.
- static MODIFIER_KEYS: readonly ["shiftKey", "ctrlKey", "altKey", "metaKey"]
No description.
- changeTarget(newEventTarget: EventTarget): void
Assign a new event target. This removes currently attached events and attaches them to the new target.
- changeState(newState: State3D): void
No description.
- changeCallback(newCallback: Function): void
No description.
- assignNewConfig(newConfig: Partial<Controls3DConfig>): void
No description.
- removeTargetEvents(eventTarget: EventTarget): void
No description.
- addTargetEvents(eventTarget: EventTarget): void
No description.
- touchDown(e: TouchEvent): void
No description.
- touchMove(e: TouchEvent): void
No description.
- touchUp(e: TouchEvent): void
No description.
- touchTransformTranslate(usedTouches: UsedTouchList): void
No description.
- touchTransformScale(usedTouches: UsedTouchList): void
No description.
- getTouchesFromIDs(targetTouches: TouchList,): UsedTouchList
touchIDs: TouchIDList No description.
- initializeTouchData(touchList: TouchList): void
No description.
- updateTouchData(touchList: TouchList): void
No description.
- preventContext(e: PointerEvent): void
No description.
- wheelAction(e: WheelEvent): Promise<void>
No description.
- pointerMove(e: PointerEvent): void
No description.
- pointerDown(e: PointerEvent): void
No description.
- pointerUp(): void
No description.
- pointerTransformTranslate(e: PointerEvent,): void
usedAxes: Array<"x" | "y"> No description.
- pointerTransformRotate(e: PointerEvent,): void
usedAxes: Array<"x" | "y"> No description.
- gamepadConnected(e: GamepadEvent): void
No description.
- gamepadDisconnected(e: GamepadEvent): void
No description.
- gamepadLoop(): void
No description.
- handleJoystick(axes: [number, number],): void
resetButton: GamepadButton,
type: TransformType No description.
- assignNewTransformAndDraw(transform: {): voidscale: {}x: number,},
y: number,
z: number
tran: {x: number,},
y: number,
z: number
rot: {x: number,}
y: number,
z: number No description.
- static getEligibleAxesFromKeyMap<Axes extends string>(keyMap: KeyboardModifier<Axes>,): Axes[]
e: MouseEvent No description.
- static getTouchesDistance(): number
Compute the distance between two supplied Touch objects.
- static getTouchesMidpoint(): [number, number]
Compute the midpoint vector of two supplied Touch objects.
namespace Touch
- type TouchData:
No description.
- type TouchIDList: [number, number]
No description.
- type UsedTouchList: [Touch, Touch]
No description.
- type TouchDataList: [TouchData, TouchData]
No description.
interface ClickState
interface TouchState
No description.
No description.
No description.
No description.
interface DrawData extends Partial<AnimationData>
No description.
- animation?: {isFinished: boolean,}
elapsed: number,
duration: number,
types: TransformType[] No description.
interface Controls3DConfig
DOM element that will register all pointer, mousewheel and touch events used for transformation.
If left unspecified, set it later using
Controls3D.changeTarget
.The initial state all transformations will operate on.
If left unspecified, set it later using
Controls3D.changeState
.The initial callback that will be called during transformations.
If left unspecified, set it later using
Controls3D.changeCallback
.Modifier that will be multiplied with the value of pointer transformation operations.
For example, a
tran
mod of .25 will reduce the pointer translation values per call to 25%, slowing down the translation.Like
mod
but only for gamepad transformations.- disableEvents: boolean | {contextmenu: boolean,}
gamepad: boolean,
pointer: boolean,
wheel: boolean,
touch: boolean Disable all or only specific event types.
- joystickThreshold: number
Configure gamepad joystick dead zone threshold in order to prevent passive drift.
Accepts a range from 0 to 1, corresponding to a threshold of 0% and 100% respectively.
- invertTranslateY: boolean
Whether to flip the Y axis within translation.
You'll want to enable this option when using Controls3D with OpenGL since it uses some counterintuitive axis math.
- keyModifier: {scale: KeyboardModifier<"x" | "y" | "z">,}
tran: KeyboardModifier<"x" | "y">,
rot: KeyboardModifier<"x" | "y"> Configure mandatory keyboard modifiers for a specified state and axis to be able to get modified during a pointer event.
- The array can contain multiple key mod arrays, any of which must be valid.
- A key mod array must match the event exactly; Non-present key modifiers inside it must NOT be pressed in order for the axis to be registered. See the example for more info.
Example (The default `scale` key modifiers.)
With this configuration, all
scale
axes are modified simultaneously upon scroll (as is the expected behavior), but as soon as the ctrl key is pressed, ONLY the X axis is changed.keyModifier: { scale: { x: [ [], [ 'ctrlKey' ] ], y: [ [], [ 'shiftKey' ] ], z: [ [], [ 'ctrlKey', 'shiftKey' ] ] } }
See also
Controls3D.MODIFIER_KEYS
for the available values.
module State3D
- type
DeepPartial<T>: T extends object ? {} : T
Deeply mark an object as Partial. From https://stackoverflow.com/a/61132308
- type TransformType: "scale" | "tran" | "rot"
No description.
- type TransformAxis: "x" | "y" | "z"
No description.
- type TransformSingle: Record<TransformAxis, number>
No description.
No description.
No description.
- type Transform: DeepPartial<TransformWhole>
No description.
class State3D
- State3D(initialTransform: {): State3Dscale: {}x: number,},
y: number,
z: number
tran: {x: number,},
y: number,
z: number
rot: {x: number,}
y: number,
z: number No description.
No description.
- static Easing: EasingList
Easing functions that can be used within
animate
.Mostly taken from https://easings.net/
- scale():
No description.
- tran():
No description.
- rot():
No description.
- animateFrom(duration: number,): Promise<void>
transform: {scale: {},x: number,},
y: number,
z: number
tran: {x: number,},
y: number,
z: number
rot: {x: number,}
y: number,
z: number
options: Omit<Parameters, "steps"> Same as
animate
but animate from the passed transform to the current transform without additional steps.Parameters
-
duration
: How long the animation should run.
-
- animateTo(duration: number,): Promise<void>
transform: {scale: {},x: number,},
y: number,
z: number
tran: {x: number,},
y: number,
z: number
rot: {x: number,}
y: number,
z: number
options: Omit<Parameters, "steps"> Same as
animate
but animate from the current transform to the passed transform without additional steps.Parameters
-
duration
: How long the animation should run.
-
- animate(duration: number, _args: Parameters): Promise<void>
Animate this state's
transform
based on the passedsteps
for the specified amount of milliseconds.Parameters
-
duration
: How long the animation should run.
-
Deeply clone and return the current transform.
- assignNewTransform(newTransform: {): State3Dscale: {}x: number,},
y: number,
z: number
tran: {x: number,},
y: number,
z: number
rot: {x: number,}
y: number,
z: number Assign a new transform.
- static fillTransform(transform: {): TransformWholescale: {}x: number,},
y: number,
z: number
tran: {x: number,},
y: number,
z: number
rot: {x: number,}
y: number,
z: number Modify a given transform such that missing values are filled with a 0, thus asserting the transform to be Whole instead of Partial.
This modifies the given transform in-place. If you need a copy, you must explicitly pass one.
- static accumulateTransforms(...transforms: Array<{): {scale: {}>x: number,},
y: number,
z: number
tran: {x: number,},
y: number,
z: number
rot: {x: number,}
y: number,
z: numberscale: {}x: number,},
y: number,
z: number
tran: {x: number,},
y: number,
z: number
rot: {x: number,}
y: number,
z: number Returns a new transform which is the accumulation of the values of passed transforms.
Parameters
-
transforms
: The transforms that will be added together.
-
- static cloneTransform(transform: State3D): {scale: {}x: number,},
y: number,
z: number
tran: {x: number,},
y: number,
z: number
rot: {x: number,}
y: number,
z: number Deeply clone a transform. Accepts either a plain transform or a State3D instance, whose transform will be cloned.
- static cloneTransform<S extends {>(scale: {}x: number,},
y: number,
z: number
tran: {x: number,},
y: number,
z: number
rot: {x: number,}
y: number,
z: numberstate: S): S Deeply clone a transform. Accepts either a plain transform or a State3D instance, whose transform will be cloned.
namespace Animation
- type Easing: (x: number) => number
No description.
- type LoopCallback: (data: LoopResult) => boolean | void
No description.
interface AnimationData
- animation: {isFinished: boolean,}
elapsed: number,
duration: number,
types: TransformType[] No description.
interface Parameters
Animation steps ranging from 0 to 100, representing a step's duration percentage.
If no 0% step is specified, the animation will start at the current transform. Similarly, if no 100% step is specified, the animation will end at the current transform.
Keys outside of the interval [0, 100] will be nonsensical.
- callback?: (data?: AnimationData) => void
The callback that will be called during every animation frame with
AnimationData
.The easing used during the whole animation.
See also
State3D.Easing
for quickly available easings.Default
Linear easing.
- useStacking?: boolean
If true, do not reset the animation to an initial state, but advance it continuously.
- fill?: boolean
If true, a specified step of 100% will become the final transform after the animation is finished, instead of resetting to the initial transform.