Skip to content

Conversation

@vnoves
Copy link
Member

@vnoves vnoves commented Jul 24, 2025

Summary by CodeRabbit

  • New Features

    • Added export logging functionality with timestamps, key event tracking, and exception logging.
    • Introduced configuration logging to record export settings during each session.
  • Improvements

    • Improved material handling by reusing existing materials when possible and refining color processing.
    • Enhanced texture assignment based on schema information for more accurate material representation.
    • Streamlined material retrieval by removing caching, simplifying export logic.
    • Centralized configuration directory usage for consistency across components.
    • Improved export process transparency by logging element counts and handling empty exports.
    • Refactored color computations for better clarity and modularity.
  • Bug Fixes

    • Minor formatting and readability improvements in export-related code.

@coderabbitai
Copy link

coderabbitai bot commented Jul 24, 2025

"""

Walkthrough

The changes introduce a centralized logging system for the glTF exporter, adding new utility classes for logging and configuration tracking. Logging is integrated into the export process, with log entries marking key events such as window opening, export start/finish, and configuration saving. The configuration directory path is now managed centrally via a static field. Material handling and color processing are refactored for clarity and schema awareness. Minor code formatting, initialization, and exception logging improvements are included.

Changes

File(s) Change Summary
Common_glTF_Exporter/Utils/ExportLog.cs, Common_glTF_Exporter/Utils/LogConfiguration.cs Added new classes for export logging and configuration logging functionality.
Common_glTF_Exporter/Common_glTF_Exporter.projitems Included new utility source files (ExportLog.cs, LogConfiguration.cs) in project compilation.
Common_glTF_Exporter/Core/GlTFExportContext.cs Integrated logging calls at export and link events; initialized default material; enhanced material reuse logic; minor code formatting updates.
Common_glTF_Exporter/Model/Links.cs Added static config directory field (configDir) initialized to user profile path combined with "Leia".
Common_glTF_Exporter/Utils/SettingsConfig.cs Replaced internal config directory logic with reference to Links.configDir.
Common_glTF_Exporter/Windows/MainWindow.xaml.cs Added logging at window open, export start/end, config save, and export element checks.
Common_glTF_Exporter/Utils/glTFExportUtils.cs Added a blank line for readability in a utility method.
Common_glTF_Exporter/ExternalCommand.cs Added exception logging in the catch block of the Execute method.
Common_glTF_Exporter/Materials/AssetProperties.cs Refactored diffuse bitmap and appearance color retrieval to use schema-based mappings; removed old methods.
Common_glTF_Exporter/Materials/MaterialProperties.cs Refactored color processing with helper methods for color conversion, blending, and default color generation.
Common_glTF_Exporter/Materials/MaterialTextures.cs Modified texture setting to use schema-based diffuse bitmap retrieval; adjusted base color setting logic.
Common_glTF_Exporter/Materials/RevitMaterials.cs Removed material caching; now fetches material directly from Revit document every time; simplified logic flow.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MainWindow
    participant ExportLog
    participant LogConfiguration
    participant GlTFExportContext

    User->>MainWindow: Open application
    MainWindow->>ExportLog: StartLog()
    MainWindow->>ExportLog: Write("Open Window")

    User->>MainWindow: Initiate Export
    MainWindow->>LogConfiguration: SaveConfig()
    LogConfiguration->>ExportLog: Write(config key-value pairs)
    MainWindow->>GlTFExportContext: Start()
    GlTFExportContext->>ExportLog: Write("Export Started")
    GlTFExportContext->>GlTFExportContext: (Export process with material reuse)
    GlTFExportContext->>ExportLog: Write("Export Finished")
    MainWindow->>ExportLog: EndLog()
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

  • Adjusted Logic Config File #111: Modifies SettingsConfig.cs to unify and improve configuration file handling by adding static constructor and thread safety, related to this PR’s update of config directory usage.
  • Fix missing textures #113: Refactors material texture handling and UV mapping, overlapping with this PR’s material export logic changes.
  • Fix textures #102: Refactors material export and document management in GlTFExportContext.cs and RevitMaterials.cs, closely related to this PR’s material handling and logging enhancements.

Poem

🐇✨ Logs now hop through every line,
Marking exports, bright and fine.
Configs saved with careful care,
Colors blend with artful flair.
From window open to export’s end,
The rabbit’s notes will always send! 📜🐰
"""

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0a962e7 and b139fad.

