cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
7.16k stars 1.83k forks source link

[tween] Add bezier / catmullrom support #17216

Closed dumganhar closed 3 months ago

dumganhar commented 3 months ago

Re: https://github.com/cocos/3d-tasks/issues/11124

Test caser depends on https://github.com/cocos/cocos-engine/pull/17213

Screenshot 2024-06-24 at 18 01 03 Screenshot 2024-06-24 at 17 58 20

Usage


const originalKnots: ReadonlyArray<Vec3> = [
    // v3(-360, -180, 0), // start
    v3(-180*1.5, 80, 0),
    v3(-100, -180+100, 0),
    v3(0, 0, 0),
    v3(0, 0, 0),
    v3(100, -180+100, 0),
    v3(180*1.5, 80, 0),
    v3(360, -180, 0),
];

const pos = this.greenBlock.getPosition().clone();
const offsetKnots = originalKnots.map((v: Vec3) => v.clone().subtract(pos));

this._tweenGreen = tween(this.greenBlock)
            .by(2, { position: tweenProgress.bezier(...offsetKnots) }).id(1)
            .reverse(1)
            .union()
            .repeatForever()
            .timeScale(0.5)
            .start();

Changelog

*


Continuous Integration

This pull request:


Compatibility Check

This pull request:

github-actions[bot] commented 3 months ago

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -54838,11 +54838,16 @@
         get relative(): boolean;
         clone(): TweenAction<T>;
         reverse(): TweenAction<T>;
         startWithTarget<U>(target: U | null): void;
+        stop(): void;
         update(t: number): void;
         progress(start: number, end: number, current: number, t: number): number;
     }
+    export namespace tweenProgress {
+        export function bezier(...knots: ReadonlyArray<math.Vec3>): ITweenCustomProperty<math.Vec3>;
+        export function catmullRom(...knots: ReadonlyArray<math.Vec3>): ITweenCustomProperty<math.Vec3>;
+    }
     /**
      * @en
      * tween is a utility function that helps instantiate Tween instances.
      * @zh
@@ -54866,8 +54871,14 @@
      */
     export function tweenUtil<T extends object = any>(target?: T): Tween<T>;
     export type TweenCustomProgress = (start: any, end: any, current: any, ratio: number) => any;
     export type TweenCustomEasing = ITweenOption["easing"];
+    export interface ITweenCustomPropertyStartParameter<Value> {
+        relative: boolean;
+        reversed: boolean;
+        start: Value;
+        end: Value;
+    }
     export interface ITweenCustomProperty<Value> {
         value: __private._cocos_tween_tween__MaybeUnionStringNumber<Value> | (() => __private._cocos_tween_tween__MaybeUnionStringNumber<Value>);
         progress?: TweenCustomProgress;
         easing?: TweenCustomEasing;
@@ -54876,8 +54887,11 @@
         add?: (a: Value, b: Value) => Value;
         sub?: (a: Value, b: Value) => Value;
         legacyProgress?: __private._cocos_tween_tween__ExtendsReturnResultOrNever<Value, object, boolean>;
         toFixed?: __private._cocos_tween_tween__ExtendsReturnResultOrNever<Value, string, number>;
+        onStart?: (param: ITweenCustomPropertyStartParameter<Value>) => void;
+        onStop?: () => void;
+        onComplete?: () => void;
     }
     export type TweenUpdateCallback<T extends object, Args extends any[]> = (target: T, ratio: number, ...args: Args) => void;
     /**
      * @en