Skip to content

feat: implement camera positioning for 3D snapshots and add related tests#2050

Open
rushabhcodes wants to merge 3 commits intotscircuit:mainfrom
rushabhcodes:fix-snapshot
Open

feat: implement camera positioning for 3D snapshots and add related tests#2050
rushabhcodes wants to merge 3 commits intotscircuit:mainfrom
rushabhcodes:fix-snapshot

Conversation

@rushabhcodes
Copy link

This pull request improves the way 3D PCB snapshots are rendered by introducing a deterministic, board-size-aware camera positioning function. This ensures consistent and optimal camera angles for different board sizes across all environments. Additionally, a new test verifies correct snapshot creation for larger boards.

Camera positioning improvements:

  • Added a new utility function getBestCameraPosition in lib/shared/get-best-camera-position.ts to calculate optimal, deterministic camera positions based on the board or panel size and center, ensuring consistent 3D rendering results.
  • Updated snapshotProject in lib/shared/snapshot-project.ts to use getBestCameraPosition instead of hardcoded camera values, resulting in improved and consistent 3D snapshot images for all board sizes. [1] [2]

Testing enhancements:

  • Added a new test in tests/cli/snapshot/snapshot.test.ts to verify that the snapshot command correctly creates a 3D snapshot for a larger board, improving test coverage for the new camera logic.

Before

before

After

after

Copilot AI review requested due to automatic review settings February 18, 2026 09:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request introduces a deterministic camera positioning system for 3D PCB snapshot rendering. The implementation adds a new utility function that calculates optimal camera positions based on board or panel dimensions, replacing hardcoded values to ensure consistent rendering across different environments.

Changes:

  • Added getBestCameraPosition utility function for deterministic camera positioning based on board/panel size and center
  • Updated 3D snapshot rendering to use the new camera positioning function instead of hardcoded values
  • Added integration test for larger board 3D snapshot generation

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/shared/get-best-camera-position.ts New utility function calculating optimal camera positions with deterministic integer values for consistency
lib/shared/snapshot-project.ts Updated to use getBestCameraPosition instead of hardcoded camera values [10, 10, 10]
tests/cli/snapshot/snapshot.test.ts Added integration test verifying 3D snapshot creation for larger boards (40.64mm x 24.13mm)
tests/cli/snapshot/snapshots/large-pcb-3d.snap.png Binary snapshot file for visual regression testing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@imrishabh18 imrishabh18 left a comment

Choose a reason for hiding this comment

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

Wait for @seveibar's review


// Use completely deterministic integer values to ensure identical rendering
// across all environments (local, CI, different Node versions, etc.)
const baseDistance = Math.round(maxDimension * 0.8)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe these numbers like 0.8 should be assigned a variable

Copy link
Contributor

@seveibar seveibar left a comment

Choose a reason for hiding this comment

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

i think more examples are needed- to me it seems like it may be zoomed out too far, and the correct calculation would perfectly place the board inside the image. This can be done with some complex math

It is an improvement, but we might as well go for the most reliable long-term solution imo- especially because this is a breaking change (snapshots will be updated downstream)

@seveibar
Copy link
Contributor

also this method should be exported from circuit-json-to-gltf, it should not be in the CLI!!!!

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.

3 participants

Comments