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 SkinnedRenderer.boundingBox updates are not timely #2267

Conversation

cptbtptpbcptdtptp
Copy link
Collaborator

@cptbtptpbcptdtptp cptbtptpbcptdtptp commented Jul 25, 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 transformation handling in the Renderer, improving encapsulation and performance.
    • Streamlined world matrix access in the SkinnedMeshRenderer for better clarity and efficiency.
  • Bug Fixes

    • Fixed issues related to root bone changes, ensuring correct transform associations during skinning updates.
    • Improved accuracy of bounding box calculations in the SkinnedMeshRenderer by validating against updated positions.

@cptbtptpbcptdtptp cptbtptpbcptdtptp added the bug Something isn't working label Jul 25, 2024
@cptbtptpbcptdtptp cptbtptpbcptdtptp self-assigned this Jul 25, 2024
Copy link

coderabbitai bot commented Jul 25, 2024

Walkthrough

The recent updates to the Renderer and SkinnedMeshRenderer classes enhance transformation management by centralizing access through a new protected property. This refactor replaces direct entity references, improving encapsulation and maintainability. Additionally, the logic for accessing world matrices in SkinnedMeshRenderer has been simplified, leading to clearer code and potentially better performance.

Changes

Files Change Summary
packages/core/src/Renderer.ts, packages/core/src/mesh/SkinnedMeshRenderer.ts - Introduced _transform property for centralized transformation handling in Renderer.
- Removed old listener management methods and added _setTransform for streamlined updates.
- Simplified access to world matrix in SkinnedMeshRenderer, enhancing clarity.
tests/src/core/SkinnedMeshRenderer.test.ts - Updated tests to accurately verify bounding box calculations against new positions for entity and rootBone0.

Poem

In a world of code where rabbits hop,
We’ve streamlined the flow, now let’s not stop!
With transforms so neat, and methods so bright,
Our rendering dance shines day and night.
Bugs, be gone! Let the code now play,
For in this new structure, we hop away! 🐰✨


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

@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 e6e90d6 and ef7aaf1.

Files selected for processing (2)
  • packages/core/src/Renderer.ts (6 hunks)
  • packages/core/src/mesh/SkinnedMeshRenderer.ts (3 hunks)
Additional comments not posted (8)
packages/core/src/mesh/SkinnedMeshRenderer.ts (3)

Line range hint 123-127: LGTM! Consistent use of this._transform.worldMatrix improves maintainability.

The update simplifies the logic by consistently using this._transform.worldMatrix for shader data updates, which should enhance maintainability and performance.


222-224: LGTM! Consistent use of this._transform.worldMatrix for bounding box transformations.

The update ensures that the bounding box is transformed using the world matrix of the transform, which is consistent with the rest of the updates.


268-270: LGTM! Properly attaching the transform of the new root bone entity.

The update ensures that the transform is correctly associated with the entity when the root bone is altered, improving the handling of skinning updates.

packages/core/src/Renderer.ts (5)

71-72: LGTM! Addition of _transform property enhances encapsulation.

The new protected property _transform centralizes the management of transformation data, improving encapsulation and maintainability.


175-176: LGTM! Addition of _attachTransform method improves modularity.

The new _attachTransform method integrates the functionality of the removed _registerEntityTransformListener method, ensuring that the previous listener is removed before a new one is added, which improves modularity and maintainability.


369-370: LGTM! Ensuring proper cleanup by detaching transform listener.

Calling _attachTransform with null in the _onDestroy method ensures that the transform listener is detached when the renderer is destroyed, which is necessary for proper cleanup.


Line range hint 395-399: LGTM! Consistent use of this._transform.worldMatrix improves maintainability.

The update simplifies the logic by consistently using this._transform.worldMatrix for shader data updates, which should enhance maintainability and performance.


468-471: LGTM! Proper implementation of _attachTransform method.

The method ensures that the previous listener is removed before a new one is added, improving modularity and maintainability.

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

Outside diff range, codebase verification and nitpick comments (1)
tests/src/core/SkinnedMeshRenderer.test.ts (1)

75-75: Initialize position with specific values for clarity.

Currently, the position is initialized with default values (0, 0, 0). Initializing it with specific values can make the test case more robust and clear.

- const position = new Vector3();
+ const position = new Vector3(0, 0, 0);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ef7aaf1 and af5adee.

Files selected for processing (2)
  • packages/core/src/mesh/SkinnedMeshRenderer.ts (3 hunks)
  • tests/src/core/SkinnedMeshRenderer.test.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/mesh/SkinnedMeshRenderer.ts
Additional comments not posted (2)
tests/src/core/SkinnedMeshRenderer.test.ts (2)

89-90: Ensure bounds are correctly updated after setting position.

The test correctly checks that the bounds are updated after setting the position. This is a good practice to ensure the bounding box reflects the current transformations.


102-105: Verify bounds update correctly after changing rootBone0 position.

The test correctly verifies that the bounds are updated after changing the position of rootBone0. This ensures that the bounding box is dynamically updated based on transformations.

const modelMesh = new ModelMesh(engine);
const entity = rootEntity.createChild("SkinEntity");
entity.transform.position = position;
Copy link

Choose a reason for hiding this comment

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

Set the position of entity after creating rootBone.

Setting the position of entity after creating rootBone ensures that all transformations are applied correctly.

- entity.transform.position = position;

Committable suggestion was skipped due to low confidence.

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 af5adee and 77e3ed4.

Files selected for processing (2)
  • packages/core/src/Renderer.ts (6 hunks)
  • packages/core/src/mesh/SkinnedMeshRenderer.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/mesh/SkinnedMeshRenderer.ts
Additional comments not posted (4)
packages/core/src/Renderer.ts (4)

71-72: Addition of _transform property looks good.

The new protected property _transform centralizes the management of transformation data, enhancing encapsulation and potentially improving maintainability.


468-471: Addition of _setTransform method looks good.

The new protected method _setTransform manages the attachment and detachment of transformation listeners, ensuring that the previous listener is removed before a new one is added. This promotes better control flow and modularity.


395-395: Update to _updateTransformShaderData method looks good.

The method now uses the new _transform property, ensuring consistent utilization across methods that deal with shader data updates and matrix calculations. This enhances clarity and reduces direct dependencies on the entity object for transformation data.


445-445: Update to _updateWorldViewRelatedShaderData method looks good.

The method now uses the new _transform property, ensuring consistent utilization across methods that deal with shader data updates and matrix calculations. This enhances clarity and reduces direct dependencies on the entity object for transformation data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants