Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3.8.6] [2D Skew comes back] Add UISkew component support. #18212

Merged
merged 25 commits into from
Jan 22, 2025

Conversation

dumganhar
Copy link
Contributor

@dumganhar dumganhar commented Jan 17, 2025

Re: #17852

Need to consider

  • Least performance overhead for Node.
  • Less code size increment.

TODO:

  • Add some UnitTests
  • Editor: gizmo support
  • Editor: skew icon

Inspector Panel Preview

WeChatbe1b87427bdc50e6f59ff0543cbd8cf6

Limitation

If the parent node has a UISkew component, the world scale and world rotation of the current node may become inaccurate. It is recommended to use local scale and local rotation to modify the scaling and rotation of the current node.
(Reason: Skew transformations alter the scale and rotation components in the world matrix, making it impossible to accurately reconstruct the world SRT components from the world matrix.)

Changelog


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.

@dumganhar dumganhar requested a review from minggo January 17, 2025 11:07
Copy link

github-actions bot commented Jan 17, 2025

⚠️ Package size ⤴ 2095 bytes, old: 5230226, new: 5232321

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -1756,8 +1756,64 @@
         getComputeAABB(out?: geometry.AABB): geometry.AABB;
         protected _selfBoundingBox(out: math.Rect): math.Rect;
         protected _parentChanged(node: Node): void;
     }
+    export class UISkew extends Component {
+        constructor();
+        protected __preload(): void;
+        protected onEnable(): void;
+        protected onDisable(): void;
+        protected onDestroy(): void;
+        /**
+         * @en Gets the skew on x axis. Unit is degree.
+         * @zh 获取 X 轴斜切角度。
+         */
+        get x(): number;
+        /**
+         * @en Sets the skew on x axis. Unit is degree.
+         * @zh 设置 X 轴斜切角度。
+         */
+        set x(v: number);
+        /**
+         * @en Gets the skew on y axis. Unit is degree.
+         * @zh 获取 Y 轴斜切角度。
+         */
+        get y(): number;
+        /**
+         * @en Sets the skew on y axis. Unit is degree.
+         * @zh 设置 Y 轴斜切角度。
+         */
+        set y(v: number);
+        /**
+         * @en Gets the skew value of the node. Unit is degree.
+         * @zh 获取节点斜切角度。
+         */
+        get skew(): Readonly<math.Vec2>;
+        /**
+         * @en Sets the skew value of the node. Unit is degree.
+         * @zh 设置节点斜切角度。
+         */
+        set skew(value: Readonly<math.Vec2>);
+        /**
+         * @en Sets the skew value of the node by Vec2.
+         * @zh 设置节点斜切角度。
+         * @param @en value The skew value in Vec2. @zh 斜切角度值。
+         */
+        setSkew(value: Readonly<math.IVec2Like>): void;
+        /**
+         * @en Sets the skew value of the node by x and y.
+         * @zh 设置节点斜切角度。
+         * @param x @en The skew on x axis. @zh X 轴斜切角度。
+         * @param y @en The skew on y axis. @zh Y 轴斜切角度。
+         */
+        setSkew(x: number, y: number): void;
+        /**
+         * @en Copies and returns the skew value of the node.
+         * @zh 拷贝节点斜切角度值并返回。
+         * @returns @en The skew value of the node. @zh 节点斜切角度。
+         */
+        getSkew(out?: math.Vec2): math.Vec2;
+    }
     /**
      * @en The entry node for 2D object data collection, all 2D rendering objects need to be rendered under the RenderRoot node.
      * @zh 2D 对象数据收集的入口节点,所有的 2D渲染对象需在 RenderRoot 节点下才可以被渲染。
      */
@@ -24197,8 +24253,11 @@
         protected _scene: Scene;
         protected _activeInHierarchy: boolean;
         protected _id: string;
         protected _eventProcessor: __private._cocos_scene_graph_node_event_processor__NodeEventProcessor;
