Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react-components): expose viewer options #3468

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.3.0",
"version": "0.4.0",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { type CogniteClient } from '@cognite/sdk';
import { useEffect, useRef, type ReactNode, useState, type ReactElement } from 'react';
import { Cognite3DViewer } from '@cognite/reveal';
import { Cognite3DViewer, type Cognite3DViewerOptions } from '@cognite/reveal';
import { RevealContext } from './RevealContext';
import { type Color } from 'three';
import { ModelsLoadingStateContext } from '../Reveal3DResources/ModelsLoadingContext';
Expand All @@ -12,9 +12,24 @@ type RevealContainerProps = {
color?: Color;
sdk: CogniteClient;
children?: ReactNode;
viewerOptions?: Pick<
Cognite3DViewerOptions,
| 'antiAliasingHint'
| 'loadingIndicatorStyle'
| 'rendererResolutionThreshold'
| 'antiAliasingHint'
| 'ssaoQualityHint'
| 'pointCloudEffects'
| 'enableEdges'
>;
};

export function RevealContainer({ children, sdk, color }: RevealContainerProps): ReactElement {
export function RevealContainer({
children,
sdk,
color,
viewerOptions
}: RevealContainerProps): ReactElement {
const [viewer, setViewer] = useState<Cognite3DViewer>();
const revealDomElementRef = useRef<HTMLDivElement>(null);

Expand Down Expand Up @@ -45,7 +60,7 @@ export function RevealContainer({ children, sdk, color }: RevealContainerProps):
if (domElement === null) {
throw new Error('Failure in mounting RevealContainer to DOM.');
}
const viewer = new Cognite3DViewer({ sdk, domElement });
const viewer = new Cognite3DViewer({ ...viewerOptions, sdk, domElement });
viewer.setBackgroundColor({ color, alpha: 1 });
setViewer(viewer);
}
Expand Down
10 changes: 9 additions & 1 deletion react-components/stories/Reveal3DResources.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ export const Main: Story = {
]
},
render: ({ resources }) => (
<RevealContainer sdk={sdk} color={new Color(0x4a4a4a)}>
<RevealContainer
sdk={sdk}
color={new Color(0x4a4a4a)}
viewerOptions={{
loadingIndicatorStyle: {
opacity: 1,
placement: 'topRight'
}
}}>
<Reveal3DResources resources={resources} />
<CameraController
initialFitCamera={{
Expand Down
Loading