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

feat(engine): enhance texture resolution handling and add distance per pixel calculations #572

Merged
merged 2 commits into from
Oct 15, 2024

Conversation

miseyu
Copy link
Contributor

@miseyu miseyu commented Oct 15, 2024

Overview

What I've done

What I haven't done

How I tested

Screenshot

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • New Features

    • Introduced a new texture handling mechanism with improved distance calculations per pixel.
    • Replaced the texture exporter for enhanced performance and quality.
  • Improvements

    • Increased texture cache size for better resource management.
    • Adjusted geometric error threshold for more flexible polygon processing.
    • Added functionality to calculate downsample scale based on geometric error.
  • Bug Fixes

    • Simplified downsampling logic to enhance efficiency.

@miseyu miseyu self-assigned this Oct 15, 2024
@miseyu miseyu requested a review from a team as a code owner October 15, 2024 04:53
Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

Walkthrough

The changes in this pull request involve significant updates to the texture handling and tile processing within the engine. Key modifications include the replacement of the JpegAtlasExporter with WebpAtlasExporter, an increase in texture cache size, and a refactoring of texture dimension calculations. Additionally, the geometric error threshold calculation in the slice.rs file has been adjusted, and several method signatures and constants have been updated across the affected files.

Changes

File Path Change Summary
engine/runtime/action-sink/src/file/cesium3dtiles/sink.rs - Replaced JpegAtlasExporter with WebpAtlasExporter.
- Increased texture cache size from 100,000,000 to 200,000,000.
- Refactored maximum texture dimensions logic.
- Removed apply_downsample_factor function.
engine/runtime/action-sink/src/file/cesium3dtiles/slice.rs - Modified slice_to_tiles function to change geometric error threshold calculation from geom_error * 2.0 to geom_error / 0.9.
engine/runtime/common/src/texture.rs - Replaced constant MAX_TEXTURE_PIXELS_PER_METER with MIN_METER_PER_PIXEL (set at 0.025).
- Added get_distance_per_pixel function.
- Updated get_texture_downsample_scale_of_polygon to remove optional parameter.
- Added apply_downsample_factor method.

Possibly related PRs

🐇 In the land of code, where textures play,
A new exporter hops in, brightening the day.
From JPEG to WebP, we’ve made a fine switch,
With dimensions refined, and downsampling rich.
Cache sizes are growing, oh what a delight,
In our engine’s realm, everything feels right! 🌟


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.

Copy link

netlify bot commented Oct 15, 2024

Deploy Preview for reearth-flow canceled.

Name Link
🔨 Latest commit 0fcd413
🔍 Latest deploy log https://app.netlify.com/sites/reearth-flow/deploys/670df73431eaf30008f5338c

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

🧹 Outside diff range and nitpick comments (3)
engine/runtime/common/src/texture.rs (2)

85-85: Consider consistent numeric types to avoid unnecessary casting

At line 85, you're casting downsample_scale to f64 and then the result back to f32. This may introduce minor precision issues.

If precision permits, perform calculations using f32 throughout the function:

-(error_factor * downsample_scale as f64).clamp(0.0, 1.0) as f32
+(error_factor as f32 * downsample_scale).clamp(0.0, 1.0)

This change eliminates the need for casting and keeps the calculations consistent.


51-55: Update function documentation to reflect parameter changes

The function get_texture_downsample_scale_of_polygon no longer accepts limit_texture_resolution as an optional parameter. The documentation should be updated to match the current function signature.

Revise the documentation to accurately describe the parameters and purpose of the function.

engine/runtime/action-sink/src/file/cesium3dtiles/sink.rs (1)

480-487: Simplify the downsample_scale calculation for clarity.

The conditional assignment of downsample_scale can be streamlined to enhance readability.

Apply this diff to simplify the logic:

 let downsample_scale = if limit_texture_resolution.unwrap_or(false) {
     get_texture_downsample_scale_of_polygon(
         &original_vertices,
         texture_size,
     ) as f32
 } else {
     1.0
 };
+let downsample_scale = downsample_scale.max(1.0);

Alternatively, ensure that get_texture_downsample_scale_of_polygon returns 1.0 when limit_texture_resolution is false.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e4f8faf and 789b4c0.

📒 Files selected for processing (3)
  • engine/runtime/action-sink/src/file/cesium3dtiles/sink.rs (8 hunks)
  • engine/runtime/action-sink/src/file/cesium3dtiles/slice.rs (1 hunks)
  • engine/runtime/common/src/texture.rs (2 hunks)
🧰 Additional context used
🔇 Additional comments (3)
engine/runtime/action-sink/src/file/cesium3dtiles/sink.rs (3)

315-315: Verify the impact of increasing texture_cache size on memory usage.

The texture_cache size has been increased from 100_000_000 to 200_000_000. While this may improve performance by caching more textures, it could also lead to higher memory consumption. Ensure that the system can handle this change without adverse effects on memory resources.


522-524: Ensure texture dimensions are within supported limits.

While adjusting max_width and max_height to the next power of two is beneficial, confirm that the resulting dimensions do not exceed hardware texture size limitations to maintain compatibility across different devices.


541-541: Confirm removal of JpegAtlasExporter references.

Since WebpAtlasExporter is now used, ensure all instances of JpegAtlasExporter have been removed from the codebase to prevent any deprecated code from lingering.

Run the following script to identify any remaining references:

#!/bin/bash
# Description: Check for residual uses of `JpegAtlasExporter`.

# Test: Search the codebase for `JpegAtlasExporter`. Expect: No matches.
rg --type rust 'JpegAtlasExporter'

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

🧹 Outside diff range and nitpick comments (1)
engine/runtime/common/src/texture.rs (1)

1-5: Approve constant change with minor comment suggestion.

The change from MAX_TEXTURE_PIXELS_PER_METER to MIN_METER_PER_PIXEL is a good improvement, allowing for higher resolution textures while maintaining a clear limit. The comment explains the reasoning well.

Consider adding the equivalent pixels per meter value to the comment for clarity:

 /// The pixel resolution should be limited to around 10cm (0.1m),
 /// but this means that signs and other objects will not be visible, so adjustments are necessary.
+/// This value (0.025m/pixel) is equivalent to 40 pixels per meter.
 const MIN_METER_PER_PIXEL: f64 = 0.025;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 789b4c0 and 0fcd413.

📒 Files selected for processing (1)
  • engine/runtime/common/src/texture.rs (2 hunks)
🧰 Additional context used
🔇 Additional comments (1)
engine/runtime/common/src/texture.rs (1)

51-66: Approve simplification of get_texture_downsample_scale_of_polygon.

The changes to this function are well-implemented:

  1. Removal of the limit_texture_resolution parameter simplifies the function signature.
  2. Utilization of the new get_distance_per_pixel function improves code modularity.
  3. The simplified logic using MIN_METER_PER_PIXEL is more straightforward and consistently applies the resolution limit.

These modifications enhance the function's clarity and maintainability.

engine/runtime/common/src/texture.rs Show resolved Hide resolved
engine/runtime/common/src/texture.rs Show resolved Hide resolved
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.

1 participant