Skip to content

Commit

Permalink
Merge branch 'master' into hflatval/coredm-support
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonflatval-cognite committed Jul 26, 2024
2 parents 2238b7f + cd14a65 commit e7d525d
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 31 deletions.
6 changes: 5 additions & 1 deletion documentation/docs/examples/controlsmodes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
```

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion react-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cognite/reveal-react-components",
"version": "0.54.0",
"version": "0.54.2",
"exports": {
".": {
"import": "./dist/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <CommandButton inputCommand={command} isHorizontal={isHorizontal} />;
};

export const CommandButton = ({
inputCommand,
isHorizontal = false
Expand Down
16 changes: 12 additions & 4 deletions react-components/src/components/Architecture/CommandButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <OptionButton inputCommand={command} isHorizontal={isHorizontal} />;
} else {
return <CommandButton inputCommand={command} isHorizontal={isHorizontal} />;
}
};
}

export function createButtonFromCommandConstructor(
commandConstructor: () => BaseCommand,
isHorizontal = false
): ReactElement {
const command = useMemo(commandConstructor, []);
return createButton(command, isHorizontal);
}

export const CommandButtons = ({
commands,
Expand Down Expand Up @@ -57,5 +65,5 @@ function CommandButtonWrapper({
const direction = !isHorizontal ? 'horizontal' : 'vertical';
return <Divider weight="2px" length="24px" direction={direction} />;
}
return CreateButton(command, isHorizontal);
return createButton(command, isHorizontal);
}
28 changes: 18 additions & 10 deletions react-components/src/components/Architecture/RevealButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions viewer/api-entry-points/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export {
CameraControlsOptions,
DebouncedCameraStopEventTrigger,
DefaultCameraManager,
isDefaultCameraManager,
CameraManagerEventType,
CameraManagerHelper,
CameraManager,
Expand Down
2 changes: 1 addition & 1 deletion viewer/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
12 changes: 10 additions & 2 deletions viewer/packages/api/src/utilities/ViewStateHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion viewer/packages/camera-manager/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
7 changes: 7 additions & 0 deletions viewer/packages/camera-manager/src/DefaultCameraManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion viewer/packages/pointclouds/src/PointCloudManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions viewer/reveal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit e7d525d

Please sign in to comment.