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

Add ability to dynamically alter 3D labels line width #4590

Merged
merged 11 commits into from
Jul 26, 2024

Conversation

CamronStaley
Copy link
Contributor

@CamronStaley CamronStaley commented Jul 23, 2024

What changes are proposed in this pull request?

https://voxel51.atlassian.net/browse/TEAMS-3117

Adding sliders in 3d datasets that allow us to increase / decrease the polylines width (both lines and cuboids)

These changes required us to move away from the default implementation of "Lines" offered by three.js because if you look in their notes line width changes will not be reflected in browsers running openGL due to a limitation (this applies to most all browsers). So instead we are using "Lines2" now which uses polygons to allow for lines to be resized.

2024-07-23 16 37 21

How is this patch tested? If it is not, please explain why.

Launched local server using dataset quickstart-3d:

yarn dev

Added polylines to the first object in quickstart-3d so that I could test those using this script:

import fiftyone as fo

dataset = fo.load_dataset("quickstart-3d")
dataset.persistent = True

sample = dataset.first()

print(sample)

# Object label
label = "lane"

# A list of lists of `[x, y, z]` points in scene coordinates describing
# the vertices of each shape in the polyline
points3d = [[[-5, -99, -2], [-8, 99, -2]], [[4, -99, -2], [1, 99, -2]]]

# A set of semantically related 3D polylines
polyline = fo.Polyline(label=label, points3d=points3d)

sample["polylines"] = fo.Polylines(polylines=[polyline]);
sample.save()

print(sample)

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

When working with 3D datasets you can now change polyline width within the dropdown under labels.

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Enhanced rendering capabilities for the Cuboid and Line components, improving visual fidelity with advanced line techniques.
    • Introduced dynamic line width controls for cuboids and polylines using state management.
    • Added new constant for panel ordering to improve component organization.
    • Expanded functionality of the modal component by integrating new interactions and verification methods.
  • Bug Fixes

    • Resolved issues related to line rendering and performance.
  • Documentation

    • Updated configurations and usage guidelines for the new line rendering and state management features.

@CamronStaley CamronStaley self-assigned this Jul 23, 2024
Copy link
Contributor

coderabbitai bot commented Jul 23, 2024

Walkthrough

The recent updates enhance the Looker 3D application's functionality by introducing new constants and significantly improving the rendering of line segments and cuboids using advanced Three.js techniques. State management with Recoil is implemented for dynamic control of line widths, enriching the user experience and visual fidelity. Collectively, these changes streamline the management of visual elements, making it easier to customize and interact with 3D components.

Changes

File Path Changes Summary
.../constants.ts Added a new constant PANEL_ORDER_LABELS with a value of 998.
.../labels/cuboid.tsx Enhanced Cuboid component with advanced line rendering and dynamic line width from Recoil state. New global JSX declarations for lineSegments2 and lineSegmentsGeometry.
.../labels/index.tsx Updated ThreeDLabels to manage line widths using Recoil state. Introduced a configuration object for line width controls.
.../labels/line.tsx Improved Line component with advanced rendering capabilities and dynamic line width control via Recoil state. Added JSX declarations for line2 and lineGeometry.
.../state.ts Introduced new atoms cuboidLabelLineWidthAtom and polylineLabelLineWidthAtom, both set to a default value of 3.
.../oss/poms/modal/index.ts Added ModalLevaPom class to enhance ModalPom, introducing new verification functionalities.
.../oss/poms/leva.ts New file defining ModalLevaPom and LevaAsserter classes for modal interactions and assertions.
.../specs/3d/fo3d-pcd-stl.spec.ts Added assertions in test cases to verify folder structure in modal and test line widths.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Recoil
    participant Cuboid
    participant Line

    User->>Cuboid: Adjust line width
    Cuboid->>Recoil: Update cuboidLineWidth
    Recoil-->>Cuboid: State updated
    Cuboid->>Line: Render with new width
    Line-->>User: Display updated line
Loading

Poem