+        /**
+         * @dontmangle Ensure _eventMask not to be mangled since it is visited by UISkew._updateNodeTransformFlags with 'any' conversion.
+         */
         protected _eventMask: number;
         protected _siblingIndex: number;
         /**
          * @en
@@ -24671,9 +24730,9 @@
         protected _lscale: math.Vec3;
         protected _mobility: number;
         protected _layer: number;
         protected _euler: math.Vec3;
-        protected _transformFlags: TransformBit;
+        protected _transformFlags: number;
         protected _eulerDirty: boolean;
         protected _flagChangeVersion: number;
         protected _hasChangedFlags: number;
         constructor(name?: string);
@@ -26022,13 +26081,22 @@
          * @zh 节点缩放
          */
         SCALE = 4,
         /**
+         * @en Skew changed
+         * @zh 节点斜切
+         */
+        SKEW = 8,
+        /**
          * @en Rotation or scale changed
          * @zh 节点旋转及缩放
          */
         RS = 6,
         /**
+         * @en Rotation, scale or skew changed
+         */
+        RSS = 14,
+        /**
          * @en Translation, rotation or scale changed
          * @zh 节点平移,旋转及缩放
          */
         TRS = 7,

@dumganhar dumganhar marked this pull request as draft January 17, 2025 15:51
@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

1 similar comment
@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

Copy link

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

Task Details

Copy link

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

Task Details

if (cur) {
if (dirtyBits & TransformBit.POSITION) {
if (positionDirty && !rotationScaleDirty) {
Vec3.transformMat4(childPos, child._lpos, cur._mat);
Copy link
Contributor Author

@dumganhar dumganhar Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If position and (rotation/scale/skew) are both dirty. Doesn't need to go here to calculate world matrix since in the following if (rotationScaleSkewDirty) { logic , it will do that in Mat4.fromSRT ( get the local matrix) + Mat4.multiply ( get the world matrix = parent's world matrix * my local matrix ).

In this case, we avoid the unused Vec3.transformMat4 operation.

Mat4.fromSRT(childMat, child._lrot, child._lpos, child._lscale);
uiSkewComp = child._uiProps._uiSkewComp;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use getter and make _uiSkewComp @engineInternal public property for fast accessing the UISkew component.

@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

Copy link

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

Task Details

Copy link

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

Task Details

@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

Copy link

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

Task Details

Copy link

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

Task Details

@dumganhar dumganhar changed the title [v3.8.6] Add UISkew component support. [v3.8.6] [2D Skew is back] Add UISkew component support. Jan 19, 2025
@dumganhar dumganhar changed the title [v3.8.6] [2D Skew is back] Add UISkew component support. [v3.8.6] [2D Skew comes back] Add UISkew component support. Jan 19, 2025
@dumganhar dumganhar marked this pull request as ready for review January 21, 2025 09:26
@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

@dumganhar
Copy link
Contributor Author

@minggo This PR is ready now. I think we could put it in the v3.8.6 beta0 and get feedback from developers.

@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

Copy link

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

Task Details

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

Copy link

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

Task Details

@minggo
Copy link
Contributor

minggo commented Jan 22, 2025

Please fix the CI error.

@dumganhar
Copy link
Contributor Author

@minggo
企业微信截图_b16840ff-f88a-40a9-bd90-bb1f653f62c0
I don't know what caused the CI failed.

@minggo
Copy link
Contributor

minggo commented Jan 22, 2025

Except clang tidy error, macOS/iOS also have error.

@dumganhar
Copy link
Contributor Author

Except clang tidy error, macOS/iOS also have error.

I will check that. Good to point that out.

@dumganhar
Copy link
Contributor Author

Fixed

@minggo minggo merged commit aa841bd into cocos:v3.8.6 Jan 22, 2025
24 of 25 checks passed
@dumganhar
Copy link
Contributor Author

Thanks for the merge. I will send an another Pull Request for UnitTest

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.

2 participants