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 axis not effect when component changed #2515

Closed
wants to merge 1 commit into from
Closed

Conversation

luzhuang
Copy link
Contributor

@luzhuang luzhuang commented Jan 16, 2025

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 hinge joint axis management with improved normalization and synchronization
    • Updated axis configuration method for more precise control
  • Bug Fixes

    • Improved axis vector handling to prevent potential calculation inconsistencies
  • Refactor

    • Optimized internal axis setting mechanism for hinge joints
    • Streamlined event handling for axis value changes

@luzhuang luzhuang added physics Engine's physical system ignore for release ignore for release labels Jan 16, 2025
@luzhuang luzhuang requested a review from GuoLei1990 January 16, 2025 13:36
Copy link

coderabbitai bot commented Jan 16, 2025

Walkthrough

The pull request introduces changes to the HingeJoint class in the physics module, focusing on axis management and normalization. A new private method _setAxis is added to the HingeJoint class to handle axis normalization and event management. The PhysXHingeJoint class has a modification where axis normalization is removed. The test file for HingeJoint now uses component-wise axis assignment instead of creating a new vector.

Changes

File Change Summary
packages/core/src/physics/joint/HingeJoint.ts Added _setAxis private method, updated axis handling and event management
packages/physics-physx/src/joint/PhysXHingeJoint.ts Removed axis vector normalization in setAxis method
tests/src/core/physics/HingeJoint.test.ts Changed axis assignment from new Vector3() to component-wise setting

Sequence Diagram

sequenceDiagram
    participant HJ as HingeJoint
    participant Axis as Axis Vector
    participant Native as Native Joint

    HJ->>Axis: Set axis value
    HJ->>HJ: _setAxis() method
    HJ->>Axis: Normalize axis
    HJ->>Native: Update native joint axis
Loading

Possibly related PRs

Suggested reviewers

  • GuoLei1990

Poem

🐰 A Hinge Joint's Dance

Vectors spinning, axis so fine,
Normalized and set with design,
Components aligned just right,
Physics engine takes its flight!

🌀 Rabbit's physics magic, hooray! 🎉

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

@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

🧹 Nitpick comments (3)
packages/core/src/physics/joint/HingeJoint.ts (3)

28-28: Enhance the axis property documentation.

The current documentation could be more descriptive. Consider adding:

  • The expected format/type of the axis vector
  • Valid ranges or constraints for the axis values
  • Whether the axis will be automatically normalized
  • Example usage
-   * The Direction of the axis around which the hingeJoint.
+   * The normalized direction vector representing the axis of rotation for the hinge joint.
+   * This vector will be automatically normalized when set.
+   * @example
+   * ```typescript
+   * joint.axis = new Vector3(0, 1, 0); // Rotation around Y-axis
+   * ```

145-146: Improve type safety by properly typing the Vector3 _onValueChanged property.

The use of @ts-ignore suggests that _onValueChanged is not properly typed in the Vector3 class. Consider adding proper type definitions instead of suppressing the TypeScript error.

Consider one of these approaches:

  1. Add proper type definitions to Vector3:
// In Vector3 class
_onValueChanged?: () => void;
  1. Create a custom type that extends Vector3:
interface ObservableVector3 extends Vector3 {
  _onValueChanged?: () => void;
}
private _axis: ObservableVector3 = new Vector3(1, 0, 0) as ObservableVector3;

202-210: LGTM! The axis normalization implementation looks correct.

The implementation properly handles:

  • Prevention of recursive updates by temporarily removing the listener
  • Normalization of the axis vector
  • Updating the native joint
  • Restoring the listener

Consider adding a comment explaining why the listener is temporarily removed to prevent future maintenance confusion:

  @ignoreClone
  private _setAxis(): void {
+   // Temporarily remove the listener to prevent recursive updates during normalization
    //@ts-ignore
    this._axis._onValueChanged = null;
    this._axis.normalize();
    (<IHingeJoint>this._nativeJoint)?.setAxis(this._axis);
    //@ts-ignore
    this._axis._onValueChanged = this._setAxis.bind(this);
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15e7b8b and 4f1c5d8.

📒 Files selected for processing (3)
  • packages/core/src/physics/joint/HingeJoint.ts (3 hunks)
  • packages/physics-physx/src/joint/PhysXHingeJoint.ts (0 hunks)
  • tests/src/core/physics/HingeJoint.test.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/physics-physx/src/joint/PhysXHingeJoint.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build (22.x, windows-latest)
  • GitHub Check: e2e (22.x)
  • GitHub Check: codecov
🔇 Additional comments (1)
tests/src/core/physics/HingeJoint.test.ts (1)

63-64: LGTM! Test changes align with the new axis change detection mechanism.

The modification from direct vector assignment to component-wise assignment properly tests that individual component changes trigger the axis normalization and update.

Copy link

codecov bot commented Jan 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.58%. Comparing base (15e7b8b) to head (4f1c5d8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2515      +/-   ##
==========================================
- Coverage   69.01%   68.58%   -0.44%     
==========================================
  Files         957      957              
  Lines      100052   100062      +10     
  Branches     8554     8565      +11     
==========================================
- Hits        69054    68625     -429     
- Misses      30742    31181     +439     
  Partials      256      256              
Flag Coverage Δ
unittests 68.58% <100.00%> (-0.44%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@luzhuang luzhuang closed this Jan 16, 2025
@luzhuang luzhuang deleted the fix/hingejoint branch January 16, 2025 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore for release ignore for release physics Engine's physical system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants