44 EasingFunction ,
55 Move ,
66 MoveContinuous ,
7+ MoveRotateScale ,
78 PBTween ,
89 Rotate ,
910 RotateContinuous ,
@@ -14,6 +15,63 @@ import {
1415 Tween
1516} from '../generated/index.gen'
1617
18+ /**
19+ * @public
20+ * Partial params for Tween.Mode.MoveRotateScale(). At least one of position, rotation, or scale must be provided.
21+ * Use this when building a mode for Tween.createOrReplace() or TweenSequence (e.g. only positionStart/positionEnd).
22+ */
23+ export interface MoveRotateScaleModeParams {
24+ /** Position tween (start → end). Optional. */
25+ position ?: { start : Vector3 ; end : Vector3 }
26+ /** Rotation tween (start → end). Optional. */
27+ rotation ?: { start : Quaternion ; end : Quaternion }
28+ /** Scale tween (start → end). Optional. */
29+ scale ?: { start : Vector3 ; end : Vector3 }
30+ }
31+
32+ /**
33+ * @public
34+ * Parameters for setMoveRotateScale. At least one of position, rotation, or scale must be provided.
35+ */
36+ export interface SetMoveRotateScaleParams extends MoveRotateScaleModeParams {
37+ /** Duration of the tween in milliseconds. */
38+ duration : number
39+ /** Easing function (defaults to EF_LINEAR). */
40+ easingFunction ?: EasingFunction
41+ }
42+
43+ function assertDuration ( duration : number , apiName : string ) : void {
44+ if ( ! Number . isFinite ( duration ) || duration < 0 ) {
45+ throw new Error ( `${ apiName } : duration must be a non-negative finite number` )
46+ }
47+ }
48+
49+ /** Shared validation for params that have optional position/rotation/scale with start & end. */
50+ function assertMoveRotateScaleAxesStartEnd ( params : MoveRotateScaleModeParams , apiName : string ) : void {
51+ if ( ! params . position && ! params . rotation && ! params . scale ) {
52+ throw new Error ( `${ apiName } : at least one of position, rotation, or scale must be provided` )
53+ }
54+
55+ if ( params . position ) {
56+ const pos = params . position !
57+ if ( ! pos . start || ! pos . end ) {
58+ throw new Error ( `${ apiName } : position must have both start and end` )
59+ }
60+ }
61+ if ( params . rotation ) {
62+ const rot = params . rotation !
63+ if ( ! rot . start || ! rot . end ) {
64+ throw new Error ( `${ apiName } : rotation must have both start and end` )
65+ }
66+ }
67+ if ( params . scale ) {
68+ const scl = params . scale !
69+ if ( ! scl . start || ! scl . end ) {
70+ throw new Error ( `${ apiName } : scale must have both start and end` )
71+ }
72+ }
73+ }
74+
1775/**
1876 * @public
1977 */
@@ -46,14 +104,19 @@ export interface TweenHelper {
46104 * @returns a texture-move-continuous mode tween
47105 */
48106 TextureMoveContinuous : ( textureMove : TextureMoveContinuous ) => PBTween [ 'mode' ]
107+ /**
108+ * @returns a move-rotate-scale mode tween
109+ * @param params - partial transform (at least one of position, rotation, scale); omit axes you don't need
110+ */
111+ MoveRotateScale : ( params : MoveRotateScaleModeParams ) => PBTween [ 'mode' ]
49112}
50113
51114/**
52115 * @public
53116 */
54117export interface TweenComponentDefinitionExtended extends LastWriteWinElementSetComponentDefinition < PBTween > {
55118 /**
56- * Texture helpers with constructor
119+ * Helpers with constructor
57120 */
58121 Mode : TweenHelper
59122
@@ -152,6 +215,17 @@ export interface TweenComponentDefinitionExtended extends LastWriteWinElementSet
152215 movementType ?: TextureMovementType ,
153216 duration ?: number
154217 ) : void
218+
219+ /**
220+ * @public
221+ *
222+ * Creates or replaces a move-rotate-scale tween component that simultaneously animates
223+ * an entity's position, rotation, and/or scale from start to end. Provide only the
224+ * properties you need (at least one of position, rotation, or scale).
225+ * @param entity - entity to apply the tween to
226+ * @param params - object with optional position, rotation, scale (each with start/end), duration, and optional easingFunction
227+ */
228+ setMoveRotateScale ( entity : Entity , params : SetMoveRotateScaleParams ) : void
155229}
156230
157231const TweenHelper : TweenHelper = {
@@ -196,6 +270,21 @@ const TweenHelper: TweenHelper = {
196270 $case : 'textureMoveContinuous' ,
197271 textureMoveContinuous
198272 }
273+ } ,
274+ MoveRotateScale ( params ) {
275+ assertMoveRotateScaleAxesStartEnd ( params , 'Tween.Mode.MoveRotateScale' )
276+ const moveRotateScale : MoveRotateScale = {
277+ positionStart : params . position ? params . position . start : undefined ,
278+ positionEnd : params . position ? params . position . end : undefined ,
279+ rotationStart : params . rotation ? params . rotation . start : undefined ,
280+ rotationEnd : params . rotation ? params . rotation . end : undefined ,
281+ scaleStart : params . scale ? params . scale . start : undefined ,
282+ scaleEnd : params . scale ? params . scale ! . end : undefined
283+ }
284+ return {
285+ $case : 'moveRotateScale' ,
286+ moveRotateScale
287+ }
199288 }
200289}
201290
@@ -337,6 +426,28 @@ export function defineTweenComponent(
337426 easingFunction : EasingFunction . EF_LINEAR ,
338427 playing : true
339428 } )
429+ } ,
430+ setMoveRotateScale ( entity : Entity , params : SetMoveRotateScaleParams ) {
431+ assertMoveRotateScaleAxesStartEnd ( params , 'setMoveRotateScale' )
432+ assertDuration ( params . duration , 'setMoveRotateScale' )
433+ const { position, rotation, scale, duration, easingFunction = EasingFunction . EF_LINEAR } = params
434+ const moveRotateScale : MoveRotateScale = {
435+ positionStart : position ? position . start : undefined ,
436+ positionEnd : position ? position . end : undefined ,
437+ rotationStart : rotation ? rotation . start : undefined ,
438+ rotationEnd : rotation ? rotation . end : undefined ,
439+ scaleStart : scale ? scale . start : undefined ,
440+ scaleEnd : scale ? scale . end : undefined
441+ }
442+ theComponent . createOrReplace ( entity , {
443+ mode : {
444+ $case : 'moveRotateScale' ,
445+ moveRotateScale
446+ } ,
447+ duration,
448+ easingFunction,
449+ playing : true
450+ } )
340451 }
341452 }
342453}
0 commit comments