📒 Files selected for processing (2)
  • Common_glTF_Exporter/Materials/RevitMaterials.cs (1 hunks)
  • Common_glTF_Exporter/Utils/LogConfiguration.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • Common_glTF_Exporter/Utils/LogConfiguration.cs
  • Common_glTF_Exporter/Materials/RevitMaterials.cs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch AddLogger

🪧 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 generate unit tests to generate unit tests for 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.

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

🧹 Nitpick comments (3)
Common_glTF_Exporter/Utils/glTFExportUtils.cs (1)

68-68: Minor formatting change - consider consistency.

Adding a blank line for readability is fine, but ensure this formatting style is consistent across the codebase.

Common_glTF_Exporter/Model/Links.cs (1)

15-15: Consider using a property instead of a public field.

While centralizing the configuration directory path is excellent, consider making this a property instead of a public field for better encapsulation and potential future flexibility.

-public static string configDir =  Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Leia");
+public static string ConfigDir => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Leia");
Common_glTF_Exporter/Utils/LogConfiguration.cs (1)

9-38: Consider refactoring for better maintainability.

The current implementation has repetitive code that could be made more maintainable and less error-prone by using a loop structure.

         public static void SaveConfig()
         {
-            string format = SettingsConfig.GetValue("format");
-            string flipAxis = SettingsConfig.GetValue("flipAxis");
-            string normals = SettingsConfig.GetValue("normals");
-            string relocateTo0 = SettingsConfig.GetValue("relocateTo0");
-            string materials = SettingsConfig.GetValue("Materials");
-            string units = SettingsConfig.GetValue("units");
-            string batchId = SettingsConfig.GetValue("batchId");
-            string levels = SettingsConfig.GetValue("levels");
-            string properties = SettingsConfig.GetValue("properties");
-            string grids = SettingsConfig.GetValue("grids");
-            string compression = SettingsConfig.GetValue("compression");
-            string release = SettingsConfig.GetValue("release");
-            string runs = SettingsConfig.GetValue("runs");
-
-            ExportLog.Write($"format: {format}");
-            ExportLog.Write($"flipAxis: {flipAxis}");
-            ExportLog.Write($"normals: {normals}");
-            ExportLog.Write($"relocateTo0: {relocateTo0}");
-            ExportLog.Write($"materials: {materials}");
-            ExportLog.Write($"units: {units}");
-            ExportLog.Write($"batchId: {batchId}");
-            ExportLog.Write($"levels: {levels}");
-            ExportLog.Write($"properties: {properties}");
-            ExportLog.Write($"grids: {grids}");
-            ExportLog.Write($"compression: {compression}");
-            ExportLog.Write($"release: {release}");
-            ExportLog.Write($"runs: {runs}");
+            var configKeys = new[] { 
+                "format", "flipAxis", "normals", "relocateTo0", "materials", 
+                "units", "batchId", "levels", "properties", "grids", 
+                "compression", "release", "runs" 
+            };
+
+            foreach (var key in configKeys)
+            {
+                string value = SettingsConfig.GetValue(key);
+                ExportLog.Write($"{key}: {value}");
+            }
         }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b0c6615 and 1fa6c6b.

📒 Files selected for processing (8)
  • Common_glTF_Exporter/Common_glTF_Exporter.projitems (1 hunks)
  • Common_glTF_Exporter/Core/GlTFExportContext.cs (9 hunks)
  • Common_glTF_Exporter/Model/Links.cs (2 hunks)
  • Common_glTF_Exporter/Utils/ExportLog.cs (1 hunks)
  • Common_glTF_Exporter/Utils/LogConfiguration.cs (1 hunks)
  • Common_glTF_Exporter/Utils/SettingsConfig.cs (1 hunks)
  • Common_glTF_Exporter/Utils/glTFExportUtils.cs (1 hunks)
  • Common_glTF_Exporter/Windows/MainWindow.xaml.cs (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
Common_glTF_Exporter/Utils/SettingsConfig.cs (1)
Common_glTF_Exporter/Model/Links.cs (1)
  • Links (9-16)
Common_glTF_Exporter/Utils/ExportLog.cs (1)
Common_glTF_Exporter/Model/Links.cs (1)
  • Links (9-16)
Common_glTF_Exporter/Utils/LogConfiguration.cs (2)
Common_glTF_Exporter/Utils/SettingsConfig.cs (3)
  • SettingsConfig (9-132)
  • SettingsConfig (19-28)
  • GetValue (30-49)
Common_glTF_Exporter/Utils/ExportLog.cs (2)
  • ExportLog (7-57)
  • Write (27-38)
🔇 Additional comments (10)
Common_glTF_Exporter/Model/Links.cs (1)

3-3: Good addition for Path operations.

The System.IO namespace import is necessary for the Path.Combine operation below.

Common_glTF_Exporter/Common_glTF_Exporter.projitems (1)

68-68: New logging utilities added to project structure.

The addition of ExportLog.cs and LogConfiguration.cs to the project compilation list is appropriate and follows the existing structure.

Note: The actual implementation quality of these logging utilities would need to be reviewed separately when those files are provided.

Also applies to: 70-70

Common_glTF_Exporter/Utils/SettingsConfig.cs (2)

15-15: Good use of centralized configuration directory.

Using Links.configDir instead of the previous _configDir field eliminates code duplication and centralizes path management.


22-23: Consistent use of centralized configuration directory.

The directory existence check and creation now uses the centralized Links.configDir, maintaining consistency with the updated file path.

Common_glTF_Exporter/Windows/MainWindow.xaml.cs (3)

52-53: Good integration of logging initialization.

Starting the export log and logging the window opening provides good traceability for the export session.


65-67: Configuration logging before export is well-placed.

Logging the configuration before starting the export process ensures the settings are captured for debugging purposes.


86-86: Appropriate logging for export validation.

Logging when no valid elements are found helps with troubleshooting export issues.

Common_glTF_Exporter/Core/GlTFExportContext.cs (3)

90-90: Good logging integration for export lifecycle tracking.

The logging calls at key export lifecycle points (Start, Finish, LinkBegin, LinkEnd) provide good visibility into the export process flow.

Also applies to: 142-142, 385-385, 399-399


115-116: Good initialization of default material.

The creation and addition of a default GLTF material during export start ensures there's always a fallback material available.


428-432: Good conditional material handling in OnRPC.

The conditional assignment and addition of currentMaterial based on material preferences aligns well with the material handling logic used elsewhere in the class.

Comment on lines +22 to +25
public static void EndLog()
{
File.AppendAllText(logFilePath, $"[END] Export ended at {DateTime.Now}\n");
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add directory existence check for consistency.

The EndLog method should ensure the directory exists before writing, similar to StartLog.

         public static void EndLog()
         {
+            if (!Directory.Exists(Links.configDir))
+            {
+                Directory.CreateDirectory(Links.configDir);
+            }
             File.AppendAllText(logFilePath, $"[END] Export ended at {DateTime.Now}\n");
         }
🤖 Prompt for AI Agents
In Common_glTF_Exporter/Utils/ExportLog.cs around lines 22 to 25, the EndLog
method writes to a file without checking if the directory exists, unlike
StartLog. Add a check to verify the directory of logFilePath exists before
appending text, and create it if it does not, to maintain consistency and
prevent errors.

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

🧹 Nitpick comments (3)
Common_glTF_Exporter/Materials/MaterialTextures.cs (2)

16-16: Remove unused import.

The System.Diagnostics import is not used in this file and should be removed to keep the code clean.

-using System.Diagnostics;

51-51: Remove unnecessary empty line.

The empty line serves no purpose and should be removed for cleaner code formatting.

-
Common_glTF_Exporter/Materials/MaterialProperties.cs (1)

3-4: Remove unused imports.

The imports System.IO.Ports and System.Xml.Linq are not used in this file and should be removed to keep the code clean.

-using System.IO.Ports;
-using System.Xml.Linq;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1fa6c6b and 5affc72.

📒 Files selected for processing (8)
  • Common_glTF_Exporter/Core/GlTFExportContext.cs (8 hunks)
  • Common_glTF_Exporter/ExternalCommand.cs (1 hunks)
  • Common_glTF_Exporter/Materials/AssetProperties.cs (1 hunks)
  • Common_glTF_Exporter/Materials/MaterialProperties.cs (2 hunks)
  • Common_glTF_Exporter/Materials/MaterialTextures.cs (3 hunks)
  • Common_glTF_Exporter/Materials/RevitMaterials.cs (2 hunks)
  • Common_glTF_Exporter/Utils/ExportLog.cs (1 hunks)
  • Common_glTF_Exporter/Windows/MainWindow.xaml.cs (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • Common_glTF_Exporter/Windows/MainWindow.xaml.cs
  • Common_glTF_Exporter/Core/GlTFExportContext.cs
  • Common_glTF_Exporter/Utils/ExportLog.cs
🧰 Additional context used
🧬 Code Graph Analysis (3)
Common_glTF_Exporter/ExternalCommand.cs (1)
Common_glTF_Exporter/Utils/ExportLog.cs (2)
  • ExportLog (7-55)
  • WriteException (38-49)
Common_glTF_Exporter/Materials/MaterialTextures.cs (1)
Common_glTF_Exporter/Materials/AssetProperties.cs (4)
  • Asset (24-39)
  • AssetPropertiesUtils (10-207)
  • GetTexturePath (81-112)
  • GetFade (196-206)
Common_glTF_Exporter/Materials/MaterialProperties.cs (1)
Common_glTF_Exporter/Materials/BitmapsUtils.cs (1)
  • SrgbToLinear (129-134)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (18)
Common_glTF_Exporter/ExternalCommand.cs (1)

42-42: LGTM! Exception logging properly integrated.

The addition of ExportLog.WriteException(ex) correctly integrates with the new logging system, maintaining proper error handling flow while providing detailed exception information for debugging.

Common_glTF_Exporter/Materials/MaterialTextures.cs (4)

40-44: Good defensive programming for schema validation.

The early return when BaseSchema is null prevents processing materials without valid schema information, which aligns well with the new schema-aware approach.


46-47: Schema-aware texture retrieval properly implemented.

The extraction of schemaName and its usage in GetDiffuseBitmap correctly implements the new schema-aware approach for material processing.


56-59: Excellent fallback logic for missing textures.

The fallback to GetAppearanceColor when textures are unavailable provides graceful degradation and maintains consistency with the schema-aware approach.


75-75: Clean separation of concerns.

Removing the BaseColor assignment from SetTextureProperties and handling it in the main method's fallback logic provides better separation of concerns.

Common_glTF_Exporter/Materials/RevitMaterials.cs (3)

31-31: Simplified material retrieval improves maintainability.

Direct retrieval of materials from the document eliminates caching complexity and ensures current material state is always used.


42-44: Good separation of PBR property initialization.

The explicit creation of GLTFPBR object and delegation to MaterialProperties.SetProperties provides clear separation of concerns.


45-50: Proper conditional texture processing.

The conditional check for both material existence and user preferences ensures textures are only processed when appropriate, improving performance and respecting user settings.

Common_glTF_Exporter/Materials/AssetProperties.cs (3)

12-22: Excellent schema-based property mapping.

The DiffusePropertyMap provides a clean, maintainable approach to map material schemas to their corresponding diffuse properties using proper Revit API constants.


24-39: Robust implementation with proper error handling.

The GetDiffuseBitmap method includes comprehensive null checks, dictionary lookup validation, and connected property verification, making it resilient to various edge cases.


41-79: Consistent schema-based color retrieval with proper conversion.

The ColorPropertyMap and GetAppearanceColor method follow the same robust pattern as the diffuse bitmap handling, with proper color value conversion from doubles to bytes.

Common_glTF_Exporter/Materials/MaterialProperties.cs (7)

29-50: Excellent refactoring improves code clarity.

The refactored color processing logic with helper methods (RgbToUnit, BlendColour, GetLinearColour) significantly improves readability and maintainability while preserving the original functionality.


60-63: Simple and effective default color implementation.

The GetDefaultColour method provides a clean white default with proper opacity handling for textured materials.


65-73: Correct multiplicative color blending implementation.

The BlendColour method properly implements multiplicative blending for tint operations with clean tuple-based syntax.


75-82: Proper sRGB to linear color space conversion.

The GetLinearColour method correctly converts sRGB colors to linear space, which is essential for accurate glTF color representation.


84-92: Standard RGB byte to unit float conversion.

The RgbToUnit method correctly normalizes RGB byte values to the 0-1 float range with proper tuple-based return values.


94-99: Standard sRGB to linear gamma correction implementation.

The SrgbToLinear method correctly implements the standard gamma correction formula for sRGB to linear color space conversion, consistent with the existing codebase patterns.


54-54: Appropriate neutral base color for textured materials.

Using GetDefaultColour for textured materials provides the correct neutral white base that won't interfere with texture appearance.

@vnoves vnoves merged commit c1ba4a3 into develop Jul 25, 2025
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jul 25, 2025
@vnoves vnoves deleted the AddLogger branch October 28, 2025 22:55
@coderabbitai coderabbitai bot mentioned this pull request Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants