8000 Fix useGravity not effect when cloned by luzhuang · Pull Request #2538 · galacean/engine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix useGravity not effect when cloned #2538

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

Merged
merged 12 commits into from
Feb 6, 2025
Merged

Conversation

luzhuang
Copy link
Contributor
@luzhuang luzhuang commented Feb 6, 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 physics control by allowing dynamic objects to toggle gravity settings.
  • Bug Fixes

    • Improved error handling in the lite physics module to avoid disruptions.
  • Tests

    • Introduced tests verifying the correct behavior of gravity and kinematic states, ensuring reliable simulation of object interactions.

@luzhuang luzhuang added Bug Something isn't working physics Engine's physical system labels Feb 6, 2025
@luzhuang luzhuang requested a review from GuoLei1990 February 6, 2025 06:54
Copy link
coderabbitai bot commented Feb 6, 2025

Walkthrough

This pull request introduces modifications in both the core physics package and its lightweight counterpart. In the core package, a new gravity setting is applied to the native collider via the _syncNative method. The lightweight package now logs an error instead of throwing one in the setUseGravity method. Additionally, the tests have been enhanced to verify correct behavior of the gravity and kinematic properties on both regular and cloned collider instances.

Changes

File(s) Change Summary
packages/core/src/physics/DynamicCollider.ts Added a call to set gravity on the native collider within the _syncNative method.
packages/physics-lite/src/LiteDynamicCollider.ts Updated setUseGravity to log an error (using Logger.error) instead of throwing an error.
tests/src/core/physics/DynamicCollider.test.ts Added tests for gravity behavior on collider clones and the isKinematic property to verify physics updates.

Sequence Diagram(s)

sequenceDiagram
    participant DC as DynamicCollider
    participant NC as NativeCollider
    DC->>NC: setUseGravity(_useGravity)
Loading
sequenceDiagram
    participant LDC as LiteDynamicCollider
    participant Logger
    LDC->>Logger: error("Gravity not supported")
Loading

Suggested reviewers

  • GuoLei1990
  • MrKou47

Poem

I’m a hopping rabbit with joyful cheer,
Gravity now guides my leap so clear.
In colliders and logs, the changes reside,
With tests and tweaks we take it in stride.
CodeRabbit dances with code all around,
In this playful update, magic is found!
🐰✨

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ 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
codecov bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.05%. Comparing base (bda63c7) to head (26a7f0b).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2538      +/-   ##
==========================================
+ Coverage   68.60%   69.05%   +0.44%     
==========================================
  Files         957      957              
  Lines      100125   100126       +1     
  Branches     8569     8566       -3     
==========================================
+ Hits        68688    69139     +451     
+ Misses      31181    30731     -450     
  Partials      256      256              
Flag Coverage Δ
unittests 69.05% <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.

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 (2)
packages/physics-lite/src/LiteDynamicCollider.ts (1)

132-134: LGTM! Consider making error handling consistent across all methods.

The change to use Logger.error instead of throwing an error is good as it prevents exceptions from breaking the execution flow. However, some methods in the class still throw errors while others use Logger.error. Consider making the error handling consistent across all methods.

Apply this diff to make error handling consistent:

-  addForce(force: Vector3): void {
-    throw "Physics-lite don't support addForce. Use Physics-PhysX instead!";
-  }
+  addForce(force: Vector3): void {
+    Logger.error("Physics-lite don't support addForce. Use Physics-PhysX instead!");
+  }

-  addTorque(torque: Vector3): void {
-    throw "Physics-lite don't support addTorque. Use Physics-PhysX instead!";
-  }
+  addTorque(torque: Vector3): void {
+    Logger.error("Physics-lite don't support addTorque. Use Physics-PhysX instead!");
+  }

-  move(positionOrRotation: Vector3 | Quaternion, rotation?: Quaternion): void {
-    throw "Physics-lite don't support move. Use Physics-PhysX instead!";
-  }
+  move(positionOrRotation: Vector3 | Quaternion, rotation?: Quaternion): void {
+    Logger.error("Physics-lite don't support move. Use Physics-PhysX instead!");
+  }

-  sleep(): void {
-    throw "Physics-lite don't support putToSleep. Use Physics-PhysX instead!";
-  }
+  sleep(): void {
+    Logger.error("Physics-lite don't support putToSleep. Use Physics-PhysX instead!");
+  }

-  isSleeping(): boolean {
-    throw "Physics-lite don't support isSleeping. Use Physics-PhysX instead!";
-  }
+  isSleeping(): boolean {
+    Logger.error("Physics-lite don't support isSleeping. Use Physics-PhysX instead!");
+    return false;
+  }

-  wakeUp(): void {
-    throw "Physics-lite don't support wakeUp. Use Physics-PhysX instead!";
-  }
+  wakeUp(): void {
+    Logger.error("Physics-lite don't support wakeUp. Use Physics-PhysX instead!");
+  }
tests/src/core/physics/DynamicCollider.test.ts (1)

371-373: LGTM! Consider adding more test cases.

The test changes properly verify that gravity behaves correctly with cloned colliders. However, consider adding more test cases to cover edge cases and improve coverage.

Consider adding these test cases:

  1. Test that re-enabling gravity on the cloned collider works correctly
  2. Test that cloning a collider with gravity already enabled works correctly
  3. Test that cloning preserves the gravity setting

Example:

// Test re-enabling gravity on clone
const cloneCollider = boxClone.getComponent<
8000
/span>(DynamicCollider);
cloneCollider.useGravity = true;
cloneCollider.wakeUp();
engine.sceneManager.activeScene.physics._update(1);
expect(formatValue(boxClone.transform.position.y)).lessThan(10);

// Test cloning with gravity enabled
boxCollider.useGravity = true;
const boxClone2 = box.clone();
expect(boxClone2.getComponent(DynamicCollider).useGravity).toBeTruthy();

Also applies to: 377-377

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bda63c7 and 26a7f0b.

📒 Files selected for processing (3)
  • packages/core/src/physics/DynamicCollider.ts (1 hunks)
  • packages/physics-lite/src/LiteDynamicCollider.ts (1 hunks)
  • tests/src/core/physics/DynamicCollider.test.ts (1 hunks)
🔇 Additional comments (1)
packages/core/src/physics/DynamicCollider.ts (1)

446-446: LGTM! The gravity setting is now properly synchronized.

The addition of setUseGravity in the _syncNative method ensures that the gravity setting is properly synchronized with the native collider, which fixes the issue with gravity not working correctly when cloning colliders.

@GuoLei1990 GuoLei1990 merged commit 9495bfb into galacean:main Feb 6, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working physics Engine's physical system
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants
0