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

Fix animation time error because of speed and animatorParameter rename bug #2273

Merged
merged 9 commits into from
Jul 29, 2024

Conversation

luzhuang
Copy link
Contributor

@luzhuang luzhuang commented Jul 29, 2024

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Other information:

Summary by CodeRabbit

  • New Features

    • Enhanced animation timing and state management for smoother transitions.
    • Added dynamic parameter name renaming functionality in the AnimatorController.
    • Streamlined parameter addition process for improved efficiency and readability.
  • Bug Fixes

    • Improved precision of cross-fade calculations to reduce transition errors.

@luzhuang luzhuang requested a review from GuoLei1990 July 29, 2024 02:18
Copy link

coderabbitai bot commented Jul 29, 2024

Walkthrough

The recent updates to the animation system significantly enhance the Animator, AnimatorController, and AnimatorControllerLoader classes. Key improvements include refined animation timing through playDeltaTime, streamlined parameter management to prevent duplicates, and simplified logic for cross-fades. These changes collectively boost the functionality and responsiveness of the animation flow, ensuring a more dynamic and engaging user experience.

Changes

Files Change Summary
packages/core/src/animation/Animator.ts Enhanced time handling with playDeltaTime, improved cross-fade calculations using crossWeight, and simplified logic for determining sub-animation events.
packages/core/src/animation/AnimatorController.ts Prevented duplicate parameter names in addParameter, updated removeParameter to accept names, and improved name change handling in _onNameChanged.
packages/loader/src/AnimatorControllerLoader.ts Streamlined parameter addition by directly calling addParameter, reducing overhead from object creation and enhancing efficiency.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Animator
    participant AnimatorController

    User->>Animator: Trigger Animation
    Animator->>AnimatorController: Check Parameter
    AnimatorController->>AnimatorController: Validate Parameter Name
    Animator->>Animator: Calculate Transition Time
    Animator->>User: Play Animation
Loading

🐇 In a world of speed and grace,
Animations dance in their place.
With names that change and timings true,
A lively flow, fresh as the dew.
Hops and skips, all in delight,
Our animations shine so bright! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jul 29, 2024

Codecov Report

Attention: Patch coverage is 64.70588% with 6 lines in your changes missing coverage. Please review.

Project coverage is 69.17%. Comparing base (4cc191e) to head (ad70775).
Report is 54 commits behind head on dev/1.3.

Files Patch % Lines
.../core/src/animation/AnimatorControllerParameter.ts 57.14% 1 Missing and 2 partials ⚠️
packages/core/src/animation/AnimatorController.ts 33.33% 2 Missing ⚠️
packages/core/src/animation/Animator.ts 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           dev/1.3    #2273      +/-   ##
===========================================
+ Coverage    68.27%   69.17%   +0.90%     
===========================================
  Files          468      523      +55     
  Lines        24353    27386    +3033     
  Branches      3632     4099     +467     
===========================================
+ Hits         16626    18945    +2319     
- Misses        6400     6955     +555     
- Partials      1327     1486     +159     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8b02aa0 and ad70775.

Files selected for processing (4)
  • packages/core/src/animation/Animator.ts (8 hunks)
  • packages/core/src/animation/AnimatorController.ts (1 hunks)
  • packages/core/src/animation/AnimatorControllerParameter.ts (1 hunks)
  • tests/src/core/Animator.test.ts (8 hunks)
Additional context used
GitHub Check: codecov/patch
packages/core/src/animation/AnimatorControllerParameter.ts

[warning] 24-24: packages/core/src/animation/AnimatorControllerParameter.ts#L24
Added line #L24 was not covered by tests

packages/core/src/animation/AnimatorController.ts

[warning] 73-74: packages/core/src/animation/AnimatorController.ts#L73-L74
Added lines #L73 - L74 were not covered by tests

Biome
packages/core/src/animation/Animator.ts

[error] 698-698: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 867-867: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (11)
packages/core/src/animation/AnimatorControllerParameter.ts (3)

13-13: LGTM!

The _onNameChanged callback is correctly declared as a nullable function.


15-15: LGTM!

The _name variable is correctly declared as a private string variable.


18-29: LGTM! But verify the references to name.

The getter and setter for name are well-implemented, ensuring encapsulation and controlled updates with a callback mechanism.

