diff --git a/documentation/docs/examples/controlsmodes.mdx b/documentation/docs/examples/controlsmodes.mdx index 22c9b128a18..9154976f802 100644 --- a/documentation/docs/examples/controlsmodes.mdx +++ b/documentation/docs/examples/controlsmodes.mdx @@ -31,10 +31,14 @@ Default value is `false`. Example of setting different camera controls options: ```jsx runnable +// import { isDefaultCameraManager } from '@cognite/reveal'; + const newControlsOptions = { mouseWheelAction: 'zoomToCursor', changeCameraTargetOnClick: true, }; -viewer.cameraManager.setCameraControlsOptions(newControlsOptions); +if (isDefaultCameraManager(viewer.cameraManager)) { + viewer.cameraManager.setCameraControlsOptions(newControlsOptions); +} ``` diff --git a/documentation/versioned_docs/version-4.x/examples/controlsmodes.mdx b/documentation/versioned_docs/version-4.x/examples/controlsmodes.mdx index 3603d0dced5..00a380ef051 100644 --- a/documentation/versioned_docs/version-4.x/examples/controlsmodes.mdx +++ b/documentation/versioned_docs/version-4.x/examples/controlsmodes.mdx @@ -31,10 +31,14 @@ Default value is `false`. Example of setting different camera controls options: ```jsx runnable-4x +// import { isDefaultCameraManager } from '@cognite/reveal'; + const newControlsOptions = { mouseWheelAction: 'zoomToCursor', changeCameraTargetOnClick: true, }; -viewer.cameraManager.setCameraControlsOptions(newControlsOptions); +if (isDefaultCameraManager(viewer.cameraManager)) { + viewer.cameraManager.setCameraControlsOptions(newControlsOptions); +} ``` diff --git a/react-components/package.json b/react-components/package.json index 9e65777e086..f685ed46751 100644 --- a/react-components/package.json +++ b/react-components/package.json @@ -1,6 +1,6 @@ { "name": "@cognite/reveal-react-components", - "version": "0.54.0", + "version": "0.54.2", "exports": { ".": { "import": "./dist/index.js", diff --git a/react-components/src/components/Architecture/CommandButton.tsx b/react-components/src/components/Architecture/CommandButton.tsx index 308332042ba..a7ef18a2551 100644 --- a/react-components/src/components/Architecture/CommandButton.tsx +++ b/react-components/src/components/Architecture/CommandButton.tsx @@ -10,14 +10,6 @@ import { type BaseCommand } from '../../architecture/base/commands/BaseCommand'; import { getButtonType, getDefaultCommand, getIcon, getTooltipPlacement } from './utilities'; import { LabelWithShortcut } from './LabelWithShortcut'; -export const createCommandButton = ( - commandConstructor: () => BaseCommand, - isHorizontal = false -): ReactElement => { - const command = useMemo(commandConstructor, []); - return ; -}; - export const CommandButton = ({ inputCommand, isHorizontal = false diff --git a/react-components/src/components/Architecture/CommandButtons.tsx b/react-components/src/components/Architecture/CommandButtons.tsx index abc2cc5f3bb..84e20378de7 100644 --- a/react-components/src/components/Architecture/CommandButtons.tsx +++ b/react-components/src/components/Architecture/CommandButtons.tsx @@ -2,20 +2,28 @@ * Copyright 2023 Cognite AS */ -import { type ReactElement } from 'react'; +import { useMemo, type ReactElement } from 'react'; import { Divider } from '@cognite/cogs.js'; import { type BaseCommand } from '../../architecture/base/commands/BaseCommand'; import { OptionButton } from './OptionButton'; import { BaseOptionCommand } from '../../architecture/base/commands/BaseOptionCommand'; import { CommandButton } from './CommandButton'; -export const CreateButton = (command: BaseCommand, isHorizontal = false): ReactElement => { +export function createButton(command: BaseCommand, isHorizontal = false): ReactElement { if (command instanceof BaseOptionCommand) { return ; } else { return ; } -}; +} + +export function createButtonFromCommandConstructor( + commandConstructor: () => BaseCommand, + isHorizontal = false +): ReactElement { + const command = useMemo(commandConstructor, []); + return createButton(command, isHorizontal); +} export const CommandButtons = ({ commands, @@ -57,5 +65,5 @@ function CommandButtonWrapper({ const direction = !isHorizontal ? 'horizontal' : 'vertical'; return ; } - return CreateButton(command, isHorizontal); + return createButton(command, isHorizontal); } diff --git a/react-components/src/components/Architecture/RevealButtons.tsx b/react-components/src/components/Architecture/RevealButtons.tsx index aaa08579235..431aa6fa1cb 100644 --- a/react-components/src/components/Architecture/RevealButtons.tsx +++ b/react-components/src/components/Architecture/RevealButtons.tsx @@ -11,30 +11,38 @@ import { SetAxisVisibleCommand } from '../../architecture/concrete/axis/SetAxisV import { ClipTool } from '../../architecture/concrete/clipping/ClipTool'; import { MeasurementTool } from '../../architecture/concrete/measurements/MeasurementTool'; import { KeyboardSpeedCommand } from '../../architecture/base/concreteCommands/KeyboardSpeedCommand'; -import { createCommandButton } from './CommandButton'; import { ObservationsTool } from '../../architecture/concrete/observations/ObservationsTool'; +import { createButtonFromCommandConstructor } from './CommandButtons'; export class RevealButtons { - static FitView = (): ReactElement => createCommandButton(() => new FitViewCommand()); + static FitView = (): ReactElement => + createButtonFromCommandConstructor(() => new FitViewCommand()); - static NavigationTool = (): ReactElement => createCommandButton(() => new NavigationTool()); + static NavigationTool = (): ReactElement => + createButtonFromCommandConstructor(() => new NavigationTool()); static SetAxisVisible = (): ReactElement => - createCommandButton(() => new SetAxisVisibleCommand()); + createButtonFromCommandConstructor(() => new SetAxisVisibleCommand()); - static Measurement = (): ReactElement => createCommandButton(() => new MeasurementTool()); + static Measurement = (): ReactElement => + createButtonFromCommandConstructor(() => new MeasurementTool()); - static Clip = (): ReactElement => createCommandButton(() => new ClipTool()); + static Clip = (): ReactElement => createButtonFromCommandConstructor(() => new ClipTool()); static SetFlexibleControlsTypeOrbit = (): ReactElement => - createCommandButton(() => new SetFlexibleControlsTypeCommand(FlexibleControlsType.Orbit)); + createButtonFromCommandConstructor( + () => new SetFlexibleControlsTypeCommand(FlexibleControlsType.Orbit) + ); static SetFlexibleControlsTypeFirstPerson = (): ReactElement => - createCommandButton(() => new SetFlexibleControlsTypeCommand(FlexibleControlsType.FirstPerson)); + createButtonFromCommandConstructor( + () => new SetFlexibleControlsTypeCommand(FlexibleControlsType.FirstPerson) + ); static Observations = (): ReactElement => { - return createCommandButton(() => new ObservationsTool()); + return createButtonFromCommandConstructor(() => new ObservationsTool()); }; - static KeyboardSpeed = (): ReactElement => createCommandButton(() => new KeyboardSpeedCommand()); + static KeyboardSpeed = (): ReactElement => + createButtonFromCommandConstructor(() => new KeyboardSpeedCommand()); } diff --git a/react-components/src/components/CacheProvider/AssetMappingAndNode3DCache.ts b/react-components/src/components/CacheProvider/AssetMappingAndNode3DCache.ts index 2b6cb7aac18..e0f36c22c81 100644 --- a/react-components/src/components/CacheProvider/AssetMappingAndNode3DCache.ts +++ b/react-components/src/components/CacheProvider/AssetMappingAndNode3DCache.ts @@ -297,7 +297,7 @@ export class AssetMappingAndNode3DCache { if (ids.length === 0) { return []; } - const idChunks = chunk(ids, 100); + const idChunks = chunk(ids, 1000); const initialIndex = 0; const assetMappings = await this.fetchMappingsInQueue( initialIndex, diff --git a/viewer/api-entry-points/core.ts b/viewer/api-entry-points/core.ts index 13384f28d32..2363bbe7e14 100644 --- a/viewer/api-entry-points/core.ts +++ b/viewer/api-entry-points/core.ts @@ -13,6 +13,7 @@ export { CameraControlsOptions, DebouncedCameraStopEventTrigger, DefaultCameraManager, + isDefaultCameraManager, CameraManagerEventType, CameraManagerHelper, CameraManager, diff --git a/viewer/package.json b/viewer/package.json index 70a0dc4e447..cde0b699972 100644 --- a/viewer/package.json +++ b/viewer/package.json @@ -1,6 +1,6 @@ { "name": "@cognite/reveal", - "version": "4.15.2", + "version": "4.16.1", "description": "WebGL based 3D viewer for CAD and point clouds processed in Cognite Data Fusion.", "homepage": "https://github.com/cognitedata/reveal/tree/master/viewer", "repository": { diff --git a/viewer/packages/api/src/utilities/ViewStateHelper.ts b/viewer/packages/api/src/utilities/ViewStateHelper.ts index f05cf50dff9..c70d6c38067 100644 --- a/viewer/packages/api/src/utilities/ViewStateHelper.ts +++ b/viewer/packages/api/src/utilities/ViewStateHelper.ts @@ -58,8 +58,16 @@ export class ViewStateHelper { return { camera: { - position: cameraPosition, - target: cameraTarget + position: { + x: cameraPosition.x, + y: cameraPosition.y, + z: cameraPosition.z + }, + target: { + x: cameraTarget.x, + y: cameraTarget.y, + z: cameraTarget.z + } }, models: modelStates, clippingPlanes: clippingPlanesState diff --git a/viewer/packages/camera-manager/index.ts b/viewer/packages/camera-manager/index.ts index 2278062ad40..9f87c5aa75b 100644 --- a/viewer/packages/camera-manager/index.ts +++ b/viewer/packages/camera-manager/index.ts @@ -1,7 +1,7 @@ /*! * Copyright 2021 Cognite AS */ -export { DefaultCameraManager } from './src/DefaultCameraManager'; +export { DefaultCameraManager, isDefaultCameraManager } from './src/DefaultCameraManager'; export { ProxyCameraManager } from './src/ProxyCameraManager'; export { StationaryCameraManager } from './src/StationaryCameraManager'; export { CameraManagerHelper } from './src/CameraManagerHelper'; diff --git a/viewer/packages/camera-manager/src/DefaultCameraManager.ts b/viewer/packages/camera-manager/src/DefaultCameraManager.ts index f42f882a250..b9478305514 100644 --- a/viewer/packages/camera-manager/src/DefaultCameraManager.ts +++ b/viewer/packages/camera-manager/src/DefaultCameraManager.ts @@ -668,3 +668,10 @@ export class DefaultCameraManager implements CameraManager { return clamp(duration, DefaultCameraManager.MinAnimationDuration, DefaultCameraManager.MaxAnimationDuration); } } + +/** + * type guard which determines if the provided camera manager is a @see { DefaultCameraManager } + */ +export function isDefaultCameraManager(cameraManager: CameraManager): cameraManager is DefaultCameraManager { + return cameraManager instanceof DefaultCameraManager; +} diff --git a/viewer/packages/pointclouds/src/PointCloudManager.ts b/viewer/packages/pointclouds/src/PointCloudManager.ts index b89b7e7c7bb..a3219f7d3f7 100644 --- a/viewer/packages/pointclouds/src/PointCloudManager.ts +++ b/viewer/packages/pointclouds/src/PointCloudManager.ts @@ -105,7 +105,7 @@ export class PointCloudManager { } updatePointClouds(camera: THREE.PerspectiveCamera): void { - const octrees = this._pointCloudNodes.map(node => node.octree); + const octrees = this._pointCloudNodes.filter(node => node.visible).map(node => node.octree); this._potreeInstance.updatePointClouds(octrees, camera, this._renderer); } diff --git a/viewer/reveal.api.md b/viewer/reveal.api.md index b8df6ec12bc..7ca02503634 100644 --- a/viewer/reveal.api.md +++ b/viewer/reveal.api.md @@ -1332,6 +1332,9 @@ export class InvertedNodeCollection extends NodeCollection { serialize(): SerializedNodeCollection; } +// @public +export function isDefaultCameraManager(cameraManager: CameraManager): cameraManager is DefaultCameraManager; + // @beta export function isFlexibleCameraManager(manager: CameraManager): manager is IFlexibleCameraManager;