Skip to content

Reload mesh with opacity #8622

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

knollengewaechs
Copy link
Contributor

@knollengewaechs knollengewaechs commented May 14, 2025

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

This PR improves the reloading of meshes by keeping their previous opacity. It also refactors the code by splitting the mesh_saga into three modules.

Steps to test:

  • Open an annotation and select some segments. Load their meshes.
  • Now change the opacity of a mesh and reload it. The opacity should not change upon reloading.
  • Do this for precomputed and ad-hoc meshes
  • As the mesh_saga was refactored, it makes sense to test the usual mesh functionality: downloading mesh(es), reloading them, removing them, toggling the visibility, changing their color, etc

TODOs:

  • precomputed meshes
  • ad-hoc meshes
  • make code pretty
  • split mesh saga (see slack)

Issues:


(Please delete unneeded items, merge only when none are left open)

@knollengewaechs knollengewaechs self-assigned this May 14, 2025
Copy link
Contributor

coderabbitai bot commented May 14, 2025

📝 Walkthrough

Walkthrough

This change refactors mesh opacity handling in the viewer by ensuring that mesh opacity is preserved and reapplied when meshes are reloaded. It introduces explicit opacity parameters through mesh loading actions, updates reducers and controllers, and splits mesh-related sagas into specialized modules for ad-hoc and precomputed meshes.

Changes

