Skip to content

Three.js components migration plan#153

Draft
rifont wants to merge 15 commits into
mainfrom
cursor/new-cloud-agent-b73a
Draft

Three.js components migration plan#153
rifont wants to merge 15 commits into
mainfrom
cursor/new-cloud-agent-b73a

Conversation

@rifont
Copy link
Copy Markdown
Contributor

@rifont rifont commented Feb 25, 2026

Migrate Three.js components to a new @taucad/three package to decouple them from the UI app and enable reuse.

This migration involved creating a new Nx library, moving all Three.js related components, hooks, and utilities, and refactoring connected components to use Zustand stores instead of xstate for state management. This significantly improves modularity and prepares the components for broader use. The UI app has been updated to consume these components from the new package.


Open in Web Open in Cursor 

rifont and others added 13 commits February 25, 2026 23:05
Copy utility files from apps/ui/app/components/geometry/graphics/three/utils/
to packages/three/src/utils/:

- camera.utils.ts, camera.utils.test.ts
- gizmo.utils.ts
- lights.utils.ts, lights.utils.test.ts
- math.utils.ts, math.utils.test.ts
- rotation.utils.ts
- snap-detection.utils.ts
- spatial.utils.ts

Add color.utils.ts with adjustHexColorBrightness (from apps/ui color.utils.ts).

Update all internal imports: #components/geometry/graphics/three/ -> #

Co-authored-by: richard <richard@fontein.co>
- gltf-mesh, axes-helper, infinite-grid, lights
- section-view, section-view-controls, transform-controls-drei
- scene-overlay

Updated imports: #components/geometry/graphics/three/ -> #
section-view-controls: #utils/color.utils.js (package local)
Updated react/index.ts with exports

Co-authored-by: richard <richard@fontein.co>
- Copy use-camera-framing.test.ts from apps/ui to packages/three
- Update imports: #components/geometry/graphics/three/ -> #react/
- Add stage.ts with StageOptions and defaultStageOptions
- Add use-camera-framing.ts and use-camera-reset.ts hooks
- Add use-graphics.ts stub for standalone package usage
- Add @vitest-environment jsdom for React hook tests

Co-authored-by: richard <richard@fontein.co>
Extract pure screenshot capture functions from the xstate machine file
into standalone pure functions in the @taucad/three package:

- captureScreenshot: Core Three.js screenshot capture with temporary
  renderer, matcap override, FOV compensation, and bounding box framing
- createCompositeImage: Creates a composite grid image from multiple
  screenshots with labels, dividers, and configurable layout
- calculateOptimalGrid: Grid layout calculator for composite images

Local type definitions (CameraAngle, ScreenshotOptions, etc.) are
defined in the package to avoid depending on @taucad/types.

No xstate or SVG-specific code was included.

Co-authored-by: richard <richard@fontein.co>
Create standalone zustand stores to replace the xstate graphics machine
for the @taucad/three package:

- viewer-store: viewer configuration (grid, axes, matcap, FOV, theme, etc.)
- measure-store: measurement state with start/complete/pin workflow
- section-view-store: section plane selection, rotation, and direction
- store-context: React context provider with typed selector hooks
- index barrel export with all stores and types

All stores use zustand/vanilla for framework-agnostic creation and
zustand's useStore hook for React integration.

Co-authored-by: richard <richard@fontein.co>
…e components

Replace app-specific useGraphicsSelector, useTheme, and useColor hooks
with zustand-based useViewerStore from the package's own store context.

- post-processing.tsx: reads enablePostProcessing from viewer store
- grid.tsx: reads gridSizes, upDirection, theme from viewer store
- viewport-gizmo.tsx: reads fieldOfView, accentColor, theme from viewer store
- All Three.js imports updated to use package-local # paths
- Export all three components from react/index.ts

Co-authored-by: richard <richard@fontein.co>
- Replace useGraphicsSelector with useViewerStore in use-camera-framing.ts
- Remove useCameraCapability from use-camera-reset.ts, accept onResetCamera callback
- Create use-geometry-bounds.ts using zustand viewer store
- Create up-direction-handler.tsx with onResetCamera callback prop
- Create use-section-view.ts using useSectionViewStore and useViewerStore
- Convert stage.ts to stage.tsx with full Stage component using zustand stores
- Delete stub hooks/use-graphics.ts
- Export new components and hooks from react/index.ts

Co-authored-by: richard <richard@fontein.co>
- Fix prettier formatting in use-camera-reset.ts function signature
- Rename enableCentering to isCenteringEnabled in stage.tsx to match boolean prop naming rule
- Add useViewerStore mock to camera framing test

Co-authored-by: richard <richard@fontein.co>
- MeasureTool uses useMeasureStore for reactive reads and
  measureStore.getState() for imperative actions (start, complete,
  cancel measurement, toggle pinned, set hovered)
- Controls uses useSectionViewStore for section view state/actions
  and useViewerStore for upDirection
- geometryKey accepted as optional prop on MeasureTool (default '')
- All imports updated from app-specific paths to package paths
- Exports added to react/index.ts

Co-authored-by: richard <richard@fontein.co>
…components

- scene.tsx: composition of Stage, Controls, UpDirectionHandler
- cad-canvas.tsx: R3F Canvas wrapper with sensible GL defaults
- cad-viewer.tsx: zero-config component mapping GLTF to GltfMesh
- presets.ts: default, minimal, and full viewer preset factories
- Export all new components from react index

Co-authored-by: richard <richard@fontein.co>
…e/react

- cad-viewer.tsx: import GltfMesh/CadCanvas from @taucad/three/react
- cad-preview.tsx: import StageOptions from @taucad/three/react
- screenshot-capability.machine.ts: import materials/utils from @taucad/three
- screenshot-capability.utils.test.ts: same import updates
- actor-bridge.tsx: import updateCameraFov from @taucad/three, add zustand sync
- three-context.tsx: wrap CadCanvas from @taucad/three/react with WebGL tracking

Co-authored-by: richard <richard@fontein.co>
… publishable build

Co-authored-by: richard <richard@fontein.co>
@cursor
Copy link
Copy Markdown

cursor Bot commented Feb 25, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 25, 2026

UI Preview 🎈

Status: ❌ Deployment Failed
URL: https://tau-ui-pr-153.fly.dev/

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 25, 2026

API Preview 🐙

Status: ✅ Deployed
URL: https://tau-api-pr-153.fly.dev

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 25, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cursor/new-cloud-agent-b73a

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Feb 25, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit e782423

Command Status Duration Result
nx affected -t lint test build typecheck ❌ Failed 8m 27s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-02 03:40:57 UTC

Resolve conflict in replicad kernel test: take payments-v1 version
using expect.arrayContaining pattern for library frame assertions.

Co-authored-by: richard <richard@fontein.co>
@cursor cursor Bot temporarily deployed to review-ui March 2, 2026 02:34 Inactive
@cursor cursor Bot temporarily deployed to review-api March 2, 2026 02:34 Inactive
…e to cad/

- Move actor-bridge.tsx and webgl-context-lost-fallback.tsx to cad/
- Refactor CadViewer to integrate ActorBridge and WebGL context tracking
  directly, removing the now-unused ThreeProvider wrapper
- Delete entire apps/ui/app/components/geometry/graphics/three/ directory
  (11,739 lines) - all components now live in @taucad/three package

Co-authored-by: richard <richard@fontein.co>
@cursor cursor Bot temporarily deployed to review-ui March 2, 2026 03:31 Inactive
@cursor cursor Bot temporarily deployed to review-api March 2, 2026 03:31 Inactive
Base automatically changed from payments-v1 to main April 19, 2026 10:07
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