diff --git a/src/index.ts b/src/index.ts index 49bba1c..90635a9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -39,6 +39,13 @@ export * from './utils/Stats'; export * from './utils/Utils'; export * from './utils/VectorUtils'; +/** @internal */ +declare module 'three/src/math/Vector2' { + export interface Vector { + lerpVectors(v1: Vector, v2: Vector, alpha: number): this; + } +} + declare module 'three/src/core/Object3D' { export interface Object3D extends Object3DExtPrototype { } } diff --git a/src/tweening/Actions.ts b/src/tweening/Actions.ts index 80c7927..d540ce2 100644 --- a/src/tweening/Actions.ts +++ b/src/tweening/Actions.ts @@ -1,14 +1,14 @@ -import { Color, ColorRepresentation, Euler, MathUtils, Quaternion, Vector3 } from "three"; +import { Color, ColorRepresentation, Euler, MathUtils, Quaternion, Vector, Vector2, Vector3, Vector4 } from "three"; import { DEFAULT_EASING, Easing, EasingFunction, Easings } from "./Easings"; import { RunningAction } from "./RunningTween"; import { Tween } from "./Tween"; const easings = new Easings(); -export type AllowedTypes = number | Vector3 | Quaternion | Euler | ColorRepresentation; +export type AllowedTypes = number | Vector | Quaternion | Euler | ColorRepresentation; export type Omitype = { [P in keyof T as T[P] extends U ? never : P]: T[P] }; export type PickType = { [P in keyof T as T[P] extends U ? P : never]: T[P] }; export type TransformType = { [P in keyof T]: T[P] extends U ? T[P] | V : T[P] }; -export type TransformedTypes = TransformType, Vector3, number>; +export type TransformedTypes = TransformType, Vector, number>; export type FilteredType = PickType>, AllowedTypes>; export type Motion = { [key in keyof FilteredType]: FilteredType[key] }; export type SetMotion = { [key in keyof T]?: T[key] }; @@ -123,7 +123,7 @@ export class ActionMotion implements IAction { if (key === "easing") continue; const actionValue = this.motion[key]; const targetValue = target[key]; - const action = this.vector3(key, actionValue as Vector3, targetValue as Vector3) + const action = this.vector(key, actionValue as Vector, targetValue as Vector) ?? this.quaternion(key, actionValue as Quaternion, targetValue as Quaternion) ?? this.euler(key, actionValue as Euler, targetValue as Euler) ?? this.color(key, actionValue as Color, targetValue as Color) @@ -140,9 +140,9 @@ export class ActionMotion implements IAction { return typeof easing === "string" ? (easings[easing].bind(easings) ?? easings.linear) : easing; } - private vector3(key: string, actionValue: Vector3 | number, targetValue: Vector3): RunningAction { - if (targetValue?.isVector3) { - const value = typeof actionValue === "number" ? new Vector3(actionValue, actionValue, actionValue) : actionValue; + private vector(key: string, actionValue: Vector | number, targetValue: Vector): RunningAction { + if ((targetValue as Vector2)?.isVector2 || (targetValue as Vector3)?.isVector3 || (targetValue as Vector4)?.isVector4) { + const value = typeof actionValue === "number" ? targetValue.clone().setScalar(actionValue) : actionValue; return { key, time: this.time,