# Feasibility Analysis: Porting MatterControl Design Features to Web **Goal:** Evaluate porting the design-only features of MatterControl to a web application using JavaScript, WebAssembly, and WebGL. ## Executive Summary | Component | Porting Difficulty | Recommended Approach | |-----------|-------------------|---------------------| | **3D Rendering** | Medium | WebGL 2.0 + three.js | | **UI Framework** | High | React/Vue + custom Canvas widgets | | **Mesh Operations** | Medium-High | WASM (C# via Blazor or manual port) | | **File Formats** | Medium | JS parsers + pako for compression | | **Persistence** | Low | IndexedDB + File API | **Overall Assessment:** Feasible but substantial effort (4-6 months for MVP) --- ## Technology Stack Comparison | Desktop (Current) | Web Equivalent | |-------------------|----------------| | .NET 6.0 (C#) | TypeScript + WASM | | OpenGL 3.3 | WebGL 2.0 | | agg-sharp (2D) | Canvas 2D API | | GuiWidget (UI) | React/Vue components | | SQLite | IndexedDB | | File System | File API + virtual FS | | Typography module | Web Fonts + Canvas text | --- ## 1. 3D Rendering (WebGL) ### Current Implementation - OpenGL 3.3 with VAO/VBO/EBO - GLSL 330 shaders (simple vertex → fragment) - Custom `IOpenGL` abstraction layer - Features: textures, lighting (2 directional), depth testing, face culling ### Web Porting Options **Option A: three.js (Recommended)** - Mature WebGL abstraction - Built-in: cameras, raycasting, materials, scene graph - Large ecosystem and documentation - Handles WebGL 1.0/2.0 fallback **Option B: Custom WebGL 2.0** - More control, smaller bundle - Requires implementing: shader management, buffer handling, picking - Similar to current `IOpenGL` abstraction **Option C: Babylon.js** - Full game engine, heavier than three.js - Excellent tooling and inspector - May be overkill for CAD-style app ### Porting Complexity | Feature | Desktop | Web Equivalent | Effort | |---------|---------|----------------|--------| | Mesh rendering | GLMeshTrianglePlugin | three.js BufferGeometry | Low | | Camera control | TrackballTumbleWidget | three.js OrbitControls | Low | | Picking/selection | Ray + BVH | three.js Raycaster | Low | | Transform gizmos | Custom implementation | three.js TransformControls | Low | | Wireframe overlay | GLMeshWirePlugin | three.js EdgesGeometry | Low | | Texture mapping | ImageGlPlugin | three.js Texture | Low | | **Total 3D rendering** | | | **2-3 weeks** | --- ## 2. UI Framework ### Current Implementation - **GuiWidget**: Custom widget system with 2500+ line base class - **Layout**: HAnchor/VAnchor enum-based positioning, FlowLayout - **Widgets**: Button, TextEdit, Slider, Menu, ScrollableWidget, TreeView, etc. - **Theming**: JSON-based ThemeConfig - **Rendering**: agg-sharp software rasterization to ImageBuffer ### Web Porting Options **Option A: React + CSS (Recommended)** ``` GuiWidget hierarchy → React component tree HAnchor/VAnchor → CSS Flexbox FlowLayoutWidget → flex-direction ThemeConfig → CSS Custom Properties Events → React synthetic events ``` **Option B: Vue + CSS** - Similar mapping to React - Reactive state management built-in **Option C: Canvas-based (like current)** - Port GuiWidget directly to Canvas 2D - High effort, poor accessibility - Not recommended ### Widget Mapping | MatterControl Widget | Web Equivalent | |---------------------|----------------| | GuiWidget | React.Component + div | | FlowLayoutWidget | Flexbox container | | Button | `