Skip to content

[功能][Spine] 补完 spine 4.2 的 PhysicsConstraint wasm 绑定#98

Merged
star-e merged 3 commits intococos:v4.0.0from
RazgrizHsu:v4.0.0
Mar 25, 2026
Merged

[功能][Spine] 补完 spine 4.2 的 PhysicsConstraint wasm 绑定#98
star-e merged 3 commits intococos:v4.0.0from
RazgrizHsu:v4.0.0

Conversation

@RazgrizHsu
Copy link
Copy Markdown
Contributor

实际项目中需要通过代码动态控制 spine 物理约束参数(如风力、重力、惯性等),
用于角色头发飘动、衣物摆动等效果的实时调整

具体使用场景例如触摸时给wind,gravity增加offset
然后再复原, 就可以达成与spine物理系统互动

原有绑定不完整,调用 getPhysicsConstraints() 会报 UnboundTypeError,
此 PR 补完缺失的绑定

Changelog

  • Add SPVectorPhysicsConstraintPtr using
  • Add DEFINE_ALLOW_RAW_POINTER for
    PhysicsConstraintData/PhysicsConstraint
  • Add REGISTER_SPINE_ENUM(Physics)
  • Add REGISTER_SPINE_VECTOR for physics types
  • Add PhysicsConstraintData/PhysicsConstraint class bindings
  • Add Skeleton.getPhysicsConstraints/findPhysicsConstraint
  • Fix SkeletonData.findPhysicsConstraint pointing to wrong function
  • Sync spine-core.d.ts type definitions

Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

- Add SPVectorPhysicsConstraintPtr using
- Add DEFINE_ALLOW_RAW_POINTER for
PhysicsConstraintData/PhysicsConstraint
- Add REGISTER_SPINE_ENUM(Physics)
- Add REGISTER_SPINE_VECTOR for physics types
- Add PhysicsConstraintData/PhysicsConstraint class bindings
- Add Skeleton.getPhysicsConstraints/findPhysicsConstraint
- Fix SkeletonData.findPhysicsConstraint pointing to wrong function
- Sync spine-core.d.ts type definitions
@github-actions
Copy link
Copy Markdown

@RazgrizHsu, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
web-mobile PASS PASS FAIL graphics-line-join
ios PASS PASS PASS
mac PASS PASS PASS

@github-actions
Copy link
Copy Markdown

@RazgrizHsu, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
windows PASS PASS PASS
android PASS PASS PASS
wechatgame PASS FAIL FAIL

@star-e star-e requested a review from bofeng-song March 18, 2026 06:19
@bofeng-song
Copy link
Copy Markdown
Contributor

Related PR: cocos/cocos-engine-external#508

@bofeng-song
Copy link
Copy Markdown
Contributor

@RazgrizHsu please merge my pr to update external version
RazgrizHsu#1

@RazgrizHsu
Copy link
Copy Markdown
Contributor Author

我其实还有另一个想暴露的api,只是不确定是不是放一起比较好?

AnimationState:clearNext这个方法
实际使用时也会用到
情境是代码可能连续呼叫某个动画播放, 这时会queue在c++层
透过呼叫这个可以使其排除掉后面queue的
也就是达成 播完当前这一个就好 的需求

我是用在攻击动画上,但中间被打断时,就播完当前的就停止

@star-e
Copy link
Copy Markdown
Contributor

star-e commented Mar 25, 2026

@cocos-robot run test cases

@star-e
Copy link
Copy Markdown
Contributor

star-e commented Mar 25, 2026

我其实还有另一个想暴露的api,只是不确定是不是放一起比较好?

AnimationState:clearNext这个方法 实际使用时也会用到 情境是代码可能连续呼叫某个动画播放, 这时会queue在c++层 透过呼叫这个可以使其排除掉后面queue的 也就是达成 播完当前这一个就好 的需求

我是用在攻击动画上,但中间被打断时,就播完当前的就停止

放在另一个pr里吧。

@github-actions
Copy link
Copy Markdown

Code Size Check Report

Wechat (WASM) Before After Diff
2D Empty (legacy pipeline) 1010419 bytes 1010419 bytes ✅ 0 bytes
2D All (legacy pipeline) 2677413 bytes 2677413 bytes ✅ 0 bytes
2D All (new pipeline) 2769154 bytes 2769154 bytes ✅ 0 bytes
(2D + 3D) All 10026387 bytes 10026387 bytes ✅ 0 bytes
Web (WASM + ASMJS) Before After Diff
(2D + 3D) All 16846038 bytes 16862946 bytes ⚠️ +16908 bytes

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -52001,8 +52001,24 @@
                 set(index: number, value: number);
                 get(index: number): number;
                 delete();
             }