Files/Groups Change Summary
frontend/javascripts/components/color_picker.tsx Synchronizes local color picker state with external color prop using useEffect.
frontend/javascripts/viewer/api/api_latest.ts, viewer/view/context_menu.tsx, viewer/model_initialization.ts, viewer/model/sagas/proofread_saga.ts, viewer/view/right-border-tabs/segments_tab/segments_view.tsx Passes Constants.DEFAULT_MESH_OPACITY to mesh loading actions to ensure default opacity is always set.
frontend/javascripts/viewer/controller/mesh_helpers.ts Adds sortByDistanceTo utility function for sorting mesh chunks or vectors by distance to a seed position.
frontend/javascripts/viewer/controller/segment_mesh_controller.ts Propagates opacity parameter through mesh creation methods and updates method signatures to accept opacity.
frontend/javascripts/viewer/model/actions/annotation_actions.ts, viewer/model/actions/segmentation_actions.ts Adds/updates opacity parameters in mesh-related action creators and types.
frontend/javascripts/viewer/model/reducers/annotation_reducer.ts Updates reducer to store and use opacity values from actions for ad-hoc and precomputed meshes.
frontend/javascripts/viewer/model/sagas/mesh_saga.ts Removes (deletes) the monolithic mesh saga file.
frontend/javascripts/viewer/model/sagas/meshes/ad_hoc_mesh_saga.ts Adds new saga for ad-hoc mesh loading, refreshing, and removal, with support for opacity.
frontend/javascripts/viewer/model/sagas/meshes/common_mesh_saga.ts Adds new saga for mesh downloading, visibility, color, and opacity updates, and handling coordinate changes.
frontend/javascripts/viewer/model/sagas/meshes/precomputed_mesh_saga.ts Adds new saga for precomputed mesh loading, chunk management, and error handling, supporting opacity.
frontend/javascripts/viewer/model/sagas/root_saga.ts Refactors saga imports and registration to use the new modular mesh sagas instead of the deleted monolithic saga.
CHANGELOG.unreleased.md Updates changelog to note that mesh opacity is now preserved when reloading meshes.

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Preserve and reuse configured mesh opacity when reloading mesh (#8504)

Possibly related PRs

Suggested labels

frontend, enhancement, automerge

Suggested reviewers

  • philippotto
  • MichaelBuessemeyer

Poem

The mesh returns, its shimmer right,
With opacity set just as light.
No more a ghost, nor solid stone,
Its see-through charm is all its own.
Reload, refresh—no fright, no fuss,
Mesh opacity now stays with us!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@knollengewaechs knollengewaechs force-pushed the reload-mesh-with-opacity branch from 2b5ddea to 7245fc1 Compare May 14, 2025 15:01
@knollengewaechs knollengewaechs marked this pull request as ready for review May 28, 2025 13:10
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: 2

🧹 Nitpick comments (1)
frontend/javascripts/viewer/model_initialization.ts (1)

37-37: Consider consolidating imports from the same module.

While this change is functionally correct, having both a named import (constants) and default import (Constants) from the same module could lead to confusion.

Consider refactoring to use a single import pattern if possible:

-import constants, { ControlModeEnum, type Vector3 } from "viewer/constants";
-import Constants from "viewer/constants";
+import Constants, { ControlModeEnum, type Vector3 } from "viewer/constants";

Then update the usage on line 517 from constants.GPU_FACTOR_MULTIPLIER to Constants.GPU_FACTOR_MULTIPLIER and similar references.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 055c9e2 and f897b89.

📒 Files selected for processing (17)
  • CHANGELOG.unreleased.md (1 hunks)
  • frontend/javascripts/components/color_picker.tsx (3 hunks)
  • frontend/javascripts/viewer/api/api_latest.ts (1 hunks)
  • frontend/javascripts/viewer/controller/mesh_helpers.ts (2 hunks)
  • frontend/javascripts/viewer/controller/segment_mesh_controller.ts (7 hunks)
  • frontend/javascripts/viewer/model/actions/annotation_actions.ts (5 hunks)
  • frontend/javascripts/viewer/model/actions/segmentation_actions.ts (3 hunks)
  • frontend/javascripts/viewer/model/reducers/annotation_reducer.ts (5 hunks)
  • frontend/javascripts/viewer/model/sagas/mesh_saga.ts (0 hunks)
  • frontend/javascripts/viewer/model/sagas/meshes/ad_hoc_mesh_saga.ts (1 hunks)
  • frontend/javascripts/viewer/model/sagas/meshes/common_mesh_saga.ts (1 hunks)
  • frontend/javascripts/viewer/model/sagas/meshes/precomputed_mesh_saga.ts (1 hunks)
  • frontend/javascripts/viewer/model/sagas/proofread_saga.ts (2 hunks)
  • frontend/javascripts/viewer/model/sagas/root_saga.ts (2 hunks)
  • frontend/javascripts/viewer/model_initialization.ts (2 hunks)
  • frontend/javascripts/viewer/view/context_menu.tsx (2 hunks)
  • frontend/javascripts/viewer/view/right-border-tabs/segments_tab/segments_view.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • frontend/javascripts/viewer/model/sagas/mesh_saga.ts
🧰 Additional context used
🧬 Code Graph Analysis (2)
frontend/javascripts/viewer/controller/mesh_helpers.ts (2)
frontend/javascripts/viewer/constants.ts (1)
  • Vector3 (13-13)
frontend/javascripts/libs/mjs.ts (1)
  • V3 (398-398)
frontend/javascripts/viewer/view/right-border-tabs/segments_tab/segments_view.tsx (1)
frontend/javascripts/viewer/model/actions/segmentation_actions.ts (1)
  • loadPrecomputedMeshAction (33-49)
🔇 Additional comments (37)
frontend/javascripts/components/color_picker.tsx (4)

4-4: LGTM: Import addition is necessary.

The addition of useEffect to the React imports is required for the state synchronization functionality added to both color picker components.


40-43: Excellent: Proper state synchronization added.

This useEffect ensures the internal state stays synchronized with external prop changes, which is essential for controlled components that maintain internal state for performance reasons (throttling). The implementation is correct with proper dependency management.


52-52: Good fix: Ensures visual consistency.

Changing the HexColorInput to use the internal value state instead of the external color prop ensures visual consistency with the HexColorPicker. Both components now display the same color value, preventing temporary visual inconsistencies during throttled updates.


100-103: Consistent implementation: State sync for RGBA picker.

This useEffect applies the same state synchronization pattern to the RGBA color picker, ensuring both color picker components behave consistently when external props change. The implementation mirrors the first useEffect and follows the same best practices.

CHANGELOG.unreleased.md (1)

21-21: LGTM! Well-documented feature addition.

The changelog entry clearly documents the new mesh opacity preservation feature and is properly formatted with the correct PR reference.

frontend/javascripts/viewer/view/context_menu.tsx (2)

39-46: LGTM! Import statement updated to support default mesh opacity constant.

The import statement correctly switches to include Constants as a default import alongside the existing named imports, enabling access to Constants.DEFAULT_MESH_OPACITY used later in the file.


965-965: LGTM! Opacity parameter properly integrated into mesh loading.

The addition of Constants.DEFAULT_MESH_OPACITY as the fifth parameter to loadPrecomputedMeshAction correctly implements the mesh opacity preservation feature. This ensures that when meshes are loaded from the context menu, they use the default opacity value consistently with the broader mesh opacity handling changes described in the PR.

frontend/javascripts/viewer/model/sagas/proofread_saga.ts (2)

14-14: LGTM: Clean import addition for Constants object.

The addition of the default Constants import is correct and necessary to access DEFAULT_MESH_OPACITY used later in the file.


178-187:

✅ Verification successful

Verify function signature and constant availability.

The addition of Constants.DEFAULT_MESH_OPACITY as a parameter aligns well with the PR objective of preserving mesh opacity during reloads. Using a default opacity constant for automatic mesh loading during proofreading is appropriate.

Please verify that:

  1. loadPrecomputedMeshAction expects this opacity parameter in the 5th position
  2. Constants.DEFAULT_MESH_OPACITY exists and has the correct type

🏁 Script executed:

#!/bin/bash
# Description: Verify that Constants.DEFAULT_MESH_OPACITY exists and loadPrecomputedMeshAction accepts the opacity parameter

# Check if Constants.DEFAULT_MESH_OPACITY is defined
echo "Checking Constants.DEFAULT_MESH_OPACITY definition:"
ast-grep --pattern 'export default {
  $$$
  DEFAULT_MESH_OPACITY: $_,
  $$$
}'

echo -e "\nChecking loadPrecomputedMeshAction function signature:"
# Find the loadPrecomputedMeshAction function definition
ast-grep --pattern 'export const loadPrecomputedMeshAction = ($_) => $$$'

echo -e "\nAlternative function definition pattern:"
ast-grep --pattern 'function loadPrecomputedMeshAction($$$) {
  $$$
}'

echo -e "\nChecking action creator pattern:"
ast-grep --pattern 'const loadPrecomputedMeshAction = ($_) => $$$'

Length of output: 715


🏁 Script executed:

#!/bin/bash
# Search for DEFAULT_MESH_OPACITY to locate its definition
echo "Searching for DEFAULT_MESH_OPACITY occurrences:"
rg -n "DEFAULT_MESH_OPACITY"

echo -e "\nSearching for loadPrecomputedMeshAction occurrences:"
rg -n "loadPrecomputedMeshAction"

Length of output: 3674


🏁 Script executed:

#!/bin/bash
# Display the definition and signature of loadPrecomputedMeshAction
echo "=== loadPrecomputedMeshAction definition (with context) ==="
rg -C10 "export const loadPrecomputedMeshAction" frontend/javascripts/viewer/model/actions/segmentation_actions.ts

# Display the DEFAULT_MESH_OPACITY constant definition
echo -e "\n=== DEFAULT_MESH_OPACITY definition ==="
sed -n '300,320p' frontend/javascripts/viewer/constants.ts

Length of output: 1451


Approved: DEFAULT_MESH_OPACITY correctly matches the action signature.

  • loadPrecomputedMeshAction’s fifth parameter is opacity: number, and the new Constants.DEFAULT_MESH_OPACITY (defined as 1 in constants.ts) satisfies this type.
  • No further updates are needed.
frontend/javascripts/viewer/api/api_latest.ts (1)

2524-2524: LGTM! Consistent opacity parameter addition.

The addition of Constants.DEFAULT_MESH_OPACITY correctly aligns with the updated loadPrecomputedMeshAction signature and supports the PR's objective of preserving mesh opacity during reload operations.

frontend/javascripts/viewer/model/actions/segmentation_actions.ts (2)

10-10: LGTM! Proper optional opacity support for ad-hoc meshes.

Adding the optional opacity property to AdHocMeshInfo maintains backward compatibility while enabling opacity specification for ad-hoc meshes.


38-38: LGTM! Correct opacity parameter integration.

The required opacity parameter ensures that precomputed meshes always have an opacity value specified, which aligns with the PR's goal of preserving mesh opacity during reloads.

Also applies to: 47-47

frontend/javascripts/viewer/model/sagas/root_saga.ts (2)

24-26: LGTM! Well-organized saga modularization.

The refactoring from a single meshSaga to three specialized sagas (adHocMeshSaga, precomputedMeshSaga, commonMeshSaga) improves code organization and maintainability by separating concerns.


73-75: LGTM! Proper saga initialization.

All three mesh sagas are correctly called in the restartableSaga, ensuring they are properly initialized and run concurrently as part of the application's saga middleware.

frontend/javascripts/viewer/model/reducers/annotation_reducer.ts (2)

356-365: LGTM: Proper opacity handling for ad hoc meshes.

The changes correctly add opacity parameter handling for ad hoc meshes. The direct assignment from the action payload ensures that the mesh's opacity value is preserved in the Redux state.


402-411: LGTM: Appropriate fallback logic for precomputed mesh opacity.

The implementation correctly handles opacity for precomputed meshes with a sensible fallback to Constants.DEFAULT_MESH_OPACITY when opacity is not provided. This ensures backward compatibility while supporting the new opacity functionality.

frontend/javascripts/viewer/model_initialization.ts (1)

894-894: LGTM: Proper default opacity parameter for precomputed mesh loading.

The addition of Constants.DEFAULT_MESH_OPACITY as a parameter to loadPrecomputedMeshAction correctly ensures that meshes loaded during initialization have the default opacity value, maintaining consistency with the new opacity-aware mesh loading flow.

frontend/javascripts/viewer/view/right-border-tabs/segments_tab/segments_view.tsx (2)

54-54: LGTM: Import statement updated to support default mesh opacity.

The import statement change to include the default Constants object is appropriate for accessing DEFAULT_MESH_OPACITY used in the dispatch function below.


245-252: LGTM: Default mesh opacity added to precomputed mesh loading.

The addition of Constants.DEFAULT_MESH_OPACITY as the opacity parameter ensures that precomputed meshes are loaded with a consistent default opacity value. This aligns with the PR objective of preserving and managing mesh opacity during loading operations.

frontend/javascripts/viewer/controller/mesh_helpers.ts (1)

85-92: LGTM: Well-implemented distance sorting utility.

The sortByDistanceTo function correctly handles both Vector3 arrays and MeshChunk arrays by checking for the position property. The Euclidean distance calculation using V3.length(V3.sub(...)) is appropriate for spatial sorting.

The type assertion in the return statement is justified given the function's polymorphic input types.

frontend/javascripts/viewer/model/actions/annotation_actions.ts (2)

330-348: LGTM: Opacity parameter added with backward compatibility.

The addition of the optional opacity parameter with a default value of Constants.DEFAULT_MESH_OPACITY maintains backward compatibility while enabling opacity specification for ad-hoc meshes. The parameter is correctly included in the returned action object.


350-368: LGTM: Required opacity parameter for precomputed meshes.

The addition of the required opacity parameter for precomputed meshes is appropriate, as these meshes should have their opacity explicitly specified during loading. This supports the PR objective of preserving mesh opacity during reload operations.

frontend/javascripts/viewer/model/sagas/meshes/common_mesh_saga.ts (5)

32-57: LGTM: Robust mesh download implementation with proper error handling.

The mesh download functionality correctly retrieves geometry, handles missing meshes with user feedback, and includes comprehensive error handling with both console logging and toast notifications.


93-102: LGTM: STL export includes proper segment metadata.

The STL blob generation correctly embeds mesh marker and segment ID metadata using the established stlMeshConstants, ensuring exported meshes retain their segment information.


124-177: LGTM: Comprehensive additional coordinate handling.

The handleAdditionalCoordinateUpdate function properly manages mesh visibility across coordinate changes using a continuous monitoring approach. The while-true loop is appropriate for this use case, and the implementation correctly updates both the Redux store and scene controller.


190-193: LGTM: Opacity change handling supports PR objectives.

The handleMeshOpacityChange function directly supports the PR objective of preserving mesh opacity by properly delegating opacity updates to the segment mesh controller.


209-219: LGTM: Well-organized saga with comprehensive event handling.

The main saga function properly initializes dependencies and registers handlers for all relevant mesh-related actions, supporting the refactored mesh saga architecture mentioned in the PR objectives.

frontend/javascripts/viewer/model/sagas/meshes/ad_hoc_mesh_saga.ts (3)

309-321: LGTM! Proper opacity handling with fallback.

The function correctly extracts opacity from meshExtraInfo and provides a sensible fallback to Constants.DEFAULT_MESH_OPACITY.


494-509: LGTM! Opacity correctly propagated to mesh controller.

The opacity value is properly extracted from meshExtraInfo with a fallback and passed to the mesh controller's addMeshFromVerticesAsync method.


665-677: Well-structured saga with proper initialization and action handling.

The saga correctly:

  • Buffers actions until the scene controller and WebKnossos are ready
  • Handles all mesh-related actions (load, remove, refresh)
  • Tracks edited cells for proper refresh behavior
frontend/javascripts/viewer/controller/segment_mesh_controller.ts (3)

20-20: LGTM! Import path correctly updated for saga refactoring.

The import path has been properly updated to reflect the new modular saga structure.


169-184: Excellent opacity animation implementation.

The tween animation now correctly animates to the specified opacity value instead of the hardcoded value of 1, properly supporting the mesh opacity feature.


109-136: Consistent opacity parameter propagation.

The opacity parameter is properly added to addMeshFromVerticesAsync and correctly passed through to addMeshFromGeometry, maintaining consistency across the mesh construction pipeline.

frontend/javascripts/viewer/model/sagas/meshes/precomputed_mesh_saga.ts (4)

56-93: Smart caching implementation using Deferred promises.

The caching mechanism efficiently prevents redundant mesh file fetches while properly handling forced refresh scenarios with the mustRequest flag.


109-135: Proper opacity handling with sensible defaults.

The function correctly extracts the opacity from the action and provides a fallback to Constants.DEFAULT_MESH_OPACITY, ensuring consistent behavior.


405-421: Excellent progressive loading strategy.

The eager chunk rendering provides immediate visual feedback while the final merged geometry is being prepared. The opacity parameter is correctly propagated through the mesh addition.


183-217: Comprehensive error handling with user-friendly feedback.

The function properly handles various error cases:

  • Missing mesh files
  • Invalid segment ID (0)
  • Mesh listing failures

Each case provides appropriate user feedback via Toast messages while logging detailed information for debugging.

Comment on lines 73 to 79
export function isMeshSTL(buffer: ArrayBuffer): boolean {
const dataView = new DataView(buffer);
const isMesh = stlMeshConstants.meshMarker.every(
(marker, index) => dataView.getUint8(index) === marker,
);
return isMesh;
}
Copy link
Contributor

@coderabbitai coderabbitai bot May 28, 2025

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify usage of the exported isMeshSTL function.

This function is exported but not used within this file. Please verify if it's being used elsewhere in the codebase.


🏁 Script executed:

#!/bin/bash
# Description: Find all usages of the isMeshSTL function across the codebase

# Search for imports and usages of isMeshSTL
rg -A 3 "isMeshSTL" --type ts --type tsx

Length of output: 68


🏁 Script executed:

#!/bin/bash
# Re-run search for usages of isMeshSTL across .ts and .tsx files
rg --glob '*.ts' --glob '*.tsx' -n "isMeshSTL"

Length of output: 174


Remove unused export isMeshSTL.

The function in
frontend/javascripts/viewer/model/sagas/meshes/ad_hoc_mesh_saga.ts:73
is exported but never referenced anywhere else in the repository. Please either:

  • Remove this dead code if it’s no longer needed
  • Or add the intended import/use where it should be invoked
