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

Improve gizmo api #314

Open
wants to merge 1 commit into
base: dev/1.4
Choose a base branch
from

Conversation

gz65555
Copy link
Collaborator

@gz65555 gz65555 commented Dec 9, 2024

This pull request introduces serveral changes:

  1. add constructor parameters of gizmo
  2. use the group of gizmo, while not pass the group
  3. abandon gizmo.init function
  4. remove _initialize property
  5. update gizmo README.md

Force the developer to set camera while add the gizmo component:

const gizmo = gizmoEntity.addComponent(Gizmo, { camera, state: State.translate });

Invoking gizmo.init(camera, group) to create a gizmo is a disconnect in the process.

Copy link

coderabbitai bot commented Dec 9, 2024

Walkthrough

The pull request introduces modifications to the Gizmo package, specifically updating the README.md and Gizmo.ts files. The README now features a new URL for examples and a streamlined initialization method for the Gizmo component. In Gizmo.ts, a public group property replaces a private one, and the constructor has been updated to accept additional parameters for initialization. The control flow has been simplified by removing certain properties and methods, enhancing the overall structure while retaining core functionality.

Changes

File Path Change Summary
packages/gizmo/README.md Updated example URL, streamlined Gizmo initialization method, and updated documentation links.
packages/gizmo/src/Gizmo.ts Added public group property, updated constructor to accept new parameters, simplified control flow.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • cptbtptpbcptdtptp

Poem

🐰 In the land of code, where gizmos play,
A new path emerges, brightening the way.
With simpler starts and links so new,
Our Gizmo shines, with a clearer view!
Hops of joy as we code and create,
Together we build, it's never too late! 🌟


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 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

🧹 Outside diff range and nitpick comments (4)
packages/gizmo/src/Gizmo.ts (4)

30-30: Consider adding JSDoc for the public group property

Since group is now a public property, it should be documented with JSDoc to describe its purpose and usage.

+/** Group instance that stores selection state and transformation information */
 readonly group: Group = new Group();

Line range hint 108-123: LGTM: Constructor properly enforces required camera parameter

The constructor now correctly enforces the camera parameter requirement while making layer and state optional. The error handling for PhysicsManager is maintained.

However, consider adding type validation for the camera parameter:

 constructor(entity: Entity, props: { camera: Camera; layer?: Layer; state?: State }) {
   super(entity);
+  if (!props.camera) {
+    throw new Error("Camera is required for Gizmo initialization");
+  }
   if (!this.entity.engine.physicsManager) {
     throw new Error("PhysicsManager is not initialized");
   }

210-223: LGTM: Initialization logic properly encapsulated

The _init method effectively encapsulates the camera and framebuffer picker initialization logic. The method properly checks for camera changes and initializes controls.

However, there's a potential improvement for error handling:

 private _init(camera: Camera) {
+  if (!camera) {
+    throw new Error("Camera is required for initialization");
+  }
   if (camera !== this._sceneCamera) {

Line range hint 139-152: Consider consolidating duplicate transform update logic

The transform update logic is duplicated between the started and non-started states. Consider extracting this into a separate method.

+private _updateTransforms() {
+  this._traverseControl(this._type, (control) => {
+    this._type === State.all ? control.onUpdate(true) : control.onUpdate(false);
+  });
+  this.group._gizmoTransformDirty = false;
+}

 // Then in both places:
-this._traverseControl(this._type, (control) => {
-  this._type === State.all ? control.onUpdate(true) : control.onUpdate(false);
-});
-this.group._gizmoTransformDirty = false;
+this._updateTransforms();

Also applies to: 174-179

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3be869b and 95c071f.

📒 Files selected for processing (2)
  • packages/gizmo/README.md (2 hunks)
  • packages/gizmo/src/Gizmo.ts (10 hunks)
🔇 Additional comments (5)
packages/gizmo/README.md (3)

39-39: LGTM: Example URL updated

The example URL has been correctly updated to the new domain.


64-64: LGTM: Usage example aligns with new API design

The example correctly demonstrates the new initialization pattern requiring explicit camera parameter, which improves API clarity.


70-70: LGTM: Documentation link updated

Documentation link has been properly updated to the new domain.

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

Line range hint 274-279: LGTM: Proper cleanup in gizmo end handler

The gizmo end handler properly cleans up the state and dispatches the event. The coordinate dirty flag is correctly set.

🧰 Tools
🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


Line range hint 340-351: LGTM: World matrix and position retrieval updated

The code correctly uses the public group property to retrieve world matrix and position information.

@cptbtptpbcptdtptp cptbtptpbcptdtptp changed the base branch from main to dev/1.4 December 11, 2024 07:26
@cptbtptpbcptdtptp
Copy link
Collaborator

cptbtptpbcptdtptp commented Dec 11, 2024

Because it involves API changes, this PR changes base to dev/1.4

@gz65555
Copy link
Collaborator Author

gz65555 commented Dec 11, 2024

@cptbtptpbcptdtptp When do you migrate framebuffer picker to raycast?

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