However, ensure that all references to name in the codebase are updated correctly.

Tools
GitHub Check: codecov/patch

[warning] 24-24: packages/core/src/animation/AnimatorControllerParameter.ts#L24
Added line #L24 was not covered by tests

packages/core/src/animation/AnimatorController.ts (1)

72-75: LGTM! But verify the _parametersMap updates.

The _onNameChanged function is well-implemented, ensuring the parameter map remains consistent when a name changes.

However, ensure that the _parametersMap updates correctly in all scenarios.

Verification successful

Verified: The _parametersMap updates are handled correctly.

The _parametersMap is consistently used for managing parameters, including adding, deleting, and retrieving them by name.

  • packages/core/src/animation/AnimatorController.ts: Lines involving _parametersMap management.
  • packages/core/src/animation/Animator.ts: Lines involving _parametersMap access.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the `_parametersMap` updates correctly in all scenarios.

# Test: Search for references to `_parametersMap`. Expect: Correct handling of name changes.
rg --type typescript -A 5 $'_parametersMap'

Length of output: 77


Script:

#!/bin/bash
# Description: Verify the `_parametersMap` updates correctly in all scenarios.

# Test: Search for references to `_parametersMap`. Expect: Correct handling of name changes.
rg --glob '*.ts' -A 5 '_parametersMap'

Length of output: 3334

Tools
GitHub Check: codecov/patch

[warning] 73-74: packages/core/src/animation/AnimatorController.ts#L73-L74
Added lines #L73 - L74 were not covered by tests

tests/src/core/Animator.test.ts (5)

328-328: LGTM!

The idleSpeed variable is correctly declared and set to 2.


329-329: LGTM!

The idleState.speed is correctly set to idleSpeed.


349-351: LGTM!

The idleToWalkTime calculation is correctly adjusted to incorporate idleSpeed.


377-377: LGTM!

The walkToIdleTime calculation is correctly adjusted to incorporate idleSpeed.


402-402: LGTM!

The anyToIdleTime calculation is correctly adjusted to incorporate idleSpeed.

packages/core/src/animation/Animator.ts (2)

26-26: Import statement for MathUtil is necessary.

The import of MathUtil is required for the updated cross-fade weight calculations.


610-612: Refined calculation of remainDeltaTime.

The adjustment to incorporate actualSpeed ensures more accurate timing during state transitions.