🤖 Prompt for AI Agents
In frontend/javascripts/viewer/model/sagas/meshes/ad_hoc_mesh_saga.ts around
lines 73 to 79, the exported function isMeshSTL is not used anywhere in the
codebase. To fix this, either remove the isMeshSTL function entirely if it is no
longer needed, or identify the appropriate place in the code where this function
should be called and add the import and usage accordingly.

✅ Addressed in commit c4f41c3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@philippotto do you agree that I should remove this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

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

♻️ Duplicate comments (1)
frontend/javascripts/viewer/model/sagas/meshes/ad_hoc_mesh_saga.ts (1)

549-561: Past opacity issue has been resolved!

The opacity is now properly retrieved from mesh info and passed to refreshMeshWithMap, addressing the previous critical issue where opacity was not preserved during bulk refresh operations.

🧹 Nitpick comments (2)
frontend/javascripts/viewer/model/sagas/meshes/ad_hoc_mesh_saga.ts (2)

53-72: Consider cleanup strategy for unbounded object growth.

The batchCounterPerSegment object could potentially grow unbounded as segment IDs accumulate over time without cleanup. While this may be acceptable for typical usage patterns, consider implementing a cleanup strategy for long-running sessions.

 const batchCounterPerSegment: Record<number, number> = {};
+
+// Optional: Add cleanup logic to prevent unbounded growth
+// This could be implemented as a periodic cleanup or size-based eviction

461-514: Consider exponential backoff bounds for retry logic.

The retry mechanism uses exponential backoff (2 ** retryCount), but with RETRY_WAIT_TIME = 5000ms and MAX_RETRY_COUNT = 5, the final retry could wait up to 160 seconds. Consider if this aligns with user experience expectations.

-      yield* call(sleep, RETRY_WAIT_TIME * 2 ** retryCount);
+      // Cap the maximum wait time to prevent excessively long delays
+      const waitTime = Math.min(RETRY_WAIT_TIME * 2 ** retryCount, 30000);
+      yield* call(sleep, waitTime);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f897b89 and c4f41c3.

📒 Files selected for processing (1)
  • frontend/javascripts/viewer/model/sagas/meshes/ad_hoc_mesh_saga.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build-smoketest-push
  • GitHub Check: backend-tests
🔇 Additional comments (6)
frontend/javascripts/viewer/model/sagas/meshes/ad_hoc_mesh_saga.ts (6)

1-52: LGTM! Well-organized imports and clear separation of concerns.

The imports are comprehensive and properly organized, clearly showing the dependencies for ad-hoc mesh operations. The separation from the original monolithic mesh saga into this specialized module aligns well with the PR objectives.


300-314: Excellent opacity preservation implementation!

The opacity handling correctly extracts the value from meshExtraInfo and provides a proper fallback to Constants.DEFAULT_MESH_OPACITY. This directly addresses the PR requirement to preserve mesh opacity during reloading operations.


484-501: Opacity properly propagated to mesh controller.

The opacity value is correctly passed to addMeshFromVerticesAsync ensuring that mesh chunks maintain their intended opacity throughout the loading process.


580-606: Comprehensive opacity handling for both mesh types.

The refresh logic correctly handles opacity preservation for both precomputed meshes (via action dispatch) and ad-hoc meshes (via refreshMeshWithMap call), ensuring consistent behavior across different mesh types.


609-660: Robust mesh refresh implementation with proper opacity handling.

The refreshMeshWithMap function correctly accepts and uses the opacity parameter throughout the mesh reloading process. The logic properly handles mesh removal, chunk iteration, and opacity preservation in the reload call.


662-673: Well-structured saga with proper initialization sequence.

The main saga correctly buffers actions until dependencies are ready and sets up appropriate event handlers for all mesh operations. The use of actionChannel for buffering and proper dependency initialization demonstrates good Redux-saga practices.

}
}

function* refreshMeshes(): Saga<void> {
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 function is not called, because in the segment view, separate refreshMeshActions are dispatched. @philippotto do you know if there is a reason for that? should I change this?

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.

Reuse configured mesh opacity when reloading mesh
1 participant