cyclecad 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,476 @@
1
+ # ExplodeView → cycleCAD Merge Plan: Viewer Mode Integration
2
+
3
+ **Status:** RESEARCH + PLANNING
4
+ **Date:** 2026-03-25
5
+ **Scope:** Integrate ExplodeView's 57 feature modules into cycleCAD as "Viewer Mode"
6
+ **Goal:** One unified platform (CAD + Viewer), two separate npm packages
7
+
8
+ ---
9
+
10
+ ## Executive Summary
11
+
12
+ ExplodeView is a 19,000+ line monolith (`app.js`) with 57 IIFE-based feature modules. cycleCAD is a modular parametric CAD system with 19 ES modules. The merge strategy:
13
+
14
+ 1. **Keep ExplodeView as standalone npm package** — no breaking changes for existing users
15
+ 2. **Port high-value ExplodeView features into cycleCAD as ES modules** — split the monolith into ~10 focused viewer modules
16
+ 3. **Share the Three.js scene** — one renderer, mode toggle (Edit Mode ↔ Viewer Mode)
17
+ 4. **Unified toolbar with tabs** — ExplodeView tools become new tab groups in cycleCAD's tabbed toolbar
18
+ 5. **Data bridge** — cycleCAD models load in Viewer Mode, viewer files (STL/Inventor) load in Viewer Mode
19
+
20
+ ---
21
+
22
+ ## Architecture Overview
23
+
24
+ ```
25
+ ┌─────────────────────────────────────────────────────────────┐
26
+ │ cycleCAD.com (unified platform) │
27
+ ├─────────────────────────────────────────────────────────────┤
28
+ │ │
29
+ │ EDIT MODE │ VIEWER MODE │
30
+ │ ├─ 2D Sketch │ ├─ Assembly Tree │
31
+ │ ├─ 3D Operations │ ├─ Explode/Collapse │
32
+ │ ├─ Constraints │ ├─ Section Cut │
33
+ │ ├─ Assembly │ ├─ BOM Export │
34
+ │ └─ Parameters │ ├─ Annotations │
35
+ │ │ ├─ AI Identification │
36
+ │ Shared Three.js Scene │ └─ Export STL/etc │
37
+ │ (camera, renderer, lights) │ │
38
+ │ │ │
39
+ │ ┌────────────────────────────────────────────────────┐ │
40
+ │ │ Tabbed Toolbar (View|Analyze|Create|Export|AI|...)│ │
41
+ │ └────────────────────────────────────────────────────┘ │
42
+ │ │
43
+ │ Mode Toggle Button (top-right): "Edit Mode" → "Viewer" │
44
+ └─────────────────────────────────────────────────────────────┘
45
+
46
+ npm packages (stay separate):
47
+ ┌──────────────────────────┐ ┌──────────────────────────┐
48
+ │ cyclecad v1.0 │ │ explodeview v1.0.5 │
49
+ │ (modeler + viewer) │ │ (standalone viewer) │
50
+ │ Uses viewer-mode.js │ │ Uses app.js monolith │
51
+ │ 30+ modules │ │ 57 IIFE modules │
52
+ └──────────────────────────┘ └──────────────────────────┘
53
+ ```
54
+
55
+ ---
56
+
57
+ ## Phase 1: Critical Features (Sprint 1 — 2 weeks)
58
+
59
+ These 8 features are foundation-level and unlock the most value. Estimated: **40 hours**.
60
+
61
+ | Feature | Module | ExplodeView Lines | LoC to Port | Priority | Effort |
62
+ |---------|--------|-------------------|------------|----------|--------|
63
+ | **Assembly Tree** | `viewer-assembly-tree.js` | 11270–13159 | 800 | P0 | 8h |
64
+ | **Explode/Collapse** | `viewer-explode.js` | 8173–8477 | 600 | P0 | 8h |
65
+ | **Section Cut** | `viewer-section-cut.js` | 10268–10445 | 400 | P1 | 6h |
66
+ | **BOM + Export** | `viewer-bom.js` | 9444–9672 | 400 | P1 | 5h |
67
+ | **Annotations** | `viewer-annotations.js` | (from initMarkup) | 350 | P2 | 5h |
68
+ | **AI Part Identifier** | `viewer-ai-identify.js` | 17460+ | 700 | P1 | 7h |
69
+ | **Context Menu** | `viewer-context-menu.js` | 8477–9184 | 300 | P2 | 4h |
70
+ | **Part Info Card** | `viewer-part-info.js` | 9928–10268 | 500 | P2 | 6h |
71
+
72
+ **Subtotal Phase 1:** ~8 new ES modules, ~4,050 LoC, 40 hours, **1-2 week sprint**
73
+
74
+ ---
75
+
76
+ ## Phase 2: Enhancement Features (Sprint 2 — 1 week)
77
+
78
+ Medium-value features that round out the Viewer experience. Estimated: **20 hours**.
79
+
80
+ | Feature | Module | Priority | Effort |
81
+ |---------|--------|----------|--------|
82
+ | **Section Measurements** | `viewer-measurements.js` (reuse from cycleCAD) | P2 | 3h |
83
+ | **Transparency Control** | `viewer-transparency.js` | P2 | 2h |
84
+ | **Screenshot Export** | `viewer-screenshot.js` | P2 | 3h |
85
+ | **Grid + Floor** | `viewer-grid.js` (enhance existing viewport) | P2 | 2h |
86
+ | **Keyboard Shortcuts** | `viewer-shortcuts.js` | P3 | 2h |
87
+ | **Part Comparison** | `viewer-comparison.js` | P3 | 4h |
88
+ | **Weight Estimator** | `viewer-weight.js` | P3 | 2h |
89
+
90
+ **Subtotal Phase 2:** ~7 new modules, ~2,000 LoC, 20 hours, **1 week sprint**
91
+
92
+ ---
93
+
94
+ ## Phase 3: Advanced Features (Sprint 3+ — ongoing)
95
+
96
+ Lower-priority features that enhance but aren't critical to launch. Estimated: **30+ hours**.
97
+
98
+ | Feature | Priority | Effort |
99
+ |---------|----------|--------|
100
+ | **3D Print Slicer** | P3 | 6h |
101
+ | **Technical Drawings** | P3 | 8h |
102
+ | **Maintenance Schedule** | P3 | 4h |
103
+ | **Voice Commands** | P4 | 6h |
104
+ | **Collab View** | P4 | 8h |
105
+ | **Blueprint Theme** | P4 | 3h |
106
+ | **Smart Filters** | P4 | 4h |
107
+
108
+ ---
109
+
110
+ ## Feature Prioritization Rationale
111
+
112
+ ### P0 (Must Have for Launch)
113
+ - **Assembly Tree:** Users need to understand model structure
114
+ - **Explode/Collapse:** Core cycleWASH differentiator (bike washing machine exploded views)
115
+
116
+ ### P1 (Should Have)
117
+ - **Section Cut:** Inspection use case (showing internal structure)
118
+ - **BOM:** Export data for procurement, manufacturing
119
+ - **AI Identifier:** Competitive advantage (parts ↔ supplier matching)
120
+
121
+ ### P2 (Nice to Have)
122
+ - **Annotations:** User comments, collaborative feedback
123
+ - **Context Menu:** Right-click convenience (select, hide, isolate)
124
+ - **Part Info Card:** Detailed view of individual parts
125
+ - **Measurements:** Service technician workflow
126
+
127
+ ### P3+ (Future)
128
+ - Voice, collab, advanced rendering, DFM analysis
129
+
130
+ ---
131
+
132
+ ## Module Architecture: Splitting the Monolith
133
+
134
+ ### Naming Convention
135
+ All viewer modules live in `/app/js/viewer-*.js`. Each module:
136
+ - Imports `{ getScene, getCamera, getControls }` from `viewport.js`
137
+ - Exports feature-specific init function (e.g., `initViewerAssemblyTree()`)
138
+ - Is self-contained with minimal global state
139
+ - Uses existing cycleCAD patterns (event delegation, CSS modules)
140
+
141
+ ### Key Patterns to Adopt
142
+
143
+ **1. IIFE to ES Module**
144
+ ```javascript
145
+ // ExplodeView (IIFE)
146
+ (function initClickExplode() {
147
+ // ... 300 lines of self-contained code
148
+ })();
149
+
150
+ // cycleCAD (ES Module)
151
+ export function initViewerExplode(scene, camera, controls) {
152
+ // ... same logic, but imported scene/camera/controls
153
+ }
154
+ ```
155
+
156
+ **2. Shared Global State**
157
+ ExplodeView uses globals:
158
+ - `window.allParts` — array of part meshes
159
+ - `window.ASSEMBLIES` — array of assembly definitions
160
+ - `window.manifest` — metadata (names, sizes, file refs)
161
+ - `window._partHighlightActive` — flag for animation loop
162
+
163
+ cycleCAD pattern:
164
+ ```javascript
165
+ // In viewer-mode.js
166
+ const viewerState = {
167
+ allParts: [],
168
+ assemblies: [],
169
+ manifest: [],
170
+ selectedPart: null,
171
+ explodeAmount: 0,
172
+ isViewerMode: false
173
+ };
174
+
175
+ // Access via accessor functions
176
+ export function getViewerState() { return viewerState; }
177
+ export function getPartByIndex(idx) { return viewerState.allParts[idx]; }
178
+ ```
179
+
180
+ **3. Panel System**
181
+ ExplodeView uses fixed-position overlays with `data-close-panel` buttons.
182
+ cycleCAD uses tabbed right panel. Strategy:
183
+ - Move "Assembly Tree" → right panel, "Model Tree" tab
184
+ - Move "Section Cut" → right panel, "Tools" tab
185
+ - Move "Annotations" → floating overlay (or right panel)
186
+ - Move "Part Info" → floating card (keep ExplodeView behavior)
187
+ - Move "BOM" → right panel, "Data" tab
188
+
189
+ ---
190
+
191
+ ## File Organization
192
+
193
+ ```
194
+ /app/js/
195
+ ├─ viewport.js [EXISTING] — shared Three.js scene
196
+ ├─ viewer-mode.js [NEW] Core — mode switching, state mgmt
197
+ ├─ viewer-loader.js [NEW] — STL/OBJ/STEP loading
198
+ ├─ viewer-assembly-tree.js [NEW] — tree navigation, part selection
199
+ ├─ viewer-explode.js [NEW] — explode slider, animation
200
+ ├─ viewer-section-cut.js [NEW] — clipping planes, visualization
201
+ ├─ viewer-bom.js [NEW] — BOM panel, CSV export
202
+ ├─ viewer-part-info.js [NEW] — info card, 3D export
203
+ ├─ viewer-annotations.js [NEW] — pins, comments
204
+ ├─ viewer-ai-identify.js [NEW] — Gemini Vision, McMaster-Carr
205
+ ├─ viewer-context-menu.js [NEW] — right-click actions
206
+ ├─ viewer-measurements.js [NEW] — distance/angle (reuse from ops)
207
+ ├─ viewer-transparency.js [NEW] — opacity slider
208
+ ├─ viewer-screenshot.js [NEW] — PNG/JPG export
209
+ ├─ viewer-grid.js [NEW] — grid + floor plane
210
+ ├─ viewer-shortcuts.js [NEW] — keyboard bindings
211
+ ├─ [... more viewer-*.js ...]
212
+
213
+ ├─ app.js [MODIFY] — add viewer mode toggle
214
+ ├─ index.html [MODIFY] — add viewer panels, import viewer modules
215
+ ├─ [... existing modules ...]
216
+ └─ js/viewer-*.js [all viewer features]
217
+ ```
218
+
219
+ ---
220
+
221
+ ## Data Flow: Model Loading
222
+
223
+ ### Edit Mode (current cycleCAD)
224
+ ```
225
+ User sketch → Extrude → Add constraint → Tree updates → 3D renders
226
+ ```
227
+
228
+ ### Viewer Mode (new)
229
+ ```
230
+ User loads STL/OBJ/STEP/Inventor
231
+
232
+ viewer-loader.js parses file
233
+
234
+ Creates THREE.Mesh for each part
235
+
236
+ Populates viewerState.allParts[]
237
+
238
+ viewerState.manifest[] = part metadata (name, size, center)
239
+
240
+ Assembly Tree renders from viewerState.assemblies[]
241
+
242
+ User clicks part → Part Info Card, Highlight, Selection
243
+
244
+ User right-click → Context menu (hide, explode, export, etc.)
245
+ ```
246
+
247
+ ### Mode Switching
248
+ ```
249
+ Edit Mode (parametric CAD) ← Toggle Button → Viewer Mode (static assembly)
250
+
251
+ When switching TO Viewer Mode:
252
+ - Hide left tree (features), hide sketch canvas
253
+ - Show Assembly Tree in right panel
254
+ - Show Explode slider in right panel
255
+ - Load viewer context menus + shortcuts
256
+
257
+ When switching TO Edit Mode:
258
+ - Hide Assembly Tree, hide explode controls
259
+ - Show feature tree, show sketch canvas
260
+ - Load CAD context menus + shortcuts
261
+ ```
262
+
263
+ ---
264
+
265
+ ## Implementation Checklist: Phase 1
266
+
267
+ ### Week 1
268
+ - [ ] Create `viewer-mode.js` base module (mode switching, state management)
269
+ - [ ] Create `viewer-loader.js` (STL/OBJ loading, manifest parsing)
270
+ - [ ] Create `viewer-assembly-tree.js` (port from initAssemblyTree)
271
+ - [ ] Add mode toggle button to toolbar
272
+ - [ ] Wire into `index.html` inline script
273
+ - [ ] Test: load STL, see assembly tree, switch modes
274
+
275
+ ### Week 2
276
+ - [ ] Create `viewer-explode.js` (port from initClickExplode)
277
+ - [ ] Create `viewer-section-cut.js` (port from initSectionCut)
278
+ - [ ] Create `viewer-bom.js` (port from initBOMExport + initBOM)
279
+ - [ ] Create `viewer-part-info.js` (port from showPartInfoCard IIFE)
280
+ - [ ] Test: explode assembly, section cut, BOM export, part info
281
+ - [ ] Performance check: 400 parts, smooth interaction
282
+
283
+ ---
284
+
285
+ ## Breaking Changes: NONE
286
+
287
+ ### ExplodeView npm package
288
+ - Remains at `v1.0.5+` with monolith `app.js`
289
+ - No imports from cycleCAD
290
+ - Fully standalone, works in separate `<script>` context
291
+ - Users can continue embedding ExplodeView on their own sites
292
+
293
+ ### cycleCAD npm package
294
+ - New exports: `initViewerMode()`, `loadViewerFile()`, `toggleViewerMode()`
295
+ - New peer dependency: none (Three.js already required)
296
+ - Backwards compatible: existing Edit Mode features unchanged
297
+ - New optional feature set: Viewer Mode
298
+
299
+ ---
300
+
301
+ ## Shared Three.js Scene Design
302
+
303
+ Both Edit Mode and Viewer Mode use the **same** Three.js scene/camera/renderer.
304
+
305
+ **Why?**
306
+ - Single animation loop, one GPU context
307
+ - Camera position preserved when switching modes
308
+ - Lighting, fog, shadows consistent
309
+ - Memory efficient
310
+
311
+ **How?**
312
+ ```javascript
313
+ // viewport.js (existing)
314
+ export function getScene() { return scene; }
315
+ export function getRenderer() { return renderer; }
316
+
317
+ // viewer-mode.js (new)
318
+ import { getScene, getRenderer, getCamera, getControls } from './viewport.js';
319
+
320
+ const scene = getScene(); // Shared reference
321
+ const renderer = getRenderer();
322
+
323
+ // Add viewer objects to shared scene
324
+ viewer.Mesh.forEach(m => scene.add(m));
325
+
326
+ // When mode changes, show/hide groups
327
+ const editModeGroup = new THREE.Group();
328
+ const viewerModeGroup = new THREE.Group();
329
+ scene.add(editModeGroup);
330
+ scene.add(viewerModeGroup);
331
+
332
+ // Toggle visibility
333
+ function switchMode(mode) {
334
+ editModeGroup.visible = (mode === 'edit');
335
+ viewerModeGroup.visible = (mode === 'viewer');
336
+ }
337
+ ```
338
+
339
+ ---
340
+
341
+ ## Toolbar Integration: Tabbed Design
342
+
343
+ cycleCAD already has tabbed toolbar. ExplodeView features map as follows:
344
+
345
+ ```
346
+ ┌─ View ─────────────────────────────────────────┐
347
+ │ Grid | Wireframe | Fit All | Reset | ViewCube │
348
+ │ [NEW] Explode | Section | Transparency │
349
+ └─────────────────────────────────────────────────┘
350
+
351
+ ┌─ Analyze ──────────────────────────────────────┐
352
+ │ [NEW] Assembly Tree | BOM | Part Info │
353
+ │ [NEW] Measurements | Weight | Comparison │
354
+ └─────────────────────────────────────────────────┘
355
+
356
+ ┌─ Create ───────────────────────────────────────┐
357
+ │ [EXISTING] Sketch | Extrude | Revolve | etc │
358
+ │ [NEW] Annotations | Markup │
359
+ └─────────────────────────────────────────────────┘
360
+
361
+ ┌─ Export ───────────────────────────────────────┐
362
+ │ [EXISTING] STL | OBJ | glTF | DXF │
363
+ │ [NEW] BOM CSV | Screenshot | 3D Export │
364
+ └─────────────────────────────────────────────────┘
365
+
366
+ ┌─ AI Tools ─────────────────────────────────────┐
367
+ │ [EXISTING] Chatbot | Reverse Engineer │
368
+ │ [NEW] Part Identifier | Batch Scan │
369
+ └─────────────────────────────────────────────────┘
370
+
371
+ ┌─ Settings ─────────────────────────────────────┐
372
+ │ [EXISTING] Theme | API Keys | Language │
373
+ │ [NEW] Viewer Presets | Shortcuts │
374
+ └─────────────────────────────────────────────────┘
375
+ ```
376
+
377
+ **Implementation:**
378
+ ```html
379
+ <!-- In index.html tabs section -->
380
+ <div class="tb-group" data-tab="View">
381
+ <!-- existing: Grid, Wireframe -->
382
+ <!-- new: Explode slider, Section Cut toggle -->
383
+ </div>
384
+
385
+ <div class="tb-group" data-tab="Analyze">
386
+ <!-- new: Assembly Tree button opens panel -->
387
+ <!-- new: BOM button opens panel -->
388
+ </div>
389
+ ```
390
+
391
+ ---
392
+
393
+ ## Estimated Effort Summary
394
+
395
+ | Phase | Modules | LoC | Hours | Weeks |
396
+ |-------|---------|-----|-------|-------|
397
+ | **Phase 1** (critical) | 8 | 4,050 | 40 | 2 |
398
+ | **Phase 2** (enhancement) | 7 | 2,000 | 20 | 1 |
399
+ | **Phase 3** (advanced) | 6+ | 3,000+ | 30+ | 2+ |
400
+ | **TOTAL** | 21+ | 9,050+ | 90+ | 5+ |
401
+
402
+ **To launch (P0 + P1):** 15 modules, ~6,050 LoC, **60 hours, 3 weeks**
403
+
404
+ ---
405
+
406
+ ## Risk Mitigation
407
+
408
+ | Risk | Impact | Mitigation |
409
+ |------|--------|-----------|
410
+ | **Breaking ExplodeView** | HIGH | Keep ExplodeView repo 100% unchanged. Merge only adds to cycleCAD. |
411
+ | **Scene conflicts** | MEDIUM | Strict namespacing: `viewerGroup`, `editModeGroup` with clear visibility rules. |
412
+ | **Performance (400 parts)** | MEDIUM | Phase 1 testing with real DUO Inventor data (342 parts). Use LOD if needed. |
413
+ | **UI clutter** | MEDIUM | Tab-based toolbar prevents UI overload. Modular CSS per feature. |
414
+ | **Porting bugs** | MEDIUM | Each module tested independently before integration. Port ExplodeView tests as reference. |
415
+
416
+ ---
417
+
418
+ ## Success Metrics (MVP Definition)
419
+
420
+ **Phase 1 Complete = MVP:**
421
+ 1. ✅ Can toggle between Edit Mode and Viewer Mode
422
+ 2. ✅ Can load STL file into Viewer Mode
423
+ 3. ✅ Assembly Tree shows all parts with hierarchy
424
+ 4. ✅ Explode/collapse works smoothly (400 parts)
425
+ 5. ✅ Section cut works (3 axis, flip)
426
+ 6. ✅ Right-click context menu works (select, hide, export)
427
+ 7. ✅ BOM can be exported to CSV
428
+ 8. ✅ Part info card shows dimensions, materials, weight
429
+ 9. ✅ No performance degradation in Edit Mode
430
+ 10. ✅ ExplodeView npm package still works standalone
431
+
432
+ ---
433
+
434
+ ## Post-Merge: npm Publishing Strategy
435
+
436
+ ### cycleCAD v1.1.0 (first Viewer Mode release)
437
+ ```json
438
+ {
439
+ "name": "cyclecad",
440
+ "version": "1.1.0",
441
+ "description": "Parametric 3D CAD modeler + STL/STEP viewer",
442
+ "exports": {
443
+ "./modeler": "./app/js/app.js",
444
+ "./viewer": "./app/js/viewer-mode.js",
445
+ "./agent-api": "./app/js/agent-api.js"
446
+ }
447
+ }
448
+ ```
449
+
450
+ ### ExplodeView v1.0.5+ (unchanged)
451
+ - No breaking changes
452
+ - Continues as standalone embed widget
453
+ - Link from cycleCAD docs: "Advanced Viewer Features → ExplodeView Widget"
454
+
455
+ ### Marketing Angle
456
+ - "cycleCAD: The CAD tool you build in AND the viewer you share with"
457
+ - One platform for design + inspection + collaboration
458
+ - Open-core + plugin architecture ready
459
+
460
+ ---
461
+
462
+ ## Next Steps
463
+
464
+ 1. **Review Plan** — Sachin's feedback on priorities, timeline, architecture
465
+ 2. **Proof of Concept** — Build `viewer-mode.js` base module (this task)
466
+ 3. **Phase 1 Sprint** — Week 1-2, port top 8 features
467
+ 4. **Integration Test** — Real DUO Inventor data (342 parts)
468
+ 5. **Publishing** — npm cyclecad@1.1.0, GitHub tag, blog post
469
+ 6. **LinkedIn Launch** — Unified platform announcement
470
+
471
+ ---
472
+
473
+ **Document Version:** 1.0
474
+ **Last Updated:** 2026-03-25
475
+ **Author:** Claude (Agent)
476
+ **Status:** READY FOR REVIEW