@@ -863,7 +864,7 @@ export class Animator extends Component {

const duration = state._getDuration() * layerData.crossFadeTransition.duration;
let crossWeight = Math.abs(destPlayData.frameTime) / duration;
(crossWeight >= 1.0 || duration === 0) && (crossWeight = 1.0);
(crossWeight >= 1.0 - MathUtil.zeroTolerance || duration === 0) && (crossWeight = 1.0);
Copy link

Choose a reason for hiding this comment

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

Improved precision in cross-fade calculations.

The update to use MathUtil.zeroTolerance enhances the precision of cross-fade weight calculations.

However, avoid assignments within expressions for better readability.

- (crossWeight >= 1.0 - MathUtil.zeroTolerance || duration === 0) && (crossWeight = 1.0);
+ if (crossWeight >= 1.0 - MathUtil.zeroTolerance || duration === 0) {
+   crossWeight = 1.0;
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(crossWeight >= 1.0 - MathUtil.zeroTolerance || duration === 0) && (crossWeight = 1.0);
if (crossWeight >= 1.0 - MathUtil.zeroTolerance || duration === 0) {
crossWeight = 1.0;
}
Tools
Biome

[error] 867-867: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ad70775 and e6a170e.

Files selected for processing (2)
  • packages/core/src/animation/Animator.ts (10 hunks)
  • packages/core/src/animation/AnimatorControllerParameter.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/animation/AnimatorControllerParameter.ts
Additional comments not posted (6)
packages/core/src/animation/Animator.ts (6)

26-26: Import statement for MathUtil is approved.

The import of MathUtil is required for precision improvements in the animation calculations.


724-724: Verify handling of updated parameters in _fireAnimationEventsAndCallScripts.

Ensure that the updated parameters are correctly handled in the function implementation.


730-730: Enhanced precision in remaining delta time calculation.

The adjustment to incorporate costTime ensures more accurate timing when switching layer states.

However, ensure that all function calls to _updateState correctly handle the new remainDeltaTime logic.


715-715: Verify handling of updated parameters in _fireAnimationEventsAndCallScripts.

Ensure that the updated parameters are correctly handled in the function implementation.

Verification successful

Verified handling of updated parameters in _fireAnimationEventsAndCallScripts.

The function _fireAnimationEventsAndCallScripts correctly handles the updated parameters.

  • packages/core/src/animation/Animator.ts lines 715 and the function implementation.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `_fireAnimationEventsAndCallScripts` to ensure correct handling of updated parameters.

# Test: Search for the function implementation. Expect: Correct handling of updated parameters.
rg --type ts -A 20 $'_fireAnimationEventsAndCallScripts'

Length of output: 6716


610-611: Enhanced precision in remaining delta time calculation.

The adjustment to incorporate actualSpeed ensures more accurate timing when switching layer states.

However, ensure that all function calls to _updateState correctly handle the new remainDeltaTime logic.


706-706: Improved precision in cross-fade weight calculations.

The update to use crossWeight enhances the precision of cross-fade calculations.

However, ensure that all function calls to _evaluateCrossFadeState correctly handle the new crossWeight parameter.

Verification successful

Improved precision in cross-fade weight calculations.

The update to use crossWeight enhances the precision of cross-fade calculations. All function calls to _evaluateCrossFadeState correctly handle the new crossWeight parameter.

  • packages/core/src/animation/Animator.ts: The function call and definition both correctly include the crossWeight parameter.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `_evaluateCrossFadeState` correctly handle the new `crossWeight` parameter.

# Test: Search for the function usage. Expect: Correct handling of the new `crossWeight` parameter.
rg --type ts -A 5 $'_evaluateCrossFadeState'

Length of output: 926


Script:

#!/bin/bash
# Description: Verify all instances of `_evaluateCrossFadeState` in the codebase to ensure the `crossWeight` parameter is correctly handled.

# Test: Search for all instances of `_evaluateCrossFadeState` in the TypeScript files.
ast-grep --lang typescript --pattern '_evaluateCrossFadeState($_$$$)'

Length of output: 71


Script:

#!/bin/bash
# Description: Verify all instances of `_evaluateCrossFadeState` in the codebase to ensure the `crossWeight` parameter is correctly handled.

# Test: Search for all instances of `_evaluateCrossFadeState` in the TypeScript files.
rg --type ts '_evaluateCrossFadeState'

Length of output: 269

@GuoLei1990 GuoLei1990 added the bug Something isn't working label Jul 29, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e6a170e and 6731c21.

Files selected for processing (1)
  • packages/core/src/animation/Animator.ts (10 hunks)
Additional context used
Biome
packages/core/src/animation/Animator.ts

[error] 698-698: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 822-822: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (4)
packages/core/src/animation/Animator.ts (4)

26-26: Import addition approved.

The MathUtil import is necessary for precision improvements in cross-fade calculations.


610-611: Change approved.

The calculation and conditional check for remainDeltaTime ensure that any remaining delta time is processed correctly.


Line range hint 706-715: Change approved.

The addition of the crossWeight parameter to _evaluateCrossFadeState improves the precision of cross-fade calculations.

Tools
Biome

[error] 698-698: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


Line range hint 730-739: Change approved.

The calculation and conditional check for remainDeltaTime ensure that any remaining delta time is processed correctly.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Outside diff range, codebase verification and nitpick comments (3)
packages/core/src/animation/Animator.ts (3)

540-541: Enhance readability by renaming variables.

Consider renaming playSpeed to adjustedPlaySpeed for clarity.

- const playSpeed = state.speed * this.speed;
+ const adjustedPlaySpeed = state.speed * this.speed;

663-665: Enhance readability by renaming variables.

Consider renaming srcPlaySpeed and dstPlaySpeed to sourcePlaySpeed and destinationPlaySpeed for clarity.

- const srcPlaySpeed = srcState.speed * speed;
- const dstPlaySpeed = destState.speed * speed;
+ const sourcePlaySpeed = srcState.speed * speed;
+ const destinationPlaySpeed = destState.speed * speed;

792-793: Enhance readability by renaming variables.

Consider renaming playSpeed to adjustedPlaySpeed for clarity.

- const playSpeed = state.speed * this.speed;
+ const adjustedPlaySpeed = state.speed * this.speed;
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6731c21 and 692b6af.

Files selected for processing (1)
  • packages/core/src/animation/Animator.ts (12 hunks)
Additional context used
Biome
packages/core/src/animation/Animator.ts

[error] 667-667: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 668-668: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 699-699: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 821-821: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (5)
packages/core/src/animation/Animator.ts (5)

548-548: Ensure accurate transition application.

Verify that the transition logic correctly handles edge cases for timing.


740-740: Ensure crossWeight is within valid range.

Verify that crossWeight is always within the range [0, 1] before using it in calculations.


818-818: Ensure crossWeight is within valid range.

Verify that crossWeight is always within the range [0, 1] before using it in calculations.


852-852: Ensure crossWeight is within valid range.

Verify that crossWeight is always within the range [0, 1] before using it in calculations.


1318-1318: Ensure accurate event firing.

Verify that the event firing logic correctly handles edge cases for timing.

Comment on lines +667 to +668
srcPlayData && srcPlayData.updateOrientation(srcPlaySpeed * deltaTime);
destPlayData && destPlayData.updateOrientation(dstPlayDeltaTime);
Copy link

Choose a reason for hiding this comment

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

Use optional chaining for safety.

The static analysis tool suggests using optional chaining for better safety.

- srcPlayData && srcPlayData.updateOrientation(srcPlaySpeed * deltaTime);
- destPlayData && destPlayData.updateOrientation(dstPlayDeltaTime);
+ srcPlayData?.updateOrientation(srcPlaySpeed * deltaTime);
+ destPlayData?.updateOrientation(dstPlayDeltaTime);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
srcPlayData && srcPlayData.updateOrientation(srcPlaySpeed * deltaTime);
destPlayData && destPlayData.updateOrientation(dstPlayDeltaTime);
srcPlayData?.updateOrientation(srcPlaySpeed * deltaTime);
destPlayData?.updateOrientation(dstPlayDeltaTime);
Tools
Biome

[error] 667-667: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 668-668: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/core/src/animation/Animator.ts Show resolved Hide resolved
this._evaluatePlayingState(srcPlayData, weight, additive, aniUpdate);
this._fireAnimationEventsAndCallScripts(layerIndex, srcPlayData, state, lastClipTime, lastPlayState, costTime);
this._fireAnimationEventsAndCallScripts(layerIndex, srcPlayData, state, lastClipTime, lastPlayState, playCostTime);

if (needSwitchLayerState) {
Copy link
Member

Choose a reason for hiding this comment

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

Opt code

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 692b6af and dc9a18a.

Files selected for processing (1)
  • packages/core/src/animation/Animator.ts (11 hunks)
Additional context used
Biome
packages/core/src/animation/Animator.ts

[error] 664-664: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 665-665: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 696-696: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 818-818: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (6)
packages/core/src/animation/Animator.ts (6)

26-26: LGTM! The import statement is correct.

The MathUtil import is necessary for the changes in the file.


540-548: LGTM! The changes improve precision in animation timing.

The use of playSpeed and playDeltaTime enhances the accuracy of animation state updates.


670-693: LGTM! The changes improve precision in cross-fade calculations.

The use of srcPlaySpeed, dstPlaySpeed, and dstPlayDeltaTime enhances the accuracy of cross-fade state updates.


737-737: LGTM! The addition of the crossWeight parameter improves precision.

Including crossWeight enhances the accuracy of cross-fade calculations.


789-792: LGTM! The changes improve precision in cross-fade from pose state calculations.

The use of playSpeed and playDeltaTime enhances the accuracy of cross-fade from pose state updates.


849-849: LGTM! The addition of the crossWeight parameter improves precision.

Including crossWeight enhances the accuracy of cross-fade from pose state calculations.

const remainDeltaTime = deltaTime - costTime;
this._updateState(layerIndex, layerData, layer, remainDeltaTime, aniUpdate);
if (transition) {
// actualCostTime = playCostTime / playSpeed
Copy link
Member

Choose a reason for hiding this comment

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

// Remove speed factor, use actual time

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dc9a18a and 50fe5e9.

Files selected for processing (4)
  • packages/core/src/animation/Animator.ts (12 hunks)
  • packages/core/src/animation/AnimatorController.ts (1 hunks)
  • packages/core/src/animation/AnimatorControllerParameter.ts (1 hunks)
  • tests/src/core/Animator.test.ts (9 hunks)
Files skipped from review as they are similar to previous changes (3)
  • packages/core/src/animation/AnimatorController.ts
  • packages/core/src/animation/AnimatorControllerParameter.ts
  • tests/src/core/Animator.test.ts
Additional context used
Biome
packages/core/src/animation/Animator.ts

[error] 664-664: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 665-665: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 696-696: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 818-818: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (7)
packages/core/src/animation/Animator.ts (7)

26-26: Import addition approved.

The addition of MathUtil import is necessary for the subsequent changes in the file.


540-548: Playback speed calculation approved.

The changes ensure that the playback speed is correctly factored into the delta time.


573-600: Transition timing calculation approved.

The changes ensure that the animation transitions are more accurately timed.


606-609: Remaining delta time calculation approved.

The changes ensure that any remaining time is properly accounted for.


660-665: Use optional chaining for safety.

The use of optional chaining improves safety and readability.

- srcPlayData && srcPlayData.updateOrientation(srcPlaySpeed * deltaTime);
- destPlayData && destPlayData.updateOrientation(dstPlayDeltaTime);
+ srcPlayData?.updateOrientation(srcPlaySpeed * deltaTime);
+ destPlayData?.updateOrientation(dstPlayDeltaTime);
Tools
Biome

[error] 664-664: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 665-665: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


789-818: Cross-fade logic and precision improvements approved.

The changes ensure accurate calculation of playDeltaTime, proper updating of destPlayData, and improved precision in cross-fade logic using MathUtil.zeroTolerance.

Tools
Biome

[error] 818-818: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


849-849: Function signature update approved.

The addition of crossWeight to the function signature is necessary for the updated cross-fade logic.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 50fe5e9 and 6729113.

Files selected for processing (3)
  • packages/core/src/animation/Animator.ts (12 hunks)
  • packages/core/src/animation/AnimatorController.ts (1 hunks)
  • packages/loader/src/AnimatorControllerLoader.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/animation/AnimatorController.ts
Additional context used
Biome
packages/core/src/animation/Animator.ts

[error] 664-664: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 665-665: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 696-696: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 818-818: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (6)
packages/loader/src/AnimatorControllerLoader.ts (1)

103-103: LGTM! Simplified parameter addition process.

The change improves code readability and efficiency by directly calling addParameter without instantiating AnimatorControllerParameter.

However, ensure that all usages of addParameter are consistent with this change.

Verification successful

The changes to addParameter are consistent across the codebase.

All usages of addParameter match the new method signature, confirming that the changes are correctly integrated.

  • tests/src/core/Animator.test.ts
  • packages/core/src/animation/AnimatorController.ts
  • packages/loader/src/AnimatorControllerLoader.ts
  • e2e/case/animator-stateMachine.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `addParameter` to ensure consistency with the new method signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type typescript -A 5 $'addParameter'

Length of output: 75


Script:

#!/bin/bash
# Description: Verify all usages of `addParameter` to ensure consistency with the new method signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg -A 5 $'addParameter'

Length of output: 3567

packages/core/src/animation/Animator.ts (5)

540-548: Improved precision in animation timing.

The update to use playDeltaTime enhances the precision of animation timing.


737-737: Enhanced precision in cross-fade calculations.

The addition of crossWeight improves the precision of cross-fade calculations.


789-792: Improved precision in animation timing.

The update to use playDeltaTime enhances the precision of animation timing.


849-849: Enhanced precision in cross-fade calculations.

The addition of crossWeight improves the precision of cross-fade calculations.


1315-1323: Simplified animation event firing logic.

The removal of the speed factor and the use of deltaTime directly simplifies the logic and reduces potential sources of error.


let crossWeight = Math.abs(destPlayData.frameTime) / transitionDuration;
(crossWeight >= 1.0 || transitionDuration === 0) && (crossWeight = 1.0);
(crossWeight >= 1.0 - MathUtil.zeroTolerance || transitionDuration === 0) && (crossWeight = 1.0);
Copy link

Choose a reason for hiding this comment

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

Avoid assignments within expressions.

The use of assignments within expressions can be confusing. Refactor the code for better readability.

- (crossWeight >= 1.0 - MathUtil.zeroTolerance || transitionDuration === 0) && (crossWeight = 1.0);
+ if (crossWeight >= 1.0 - MathUtil.zeroTolerance || transitionDuration === 0) {
+   crossWeight = 1.0;
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(crossWeight >= 1.0 - MathUtil.zeroTolerance || transitionDuration === 0) && (crossWeight = 1.0);
if (crossWeight >= 1.0 - MathUtil.zeroTolerance || transitionDuration === 0) {
crossWeight = 1.0;
}
Tools
Biome

[error] 696-696: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


let crossWeight = Math.abs(destPlayData.frameTime) / transitionDuration;
(crossWeight >= 1.0 || transitionDuration === 0) && (crossWeight = 1.0);
(crossWeight >= 1.0 - MathUtil.zeroTolerance || transitionDuration === 0) && (crossWeight = 1.0);
Copy link

Choose a reason for hiding this comment

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

Avoid assignments within expressions.

The use of assignments within expressions can be confusing. Refactor the code for better readability.

- (crossWeight >= 1.0 - MathUtil.zeroTolerance || transitionDuration === 0) && (crossWeight = 1.0);
+ if (crossWeight >= 1.0 - MathUtil.zeroTolerance || transitionDuration === 0) {
+   crossWeight = 1.0;
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(crossWeight >= 1.0 - MathUtil.zeroTolerance || transitionDuration === 0) && (crossWeight = 1.0);
if (crossWeight >= 1.0 - MathUtil.zeroTolerance || transitionDuration === 0) {
crossWeight = 1.0;
}
Tools
Biome

[error] 818-818: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Comment on lines +660 to +665
const srcPlaySpeed = srcState.speed * speed;
const dstPlaySpeed = destState.speed * speed;
const dstPlayDeltaTime = dstPlaySpeed * deltaTime;

srcPlayData && srcPlayData.updateOrientation(actualSrcSpeed * deltaTime);
destPlayData && destPlayData.updateOrientation(actualDestDeltaTime);
srcPlayData && srcPlayData.updateOrientation(srcPlaySpeed * deltaTime);
destPlayData && destPlayData.updateOrientation(dstPlayDeltaTime);
Copy link

Choose a reason for hiding this comment

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

Use optional chaining for safety.

The static analysis tool suggests using optional chaining for better safety.

- srcPlayData && srcPlayData.updateOrientation(srcPlaySpeed * deltaTime);
- destPlayData && destPlayData.updateOrientation(dstPlayDeltaTime);
+ srcPlayData?.updateOrientation(srcPlaySpeed * deltaTime);
+ destPlayData?.updateOrientation(dstPlayDeltaTime);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const srcPlaySpeed = srcState.speed * speed;
const dstPlaySpeed = destState.speed * speed;
const dstPlayDeltaTime = dstPlaySpeed * deltaTime;
srcPlayData && srcPlayData.updateOrientation(actualSrcSpeed * deltaTime);
destPlayData && destPlayData.updateOrientation(actualDestDeltaTime);
srcPlayData && srcPlayData.updateOrientation(srcPlaySpeed * deltaTime);
destPlayData && destPlayData.updateOrientation(dstPlayDeltaTime);
const srcPlaySpeed = srcState.speed * speed;
const dstPlaySpeed = destState.speed * speed;
const dstPlayDeltaTime = dstPlaySpeed * deltaTime;
srcPlayData?.updateOrientation(srcPlaySpeed * deltaTime);
destPlayData?.updateOrientation(dstPlayDeltaTime);
Tools
Biome

[error] 664-664: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 665-665: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

@GuoLei1990 GuoLei1990 added the animation Built-in animation system related functions label Jul 29, 2024
@GuoLei1990 GuoLei1990 changed the title fix: animation time error because of speed and precision && fix: animatorParameter rename bug Fix animation time error because of speed and precision && fix: animatorParameter rename bug Jul 29, 2024
@GuoLei1990 GuoLei1990 merged commit 9d34912 into galacean:dev/1.3 Jul 29, 2024
7 checks passed
@GuoLei1990 GuoLei1990 changed the title Fix animation time error because of speed and precision && fix: animatorParameter rename bug Fix animation time error because of speed and animatorParameter rename bug Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
animation Built-in animation system related functions bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants