Skip to content

Commit

Permalink
Merge branch 'pramodcog/UX-1220' of https://github.com/cognitedata/re…
Browse files Browse the repository at this point in the history
…veal into pramodcog/UX-1220
  • Loading branch information
pramodcog committed Aug 21, 2023
2 parents 15cdf66 + 7531c3a commit cb48dc2
Show file tree
Hide file tree
Showing 36 changed files with 18,465 additions and 17,716 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ that can be explored in the browser.

### Building on Macbook M1

Building Reveal on Macbook M1 migth require some special care.
Building Reveal on Macbook M1 might require some special care.

If you experience issues during the `yarn`-stage in `viewer/`, e.g.
```
Expand Down
19 changes: 4 additions & 15 deletions examples/src/pages/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Stats from 'stats.js';
import { useEffect, useRef } from 'react';
import { CanvasWrapper } from '../components/styled';
import * as THREE from 'three';
import { CogniteClient } from '@cognite/sdk';
import dat from 'dat.gui';
import {
Cognite3DViewer,
Expand All @@ -29,7 +28,6 @@ import { CameraUI } from '../utils/CameraUI';
import { PointCloudUi } from '../utils/PointCloudUi';
import { ModelUi } from '../utils/ModelUi';
import { NodeTransformUI } from '../utils/NodeTransformUI';
import { createSDKFromEnvironment, createSDKFromToken } from '../utils/example-helpers';
import { PointCloudClassificationFilterUI } from '../utils/PointCloudClassificationFilterUI';
import { PointCloudObjectStylingUI } from '../utils/PointCloudObjectStylingUI';
import { CustomCameraManager } from '../utils/CustomCameraManager';
Expand All @@ -38,6 +36,7 @@ import { Image360UI } from '../utils/Image360UI';
import { Image360StylingUI } from '../utils/Image360StylingUI';
import { LoadGltfUi } from '../utils/LoadGltfUi';
import { createFunnyButton } from '../utils/PageVariationUtils';
import { getCogniteClient } from '../utils/example-helpers';

window.THREE = THREE;
(window as any).reveal = reveal;
Expand All @@ -51,7 +50,7 @@ export function Viewer() {
// Check in order to avoid double initialization of everything, especially dat.gui.
// See https://reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects for why its called twice.
if (!canvasWrapperRef.current) {
return () => {};
return;
}

const gui = new dat.GUI({ width: Math.min(500, 0.8 * window.innerWidth) });
Expand All @@ -76,18 +75,7 @@ export function Viewer() {
window.history.pushState({}, '', url.toString());
}

let client: CogniteClient;
if (project && overrideToken) {
client = createSDKFromToken('reveal.example.example', project, overrideToken);
} else if (project && environment) {
client = await createSDKFromEnvironment('reveal.example.example', project, environment);
} else {
client = new CogniteClient({
appId: 'reveal.example.example',
project: 'dummy',
getToken: async () => 'dummy'
});
}
let client = await getCogniteClient({ project, environment, overrideToken });

const edlEnabled = (urlParams.get('edl') ?? 'true') === 'true';
const progress = (itemsLoaded: number, itemsRequested: number, itemsCulled: number) => {
Expand Down Expand Up @@ -502,5 +490,6 @@ export function Viewer() {
viewer?.dispose();
};
}, []);

return <CanvasWrapper ref={canvasWrapperRef} />;
}
24 changes: 24 additions & 0 deletions examples/src/utils/example-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,27 @@ export async function createSDKFromEnvironment(
await client.authenticate();
return client;
}

export const getCogniteClient = async ({
project,
environment,
overrideToken
}: {
project: string | null;
environment: string | null;
overrideToken: string | null;
}): Promise<CogniteClient> => {
if (project !== null && overrideToken !== null) {
return createSDKFromToken('reveal.example.example', project, overrideToken);
}

if (project !== null && environment !== null) {
return await createSDKFromEnvironment('reveal.example.example', project, environment);
}

return new CogniteClient({
appId: 'reveal.example.example',
project: 'dummy',
getToken: async () => 'dummy'
});
};
20 changes: 10 additions & 10 deletions 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.10.0",
"version": "0.12.0",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
Expand Down Expand Up @@ -35,12 +35,12 @@
"@cognite/cogs.js": "^9.17.0",
"@cognite/reveal": "4.4.0",
"@cognite/sdk": "^8.2.0",
"@storybook/addon-essentials": "7.2.3",
"@storybook/addon-interactions": "7.2.3",
"@storybook/addon-links": "7.2.3",
"@storybook/blocks": "7.2.3",
"@storybook/react": "7.2.3",
"@storybook/react-webpack5": "7.2.3",
"@storybook/addon-essentials": "7.3.1",
"@storybook/addon-interactions": "7.3.1",
"@storybook/addon-links": "7.3.1",
"@storybook/blocks": "7.3.1",
"@storybook/react": "7.3.1",
"@storybook/react-webpack5": "7.3.1",
"@storybook/testing-library": "0.2.0",
"@tanstack/react-query-devtools": "^4.29.19",
"@types/lodash": "^4.14.190",
Expand All @@ -50,7 +50,7 @@
"@types/three": "0.155.0",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.8.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard-with-typescript": "latest",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.25.2",
Expand All @@ -64,7 +64,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-router-dom": "^6.15.0",
"storybook": "7.2.3",
"storybook": "7.3.1",
"style-loader": "^3.3.3",
"styled-components": "5.3.11",
"three": "0.155.0",
Expand All @@ -82,4 +82,4 @@
"@tanstack/react-query": "^4.29.19",
"lodash": "^4.17.21"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export function Image360CollectionContainer({
return collection;
}

return await viewer.add360ImageSet('events', { site_id: siteId });
return await viewer.add360ImageSet(
'events',
{ site_id: siteId },
{ preMultipliedRotation: false }
);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*!
* Copyright 2023 Cognite AS
*/

import { useState, type ReactElement, useCallback, useEffect } from 'react';
import styled from 'styled-components';
import { Image360HistoricalDetails } from '../Image360HistoricalDetails/Image360HistoricalDetails';
import { useReveal } from '../..';
import { type Image360 } from '@cognite/reveal';
import { Button } from '@cognite/cogs.js';

export function Image360Details(): ReactElement {
const viewer = useReveal();
const [enteredEntity, setEnteredEntity] = useState<Image360 | undefined>();
const [is360HistoricalPanelExpanded, setIs360HistoricalPanelExpanded] = useState<boolean>(false);
const handleExpand = useCallback((isExpanded: boolean) => {
setIs360HistoricalPanelExpanded(isExpanded);
}, []);

const clearEnteredImage360 = (): void => {
setEnteredEntity(undefined);
};

const exitImage360Image = (): void => {
viewer.exit360Image();
};

const collections = viewer.get360ImageCollections();

useEffect(() => {
collections.forEach((collection) => {
collection.on('image360Entered', setEnteredEntity);
collection.on('image360Exited', clearEnteredImage360);
});
return () => {
collections.forEach((collection) => {
collection.off('image360Entered', setEnteredEntity);
collection.off('image360Exited', clearEnteredImage360);
});
};
}, [viewer, collections]);

return (
<>
{enteredEntity !== undefined && (
<>
<Image360HistoricalPanel isExpanded={is360HistoricalPanelExpanded}>
<Image360HistoricalDetails
viewer={viewer}
image360Entity={enteredEntity}
onExpand={handleExpand}
/>
</Image360HistoricalPanel>
<ExitButtonContainer>
<StyledExitButton icon="CloseLarge" type="tertiary" onClick={exitImage360Image} />
</ExitButtonContainer>
</>
)}
</>
);
}

const StyledExitButton = styled(Button)`
border-radius: 8px;
`;

const ExitButtonContainer = styled.div`
position: absolute;
right: 20px;
top: 20px;
background-color: #ffffff;
height: 36px;
width: 36px;
border-radius: 8px;
outline: none;
`;

const Image360HistoricalPanel = styled.div<{ isExpanded: boolean }>`
position: absolute;
bottom: ${({ isExpanded }) => (isExpanded ? '0px' : '40px')};
display: flex;
flex-direction: column;
height: fit-content;
width: fit-content;
max-width: 100%;
min-width: fill-available;
transition: transform 0.25s ease-in-out;
transform: ${({ isExpanded }) => (isExpanded ? 'translateY(0)' : 'translateY(100%)')};
`;
Loading

0 comments on commit cb48dc2

Please sign in to comment.