+            /**
+             * @version 4.2
+             */
+            export class SPVectorPhysicsConstraintPtr {
+                size(): number;
+                get(index: number): PhysicsConstraint;
+                delete();
+            }
+            /**
+             * @version 4.2
+             */
+            export class SPVectorPhysicsConstraintDataPtr {
+                size(): number;
+                get(index: number): PhysicsConstraintData;
+                delete();
+            }
             export class Animation {
                 constructor(name: string, timelines: Array<Timeline>, duration: number);
                 duration: number;
                 name: string;
@@ -52645,8 +52661,12 @@
                 drawOrder: Array<Slot>;
                 ikConstraints: Array<IkConstraint>;
                 transformConstraints: Array<TransformConstraint>;
                 pathConstraints: Array<PathConstraint>;
+                /**
+                 * @version 4.2
+                 */
+                physicsConstraints: Array<PhysicsConstraint>;
                 _updateCache: Updatable[];
                 skin: Skin;
                 color: Color;
                 time: number;
@@ -52672,10 +52692,26 @@
                 setAttachment(slotName: string, attachmentName: string): void;
                 findIkConstraint(constraintName: string): IkConstraint;
                 findTransformConstraint(constraintName: string): TransformConstraint;
                 findPathConstraint(constraintName: string): PathConstraint;
+                /**
+                 * @version 4.2
+                 */
+                findPhysicsConstraint(constraintName: string): PhysicsConstraint;
+                /**
+                 * @version 4.2
+                 */
+                getPhysicsConstraints(): SPVectorPhysicsConstraintPtr;
                 //getBounds(offset: Vector2, size: Vector2, temp?: Array<number>): void;
                 update(delta: number): void;
+                /**
+                 * @version 4.2
+                 */
+                updateWorldTransform(physics: Physics): void;
+                /**
+                 * @version 4.2
+                 */
+                updateWorldTransform(physics: Physics, parent: Bone): void;
             }
             export class SkeletonBinary {
                 static AttachmentTypeValues: number[];
                 static TransformModeValues: TransformMode[];
@@ -52735,8 +52771,12 @@
                 animations: Animation[];
                 ikConstraints: IkConstraintData[];
                 transformConstraints: TransformConstraintData[];
                 pathConstraints: PathConstraintData[];
+                /**
+                 * @version 4.2
+                 */
+                physicsConstraints: PhysicsConstraintData[];
                 x: number;
                 y: number;
                 width: number;
                 height: number;
@@ -52758,8 +52798,16 @@
                 findIkConstraint(constraintName: string): IkConstraintData;
                 findTransformConstraint(constraintName: string): TransformConstraintData;
                 findPathConstraint(constraintName: string): PathConstraintData;
                 findPathConstraintIndex(pathConstraintName: string): number;
+                /**
+                 * @version 4.2
+                 */
+                findPhysicsConstraint(constraintName: string): PhysicsConstraintData;
+                /**
+                 * @version 4.2
+                 */
+                getPhysicsConstraints(): SPVectorPhysicsConstraintDataPtr;
             }
             export class SkeletonJson {
                 attachmentLoader: AttachmentLoader;
                 scale: number;
@@ -52925,8 +52973,84 @@
                 relative: boolean;
                 local: boolean;
                 constructor(name: string);
             }
+            /**
+             * @version 4.2
+             */
+            export enum Physics {
+                none = 0,
+                reset = 1,
+                update = 2,
+                pose = 3
+            }
+            /**
+             * @version 4.2
+             */
+            export class PhysicsConstraint implements Updatable {
+                data: PhysicsConstraintData;
+                bone: Bone;
+                inertia: number;
+                strength: number;
+                damping: number;
+                massInverse: number;
+                wind: number;
+                gravity: number;
+                mix: number;
+                _reset: boolean;
+                ux: number;
+                uy: number;
+                cx: number;
+                cy: number;
+                tx: number;
+                ty: number;
+                xOffset: number;
+                xVelocity: number;
+                yOffset: number;
+                yVelocity: number;
+                rotateOffset: number;
+                rotateVelocity: number;
+                scaleOffset: number;
+                scaleVelocity: number;
+                remaining: number;
+                lastTime: number;
+                active: boolean;
+                constructor(data: PhysicsConstraintData, skeleton: Skeleton);
+                isActive(): boolean;
+                reset(): void;
+                setToSetupPose(): void;
+                update(): void;
+                translate(x: number, y: number): void;
+                rotate(x: number, y: number, degrees: number): void;
+            }
+            /**
+             * @version 4.2
+             */
+            export class PhysicsConstraintData extends ConstraintData {
+                bone: BoneData;
+                x: number;
+                y: number;
+                rotate: number;
+                scaleX: number;
+                shearX: number;
+                limit: number;
+                step: number;
+                inertia: number;
+                strength: number;
+                damping: number;
+                massInverse: number;
+                wind: number;
+                gravity: number;
+                mix: number;
+                inertiaGlobal: boolean;
+                strengthGlobal: boolean;
+                dampingGlobal: boolean;
+                massGlobal: boolean;
+                windGlobal: boolean;
+                gravityGlobal: boolean;
+                mixGlobal: boolean;
+                constructor(name: string);
+            }
             export class Triangulator {
                 triangulate(verticesArray: ArrayLike<number>): Array<number>;
                 decompose(verticesArray: Array<number>, triangles: Array<number>): Array<Array<number>>;
             }

@github-actions
Copy link
Copy Markdown

@RazgrizHsu, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
web-mobile PASS PASS FAIL BuildTimeConstantsTest
ios PASS PASS FAIL BuildTimeConstantsTest
mac PASS PASS FAIL BuildTimeConstantsTest

@github-actions
Copy link
Copy Markdown

@RazgrizHsu, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
windows PASS PASS FAIL BuildTimeConstantsTest
android PASS PASS FAIL BuildTimeConstantsTest
wechatgame PASS FAIL FAIL

@star-e star-e merged commit ea6ff53 into cocos:v4.0.0 Mar 25, 2026
34 of 35 checks passed
@github-actions
Copy link
Copy Markdown

@RazgrizHsu ❗ There was an error during the execution of the tasks. Please check the logs for more details.

@github-actions
Copy link
Copy Markdown

@RazgrizHsu, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
web-mobile PASS PASS FAIL BuildTimeConstantsTest
ios PASS PASS FAIL BuildTimeConstantsTest
mac PASS PASS FAIL BuildTimeConstantsTest

@github-actions
Copy link
Copy Markdown

@RazgrizHsu, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
windows PASS PASS FAIL BuildTimeConstantsTest
android PASS PASS FAIL BuildTimeConstantsTest
wechatgame PASS FAIL FAIL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants