How thomthom/bitmap-2-mesh works
Project type and purpose
• This is a Ruby-based SketchUp extension (“Bitmap to Mesh”) that reads bitmap (or heightmap) images and generates 2D/3D triangle meshes inside the SketchUp environment.
• Its primary use case is converting pixel data to geometry for terrains or pixel-based models.
File structure
Top‐level files:
– Gemfile, .rubocop.yml: Ruby gem and style config
– README.md, LICENSE.md: documentation and licensing
Folders of interest:
– docs/ (images used in the README)
– resources/ (sample heightmaps and SketchUp models for demos)
– src/tt_bitmap2mesh/ (the heart of the plugin)
• image processing (image/, helpers/)
• heightmap sampling and core mesh logic (heightmap.rb, sampler.rb, core.rb)
• UI tools and SketchUp integration (bootstrap.rb, place_mesh_tool.rb, cursor.rb, draggable.rb, leader.rb, text.rb)
• error handling (error_reporter/)
• debug & profiling (debug.rb, debug_tools.rb, profiling/)
– tests/ (unit‐test helpers)
README for additional insights
• Describes two main features: “Mesh from Heightmap” and “Mesh from Bitmap.”
• Lists SketchUp menu/toolbar integration points.
• Notes performance considerations (large images → many faces → slow generation).
Main components & their relationships
a. UI & Bootstrap Layer
• bootstrap.rb registers menu items and context‐menu commands in SketchUp
• When the user invokes “Mesh From Heightmap/Bitmap,” SketchUp hands control to a Tool object (place_mesh_tool.rb)
b. Configuration & Error Reporting
• settings.rb reads default and user preferences
• error_reporter/* captures uncaught exceptions and renders an HTML/JS/CSS report in the user’s browser for easy debugging
c. Image‐to‐Data Conversion
• helpers/image* and image_rep handle pixel‐level data extraction
d. Mesh Generation Core
• core.rb orchestrates creation of vertices and faces (two triangles per pixel)
e. SketchUp API Integration
• place_mesh_tool.rb, cursor.rb, draggable.rb implement interactive placement of the generated mesh in the SketchUp scene
f. Debug & Profiling
• debug.rb, debug_tools.rb provide instrumentation hooks; profiling/ scripts to measure performance
Architectural patterns & principles
• Layered approach:
– Presentation/UI layer (SketchUp menu & Tool classes)
– Application layer (bootstrap, command dispatch)
– Domain layer (image processing, sampling, mesh‐builder)
– Infrastructure (SketchUp API, file system for resources)
• Modularity: each responsibility lives in its own Ruby module/class
• Separation of concerns: error handling, config, and debugging are isolated from core logic