Skip to content

Commit

Permalink
Merge pull request #69 from FormantIO/DEV-8264
Browse files Browse the repository at this point in the history
DEV-8264 - Enable realtime pointcloud and improvements to subscription
  • Loading branch information
andrey-mazepas authored May 21, 2024
2 parents e3d812d + a44d270 commit dfa79e3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
6 changes: 6 additions & 0 deletions public/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@
["visualizationType", "=", "Points of interest"]
]
},
"pointCloudRealtimeStream": {
"title": "Realtime stream",
"type": "string",
"description": "Optional, will override the telemetry stream if set.",
"$formant.visible.when": ["visualizationType", "=", "Point cloud"]
},
"telemetryLatestDataPoint": {
"title": "Use historical data",
"type": "boolean",
Expand Down
10 changes: 7 additions & 3 deletions src/Viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Universe } from "./layers/common/Universe";
import { UniverseDataContext } from "./layers/common/UniverseDataContext";
import { useCallback, useEffect, useRef, useState } from "react";
import { Authentication, App as FormantApp } from "@formant/data-sdk";
import { Authentication, App as FormantApp, Fleet } from "@formant/data-sdk";
import { Viewer3DConfiguration } from "./config";
import { definedAndNotNull, IUniverseData } from "@formant/data-sdk";
import {
Expand All @@ -20,6 +20,7 @@ export function Viewer() {
const [configuration, setConfiguration] = useState<
Viewer3DConfiguration | undefined
>();
const [deviceConfig, setDeviceConfig] = useState<any>();
const [universeData] = useState<IUniverseData>(
() => new TelemetryUniverseData()
);
Expand All @@ -33,10 +34,13 @@ export function Viewer() {
(async () => {
await Authentication.waitTilAuthenticated();
const currentConfig = await FormantApp.getCurrentModuleConfiguration();
if (currentConfig) {
const device = await Fleet.getDevice(currentDeviceId);
const deviceConfig = await device.getConfiguration();
if (currentConfig && deviceConfig) {
const parsedConfig = JSON.parse(currentConfig) as Viewer3DConfiguration;
if (checkConfiguration(parsedConfig)) {
setConfiguration(parsedConfig);
setDeviceConfig(deviceConfig);
}
}
setAuthenticated(true);
Expand Down Expand Up @@ -107,7 +111,7 @@ export function Viewer() {
key={getUuidByString(JSON.stringify(config))}
config={config}
>
{buildScene(config, definedAndNotNull(currentDeviceId))}
{buildScene(config, definedAndNotNull(currentDeviceId), deviceConfig)}
<group>
<pointLight
position={[1000, 1000, 1000]}
Expand Down
15 changes: 13 additions & 2 deletions src/buildScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { UniverseTelemetrySource } from "@formant/data-sdk";

import {
getRealtimeJointStateDataSource,
getRealtimePointCloudDataSource,
getTeletryJointStateDataSource,
parseDataSource,
parsePositioning,
Expand Down Expand Up @@ -29,7 +30,8 @@ import { definedAndNotNull } from "./common/defined";

export function buildScene(
config: Viewer3DConfiguration,
currentDeviceId: string
currentDeviceId: string,
deviceConfig: any
): React.ReactNode {
const devices: React.ReactNode[] = [];
let deviceLayers: React.ReactNode[] = [];
Expand Down Expand Up @@ -148,7 +150,16 @@ export function buildScene(
/>
);
} else if (layer.visualizationType === "Point cloud") {
const dataSource = parseDataSource(layer);
const rtcDataSource = layer.pointCloudRealtimeStream;
let dataSource;
if (rtcDataSource) {
dataSource = getRealtimePointCloudDataSource(layer);
} else {
dataSource = parseDataSource(layer);
const streamType = deviceConfig.telemetry.streams.find(s => s.name === layer.telemetryStreamName)?.configuration.type === "ros-localization" ? "localization" : "point cloud";
dataSource.streamType = streamType;
}

const { pointCloudDecayTime, pointCloudUseColors } = layer;
deviceLayers.push(
<PointCloudLayer
Expand Down
14 changes: 14 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type Viewer3DVisualization = {
jointStateTelemetryStreamName?: string;
geometryAllowTransparency?: boolean;
realtimeJointStateStream?: string;
pointCloudRealtimeStream?: string;
markerSize?: number;
markerSizeType?: "dynamic" | "static";
pointCloudDecayTime?: number;
Expand Down Expand Up @@ -110,6 +111,19 @@ export function parseDataSource(
return undefined;
}

export function getRealtimePointCloudDataSource(
vizLayer: Viewer3DVisualization
): UniverseDataSource | undefined {
if (vizLayer.pointCloudRealtimeStream) {
return DataSourceBuilder.realtime(
vizLayer.pointCloudRealtimeStream,
"point cloud"
);
}

return undefined;
}

export function getRealtimeJointStateDataSource(
vizLayer: Viewer3DVisualization
): UniverseDataSource | undefined {
Expand Down
3 changes: 2 additions & 1 deletion src/layers/PointCloudLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ export const PointCloudLayer = (props: IPointCloudProps) => {
let timer: number = 0;
let isReady = false;
if (dataSource) {
const unsubscribe = universeData.subscribeToPointCloud(

const unsubscribe = (dataSource.sourceType === "realtime" ? liveUniverseData : universeData).subscribeToPointCloud(
deviceId,
dataSource,
(data: IUniversePointCloud | Symbol) => {
Expand Down

0 comments on commit dfa79e3

Please sign in to comment.