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 gizmo not update when rotate around #329

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cptbtptpbcptdtptp
Copy link
Collaborator

@cptbtptpbcptdtptp cptbtptpbcptdtptp commented Feb 14, 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

  • Refactor

    • Improved control updates by streamlining camera and object state management for a smoother, more responsive experience.
  • New Features

    • Enhanced pointer drag interactions with clear start and end actions, leading to more intuitive navigation controls.

@cptbtptpbcptdtptp
Copy link
Collaborator Author

  • Gizmo.ts 修复 @gz65555 提的 Gizmo 在 Orbit 相机围绕旋转的时候没有调用 Update 的问题
  • 意外发现 SphereScript.ts 如果在碰撞体外 Up 会出现问题,isTriggered 这个脏标记貌似被锁住了,看了下 SphereScript 的计算逻辑略为复杂,计划分布优化

@cptbtptpbcptdtptp
Copy link
Collaborator Author

此外,Gizmo 的一些命名和逻辑待优化:

  • update 中携带的 isModified 看代码含义应该是 isAll(是否全模式), 全模式的情况下貌似尺寸会有变化
  • onSwitch 的意义感觉不是很大

Copy link

coderabbitai bot commented Feb 14, 2025

Walkthrough

This pull request updates three modules to refine internal state management and event handling. In the Gizmo class, new private flags and a listener are introduced for camera state tracking, replacing older properties. The Group class now uses a BoolUpdateFlag rather than a boolean for marking transformations, with the dispatch call replacing direct boolean assignments. In the SphereScript class, pointer events are refactored: the pointer down event is renamed to begin a drag, the pointer up event is removed in favor of a dedicated end-drag method, and pointer dragging now consistently updates the camera transformation.

Changes

File(s) Change Summary
packages/gizmo/src/Gizmo.ts
packages/gizmo/src/Group.ts
Gizmo: Added private _cameraTransformFlag and _cameraModifyDirtyFlag, removed legacy tracking properties, bound and introduced _onCameraModifyListener, and updated init and onUpdate to use the new flags.
Group: Replaced _gizmoTransformDirty (boolean) with _transformFlag (BoolUpdateFlag), and updated setDirtyFlagTrue to dispatch the flag.
packages/navigation-gizmo/src/SphereScript.ts Renamed onPointerDown to onPointerBeginDrag, removed the _isTriggered flag and onPointerUp method, added onPointerEndDrag to consolidate pointer-up logic, and modified onPointerDrag to continuously update the camera transformation during drag events.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SphereScript
    participant Camera

    User->>SphereScript: onPointerBeginDrag(eventData)
    Note right of SphereScript: Begin drag operation
    User->>SphereScript: onPointerDrag(eventData)
    SphereScript->>Camera: Update camera transformation continuously
    User->>SphereScript: End drag (event trigger)
    SphereScript->>Camera: onPointerEndDrag(eventData) finalizes changes
Loading
sequenceDiagram
    participant Camera
    participant Gizmo
    participant Controls

    Note over Camera,Gizmo: Camera property changes occur
    Camera->>Gizmo: Invoke _onCameraModifyListener(flag)
    Gizmo->>Gizmo: Update _cameraModifyDirtyFlag internally
    Gizmo->>Gizmo: onUpdate checks _cameraTransformFlag & projection changes
    Gizmo->>Controls: Traverse controls if conditions met
Loading

Possibly related PRs

Suggested labels

bug, enhancement

Suggested reviewers

  • gz65555

Poem

Hi, I'm a bouncy little rabbit, full of delight,
Hop, hop—my code now shines so bright.
Flags and flows have danced their way anew,
In Gizmo, Group, and SphereScript too.
I nibble on bugs and carrots with cheer,
Code and hops forever near!
🐇✨

✨ 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 (2)
packages/navigation-gizmo/src/SphereScript.ts (1)

119-119: Consider reintroducing or removing _isTriggered.

No code sets _isTriggered to true in onPointerBeginDrag(), so the _isTriggered property never updates to reflect a drag state. This might cause confusion with the usage in onPointerExit() and leads to dead code. Evaluate if _isTriggered is needed or remove it for clarity.

packages/gizmo/src/Gizmo.ts (1)

58-59: Naming clarity for new state fields.

_cameraTransformFlag and _cameraModifyDirtyFlag are well-named but consider documenting their roles and how they differ if there's a possibility of confusion.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2d74aac and 7705935.

📒 Files selected for processing (3)
  • packages/gizmo/src/Gizmo.ts (5 hunks)
  • packages/gizmo/src/Group.ts (3 hunks)
  • packages/navigation-gizmo/src/SphereScript.ts (2 hunks)
🔇 Additional comments (10)
packages/navigation-gizmo/src/SphereScript.ts (2)

145-152: Ensure camera transformations remain consistent with scale or pivot.

These lines directly invert the lookAt matrix and assign it as the camera's worldMatrix, which might ignore any existing camera scale or pivot offsets. Verify if this approach is intentional and confirm it doesn't conflict with other transformations in the scene.


161-171: Confirm logic for hiding entities only when raycast fails.

If the raycast does not collide with anything, the code hides the round and axis entities. Consider whether the same logic should apply when the raycast hits non-gizmo objects.

packages/gizmo/src/Group.ts (3)

1-1: Import addition looks good.


36-36: Good move to use a BoolUpdateFlag.

This approach standardizes dirty state detection and helps sync with external cameras or gizmos.


246-246: Ensure repeated calls won't cause performance overhead.

Repeatedly dispatching the transform flag can trigger multiple re-renders if there's no throttling or deduplication. Confirm that the system gracefully handles consecutive dispatches.

packages/gizmo/src/Gizmo.ts (5)

2-4: Importing new flags looks good.

These new imports align with the shift to a more robust state-based approach for camera modifications.


64-70: Handle disposal or re-initialization logic carefully.

When switching cameras, the code clears _cameraTransformFlag from managers, sets it to null, and unregisters the modify listener. Ensure that subsequent calls on the old camera won't cause stale references or memory leaks.


75-79: Confirm synergy between _cameraTransformFlag and _registerModifyListener.

These lines ensure the camera transform updates can be tracked. Verify that the FramebufferPicker usage doesn't conflict with the new camera-based flag logic.


93-99: Camera modify listener is well-defined.

By tracking all camera modification flags in _cameraModifyDirtyFlag, the code can handle multiple changes in a single frame. Just ensure large changes don't cause performance bottlenecks if flags accumulate.


185-205: Cohesive approach to camera and group transform changes.

The updated conditional logic checks both _transformFlag.flag and _cameraModifyDirtyFlag. This ensures the gizmo updates promptly whenever the group or camera changes. Confirm that resetting this._cameraModifyDirtyFlag to 0 won't skip subsequent flags if multiple modifications happen within the same frame.

this._cameraTransformFlag = cameraEntity.registerWorldChangeFlag();
// @ts-ignore
camera._registerModifyListener(this._onCameraModifyListener);
this._framebufferPicker = cameraEntity.addComponent(FramebufferPicker);
Copy link
Collaborator

Choose a reason for hiding this comment

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

这种内部接口后续会以更友好的方式开放出来么?

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