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(web): scene settings fov not applied #1223

Merged
merged 3 commits into from
Nov 7, 2024

Conversation

airslice
Copy link
Contributor

@airslice airslice commented Nov 5, 2024

Overview

Fov was not included in camera when set from scene properties.

What I've done

What I haven't done

How I tested

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • New Features

    • Enhanced camera initialization logic to include field of view (fov) settings for improved visual experience.
    • Updated camera state management to ensure correct updates when the initial camera configuration changes.
  • Bug Fixes

    • Resolved issues with camera state not reflecting changes accurately due to previous logic constraints.

@airslice airslice requested a review from mkumbobeaty as a code owner November 5, 2024 03:17
Copy link

coderabbitai bot commented Nov 5, 2024

Walkthrough

The changes in this pull request focus on updating the logic for initializing the initialCamera state in two files: hooks.ts within the Visualizer and Published features. The new implementation checks for both the camera settings and the field of view (fov), ensuring a more comprehensive camera configuration. Additionally, the useEffect hooks have been modified to depend on the new initialCamera, ensuring that the current camera updates correctly. Minor formatting adjustments were also made, but no changes to function signatures or return values occurred.

Changes

File Path Change Summary
web/src/beta/features/Editor/Visualizer/hooks.ts Updated logic for initialCamera to include both camera settings and fov. Modified useEffect to depend on the new initialCamera. Minor formatting changes.
web/src/beta/features/Published/hooks.ts Similar updates to initialCamera logic and useEffect dependency. No changes to exported entities.

Possibly related PRs

Suggested labels

web

Suggested reviewers

  • mkumbobeaty
  • pyshx

Poem

In the world of code, we hop and play,
Adjusting cameras in a clever way.
With fov and settings, we craft with glee,
A smoother view for all to see!
So let’s cheer for changes, both big and small,
For a brighter canvas, we’ll give it our all! 🐇✨


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.

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.

@github-actions github-actions bot added the web label Nov 5, 2024
Copy link

netlify bot commented Nov 5, 2024

Deploy Preview for reearth-web ready!

Name Link
🔨 Latest commit fe06517
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/672c1db11fc0bd0008bfa917
😎 Deploy Preview https://deploy-preview-1223--reearth-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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 (2)
web/src/beta/features/Published/hooks.ts (1)

51-61: Improve type safety and object initialization.

While the implementation correctly addresses the FOV issue, consider these improvements:

  1. Add type checking for the camera object structure
  2. Avoid spreading empty objects when camera settings are null

Consider this safer implementation:

-      const initialCamera =
-        sceneProperty?.camera?.camera || sceneProperty?.camera?.fov
-          ? {
-              ...(sceneProperty?.camera?.camera ?? {}),
-              ...(sceneProperty?.camera?.fov
-                ? { fov: sceneProperty.camera.fov }
-                : {})
-            }
-          : undefined;
+      const initialCamera = (() => {
+        const cameraSettings = sceneProperty?.camera?.camera;
+        const fov = sceneProperty?.camera?.fov;
+        if (!cameraSettings && !fov) return undefined;
+        return {
+          ...(cameraSettings || {}),
+          ...(fov ? { fov } : {})
+        } as Camera;
+      })();
web/src/beta/features/Editor/Visualizer/hooks.ts (1)

101-109: LGTM! Consider simplifying the camera initialization logic.

The implementation correctly addresses the FOV issue by including it in the camera settings. The use of optional chaining and spread operators ensures safe property access.

Consider simplifying the nested conditionals for better readability:

-    const initialCamera =
-      sceneProperty?.camera?.camera || sceneProperty?.camera?.fov
-        ? {
-            ...(sceneProperty?.camera?.camera ?? {}),
-            ...(sceneProperty?.camera?.fov
-              ? { fov: sceneProperty.camera.fov }
-              : {})
-          }
-        : undefined;
+    const initialCamera = sceneProperty?.camera && {
+      ...(sceneProperty.camera.camera ?? {}),
+      ...(sceneProperty.camera.fov && { fov: sceneProperty.camera.fov })
+    };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d83191a and 183b39b.

📒 Files selected for processing (2)
  • web/src/beta/features/Editor/Visualizer/hooks.ts (1 hunks)
  • web/src/beta/features/Published/hooks.ts (1 hunks)
🔇 Additional comments (2)
web/src/beta/features/Published/hooks.ts (1)

Line range hint 28-33: Verify camera state synchronization.

The current implementation uses separate state variables and an effect for camera synchronization. While this works, there could be a brief moment where currentCamera and initialCamera are out of sync during initialization.

Let's verify the camera state management implementation:

Also applies to: 77-79

✅ Verification successful

Based on the search results, I can now generate the final response:

Camera state management is implemented correctly

The search results show that the camera state synchronization pattern is consistently implemented across the codebase:

  • The camera state updates are handled through a straightforward useEffect dependency on initialCamera
  • Similar patterns are used in other components (PluginPlayground, Editor/Visualizer)
  • The state update is immediate and atomic, making race conditions unlikely in practice

The current implementation follows React's state management best practices and doesn't require modification.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other camera state management patterns in the codebase
echo "Searching for camera state management patterns..."
rg -A 5 "const \[.*Camera.*useState.*\]"

# Search for potential race conditions in camera state updates
echo "Searching for camera state updates..."
rg -A 5 "setCurrentCamera"

Length of output: 4960

web/src/beta/features/Editor/Visualizer/hooks.ts (1)

110-111: Verify camera state initialization sequence.

The conditional setting of initialCamera followed by the useEffect that updates currentCamera could potentially lead to a race condition. While the current implementation works, it's worth verifying that the camera state is always properly initialized.

Let's check for any potential issues in the camera state initialization:

Also applies to: 337-339

@airslice airslice merged commit 8e9556f into main Nov 7, 2024
13 checks passed
@airslice airslice deleted the fix/scene-settings-fov-not-working branch November 7, 2024 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants