Skip to content

Commit

Permalink
[PLAT-4743] Include scene comparison information in stream attributes (
Browse files Browse the repository at this point in the history
…#627)

* Include scene comparison information

* Include scene comparison information

* Update typing for ten arguments (#628)

---------

Co-authored-by: Jeff Murray <jeff.murray@vertexvis.com>
  • Loading branch information
amvertex and jdm717 authored Sep 6, 2024
1 parent 7abe91e commit 236fed5
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 71 deletions.
2 changes: 1 addition & 1 deletion packages/stream-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"test:coverage": "yarn test --coverage"
},
"dependencies": {
"@vertexvis/frame-streaming-protos": "^0.13.2"
"@vertexvis/frame-streaming-protos": "^0.13.11"
},
"devDependencies": {
"@types/jest": "^27.5.1",
Expand Down
36 changes: 36 additions & 0 deletions packages/utils/src/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,18 @@ export function read<T, R1, R2, R3, R4, R5, R6, R7, R8, R9>(
h: Func<T, R8>,
i: Func<T, R9>
): Func<T, [R1, R2, R3, R4, R5, R6, R7, R8, R9]>;
export function read<T, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10>(
a: Func<T, R1>,
b: Func<T, R2>,
c: Func<T, R3>,
d: Func<T, R4>,
e: Func<T, R5>,
f: Func<T, R6>,
g: Func<T, R7>,
h: Func<T, R8>,
i: Func<T, R9>,
j: Func<T, R10>
): Func<T, [R1, R2, R3, R4, R5, R6, R7, R8, R9, R10]>;
export function read(
...mappers: Func<unknown, unknown>[]
): Func<unknown, unknown[]> {
Expand Down Expand Up @@ -497,6 +509,18 @@ export function compose<T, A, B, C, D, E, F, G, H, R>(
h: Func<G, H>,
i: Func<H, R>
): Func<T, R>;
export function compose<T, A, B, C, D, E, F, G, H, I, R>(
a: Func<T, A>,
b: Func<A, B>,
c: Func<B, C>,
d: Func<C, D>,
e: Func<D, E>,
f: Func<E, F>,
g: Func<F, G>,
h: Func<G, H>,
i: Func<H, I>,
j: Func<I, R>
): Func<T, R>;
export function compose(
...decoders: Func<unknown, unknown>[]
): Func<unknown, unknown> {
Expand Down Expand Up @@ -577,6 +601,18 @@ export function pickFirst<T, A, B, C, D, E, F, G, H, I>(
h: Func<T, H | undefined>,
i: Func<T, I | undefined>
): Func<T, A | B | C | D | E | F | G | H | I | undefined>;
export function pickFirst<T, A, B, C, D, E, F, G, H, I, J>(
a: Func<T, A | undefined>,
b: Func<T, B | undefined>,
c: Func<T, C | undefined>,
d: Func<T, D | undefined>,
e: Func<T, E | undefined>,
f: Func<T, F | undefined>,
g: Func<T, G | undefined>,
h: Func<T, H | undefined>,
i: Func<T, I | undefined>,
j: Func<T, J | undefined>
): Func<T, A | B | C | D | E | F | G | H | I | J | undefined>;
export function pickFirst(
...decoders: Func<unknown, unknown | undefined>[]
): Func<unknown, unknown | undefined> {
Expand Down
2 changes: 1 addition & 1 deletion packages/viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@improbable-eng/grpc-web": "^0.15.0",
"@stencil/core": "^2.16.1",
"@types/classnames": "^2.3.1",
"@vertexvis/frame-streaming-protos": "^0.13.2",
"@vertexvis/frame-streaming-protos": "^0.13.11",
"@vertexvis/geometry": "0.22.0",
"@vertexvis/html-templates": "0.22.0",
"@vertexvis/scene-tree-protos": "^0.1.21",
Expand Down
9 changes: 9 additions & 0 deletions packages/viewer/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
FeatureLineOptions,
FrameType,
PhantomOptions,
SceneComparisonOptions,
SelectionHighlightingOptions,
} from './interfaces';
import { Frame, FrameCameraBase } from './lib/types/frame';
Expand Down Expand Up @@ -651,6 +652,10 @@ export namespace Components {
* Returns an object that is used to perform operations on the `Scene` that's currently being viewed. These operations include updating items, positioning the camera and performing hit tests.
*/
scene: () => Promise<Scene>;
/**
* Specifies if and how to compare to another scene
*/
sceneComparison?: SceneComparisonOptions;
/**
* Specifies the halo selection properties. Parameter notes:
*
Expand Down Expand Up @@ -2486,6 +2491,10 @@ declare namespace LocalJSX {
* Enables or disables the default rotation interaction being changed to rotate around the pointer down location.
*/
rotateAroundTapPoint?: boolean;
/**
* Specifies if and how to compare to another scene
*/
sceneComparison?: SceneComparisonOptions;
/**
* Specifies the halo selection properties. Parameter notes:
*
Expand Down
1 change: 1 addition & 0 deletions packages/viewer/src/components/viewer/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
| `phantom` | -- | Specifies how phantom parts should appear. The opacity must be between 0 and 1, where 0 is completely hidden and 1 is completely visible. | `PhantomOptions \| undefined` | `{ opacity: 0.1 }` |
| `resizeDebounce` | `resize-debounce` | An optional value that will debounce frame updates when resizing this viewer element. | `number` | `100` |
| `rotateAroundTapPoint` | `rotate-around-tap-point` | Enables or disables the default rotation interaction being changed to rotate around the pointer down location. | `boolean` | `true` |
| `sceneComparison` | -- | Specifies if and how to compare to another scene | `SceneComparisonOptions \| undefined` | `undefined` |
| `selectionHighlighting` | -- | Specifies the halo selection properties. Parameter notes: * lineWidth values supported currently are 0-5. This width is currently the value x2. For example, 1 will have a pixel width of 2. * color is optional. This will be the color of the selected items in the viewer. * opacity is also optional. The opacity will be applied to everything selected besides the highlighted outer line. | `SelectionHighlightingOptions \| undefined` | `undefined` |
| `src` | `src` | A URN of the scene resource to load when the component is mounted in the DOM tree. The specified resource is a URN in the following format: * `urn:vertex:scene:<sceneid>` | `string \| undefined` | `undefined` |
| `viewport` | -- | Represents the current viewport of the viewer. The viewport represents the dimensions of the canvas where a frame is rendered. It contains methods for translating between viewport coordinates, frame coordinates and world coordinates. | `Viewport` | `Viewport.fromDimensions(Dimensions.create(0, 0))` |
Expand Down
82 changes: 21 additions & 61 deletions packages/viewer/src/components/viewer/viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
FeatureLineOptions,
FrameType,
PhantomOptions,
SceneComparisonOptions,
SelectionHighlightingOptions,
StreamAttributes,
} from '../../interfaces';
Expand Down Expand Up @@ -273,6 +274,12 @@ export class Viewer {
@Prop({ attribute: null })
public featureHighlighting?: FeatureHighlightOptions;

/**
* Specifies if and how to compare to another scene
*/
@Prop({ attribute: null })
public sceneComparison?: SceneComparisonOptions;

/**
* Specifies when a feature map is returned from rendering. Feature maps
* include information about the surfaces, edges and cross sections that are
Expand Down Expand Up @@ -795,32 +802,16 @@ export class Viewer {
/**
* @ignore
*/
@Watch('experimentalRenderingOptions')
@Watch('depthBuffers')
protected handleDepthBuffersChanged(): void {
this.updateStreamAttributes();
}

/**
* @ignore
*/
@Watch('phantom')
protected handlePhantomChanged(): void {
this.updateStreamAttributes();
}

/**
* @ignore
*/
@Watch('featureHighlighting')
@Watch('featureLines')
@Watch('featureMaps')
@Watch('noDefaultLights')
protected handleNoDefaultLightsChanged(): void {
this.updateStreamAttributes();
}

/**
* @ignore
*/
@Watch('experimentalRenderingOptions')
protected handleExperimentalRenderingOptionsChanged(): void {
@Watch('phantom')
@Watch('sceneComparison')
@Watch('selectionHighlighting')
protected handleStreamAttributesChanged(): void {
this.updateStreamAttributes();
}

Expand All @@ -832,38 +823,6 @@ export class Viewer {
this.updateEnableTemporalRefinement();
}

/**
* @ignore
*/
@Watch('featureLines')
protected handleFeatureLinesChanged(): void {
this.updateStreamAttributes();
}

/**
* @ignore
*/
@Watch('selectionHighlighting')
protected handleSelectionHighlightingChanged(): void {
this.updateStreamAttributes();
}

/**
* @ignore
*/
@Watch('featureHighlighting')
protected handleFeatureHighlightingChanged(): void {
this.updateStreamAttributes();
}

/**
* @ignore
*/
@Watch('featureMaps')
protected handleFeatureMapsChanged(): void {
this.updateStreamAttributes();
}

/**
* @ignore
*/
Expand Down Expand Up @@ -1498,16 +1457,17 @@ export class Viewer {
private getStreamAttributes(): StreamAttributes {
return {
depthBuffers: this.getDepthBufferStreamAttributesValue(),
phantom: this.phantom,
noDefaultLights: this.noDefaultLights,
featureLines: this.featureLines,
experimentalRenderingOptions: this.experimentalRenderingOptions,
featureHighlighting: this.featureHighlighting,
featureLines: this.featureLines,
featureMaps: this.featureMaps,
experimentalRenderingOptions: this.experimentalRenderingOptions,
selectionHighlighting: this.selectionHighlighting,
frames: {
frameBackgroundColor: this.getBackgroundColor(),
},
noDefaultLights: this.noDefaultLights,
phantom: this.phantom,
sceneComparison: this.sceneComparison,
selectionHighlighting: this.selectionHighlighting,
};
}

Expand Down
7 changes: 6 additions & 1 deletion packages/viewer/src/interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Euler, Matrix4, Quaternion, Vector3 } from '@vertexvis/geometry';
import { Color } from '@vertexvis/utils';
import { Color, UUID } from '@vertexvis/utils';

export type Color3 = Omit<Color.Color, 'a'> | string | number;

Expand Down Expand Up @@ -30,6 +30,10 @@ export interface FrameOptions {
frameBackgroundColor?: Color3;
}

export interface SceneComparisonOptions {
sceneIdToCompare?: UUID.UUID;
}

export interface HTMLDomRendererPositionableElement {
position: Vector3.Vector3;
positionJson: string;
Expand All @@ -52,4 +56,5 @@ export interface StreamAttributes {
experimentalRenderingOptions?: string;
selectionHighlighting?: SelectionHighlightingOptions;
frames?: FrameOptions;
sceneComparison?: SceneComparisonOptions;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { vertexvis } from '@vertexvis/frame-streaming-protos';
import { Color } from '@vertexvis/utils';
import { Color, UUID } from '@vertexvis/utils';
import Long from 'long';

import { random } from '../../../testing/random';
import { toPbStreamAttributes } from '../streamAttributes';

describe(toPbStreamAttributes, () => {
Expand Down Expand Up @@ -150,4 +152,25 @@ describe(toPbStreamAttributes, () => {
});
});
});

describe('scene comparison', () => {
it('enables comparing scenes if set', () => {
const sceneId = random.guid();
const sceneId2l = UUID.toMsbLsb(sceneId);

const res = toPbStreamAttributes({
sceneComparison: {
sceneIdToCompare: sceneId,
},
});
expect(res).toMatchObject({
sceneComparison: {
sceneIdToCompare: {
msb: Long.fromString(sceneId2l.msb),
lsb: Long.fromString(sceneId2l.lsb),
},
},
});
});
});
});
18 changes: 16 additions & 2 deletions packages/viewer/src/lib/mappers/streamAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
FrameOptions,
FrameType,
PhantomOptions,
SceneComparisonOptions,
SelectionHighlightingOptions,
StreamAttributes,
} from '../../interfaces';
import { toPbJsUuid2l } from './corePbJs';
import { toPbRGBi } from './material';
import { toPbFloatValue } from './scalar';

Expand Down Expand Up @@ -115,6 +117,16 @@ const toPbFrameOptions: M.Func<
([frameBackgroundColor]) => ({ frameBackgroundColor })
);

const toPbSceneComparison: M.Func<
SceneComparisonOptions | undefined,
vertexvis.protobuf.stream.ISceneComparisonAttributes
> = M.defineMapper(
M.read(M.ifDefined(M.mapProp('sceneIdToCompare', M.ifDefined(toPbJsUuid2l)))),
([sceneIdToCompare]) => ({
sceneIdToCompare,
})
);

export const toPbStreamAttributes: M.Func<
StreamAttributes,
vertexvis.protobuf.stream.IStreamAttributes
Expand All @@ -128,9 +140,10 @@ export const toPbStreamAttributes: M.Func<
M.mapProp('featureMaps', toPbFrameType),
M.mapProp('experimentalRenderingOptions', toPbExperimentalRenderingOptions),
M.mapProp('selectionHighlighting', toPbSelectionHighlighting),
M.mapProp('frames', toPbFrameOptions)
M.mapProp('frames', toPbFrameOptions),
M.mapProp('sceneComparison', toPbSceneComparison)
),
([db, pi, ndl, fl, fh, fm, ero, hs, fa]) => {
([db, pi, ndl, fl, fh, fm, ero, hs, fa, sc]) => {
const value = {
depthBuffers: db,
phantomItems: pi,
Expand All @@ -141,6 +154,7 @@ export const toPbStreamAttributes: M.Func<
experimentalRenderingOptions: ero,
selectionHighlighting: hs,
frames: fa,
sceneComparison: sc,
};

return value;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2210,10 +2210,10 @@
eslint-plugin-simple-import-sort "^7.0.0"
prettier "^2.5.1"

"@vertexvis/frame-streaming-protos@^0.13.2":
version "0.13.9"
resolved "https://registry.yarnpkg.com/@vertexvis/frame-streaming-protos/-/frame-streaming-protos-0.13.9.tgz#250c9bec3fbe1abc927f8bd3f3eb4dd505cee18b"
integrity sha512-oozmHFz8fTIPIK7iph1EhfErhm52aQSwFXRHxbpu+cfZxM1QDpgURhvotqsC+sSAXuWXvH716ypRhrNZ/EP6VA==
"@vertexvis/frame-streaming-protos@^0.13.11":
version "0.13.11"
resolved "https://registry.yarnpkg.com/@vertexvis/frame-streaming-protos/-/frame-streaming-protos-0.13.11.tgz#a18b01e7f9fc3ec5b933fb73a58ebf032a7f9197"
integrity sha512-y2L3+N4Zm7RxeV+hYB8h1ktISMg0aJi7VzJNIFwWkljnGs+MSHIeykWErRw6el/UGqauZnwo8Sm6cOlgrcetcg==

"@vertexvis/jest-config-vertexvis@^0.5.4":
version "0.5.4"
Expand Down

0 comments on commit 236fed5

Please sign in to comment.