In the 3D world, bright and wide,
New lines and constants, we now abide.
With widths that change and form anew,
A rabbit jumps in joy, just for you! 🐇✨
Let’s hop through the lines, with colors that sing,
Celebrating the magic these changes bring!


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
Contributor

@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.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 59e6e6e and 0b7be86.

Files selected for processing (5)
  • app/packages/looker-3d/src/constants.ts (1 hunks)
  • app/packages/looker-3d/src/labels/cuboid.tsx (4 hunks)
  • app/packages/looker-3d/src/labels/index.tsx (3 hunks)
  • app/packages/looker-3d/src/labels/line.tsx (3 hunks)
  • app/packages/looker-3d/src/state.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • app/packages/looker-3d/src/constants.ts
Additional context used
Path-based instructions (4)
app/packages/looker-3d/src/labels/line.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker-3d/src/state.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker-3d/src/labels/cuboid.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker-3d/src/labels/index.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Additional comments not posted (22)
app/packages/looker-3d/src/labels/line.tsx (7)

4-10: Imports look good.

The new imports for useRecoilState, polylineLabelLineWidthAtom, Line2, LineMaterial, LineGeometry, and extend are necessary and correctly used in the file.


11-11: Extend function usage looks good.

The extend function is correctly used to register Line2, LineMaterial, and LineGeometry globally.


13-20: JSX namespace extension looks good.

The global JSX namespace extension for line2 and lineGeometry is correctly implemented.


35-35: Recoil state usage looks good.

The useRecoilState hook is correctly used to manage the line width dynamically.


50-54: Geometry creation looks good.

The LineGeometry is correctly created using the positions from the geo attributes.


55-60: Material creation looks good.

The LineMaterial is correctly created using the color and line width from the Recoil state.


63-65: Component rendering looks good.

The Line component correctly renders the line2 element with the created geometry and material.

app/packages/looker-3d/src/state.ts (2)

131-134: Cuboid label line width atom looks good.

The cuboidLabelLineWidthAtom is correctly implemented with a default value of 3.


136-139: Polyline label line width atom looks good.

The polylineLabelLineWidthAtom is correctly implemented with a default value of 3.

app/packages/looker-3d/src/labels/cuboid.tsx (7)

3-10: Imports look good.

The new imports for LineSegments2, LineMaterial, LineSegmentsGeometry, useRecoilState, and cuboidLabelLineWidthAtom are necessary and correctly used in the file.


12-12: Extend function usage looks good.

The extend function is correctly used to register LineSegments2, LineMaterial, and LineSegmentsGeometry globally.


14-23: JSX namespace extension looks good.

The global JSX namespace extension for lineSegments2 and lineSegmentsGeometry is correctly implemented.


45-45: Recoil state usage looks good.

The useRecoilState hook is correctly used to manage the line width dynamically.


75-79: Geometry creation looks good.

The LineSegmentsGeometry is correctly created using the edges of the box geometry.


80-89: Material creation looks good.

The LineMaterial is correctly created using the opacity, color, and line width from the Recoil state.


100-100: Component rendering looks good.

The Cuboid component correctly renders the lineSegments2 element with the created geometry and material.

app/packages/looker-3d/src/labels/index.tsx (6)

10-10: Import statement updated correctly.

The import statement now includes useRecoilState, which is necessary for managing state with Recoil.


20-21: New imports are appropriate.

The imports from leva and the state file are necessary for the new functionality.


26-32: Global namespace declaration is correct.

The global namespace declaration for lineMaterial is necessary for using it as a JSX intrinsic element.


50-55: State management for line widths is implemented correctly.

The state for cuboidLineWidth and polylineWidth is managed using Recoil atoms.


60-81: Configuration for line width controls is well-defined.

The configuration object constLabelLevaContrals defines properties for the line width controls, facilitating their integration into the UI using leva.


83-91: Controls integrated into the UI correctly.

The useControls hook from leva integrates the line width controls into the UI, allowing dynamic adjustments.

Copy link
Contributor

@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.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0b7be86 and 8de1b19.

