Fix active floorplan rotation feedback

This commit is contained in:
Aymeric Rabot
2026-06-08 01:14:12 -04:00
parent f7789a5c7a
commit 4445c60532
@@ -5626,8 +5626,46 @@ export function FloorplanPanel() {
}) })
}) })
const applyFloorplanNavigationView = useCallback(
(localCenter: SvgPoint, userRotationDeg: number, viewWidth?: number) => {
const currentViewport = latestViewportRef.current ?? latestFittedViewportRef.current
if (!currentViewport) {
return
}
const nextSceneRotationDeg =
FLOORPLAN_VIEW_ROTATION_DEG + userRotationDeg - buildingRotationDeg
const centerSvg = rotateSvgPoint(localCenter, nextSceneRotationDeg)
const fitted = latestFittedViewportRef.current
const minWidth = fitted ? fitted.width * MIN_VIEWPORT_WIDTH_RATIO : 0.001
const maxWidth = fitted ? fitted.width * MAX_VIEWPORT_WIDTH_RATIO : Number.POSITIVE_INFINITY
const nextWidth = clamp(viewWidth ?? currentViewport.width, minWidth, maxWidth)
const nextViewport = {
centerX: centerSvg.x,
centerY: centerSvg.y,
width: nextWidth,
}
hasUserAdjustedViewportRef.current = true
latestFloorplanUserRotationDegRef.current = userRotationDeg
latestViewportRef.current = nextViewport
setFloorplanUserRotationDeg((current) =>
current === userRotationDeg ? current : userRotationDeg,
)
setViewport((current) =>
floorplanViewportEquals(current, nextViewport) ? current : nextViewport,
)
},
[buildingRotationDeg],
)
const syncFloorplanViewportToNavigationPose = useCallback( const syncFloorplanViewportToNavigationPose = useCallback(
(pose: NavigationSyncPose) => { (pose: NavigationSyncPose) => {
if (floorplanRotationStateRef.current) {
return
}
const nextUserRotationDeg = floorplanRotationFromCameraAzimuth( const nextUserRotationDeg = floorplanRotationFromCameraAzimuth(
pose.azimuth, pose.azimuth,
latestFloorplanUserRotationDegRef.current, latestFloorplanUserRotationDegRef.current,
@@ -5638,37 +5676,10 @@ export function FloorplanPanel() {
buildingPosition, buildingPosition,
buildingRotationY, buildingRotationY,
) )
const nextSceneRotationDeg =
FLOORPLAN_VIEW_ROTATION_DEG + nextUserRotationDeg - buildingRotationDeg
const centerSvg = rotateSvgPoint(localCenter, nextSceneRotationDeg)
const currentViewport = latestViewportRef.current ?? latestFittedViewportRef.current
const fitted = latestFittedViewportRef.current
if (!currentViewport) { applyFloorplanNavigationView(localCenter, nextUserRotationDeg, pose.viewWidth)
return
}
const minWidth = fitted ? fitted.width * MIN_VIEWPORT_WIDTH_RATIO : 0.001
const maxWidth = fitted ? fitted.width * MAX_VIEWPORT_WIDTH_RATIO : Number.POSITIVE_INFINITY
const nextWidth = clamp(pose.viewWidth, minWidth, maxWidth)
const nextViewport = {
centerX: centerSvg.x,
centerY: centerSvg.y,
width: nextWidth,
}
hasUserAdjustedViewportRef.current = true
latestFloorplanUserRotationDegRef.current = nextUserRotationDeg
latestViewportRef.current = nextViewport
setFloorplanUserRotationDeg((current) =>
current === nextUserRotationDeg ? current : nextUserRotationDeg,
)
setViewport((current) =>
floorplanViewportEquals(current, nextViewport) ? current : nextViewport,
)
}, },
[buildingPosition, buildingRotationDeg, buildingRotationY], [applyFloorplanNavigationView, buildingPosition, buildingRotationY],
) )
useEffect(() => { useEffect(() => {
@@ -7825,6 +7836,7 @@ export function FloorplanPanel() {
(event.clientX - rotationState.startClientX) * FLOORPLAN_ROTATION_DEGREES_PER_PIXEL (event.clientX - rotationState.startClientX) * FLOORPLAN_ROTATION_DEGREES_PER_PIXEL
const nextUserRotationDeg = rotationState.initialUserRotationDeg + angleDeltaDeg const nextUserRotationDeg = rotationState.initialUserRotationDeg + angleDeltaDeg
applyFloorplanNavigationView(rotationState.viewportCenterLocal, nextUserRotationDeg)
publishFloorplanNavigationPose(rotationState.viewportCenterLocal, nextUserRotationDeg) publishFloorplanNavigationPose(rotationState.viewportCenterLocal, nextUserRotationDeg)
setCursorPoint(null) setCursorPoint(null)
return return
@@ -8146,6 +8158,7 @@ export function FloorplanPanel() {
isPolygonBuildActive, isPolygonBuildActive,
isRoofBuildActive, isRoofBuildActive,
isWallBuildActive, isWallBuildActive,
applyFloorplanNavigationView,
publishFloorplanNavigationPose, publishFloorplanNavigationPose,
referenceScaleDraft, referenceScaleDraft,
roofDraftStart, roofDraftStart,