-
Notifications
You must be signed in to change notification settings - Fork 0
Background Image Calibration
When you start from a photo, a floor plan, or a hand-drawn sketch, you can import it as a background image and trace your geometry on top of it. The two-point calibration tool sets the real-world scale of the image so the lines you draw over it carry correct millimetre dimensions.
Feature line from the README: πΌοΈ Background image import with two-point calibration.
- Open a project.
- Use File β Import (or drag a PNG / JPG onto the canvas β the handler converts it to a project-local blob).
- The image is added as a
BackgroundImageRefwith:- A unique id, either a
dataUrlor ablobKey(for large images stored in IndexedDB). - A world-space
position(mm) androtationDeg. - A
scaleMmPerPx(initialised to1mm/px β that is not accurate yet; calibration fixes that). -
opacity01,lockedandvisibletoggles.
- A unique id, either a
The image is rendered behind everything else on the canvas. While
locked is on, you cannot accidentally drag or resize it from the Select
tool.
The image is just a raster β the planner has no idea how many millimetres one pixel represents until you tell it. The Calibrate background image tool turns any known segment (door width, ruler in the photo, a printed scale barβ¦) into the source of truth.
How to calibrate:
- With a background image present, activate Calibrate background image from the toolbox.
- Click the first endpoint of a real-world segment on the image.
- Click the second endpoint.
- A prompt asks for the real distance (accepts
2400,2.4 m,8 ftβ the standardparseLengthparser is used). - The image is re-scaled and re-positioned so that the midpoint of the two clicked points stays anchored. After calibration, every existing shape on the canvas keeps its real-world position; only the image moves and resizes around the anchor.
The math (calibrateImage):
pixelDistance = hypot(B.x β A.x, B.y β A.y)
newScale = realDistanceMm / pixelDistance
// Keep midpoint of A/B stationary after rescaling:
midPx = (A + B) / 2
worldMid = image.position + midPx * image.scaleMmPerPx
image.position = worldMid β midPx * newScaleThe previous scaleMmPerPx is replaced and the calibration data is
stored (pointAPx, pointBPx, distanceMm) so you can revisit or
re-run the operation at any time.
After calibration:
- The Line, Rectangle, Polygon and Surface tools can trace directly over the image with accurate dimensions.
- Toggle opacity to fade the image while you focus on the drawing.
- Toggle lock to prevent accidental moves; uncalibrated or uncalibrated-yet images can be repositioned with the Select tool.
- Toggle visibility to hide the image entirely for clean presentations.
- Schema β
src/types/backgroundImage.ts - Calibration math β
src/domain/backgroundImage/calibrateImage.ts - Canvas layer β
src/features/editor/canvas/LayersRoot.tsx - Tool entry β
calibrateImageentry insrc/features/info/infoEntries.ts
Documentation for the material-layout-planner project. Every feature in the application is documented here β see the contribution rules before opening a pull request.