Files selected for processing (1)
  • app/packages/looker-3d/src/labels/line.tsx (3 hunks)
Additional context used
Path-based instructions (1)
app/packages/looker-3d/src/labels/line.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Additional comments not posted (6)
app/packages/looker-3d/src/labels/line.tsx (6)

4-10: Imports look good.

The new imports are necessary for the updated functionality and are correctly used in the code.


11-11: Extend call is correctly used.

The extend function is correctly used to add Line2, LineMaterial, and LineGeometry to the JSX namespace.


13-20: Global declarations are correctly added.

The declare global block correctly adds line2 and lineGeometry to the JSX intrinsic elements.


35-35: Recoil state integration looks good.

The Line component correctly uses the Recoil state for line width.


50-59: Memoized geometry and material look good.

The geometry and material are correctly memoized to optimize performance.


62-64: Return statement integration looks good.

The return statement correctly integrates the new line2 and lineGeometry components.

@swheaton
Copy link
Contributor

whoa code rabbit is making seq diagrams now lol

Copy link
Contributor

@sashankaryal sashankaryal left a comment

Choose a reason for hiding this comment

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

Looking good! 🚀

Not the most trivial of things, but a good opportunity (both in terms of learning + adding coverage for 3D labels) to add e2e tests.

Comment on lines 79 to 80
}, [geo]);
const material = useMemo(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: newline here

const selectedLabels = useRecoilValue(fos.selectedLabelMap);
const tooltip = fos.useTooltip();
const labelAlpha = colorScheme.opacity;

const constLabelLevaContrals = {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: typo. Contrals -> Controls

Comment on lines 13 to 20
declare global {
namespace JSX {
interface IntrinsicElements {
line2: ReactThreeFiber.Node<Line2, typeof Line2>;
lineGeometry: ReactThreeFiber.Node<LineGeometry, typeof LineGeometry>;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we put these declaration merging / global augmentation code in a separate file? maybe three-d-labels.d.ts, or even better index.d.ts in looker-3d package root?

Comment on lines 52 to 53
}, [geo]);
const material = React.useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: linebreak

@sashankaryal sashankaryal added the app Issues related to App features label Jul 24, 2024
@sashankaryal sashankaryal changed the title Feature/3 dpolylines/sliders Add ability to dynamically alter 3D labels line width Jul 24, 2024
@swheaton
Copy link
Contributor

@CamronStaley great work tracking down what turned into a bigger task than initially expected!

Couple feature questions before looking at the code:
1.

So instead we are using "Lines2" now which uses polygons to allow for lines to be resized.

Will this impact performance or number of lines we can support? I'm imagining number of points quadrupling - 2 points in a line to 8 points for a long cuboid.

Where does the line width setting live? Is it for the current scene only or the whole session? Stored in the fo3d file?
Users that care about line width likely will want to set it once somewhere and have it persist.

@CamronStaley
Copy link
Contributor Author

@swheaton

Will this impact performance or number of lines we can support? I'm imagining number of points quadrupling - 2 points in a line to 8 points for a long cuboid.

I think this could impact performance in cases where there are tons of lines / cuboids, but I can't say for certain how much it will hurt it. Since it's an extension of mesh I would assume it's similar efficiency to that, which was already used for cuboids.

One potential solution could be if we are seeing performance issues with >X amount of lines we could disable the option to increase line thickness and default back to the old implementation to save performance in those cases.

Where does the line width setting live? Is it for the current scene only or the whole session? Stored in the fo3d file? Users that care about line width likely will want to set it once somewhere and have it persist.

Currently it's only stored in state so it won't persist between sessions, but it will persist between samples. We can discuss if we think it should persist between sessions in some way since I agree users who want it to always remain at X size should have that option.

This could be a bigger discussion about settings as a whole since there are other settings which could probably live in the user's settings such as lighting for 3d scenes.

@swheaton
Copy link
Contributor

I think this could impact performance in cases where there are tons of lines / cuboids, but I can't say for certain how much it will hurt it. Since it's an extension of mesh I would assume it's similar efficiency to that, which was already used for cuboids.

I'm not sure exactly how to measure performance of a web drawing tool but you could try this? Add a zillion lines to one of the scenes until the approach in this PR slows down. Then try same scene with the old lines approach and note any differences.

This could be a bigger discussion about settings as a whole since there are other settings which could probably live in the user's settings such as lighting for 3d scenes.

lighting settings can be persisted in the FO3D file

@sashankaryal
Copy link
Contributor

We can persist line width settings in the browser storage for now. Add getBrowserStorageEffectForKey effect to the atom and you should be all set.

Copy link
Contributor

@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 (3)
e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts (1)

86-87: Add a comment to explain the purpose of the new assertion.

The new assertion modal.assert.verifyLevaFolders(["stl", "pcd"]); verifies the presence of specific folders in the modal context. Adding a comment to explain its purpose would improve code readability.

+    // Verify that the modal contains the expected folders for STL and PCD assets.
     await modal.assert.verifyLevaFolders(["stl", "pcd"]);
app/packages/looker-3d/src/labels/cuboid.tsx (1)

33-33: Add a default value for lineWidth.

To prevent potential issues with undefined values, consider adding a default value for lineWidth.

-  const [lineWidth] = useRecoilState(cuboidLabelLineWidthAtom);
+  const [lineWidth] = useRecoilState(cuboidLabelLineWidthAtom) || 1;
e2e-pw/src/oss/poms/modal/index.ts (1)

38-38: Add a comment to explain the purpose of the leva property.

Adding a comment to explain the purpose of the leva property would improve code readability.

+    // Initialize the Leva property for managing Leva controls in the modal.
     this.leva = new ModalLevaPom(page, this);
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8de1b19 and 7741bcf.

Files selected for processing (8)
  • app/packages/looker-3d/index.d.ts (1 hunks)
  • app/packages/looker-3d/src/labels/cuboid.tsx (4 hunks)
  • app/packages/looker-3d/src/labels/index.tsx (3 hunks)
  • app/packages/looker-3d/src/labels/line.tsx (3 hunks)
  • app/packages/looker-3d/src/state.ts (1 hunks)
  • e2e-pw/src/oss/poms/modal/index.ts (4 hunks)
  • e2e-pw/src/oss/poms/modal/leva.ts (1 hunks)
  • e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/packages/looker-3d/src/labels/index.tsx
  • app/packages/looker-3d/src/state.ts
Additional context used
Path-based instructions (6)
app/packages/looker-3d/index.d.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

e2e-pw/src/oss/poms/modal/leva.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker-3d/src/labels/line.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker-3d/src/labels/cuboid.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

e2e-pw/src/oss/poms/modal/index.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Additional comments not posted (16)
app/packages/looker-3d/index.d.ts (2)

1-6: Imports are correctly referenced.

The necessary modules from three.js and react-three-fiber are correctly imported.


8-21: Global JSX declarations are correctly defined.

The custom JSX elements for Line2, LineGeometry, LineSegments2, LineSegmentsGeometry, and LineMaterial are correctly declared.

e2e-pw/src/oss/poms/modal/leva.ts (2)

4-13: Class ModalLevaPom is correctly defined.

The properties and constructor are correctly defined and initialized.


16-35: Class LevaAsserter is correctly defined.

The methods for verifying folders are correctly defined and perform the intended assertions.

app/packages/looker-3d/src/labels/line.tsx (4)

4-9: Imports are correctly referenced.

The necessary modules from three.js, recoil, and react-three-fiber are correctly imported.


11-11: Extend statement is correctly defined.

The custom elements are correctly registered with react-three-fiber.


26-26: State management is correctly implemented.

The line width state is correctly managed using Recoil.


41-56: Rendering logic is correctly implemented.

The component correctly uses Line2, LineGeometry, and LineMaterial for rendering.

app/packages/looker-3d/src/labels/cuboid.tsx (5)

12-12: Ensure the extended components are registered correctly.

The extend function registers the new components globally. Verify that the components are correctly registered and used in the JSX syntax.


90-90: Ensure the lineSegments2 component is correctly rendered.

The lineSegments2 component should be correctly rendered within the mesh. Verify its rendering in different scenarios.


69-78: Ensure the material properties are correctly applied.

The LineMaterial properties should be correctly applied, especially the opacity and linewidth. Verify that these properties are working as expected.

Verification successful

Ensure the material properties are correctly applied.

The LineMaterial properties opacity and linewidth are correctly applied in the following locations:

  • app/packages/looker-3d/src/labels/line.tsx:
    return new LineMaterial({
      color: color,
      linewidth: lineWidth,
      opacity: opacity,
    });
  • app/packages/looker-3d/src/labels/cuboid.tsx:
    new LineMaterial({
      opacity: opacity,
      transparent: false,
      color: selected ? "orange" : color,
      linewidth: lineWidth,
    }),

These properties are correctly set and used within the LineMaterial instances.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct application of `LineMaterial` properties.

# Test: Search for the usage of `LineMaterial` and verify the properties.
rg --type tsx --pattern 'LineMaterial'

Length of output: 450


Script:

#!/bin/bash
# Description: Verify the correct application of `LineMaterial` properties.

# Test: Search for the usage of `LineMaterial` and verify the properties.
rg 'LineMaterial' --type tsx -A 5

Length of output: 61


Script:

#!/bin/bash
# Description: Verify the correct application of `LineMaterial` properties.

# Test: Search for the usage of `LineMaterial` and verify the properties.
rg 'LineMaterial' --type ts -A 5

Length of output: 3347


3-5: Ensure compatibility with Three.js version.

The new imports from three/examples/jsm/lines should be compatible with the current version of Three.js used in the project. Verify that the project dependencies are updated if necessary.

Verification successful

Verified Three.js version compatibility

The project uses Three.js version ^0.165.0, which supports the LineSegments2, LineMaterial, and LineSegmentsGeometry classes from three/examples/jsm/lines. The imports are compatible with the specified version.

  • Three.js version: ^0.165.0 found in app/packages/looker-3d/package.json
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the compatibility of new imports with the current version of Three.js.

# Test: Check the version of Three.js used in the project.
rg --type js --pattern 'three' package.json

Length of output: 455


Script:

#!/bin/bash
# Description: Verify the compatibility of new imports with the current version of Three.js.

# Test: Check the version of Three.js used in the project.
rg 'three' package.json

Length of output: 76


Script:

#!/bin/bash
# Description: Locate the package.json file and verify the compatibility of new imports with the current version of Three.js.

# Step 1: Locate the package.json file.
fd package.json

# Step 2: Check the version of Three.js used in the located package.json file.
fd package.json --exec rg 'three'

Length of output: 806


8-9: Ensure the Recoil atom is defined and used correctly.

The cuboidLabelLineWidthAtom should be defined in the Recoil state and used correctly. Verify its definition and usage in the state management.

Verification successful

The cuboidLabelLineWidthAtom is defined and used correctly.

The cuboidLabelLineWidthAtom is defined in app/packages/looker-3d/src/state.ts and is used in multiple files, including index.tsx and cuboid.tsx. Here are the relevant locations:

  • Definition:

    • app/packages/looker-3d/src/state.ts:1
      export const cuboidLabelLineWidthAtom = atom<number>({
        key: "fo3d-cuboidLabelLineWidth",
        default: 3,
        effects: [getBrowserStorageEffectForKey("fo3d-cuboidLabelLineWidth")],
      });
  • Usages:

    • app/packages/looker-3d/src/labels/index.tsx:1
      import { cuboidLabelLineWidthAtom, polylineLabelLineWidthAtom } from "../state";
    • app/packages/looker-3d/src/labels/index.tsx:5
      const [lineWidth] = useRecoilState(cuboidLabelLineWidthAtom);
    • app/packages/looker-3d/src/labels/cuboid.tsx:1
      import { cuboidLabelLineWidthAtom } from "../state";

These findings confirm that the atom is properly defined and utilized within the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and usage of `cuboidLabelLineWidthAtom` in the Recoil state.

# Test: Search for the definition and usage of `cuboidLabelLineWidthAtom`.
rg --type tsx --pattern 'cuboidLabelLineWidthAtom'

Length of output: 462


Script:

#!/bin/bash
# Description: Verify the definition and usage of `cuboidLabelLineWidthAtom` in the Recoil state.

# Test: Search for the definition and usage of `cuboidLabelLineWidthAtom`.
rg 'cuboidLabelLineWidthAtom' --type ts --type tsx -A 3

Length of output: 83


Script:

#!/bin/bash
# Description: Verify the definition and usage of `cuboidLabelLineWidthAtom` in the Recoil state.

# Test: Search for the definition and usage of `cuboidLabelLineWidthAtom`.
rg 'cuboidLabelLineWidthAtom' --glob '*.ts' --glob '*.tsx' -A 3

Length of output: 1732

e2e-pw/src/oss/poms/modal/index.ts (3)

8-8: Ensure the new dependency is correctly imported.

The ModalLevaPom class should be correctly imported and used in the ModalPom class.


21-21: Ensure the new property is correctly initialized.

The leva property should be correctly initialized in the constructor of the ModalPom class.


264-267: Ensure the new method is correctly defined and used.

The verifyLevaFolders method should be correctly defined and used in the ModalAsserter class. Verify its usage in the test cases.

Comment on lines 63 to 67
const geometry = useMemo(() => {
return new LineSegmentsGeometry().fromLineSegments(
new THREE.LineSegments(new THREE.EdgesGeometry(geo))
);
}, [geo]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Optimize the geometry creation.

The geometry creation can be optimized by memoizing the EdgesGeometry instance.

-  const geometry = useMemo(() => {
-    return new LineSegmentsGeometry().fromLineSegments(
-      new THREE.LineSegments(new THREE.EdgesGeometry(geo))
-    );
-  }, [geo]);
+  const edgesGeo = useMemo(() => new THREE.EdgesGeometry(geo), [geo]);
+  const geometry = useMemo(() => new LineSegmentsGeometry().fromLineSegments(new THREE.LineSegments(edgesGeo)), [edgesGeo]);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const geometry = useMemo(() => {
return new LineSegmentsGeometry().fromLineSegments(
new THREE.LineSegments(new THREE.EdgesGeometry(geo))
);
}, [geo]);
const edgesGeo = useMemo(() => new THREE.EdgesGeometry(geo), [geo]);
const geometry = useMemo(() => new LineSegmentsGeometry().fromLineSegments(new THREE.LineSegments(edgesGeo)), [edgesGeo]);

Copy link
Contributor

@benjaminpkane benjaminpkane left a comment

Choose a reason for hiding this comment

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

Awesome addition! Looks like a tricky configuration 🙇

Just leaving a few linting comments

@@ -127,3 +127,15 @@ export const activeNodeAtom = atom<FoSceneNode>({
key: "fo3d-activeNode",
default: null,
});

export const cuboidLabelLineWidthAtom = atom<number>({
Copy link
Contributor

Choose a reason for hiding this comment

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

Type is implicit via the default value :)

Suggested change
export const cuboidLabelLineWidthAtom = atom<number>({
export const cuboidLabelLineWidthAtom = atom({

app/packages/looker-3d/src/state.ts Outdated Show resolved Hide resolved
export const polylineLabelLineWidthAtom = atom<number>({
key: "fo3d-polylineLabelLineWidth",
default: 3,
effects: [getBrowserStorageEffectForKey("fo3d-polylineLabelLineWidth")],
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above :)

e2e-pw/src/oss/poms/modal/leva.ts Outdated Show resolved Hide resolved
@@ -22,6 +30,7 @@ export const Cuboid = ({
color,
useLegacyCoordinates,
}: CuboidProps) => {
const [lineWidth] = useRecoilState(cuboidLabelLineWidthAtom);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: useRecoilValue can be used when read only

Suggested change
const [lineWidth] = useRecoilState(cuboidLabelLineWidthAtom);
const lineWidth = useRecoilValue(cuboidLabelLineWidthAtom);

readonly locator: Locator;
readonly assert: LevaAsserter;

constructor(page: Page, private readonly modal: ModalPom) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The Page is only used by the constructor for creating a Locator. Maybe a locator of the ModalPom can be used to find "#fo-leva-container"? Also, the dataCy plus getByTestId pattern is preferred over an HTML #id e.g. here

@sashankaryal is the e2e guru, but this has been my observation :)

Copy link
Contributor

@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.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7741bcf and 81e1562.

Files ignored due to path filters (4)
  • e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts-snapshots/max-line-width-scene-chromium-darwin.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts-snapshots/min-line-width-scene-chromium-darwin.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts-snapshots/scene-chromium-darwin.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts-snapshots/scene-chromium-linux.png is excluded by !**/*.png, !**/*.png
Files selected for processing (6)
  • app/packages/looker-3d/src/labels/cuboid.tsx (4 hunks)
  • app/packages/looker-3d/src/labels/line.tsx (3 hunks)
  • app/packages/looker-3d/src/state.ts (1 hunks)
  • e2e-pw/src/oss/poms/modal/index.ts (3 hunks)
  • e2e-pw/src/oss/poms/modal/leva.ts (1 hunks)
  • e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • app/packages/looker-3d/src/state.ts
Files skipped from review as they are similar to previous changes (3)
  • app/packages/looker-3d/src/labels/cuboid.tsx
  • e2e-pw/src/oss/poms/modal/index.ts
  • e2e-pw/src/oss/poms/modal/leva.ts
Additional context used
Path-based instructions (2)
app/packages/looker-3d/src/labels/line.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Additional comments not posted (12)
app/packages/looker-3d/src/labels/line.tsx (6)

4-10: Ensure proper use of imported modules.

The new imports and extension of three.js components are necessary for the new functionality. Verify that these modules are used correctly throughout the file.


26-26: Recoil state management implementation looks good.

The lineWidth is correctly obtained from polylineLabelLineWidthAtom using useRecoilValue.


41-43: Geometry creation using LineGeometry looks good.

The geometry is correctly created using LineGeometry and THREE.Line.


45-51: Material creation using LineMaterial looks good.

The material is correctly created using LineMaterial with color, lineWidth, and opacity.


54-56: JSX return statement looks good.

The return statement correctly includes a <mesh> with a <line2> element.


11-11: JSX namespace extension looks good.

The JSX namespace is correctly extended to include custom elements for line2 and lineGeometry.

e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts (6)

58-60: Creation of Polyline object looks good.

The Polyline object is correctly created with predefined 3D points and added to the sample under the key "polylines".


62-66: Creation of Detection object looks good.

The Detection object is correctly created with specified location, rotation, and dimensions and added to the sample under the key "bounding_box".


67-67: Addition of sample to dataset looks good.

The sample with Polyline and Detection objects is correctly added to the dataset.


69-69: Computation of orthographic projection images looks good.

The orthographic projection images are correctly computed for the dataset.


97-99: Assertions for default and asset folders look good.

The assertions correctly verify the default and asset folders in the modal interface.


101-119: Assertions for minimum and maximum line widths look good.

The assertions correctly verify the minimum and maximum line widths for the polyline and cuboid.

Copy link
Contributor

@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: 3

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 81e1562 and cc04d51.

Files ignored due to path filters (4)
  • e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts-snapshots/max-line-width-scene-chromium-linux.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts-snapshots/min-line-width-scene-chromium-linux.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts-snapshots/scene-chromium-darwin.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts-snapshots/scene-chromium-linux.png is excluded by !**/*.png, !**/*.png
Files selected for processing (2)
  • e2e-pw/src/oss/poms/modal/leva.ts (1 hunks)
  • e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • e2e-pw/src/oss/poms/modal/leva.ts
Additional context used
Path-based instructions (1)
e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts Show resolved Hide resolved
e2e-pw/src/oss/specs/3d/fo3d-pcd-stl.spec.ts Show resolved Hide resolved
Comment on lines +102 to +115
await modal.leva.minSlider("Polyline Line Width");
await modal.leva.minSlider("Cuboid Line Width");
await expect(modal.modalContainer).toHaveScreenshot(
"min-line-width-scene.png",
{
mask,
animations: "allow",
}
);

await modal.leva.maxSlider("Polyline Line Width");
await modal.leva.maxSlider("Cuboid Line Width");
await expect(modal.modalContainer).toHaveScreenshot(
"max-line-width-scene.png",
Copy link
Contributor

Choose a reason for hiding this comment

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

Add assertions to verify slider values.

While the slider interaction logic is correct, it would be beneficial to add assertions to verify the slider values for polyline and cuboid line widths.

+    await expect(modal.leva.getSliderValue("Polyline Line Width")).toBe(minValue);
+    await expect(modal.leva.getSliderValue("Cuboid Line Width")).toBe(minValue);
+    await expect(modal.leva.getSliderValue("Polyline Line Width")).toBe(maxValue);
+    await expect(modal.leva.getSliderValue("Cuboid Line Width")).toBe(maxValue);

Committable suggestion was skipped due to low confidence.

Copy link
Contributor

@sashankaryal sashankaryal left a comment

Choose a reason for hiding this comment

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

LGTM, love it!
Feel free to address the remaining comments or not, to your discretion.

Comment on lines +10 to 12

extend({ Line2, LineMaterial, LineGeometry });

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming THREE.LineBasicMaterial didn't work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah Line2 requires type of "LineMaterial" as its material attribute

Comment on lines +17 to +19
return this.page.locator('div[style*="--leva-colors-folderWidgetColor"]', {
has: this.page.locator(`text="${folderName}"`),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Substituting this.page.locator with this.locator didn't work? (basically restricting the search space)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah it would just hang for whatever reason I tried a few different combinations and could only get this one working properly.

Comment on lines +28 to +29
const slider = this.page
.locator("div")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above. this.locator's search space makes more sense, but if that's somehow not working, all is well.

Comment on lines +72 to +73
expect(this.modalLevaPom.getFolder(assetName)).toHaveCount(2)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

why two? Curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is because the leva component has two divs containing that assets name (the asset which was added to the scene. One is the visibility dropdown and the other is the dropdown named after that assets allowing you to edit it.

Comment on lines +59 to +67
async verifyDefaultFolders() {
await Promise.all(
DEFAULT_FOLDER_NAMES.map((folderName) =>
expect(this.modalLevaPom.getFolder(folderName)).toContainText(
folderName
)
)
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🧑‍🎨

Comment on lines +98 to +115
await modal.leva.toggleFolder("Labels");
await modal.leva.assert.verifyDefaultFolders();
await modal.leva.assert.verifyAssetFolders(["pcd", "stl"]);

await modal.leva.minSlider("Polyline Line Width");
await modal.leva.minSlider("Cuboid Line Width");
await expect(modal.modalContainer).toHaveScreenshot(
"min-line-width-scene.png",
{
mask,
animations: "allow",
}
);

await modal.leva.maxSlider("Polyline Line Width");
await modal.leva.maxSlider("Cuboid Line Width");
await expect(modal.modalContainer).toHaveScreenshot(
"max-line-width-scene.png",
Copy link
Contributor

Choose a reason for hiding this comment

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

beautiful

@CamronStaley CamronStaley merged commit ff96f24 into develop Jul 26, 2024
17 checks passed
@CamronStaley CamronStaley deleted the feature/3Dpolylines/sliders branch July 26, 2024 14:33
@coderabbitai coderabbitai bot mentioned this pull request Nov 7, 2024
5 tasks
@coderabbitai coderabbitai bot mentioned this pull request Nov 15, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app Issues related to App features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants