diff --git a/typescript/packages/subsurface-viewer/src/components/Map.tsx b/typescript/packages/subsurface-viewer/src/components/Map.tsx index 21aee93c5..9ebd3fccb 100644 --- a/typescript/packages/subsurface-viewer/src/components/Map.tsx +++ b/typescript/packages/subsurface-viewer/src/components/Map.tsx @@ -52,9 +52,9 @@ import { getWellLayerByTypeAndSelectedWells, } from "../layers/utils/layerTools"; import type { WellsPickInfo } from "../layers/wells/wellsLayer"; -import type { BoundingBox2D } from "../utils/BoundingBox2D"; +import type { BoundingBox2D, Point2D } from "../utils/BoundingBox2D"; import { isEmpty as isEmptyBox2D } from "../utils/BoundingBox2D"; -import type { BoundingBox3D } from "../utils/BoundingBox3D"; +import type { BoundingBox3D, Point3D } from "../utils/BoundingBox3D"; import { boxCenter, boxUnion, @@ -78,7 +78,7 @@ import { useVerticalScale } from "../views/viewport"; import mergeRefs from "merge-refs"; -export type { BoundingBox2D, BoundingBox3D }; +export type { BoundingBox2D, BoundingBox3D, Point2D, Point3D }; /** * Type of the function returning coordinate boundary for the view defined as [left, bottom, right, top]. */ @@ -189,8 +189,8 @@ export interface ViewsType { * Camera view state. */ export interface ViewStateType { - target: number[]; - zoom: number | [number, number] | BoundingBox3D | undefined; + target: Point2D | Point3D | undefined; + zoom: number | Point2D | BoundingBox3D | undefined; rotationX: number; rotationOrbit: number; minZoom?: number; @@ -590,8 +590,8 @@ const Map: React.FC = ({ // Left button click identifies new camera rotation anchor. if (infos.length >= 1) { if (infos[0].coordinate) { - viewController.setTarget( - infos[0].coordinate as [number, number, number] + viewController.setScaledTarget( + infos[0].coordinate as Point3D ); } } @@ -981,14 +981,23 @@ type ViewControllerState = { }; type ViewControllerDerivedState = { // Derived state - target: [number, number, number] | undefined; + cameraClone: ViewStateType | undefined; // clone of the camera + eventTarget: Point3D | undefined; // target set by events readyForInteraction: boolean; viewStateChanged: boolean; }; type ViewControllerFullState = ViewControllerState & ViewControllerDerivedState; + class ViewController { private rerender_: React.DispatchWithoutAction; + private derivedState_: ViewControllerDerivedState = { + cameraClone: undefined, + eventTarget: undefined, + readyForInteraction: false, + viewStateChanged: false, + }; + private state_: ViewControllerFullState = { triggerHome: undefined, camera: undefined, @@ -1003,15 +1012,7 @@ class ViewController { bottom: 0, }, // Derived state - target: undefined, - readyForInteraction: false, - viewStateChanged: false, - }; - - private derivedState_: ViewControllerDerivedState = { - target: undefined, - readyForInteraction: false, - viewStateChanged: false, + ...this.derivedState_, }; private views_: ViewsType | undefined = undefined; @@ -1027,8 +1028,13 @@ class ViewController { this.rerender_ = rerender; } - public readonly setTarget = (target: [number, number, number]) => { - this.derivedState_.target = [target[0], target[1], target[2]]; + /** + * Sets the target from picks, which comes from the displayed + * scaled data. + * @param target scaled 3D point. + */ + public readonly setScaledTarget = (target: Point3D) => { + this.derivedState_.eventTarget = [target[0], target[1], target[2]]; this.rerender_(); }; @@ -1040,7 +1046,10 @@ class ViewController { const newViews = this.getDeckGlViews(views, fullState); const newViewState = this.getDeckGlViewState(views, fullState); - this.state_ = fullState; + // do not update this.state_ as it has not yet been applied + if (!isEmpty(newViewState)) { + this.state_ = fullState; + } this.views_ = views; this.result_.views = newViews; this.result_.viewState = newViewState; @@ -1051,7 +1060,12 @@ class ViewController { private readonly consolidateState = ( state: ViewControllerState ): ViewControllerFullState => { - return { ...state, ...this.derivedState_ }; + const fullState = { ...state, ...this.derivedState_ }; + if (fullState.camera != this.state_.camera) { + // create a clone of the camera property to avoid editing it + fullState.cameraClone = cloneDeep(fullState.camera); + } + return fullState; }; // returns the DeckGL views (ie. view position and viewport) @@ -1075,8 +1089,12 @@ class ViewController { const viewsChanged = views != this.views_; const triggerHome = state.triggerHome !== this.state_.triggerHome; const updateTarget = - (viewsChanged || state.target !== this.state_?.target) && - state.target != undefined; + (viewsChanged || state.eventTarget !== this.state_.eventTarget) && + state.eventTarget != undefined; + // reset old zScale if new camera + if (state.camera != this.state_.camera) { + this.state_.zScale = 1; + } const updateZScale = viewsChanged || state.zScale !== this.state_?.zScale || triggerHome; const updateViewState = @@ -1102,14 +1120,16 @@ class ViewController { viewState = buildDeckGlViewStates( views, state.viewPortMargins, - state.camera, + state.cameraClone, state.boundingBox3d, + state.zScale, + this.state_.zScale, state.bounds, state.deckSize ); // reset state this.derivedState_.readyForInteraction = canCameraBeDefined( - state.camera, + state.cameraClone, state.boundingBox3d, state.bounds, state.deckSize @@ -1125,7 +1145,7 @@ class ViewController { const viewStateKeys = Object.keys(viewState); if ( updateTarget && - this.derivedState_.target && + this.derivedState_.eventTarget && viewStateKeys?.length === 1 ) { // deep clone to notify change (memo checks object address) @@ -1133,10 +1153,10 @@ class ViewController { viewState = cloneDeep(prevViewState); } // update target - viewState[viewStateKeys[0]].target = this.derivedState_.target; + viewState[viewStateKeys[0]].target = this.derivedState_.eventTarget; viewState[viewStateKeys[0]].transitionDuration = 1000; // reset - this.derivedState_.target = undefined; + this.derivedState_.eventTarget = undefined; } if (updateZScale) { // deep clone to notify change (memo checks object address) @@ -1147,12 +1167,12 @@ class ViewController { // - if triggerHome: the target was recomputed from the input data (ie. without any scale applied) // - otherwise: previous scale (ie. this.state_.zScale) was already applied, and must be "reverted" const targetScale = - state.zScale / (triggerHome ? 1 : this.state_.zScale); + state.zScale / + (triggerHome ? state.zScale : this.state_.zScale); // update target for (const key in viewState) { - const t = viewState[key].target; - if (t) { - viewState[key].target = [t[0], t[1], t[2] * targetScale]; + if (viewState[key].target) { + applyZScale(viewState[key].target, targetScale); } } } @@ -1168,9 +1188,11 @@ class ViewController { return; } const viewports = this.views_?.viewports ?? []; - if (viewState.target.length === 2) { + if (viewState.target?.length === 2) { // In orthographic mode viewState.target contains only x and y. Add existing z value. - viewState.target.push(this.result_.viewState[viewId].target[2]); + viewState.target.push( + this.result_.viewState[viewId].target?.[2] ?? 1 + ); } const isSyncIds = viewports .filter((item) => item.isSync) @@ -1244,7 +1266,7 @@ function computeCameraZoom( zMin + (zMax - zMin) / 2, ]; - const points: [number, number, number][] = [ + const points: Point3D[] = [ [xMin, yMin, zMin], [xMin, yMax, zMin], [xMax, yMax, zMin], @@ -1285,7 +1307,7 @@ function computeCameraZoom( function getViewStateFromBounds( viewPortMargins: MarginsType, bounds_accessor: BoundingBox2D | BoundsAccessor, - target: [number, number, number], + target: Point3D, views: ViewsType | undefined, viewPort: ViewportType, size: Size @@ -1301,7 +1323,7 @@ function getViewStateFromBounds( const z = target[2]; const fb = fitBounds({ width: w, height: h, bounds }); - let fb_target = [fb.x, fb.y, z]; + let fb_target: Point3D = [fb.x, fb.y, z]; let fb_zoom = fb.zoom; if (size.width > 0 && size.height > 0) { @@ -1584,6 +1606,23 @@ function canCameraBeDefined( ); } +/** + * Applies the zScale to the camera target. + * This is needed, as the camera target is specified in world coordinates, while the Z scale + * is applied to the transformation matrix of the object coordinates. The target must be applied + * the same scale to be consistent with the display. + * @param target camera target that must take into account the Z scale. + * @param zScale Z scale. + */ +function applyZScale( + target: Point2D | Point3D | undefined, + zScale: number +): void { + if (target?.[2]) { + target[2] = target[2] * zScale; + } +} + /** * Returns the camera if it is fully specified (ie. the zoom is a valid number), otherwise computes * the zoom to visualize the complete camera boundingBox if set, the provided boundingBox otherwise. @@ -1594,10 +1633,15 @@ function canCameraBeDefined( function updateViewState( camera: ViewStateType, boundingBox: BoundingBox3D, + zScale: number, size: Size, is3D = true ): ViewStateType { if (isCameraDefined(camera)) { + if (is3D) { + // apply zScaling to target (target is in real coordinates while zScaling is applied to matrix transform) + applyZScale(camera.target, zScale); + } return camera; } @@ -1622,6 +1666,10 @@ function updateViewState( } if (!cameraHasTarget(camera_)) { camera_.target = boxCenter(boundingBox); + if (is3D) { + // apply zScaling to target (target is in real coordinates while zScaling is applied to matrix transform) + applyZScale(camera.target, zScale); + } } camera_.minZoom = camera_.minZoom ?? minZoom3D; camera_.maxZoom = camera_.maxZoom ?? maxZoom3D; @@ -1636,6 +1684,8 @@ function computeViewState( viewPort: ViewportType, cameraPosition: ViewStateType | undefined, boundingBox: BoundingBox3D | undefined, + zScale: number, + oldZScale: number, bounds: BoundingBox2D | BoundsAccessor | undefined, viewportMargins: MarginsType, views: ViewsType | undefined, @@ -1655,13 +1705,17 @@ function computeViewState( if (viewPort.show3D ?? false) { // If the camera is defined, use it if (isCameraPositionDefined) { - return updateViewState(cameraPosition, boundingBox, size); + return updateViewState( + cameraPosition, + boundingBox, + zScale / (oldZScale || 1), + size + ); } // deprecated in 3D, kept for backward compatibility if (isBoundsDefined) { - const centerOfData: [number, number, number] = - boxCenter(boundingBox); + const centerOfData: Point3D = boxCenter(boundingBox); return getViewStateFromBounds( viewportMargins, bounds, @@ -1671,24 +1725,30 @@ function computeViewState( size ); } - const defaultCamera = { - target: [], // force computation from the bounding box 3D + const defaultCamera: ViewStateType = { + target: undefined, // force computation from the bounding box 3D zoom: NaN, // force computation from the bounding box 3D rotationX: 45, // look down z -axis at 45 degrees rotationOrbit: 0, }; - return updateViewState(defaultCamera, boundingBox, size); + return updateViewState(defaultCamera, boundingBox, zScale, size); } else { const is3D = false; // If the camera is defined, use it if (isCameraPositionDefined) { - return updateViewState(cameraPosition, boundingBox, size, is3D); + return updateViewState( + cameraPosition, + boundingBox, + zScale, + size, + is3D + ); } - const centerOfData: [number, number, number] = boxCenter(boundingBox); + const centerOfData: Point3D = boxCenter(boundingBox); - // In 2D set camera target (centerOfDatea) to 0; Zoom scales world around target. + // In 2D set camera target (centerOfData) to 0; Zoom scales world around target. centerOfData[2] = 0; // if bounds are defined, use them @@ -1720,6 +1780,8 @@ function buildDeckGlViewStates( viewPortMargins: MarginsType, cameraPosition: ViewStateType | undefined, boundingBox: BoundingBox3D | undefined, + zScale: number, + oldZScale: number, bounds: BoundingBox2D | BoundsAccessor | undefined, size: Size ): Record { @@ -1738,6 +1800,8 @@ function buildDeckGlViewStates( views.viewports[0], cameraPosition, boundingBox, + zScale, + oldZScale, bounds, viewPortMargins, views, @@ -1763,6 +1827,8 @@ function buildDeckGlViewStates( currentViewport, cameraPosition, boundingBox, + zScale, + oldZScale, bounds, viewPortMargins, views, diff --git a/typescript/packages/subsurface-viewer/src/storybook/examples/CameraControlExamples.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/examples/CameraControlExamples.stories.tsx index 19c1cd82b..56faf8b9d 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/examples/CameraControlExamples.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/examples/CameraControlExamples.stories.tsx @@ -11,7 +11,11 @@ import { styled } from "@mui/material/styles"; import type { SubsurfaceViewerProps } from "../../SubsurfaceViewer"; import SubsurfaceViewer from "../../SubsurfaceViewer"; -import type { BoundingBox3D, ViewStateType } from "../../components/Map"; +import type { + BoundingBox3D, + Point3D, + ViewStateType, +} from "../../components/Map"; import { Axes2DLayer, AxesLayer } from "../../layers"; import { GeoJsonLayer } from "@deck.gl/layers"; @@ -39,8 +43,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer/Examples/Camera", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; @@ -62,7 +65,7 @@ const Root = styled("div")({ }); const CAMERA_POSITION: ViewStateType = { - target: [435800, 6478000, -2000], + target: [435800, 6478000, -2000] as Point3D, zoom: -3.5, rotationX: 90, rotationOrbit: 0, @@ -70,7 +73,7 @@ const CAMERA_POSITION: ViewStateType = { const SIDE_CAMERA = { rotationX: 0, - target: [435800, 6478000, -4000], + target: [435800, 6478000, -3250] as Point3D, rotationOrbit: 90, zoom: -3.3, }; @@ -132,8 +135,8 @@ const DisplayCameraPositionComponent: React.FC = (
zoom: {cameraState?.zoom}
rotationX: {cameraState?.rotationX}
rotationOrbit: {cameraState?.rotationOrbit}
-
targetX: {cameraState?.target[0]}
-
targetY: {cameraState?.target[1]}
+
targetX: {cameraState?.target?.[0]}
+
targetY: {cameraState?.target?.[1]}
); @@ -288,7 +291,7 @@ const AutoZoomToBox = (args: SubsurfaceViewerProps) => { rotationX: rotX, rotationOrbit: rotZ, zoom: zoomBox3D, - target: [], + target: undefined, }; const props = { @@ -444,7 +447,7 @@ export const ScaleZ: StoryObj = { const ResetCameraPropertyDefaultCameraPosition = { rotationOrbit: 0, rotationX: 45, - target: [435775, 6478650, -2750], + target: [435775, 6478650, -2750] as Point3D, zoom: -3.8, }; @@ -538,7 +541,7 @@ export const AddLayer: StoryObj = { rotationOrbit: 45, rotationX: 45, zoom: hugin3DBounds, - target: [], + target: undefined, }, views: default3DViews, }, @@ -630,15 +633,15 @@ export const ScaleYWithCameraPosition: StoryObj< render: (args) => , }; -const ScaleVertical3dComponent = ({ - verticalScale, -}: { - verticalScale: number; -}) => { +const ScaleVertical3dComponent = ( + props: SubsurfaceViewerProps & { + verticalScale: number; + } +) => { const viewerProps: SubsurfaceViewerProps = { ...DEFAULT_PROPS, cameraPosition: SIDE_CAMERA, - verticalScale, + ...props, }; return ; }; @@ -661,20 +664,21 @@ export const ScaleVertical3d: StoryObj = { render: (args) => , }; -const ScaleFactorHookComponent = ({ - verticalScale, -}: { - verticalScale: number; -}) => { +const ScaleFactorHookComponent = ( + props: SubsurfaceViewerProps & { + verticalScale: number; + } +) => { const { factor: scaleFactor, setFactor, elementRef } = useScaleFactor(); React.useEffect(() => { - setFactor(verticalScale); - }, [setFactor, verticalScale]); + setFactor(props.verticalScale); + }, [setFactor, props.verticalScale]); const viewerProps: SubsurfaceViewerProps = { ...DEFAULT_PROPS, cameraPosition: SIDE_CAMERA, + ...props, verticalScale: scaleFactor, innerRef: elementRef, coords: { visible: false }, diff --git a/typescript/packages/subsurface-viewer/src/storybook/examples/MultiViewExamples.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/examples/MultiViewExamples.stories.tsx index 9db53cb45..5895ae9ed 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/examples/MultiViewExamples.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/examples/MultiViewExamples.stories.tsx @@ -33,8 +33,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer/Examples/MutiView", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/examples/RenderingExamples.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/examples/RenderingExamples.stories.tsx index ce035ebbb..639b2132a 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/examples/RenderingExamples.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/examples/RenderingExamples.stories.tsx @@ -34,8 +34,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer/Examples/Rendering", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/examples/TooltipExamples.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/examples/TooltipExamples.stories.tsx index 94525de00..cb5c6f4cc 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/examples/TooltipExamples.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/examples/TooltipExamples.stories.tsx @@ -30,8 +30,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer/Examples/Tooltip", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--display-camera-state.png b/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--display-camera-state.png index 84a7a1ade..e49b099be 100644 Binary files a/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--display-camera-state.png and b/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--display-camera-state.png differ diff --git a/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--scale-factor-hook.png b/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--scale-factor-hook.png index 730e62acb..6d93daece 100644 Binary files a/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--scale-factor-hook.png and b/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--scale-factor-hook.png differ diff --git a/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--scale-vertical-3-d.png b/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--scale-vertical-3-d.png index d6fa1397f..76e7a2061 100644 Binary files a/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--scale-vertical-3-d.png and b/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--scale-vertical-3-d.png differ diff --git a/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--synced-subsurface-viewers.png b/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--synced-subsurface-viewers.png index de078fc0d..ecaf764b8 100644 Binary files a/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--synced-subsurface-viewers.png and b/typescript/packages/subsurface-viewer/src/storybook/examples/__image_snapshots__/subsurfaceviewer-examples-camera--synced-subsurface-viewers.png differ diff --git a/typescript/packages/subsurface-viewer/src/storybook/examples/miscExamples.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/examples/miscExamples.stories.tsx index c3b5e5ea3..6d6928c8c 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/examples/miscExamples.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/examples/miscExamples.stories.tsx @@ -40,11 +40,9 @@ import { const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer/Examples", - // @ts-expect-error TS2322 argTypes: argTypes, args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/layers/Axes2DLayer.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/layers/Axes2DLayer.stories.tsx index e797cb13f..ef50214f1 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/layers/Axes2DLayer.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/layers/Axes2DLayer.stories.tsx @@ -17,8 +17,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer / Axes2DLayer", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/layers/BoxSelectionLayer.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/layers/BoxSelectionLayer.stories.tsx index 12212404a..bd0d9827f 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/layers/BoxSelectionLayer.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/layers/BoxSelectionLayer.stories.tsx @@ -15,8 +15,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer / Box Selection Layer", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/layers/Grid3DLayer.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/layers/Grid3DLayer.stories.tsx index db2f688b1..c360f7dec 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/layers/Grid3DLayer.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/layers/Grid3DLayer.stories.tsx @@ -35,8 +35,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer/Grid3D Layer", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/layers/Hillshading2DLayer.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/layers/Hillshading2DLayer.stories.tsx index ddfc5ec33..4bfebc75c 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/layers/Hillshading2DLayer.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/layers/Hillshading2DLayer.stories.tsx @@ -12,8 +12,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer/HillshadingLayer", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/layers/MapLayer.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/layers/MapLayer.stories.tsx index 794bbfc3b..cafbcfeb7 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/layers/MapLayer.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/layers/MapLayer.stories.tsx @@ -36,8 +36,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer / Map Layer", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; @@ -525,7 +524,7 @@ const TypedArrayInputComponent: React.FC<{ rotationOrbit: 45, rotationX: 45, zoom: [-100, -100, -10, 100, 100, 60] as BoundingBox3D, - target: [], + target: undefined, }, views: default3DViews, triggerHome: args.triggerHome, diff --git a/typescript/packages/subsurface-viewer/src/storybook/layers/MapLayerColormap.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/layers/MapLayerColormap.stories.tsx index 89129d475..9e388d5c3 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/layers/MapLayerColormap.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/layers/MapLayerColormap.stories.tsx @@ -32,8 +32,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer / Map Layer / Colormap", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/layers/NorthArrow3DLayer.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/layers/NorthArrow3DLayer.stories.tsx index 11446925e..bf345bb13 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/layers/NorthArrow3DLayer.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/layers/NorthArrow3DLayer.stories.tsx @@ -15,8 +15,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer / North Arrow Layer", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/layers/PointsLayer.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/layers/PointsLayer.stories.tsx index 7ab691cf0..d141e502c 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/layers/PointsLayer.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/layers/PointsLayer.stories.tsx @@ -10,8 +10,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer / Points Layer", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/layers/PolylinesLayer.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/layers/PolylinesLayer.stories.tsx index 34bfb75e3..2f6278fb8 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/layers/PolylinesLayer.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/layers/PolylinesLayer.stories.tsx @@ -13,8 +13,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer / Polylines Layer", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/layers/TriangleLayer.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/layers/TriangleLayer.stories.tsx index 02bbfde7d..a85fdb914 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/layers/TriangleLayer.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/layers/TriangleLayer.stories.tsx @@ -18,8 +18,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer / Triangle Layer", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/layers/WellMarkersLayer.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/layers/WellMarkersLayer.stories.tsx index 32ed490bd..7f4a4e02e 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/layers/WellMarkersLayer.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/layers/WellMarkersLayer.stories.tsx @@ -11,8 +11,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer/Well Markers Layer", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; diff --git a/typescript/packages/subsurface-viewer/src/storybook/layers/WellsLayer.stories.tsx b/typescript/packages/subsurface-viewer/src/storybook/layers/WellsLayer.stories.tsx index 707c9855e..26105bbc3 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/layers/WellsLayer.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/layers/WellsLayer.stories.tsx @@ -35,8 +35,7 @@ const stories: Meta = { component: SubsurfaceViewer, title: "SubsurfaceViewer / Wells Layer", args: { - // Add a reset button for all the stories. - // Somehow, I do not manage to add the triggerHome to the general "unset" controls :/ + // Add some common controls for all the stories. triggerHome: 0, }, }; @@ -542,7 +541,7 @@ export const WellsRefine: StoryObj = { rotationOrbit: -45, rotationX: 15, zoom: BBox, - target: [], + target: undefined, }, views: default3DViews, }, diff --git a/typescript/packages/subsurface-viewer/src/storybook/sharedDoc.tsx b/typescript/packages/subsurface-viewer/src/storybook/sharedDoc.tsx index f7651e1a5..c181f6a93 100644 --- a/typescript/packages/subsurface-viewer/src/storybook/sharedDoc.tsx +++ b/typescript/packages/subsurface-viewer/src/storybook/sharedDoc.tsx @@ -29,10 +29,7 @@ export const argTypes = { }, triggerHome: { - description: "Forces resetting to initial home position", - control: { - type: "number", - }, + description: "Forces resetting to initial home position.", }, views: { diff --git a/typescript/packages/subsurface-viewer/src/utils/BoundingBox2D.ts b/typescript/packages/subsurface-viewer/src/utils/BoundingBox2D.ts index 5d1833aef..0af9ad0b5 100644 --- a/typescript/packages/subsurface-viewer/src/utils/BoundingBox2D.ts +++ b/typescript/packages/subsurface-viewer/src/utils/BoundingBox2D.ts @@ -30,12 +30,17 @@ export const boxUnion = ( return [xmin, ymin, xmax, ymax]; }; +/** + * 3D point defined as [x, y]. + */ +export type Point2D = [number, number]; + /** * Returns the center of the bounding box. * @param box1 bounding box. * @returns the center of the bounding box. */ -export const boxCenter = (box: BoundingBox2D): [number, number] => { +export const boxCenter = (box: BoundingBox2D): Point2D => { const xmin = box[0]; const ymin = box[1]; diff --git a/typescript/packages/subsurface-viewer/src/utils/BoundingBox3D.ts b/typescript/packages/subsurface-viewer/src/utils/BoundingBox3D.ts index ff61b4f06..31786ba84 100644 --- a/typescript/packages/subsurface-viewer/src/utils/BoundingBox3D.ts +++ b/typescript/packages/subsurface-viewer/src/utils/BoundingBox3D.ts @@ -32,12 +32,17 @@ export const boxUnion = ( return [xmin, ymin, zmin, xmax, ymax, zmax]; }; +/** + * 3D point defined as [x, y, z]. + */ +export type Point3D = [number, number, number]; + /** * Returns the center of the bounding box. * @param box1 bounding box. * @returns the center of the bounding box. */ -export const boxCenter = (box: BoundingBox3D): [number, number, number] => { +export const boxCenter = (box: BoundingBox3D): Point3D => { const xmin = box[0]; const ymin = box[1]; const zmin = box[2];