-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge master into hflatval/clicked-node-hook
- Loading branch information
Showing
8 changed files
with
226 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
react-components/src/components/RevealToolbar/SettingsButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*! | ||
* Copyright 2023 Cognite AS | ||
*/ | ||
|
||
import { type ReactElement } from 'react'; | ||
import { Button, Dropdown, Menu } from '@cognite/cogs.js'; | ||
import { type QualitySettings } from './SettingsContainer/types'; | ||
import { HighFidelityContainer } from './SettingsContainer/HighFidelityContainer'; | ||
|
||
type CustomSettingsProps = { | ||
customSettingsContent?: ReactElement; | ||
lowQualitySettings?: Partial<QualitySettings>; | ||
highQualitySettings?: Partial<QualitySettings>; | ||
}; | ||
|
||
export const SettingsButton = ({ | ||
customSettingsContent, | ||
lowQualitySettings, | ||
highQualitySettings | ||
}: CustomSettingsProps): ReactElement => { | ||
return ( | ||
<Dropdown | ||
appendTo={document.body} | ||
content={ | ||
<Menu> | ||
<HighFidelityContainer | ||
lowQualitySettings={lowQualitySettings} | ||
highQualitySettings={highQualitySettings} | ||
/> | ||
{customSettingsContent ?? <></>} | ||
</Menu> | ||
} | ||
placement="auto"> | ||
<Button icon="Settings" type="ghost" aria-label="Show settings" /> | ||
</Dropdown> | ||
); | ||
}; |
76 changes: 76 additions & 0 deletions
76
react-components/src/components/RevealToolbar/SettingsContainer/HighFidelityContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*! | ||
* Copyright 2023 Cognite AS | ||
*/ | ||
|
||
import { type ReactElement, useState } from 'react'; | ||
import { Menu } from '@cognite/cogs.js'; | ||
import { useReveal } from '../../RevealContainer/RevealContext'; | ||
import { type QualitySettings, type QualityProps } from './types'; | ||
import { type Cognite3DViewer } from '@cognite/reveal'; | ||
|
||
const defaultLowFidelitySettings: QualitySettings = { | ||
cadBudget: { | ||
maximumRenderCost: 15_000_000, | ||
highDetailProximityThreshold: 10 | ||
}, | ||
pointCloudBudget: { | ||
numberOfPoints: 3_000_000 | ||
}, | ||
resolutionOptions: { | ||
maxRenderResolution: 1.4e6, | ||
movingCameraResolutionFactor: 1 | ||
} | ||
}; | ||
|
||
const defaultHighFidelitySettings: QualitySettings = { | ||
cadBudget: { | ||
maximumRenderCost: 45_000_000, | ||
highDetailProximityThreshold: 30 | ||
}, | ||
pointCloudBudget: { | ||
numberOfPoints: 12_000_000 | ||
}, | ||
resolutionOptions: { | ||
maxRenderResolution: Infinity, | ||
movingCameraResolutionFactor: 1 | ||
} | ||
}; | ||
|
||
export const HighFidelityContainer = ({ | ||
lowQualitySettings, | ||
highQualitySettings | ||
}: QualityProps): ReactElement => { | ||
const viewer = useReveal(); | ||
const [active, setActive] = useState(!isLowFidelity(viewer)); | ||
|
||
const lowFidelityOptions: QualitySettings = { | ||
...defaultLowFidelitySettings, | ||
...lowQualitySettings | ||
}; | ||
const highFidelityOptions: QualitySettings = { | ||
...defaultHighFidelitySettings, | ||
...highQualitySettings | ||
}; | ||
|
||
const onClick = (): void => { | ||
const config = active ? lowFidelityOptions : highFidelityOptions; | ||
viewer.cadBudget = config.cadBudget; | ||
viewer.pointCloudBudget = config.pointCloudBudget; | ||
viewer.setResolutionOptions(config.resolutionOptions); | ||
setActive((prevState) => !prevState); | ||
}; | ||
|
||
return ( | ||
<Menu.Item hasSwitch toggled={active} onChange={onClick}> | ||
High fidelity | ||
</Menu.Item> | ||
); | ||
}; | ||
|
||
function isLowFidelity(viewer: Cognite3DViewer): boolean { | ||
return ( | ||
viewer.cadBudget.maximumRenderCost <= defaultLowFidelitySettings.cadBudget.maximumRenderCost && | ||
viewer.pointCloudBudget.numberOfPoints <= | ||
defaultLowFidelitySettings.pointCloudBudget.numberOfPoints | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
react-components/src/components/RevealToolbar/SettingsContainer/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*! | ||
* Copyright 2023 Cognite AS | ||
*/ | ||
|
||
import { | ||
type CadModelBudget, | ||
type PointCloudBudget, | ||
type ResolutionOptions | ||
} from '@cognite/reveal'; | ||
import { type ReactElement } from 'react'; | ||
|
||
export type QualityProps = { | ||
lowQualitySettings?: Partial<QualitySettings>; | ||
highQualitySettings?: Partial<QualitySettings>; | ||
}; | ||
|
||
export type SettingsContainerProps = QualityProps & { | ||
customSettingsContent?: ReactElement; | ||
}; | ||
|
||
export type QualitySettings = { | ||
cadBudget: CadModelBudget; | ||
pointCloudBudget: PointCloudBudget; | ||
resolutionOptions: ResolutionOptions; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters