From bfa4c5f622d2e4e53e3babdca292904da1c52f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Fri, 6 May 2022 15:42:32 +0200 Subject: [PATCH] refactor: let EPT loader take non-hardcoded object list --- .../pointclouds/src/CognitePointCloudModel.ts | 9 ++++---- .../pointclouds/src/PointCloudFactory.ts | 16 +++++++++----- .../pointclouds/src/PointCloudManager.ts | 3 ++- .../pointclouds/src/PointCloudNode.ts | 21 ++++++------------ .../pointclouds/src/PotreeNodeWrapper.ts | 14 +++++++++++- .../src/potree-three-loader/Potree.ts | 5 +++-- .../geometry/PointCloudEptGeometry.ts | 7 ++++-- .../loading/EptBinaryLoader.ts | 22 +++++++++++-------- .../potree-three-loader/loading/EptLoader.ts | 6 +++-- .../rendering/PointCloudMaterial.ts | 7 ++++-- .../src/potree-three-loader/types/IPotree.ts | 3 ++- .../workers/assignObjects.ts | 22 +++++++++---------- .../workers/eptBinaryDecoder.worker.ts | 14 ++++++------ .../potree-three-loader/workers/parseEpt.ts | 17 ++++++-------- .../{StyleObject.ts => StyledObject.ts} | 6 ++--- .../src/styling/StyledObjectInfo.ts | 9 ++++++++ .../src/styling/shapes/AxisAlignedBox.ts | 2 +- .../src/styling/shapes/CompositeShape.ts | 2 +- .../src/styling/shapes/Cylinder.ts | 5 ++--- .../src/styling/shapes/IRawShape.ts | 2 +- .../src/styling/shapes/fromRawShape.ts | 7 ++---- .../pointclouds/src/styling/shapes/linalg.ts | 21 +++++++++--------- .../pointclouds/src/styling/staticObjects.ts | 12 ++++++---- 23 files changed, 132 insertions(+), 100 deletions(-) rename viewer/packages/pointclouds/src/styling/{StyleObject.ts => StyledObject.ts} (72%) create mode 100644 viewer/packages/pointclouds/src/styling/StyledObjectInfo.ts diff --git a/viewer/packages/pointclouds/src/CognitePointCloudModel.ts b/viewer/packages/pointclouds/src/CognitePointCloudModel.ts index 3aef432e4c3..61d34f3e16f 100644 --- a/viewer/packages/pointclouds/src/CognitePointCloudModel.ts +++ b/viewer/packages/pointclouds/src/CognitePointCloudModel.ts @@ -10,7 +10,7 @@ import { PointCloudNode } from './PointCloudNode'; import { PotreePointColorType, PotreePointShape, PotreePointSizeType } from './potree-three-loader'; import { SupportedModelTypes, CogniteModelBase } from '@reveal/model-base'; -import { RawStyleObject } from './styling/StyleObject'; +import { RawStyledObject } from './styling/StyledObject'; /** * Represents a point clouds model loaded from CDF. @@ -213,15 +213,14 @@ export class CognitePointCloudModel extends THREE.Object3D implements CogniteMod /** * Gets the stylable objects associated with this point cloud. */ - get stylableObjects(): RawStyleObject[] { - return this.pointCloudNode.objects; + get stylableObjects(): RawStyledObject[] { + return this.pointCloudNode.stylingInfo.styledObjects; } /** * Sets the style of one object */ - setObjectStyle(objectId: number, color: [number, number, number]) { + setObjectStyle(objectId: number, color: [number, number, number]): void { this.pointCloudNode.setObjectStyle(objectId, color); } - } diff --git a/viewer/packages/pointclouds/src/PointCloudFactory.ts b/viewer/packages/pointclouds/src/PointCloudFactory.ts index 870196909b4..b9923fb89bb 100644 --- a/viewer/packages/pointclouds/src/PointCloudFactory.ts +++ b/viewer/packages/pointclouds/src/PointCloudFactory.ts @@ -8,6 +8,7 @@ import { PointCloudMetadata } from './PointCloudMetadata'; import { ModelDataProvider } from '@reveal/modeldata-api'; import { PointCloudOctree, Potree } from './potree-three-loader'; +import { StyledObjectInfo } from './styling/StyledObjectInfo'; export class PointCloudFactory { private readonly _potreeInstance: Potree; @@ -20,12 +21,17 @@ export class PointCloudFactory { return this._potreeInstance; } - async createModel(modelMetadata: PointCloudMetadata): Promise { + async createModel( + modelMetadata: PointCloudMetadata, + styledObjectInfo?: StyledObjectInfo + ): Promise { const { modelBaseUrl } = modelMetadata; - return this._potreeInstance.loadPointCloud(modelBaseUrl, 'ept.json').then((pco: PointCloudOctree) => { - pco.name = `PointCloudOctree: ${modelBaseUrl}`; - return new PotreeNodeWrapper(pco); - }); + return this._potreeInstance + .loadPointCloud(modelBaseUrl, 'ept.json', styledObjectInfo) + .then((pco: PointCloudOctree) => { + pco.name = `PointCloudOctree: ${modelBaseUrl}`; + return new PotreeNodeWrapper(pco, styledObjectInfo); + }); } } diff --git a/viewer/packages/pointclouds/src/PointCloudManager.ts b/viewer/packages/pointclouds/src/PointCloudManager.ts index 66dbf72cecb..4c3dea5c4f6 100644 --- a/viewer/packages/pointclouds/src/PointCloudManager.ts +++ b/viewer/packages/pointclouds/src/PointCloudManager.ts @@ -18,6 +18,7 @@ import { asyncScheduler, combineLatest, Observable, scan, Subject, throttleTime import { ModelIdentifier } from '@reveal/modeldata-api'; import { MetricsLogger } from '@reveal/metrics'; import { SupportedModelTypes } from '@reveal/model-base'; +import { hardCodedObjects } from './styling/staticObjects'; export class PointCloudManager { private readonly _pointCloudMetadataRepository: PointCloudMetadataRepository; @@ -129,7 +130,7 @@ export class PointCloudManager { metadata.formatVersion ); - const nodeWrapper = await this._pointCloudFactory.createModel(metadata); + const nodeWrapper = await this._pointCloudFactory.createModel(metadata, hardCodedObjects); this._pointCloudGroupWrapper.addPointCloud(nodeWrapper); const node = new PointCloudNode(this._pointCloudGroupWrapper, nodeWrapper, metadata.cameraConfiguration); node.setModelTransformation(metadata.modelMatrix); diff --git a/viewer/packages/pointclouds/src/PointCloudNode.ts b/viewer/packages/pointclouds/src/PointCloudNode.ts index bb2a07f267e..2ae6c7a6739 100644 --- a/viewer/packages/pointclouds/src/PointCloudNode.ts +++ b/viewer/packages/pointclouds/src/PointCloudNode.ts @@ -10,10 +10,9 @@ import { PotreeNodeWrapper } from './PotreeNodeWrapper'; import { WellKnownAsprsPointClassCodes } from './types'; import { createPointClassKey } from './createPointClassKey'; -import { RawStyleObject } from './styling/StyleObject'; - import { PotreePointColorType, PotreePointShape, PotreePointSizeType } from './potree-three-loader'; -import { hardCodedObjects } from './styling/staticObjects'; + +import { StyledObjectInfo } from './styling/StyledObjectInfo'; const PotreeDefaultPointClass = 'DEFAULT'; @@ -21,7 +20,6 @@ export class PointCloudNode extends THREE.Group { private readonly _potreeGroup: PotreeGroupWrapper; private readonly _potreeNode: PotreeNodeWrapper; private readonly _cameraConfiguration?: CameraConfiguration; - private readonly _objects: RawStyleObject[]; constructor( potreeGroup: PotreeGroupWrapper, @@ -34,8 +32,7 @@ export class PointCloudNode extends THREE.Group { this._potreeNode = potreeNode; this._cameraConfiguration = cameraConfiguration; this.add(this._potreeNode.octree); - - this._objects = this.loadObjects(); + this._potreeNode.octree; this.matrixAutoUpdate = false; } @@ -100,12 +97,12 @@ export class PointCloudNode extends THREE.Group { this._potreeNode.pointShape = value; } - get objects(): RawStyleObject[] { - return this._objects; + get stylingInfo(): StyledObjectInfo { + return this._potreeNode.styledObjectInfo; } - setObjectStyle(objectId: number, color: [number, number, number]) { - this.potreeNode.octree.material.setObjectColor(objectId, new THREE.Color(color[0], color[1], color[2])); + setObjectStyle(objectId: number, color: [number, number, number]): void { + this.potreeNode.setObjectStyle(objectId, color); this.requestRedraw(); } @@ -174,8 +171,4 @@ export class PointCloudNode extends THREE.Group { getModelTransformation(out = new THREE.Matrix4()): THREE.Matrix4 { return out.copy(this.matrix); } - - loadObjects(): RawStyleObject[] { - return hardCodedObjects; - } } diff --git a/viewer/packages/pointclouds/src/PotreeNodeWrapper.ts b/viewer/packages/pointclouds/src/PotreeNodeWrapper.ts index e68023cb41e..35ff5b0a5b7 100644 --- a/viewer/packages/pointclouds/src/PotreeNodeWrapper.ts +++ b/viewer/packages/pointclouds/src/PotreeNodeWrapper.ts @@ -10,6 +10,7 @@ import { PointCloudOctree, PotreePointColorType, PotreePointShape, IClassificati import { WellKnownAsprsPointClassCodes } from './types'; import { createPointClassKey } from './createPointClassKey'; +import { StyledObjectInfo } from './styling/StyledObjectInfo'; /** * Wrapper around `Potree.PointCloudOctree` with some convenience functions. @@ -18,17 +19,19 @@ export class PotreeNodeWrapper { readonly octree: PointCloudOctree; private _needsRedraw = false; private readonly _classification: IClassification = {} as IClassification; + private readonly _styledObjectInfo: StyledObjectInfo | undefined; get needsRedraw(): boolean { return this._needsRedraw; } - constructor(octree: PointCloudOctree) { + constructor(octree: PointCloudOctree, styledObjectInfo: StyledObjectInfo) { this.octree = octree; this.pointSize = 2; this.pointColorType = PotreePointColorType.Rgb; this.pointShape = PotreePointShape.Circle; this._classification = octree.material.classification; + this._styledObjectInfo = styledObjectInfo; } get pointSize(): number { @@ -72,6 +75,15 @@ export class PotreeNodeWrapper { return this._classification; } + get styledObjectInfo(): StyledObjectInfo { + return this._styledObjectInfo; + } + + setObjectStyle(objectId: number, color: [number, number, number]): void { + this.octree.material.setObjectColor(objectId, new THREE.Color(color[0], color[1], color[2])); + this._needsRedraw = true; + } + setClassificationAndRecompute(pointClass: number | WellKnownAsprsPointClassCodes, visible: boolean): void { const key = createPointClassKey(pointClass); diff --git a/viewer/packages/pointclouds/src/potree-three-loader/Potree.ts b/viewer/packages/pointclouds/src/potree-three-loader/Potree.ts index 9604644f379..5afc72b0dc2 100644 --- a/viewer/packages/pointclouds/src/potree-three-loader/Potree.ts +++ b/viewer/packages/pointclouds/src/potree-three-loader/Potree.ts @@ -33,6 +33,7 @@ import { BinaryHeap } from './utils/BinaryHeap'; import { Box3Helper } from './utils/box3-helper'; import { LRU } from './utils/lru'; import { ModelDataProvider } from '@reveal/modeldata-api'; +import { StyledObjectInfo } from '../styling/StyledObjectInfo'; export class QueueItem { constructor( @@ -60,9 +61,9 @@ export class Potree implements IPotree { async loadPointCloud( baseUrl: string, fileName: string, - _xhrRequest = (input: RequestInfo, init?: RequestInit) => fetch(input, init) + styledObjectInfo?: StyledObjectInfo ): Promise { - return EptLoader.load(baseUrl, fileName, this._modelDataProvider).then( + return EptLoader.load(baseUrl, fileName, this._modelDataProvider, styledObjectInfo).then( geometry => new PointCloudOctree(this, geometry) ); } diff --git a/viewer/packages/pointclouds/src/potree-three-loader/geometry/PointCloudEptGeometry.ts b/viewer/packages/pointclouds/src/potree-three-loader/geometry/PointCloudEptGeometry.ts index a6d6838b2e5..3fb9a83dd45 100644 --- a/viewer/packages/pointclouds/src/potree-three-loader/geometry/PointCloudEptGeometry.ts +++ b/viewer/packages/pointclouds/src/potree-three-loader/geometry/PointCloudEptGeometry.ts @@ -15,6 +15,7 @@ import { IPointCloudTreeGeometry } from './IPointCloudTreeGeometry'; import proj4 from 'proj4'; import { ModelDataProvider } from '@reveal/modeldata-api'; import { toVector3, toBox3 } from './translationUtils'; +import { StyledObjectInfo } from '../../styling/StyledObjectInfo'; type EptSchemaEntry = { name: string; @@ -52,6 +53,8 @@ export class PointCloudEptGeometry implements IPointCloudTreeGeometry { private readonly _projection: string | null; + private readonly _styledObjectInfo: StyledObjectInfo | undefined; + get root(): PointCloudEptGeometryNode | undefined { return this._root; } @@ -96,7 +99,7 @@ export class PointCloudEptGeometry implements IPointCloudTreeGeometry { return this._loader; } - constructor(url: string, info: any, dataLoader: ModelDataProvider) { + constructor(url: string, info: any, dataLoader: ModelDataProvider, styledInfo?: StyledObjectInfo) { const schema = info.schema; const bounds = info.bounds; const boundsConforming = info.boundsConforming; @@ -142,7 +145,7 @@ export class PointCloudEptGeometry implements IPointCloudTreeGeometry { throw new Error('Could not read data type: ' + info.dataType); } - this._loader = new EptBinaryLoader(dataLoader); + this._loader = new EptBinaryLoader(dataLoader, styledInfo); } dispose(): void {} diff --git a/viewer/packages/pointclouds/src/potree-three-loader/loading/EptBinaryLoader.ts b/viewer/packages/pointclouds/src/potree-three-loader/loading/EptBinaryLoader.ts index 8b23971c905..0a794c5daa7 100644 --- a/viewer/packages/pointclouds/src/potree-three-loader/loading/EptBinaryLoader.ts +++ b/viewer/packages/pointclouds/src/potree-three-loader/loading/EptBinaryLoader.ts @@ -15,10 +15,11 @@ import { ParseCommand, ObjectsCommand } from '../workers/eptBinaryDecoder.worker import { ParsedEptData, EptInputData } from '../workers/parseEpt'; -import { hardCodedObjects } from '../../styling/staticObjects'; +import { StyledObjectInfo } from '../../styling/StyledObjectInfo'; export class EptBinaryLoader implements ILoader { private readonly _dataLoader: ModelDataProvider; + private readonly _styledObjectInfo: StyledObjectInfo | undefined; static readonly WORKER_POOL = new WorkerPool(32, EptDecoderWorker); @@ -26,8 +27,9 @@ export class EptBinaryLoader implements ILoader { return '.bin'; } - constructor(dataLoader: ModelDataProvider) { + constructor(dataLoader: ModelDataProvider, styledObjectInfo?: StyledObjectInfo) { this._dataLoader = dataLoader; + this._styledObjectInfo = styledObjectInfo; } async load(node: PointCloudEptGeometryNode): Promise { @@ -103,15 +105,17 @@ export class EptBinaryLoader implements ILoader { mins: toArray(node.key.b.min) }; - const offsetVec = node.boundingBox.min; + if (this._styledObjectInfo) { + const offsetVec = node.boundingBox.min; - const objectMessage: ObjectsCommand = { - type: 'objects', - objects: hardCodedObjects, - pointOffset: [offsetVec.x, offsetVec.y, offsetVec.z] as [number, number, number] - }; + const objectMessage: ObjectsCommand = { + type: 'objects', + objects: this._styledObjectInfo.styledObjects, + pointOffset: [offsetVec.x, offsetVec.y, offsetVec.z] as [number, number, number] + }; - autoTerminatingWorker.worker.postMessage(objectMessage); + autoTerminatingWorker.worker.postMessage(objectMessage); + } const parseMessage: ParseCommand = { type: 'parse', diff --git a/viewer/packages/pointclouds/src/potree-three-loader/loading/EptLoader.ts b/viewer/packages/pointclouds/src/potree-three-loader/loading/EptLoader.ts index 2f69b5541c3..339558f0c75 100644 --- a/viewer/packages/pointclouds/src/potree-three-loader/loading/EptLoader.ts +++ b/viewer/packages/pointclouds/src/potree-three-loader/loading/EptLoader.ts @@ -1,4 +1,5 @@ import { ModelDataProvider } from '@reveal/modeldata-api'; +import { StyledObjectInfo } from '../../styling/StyledObjectInfo'; import { PointCloudEptGeometry } from '../geometry/PointCloudEptGeometry'; import { PointCloudEptGeometryNode } from '../geometry/PointCloudEptGeometryNode'; @@ -6,11 +7,12 @@ export class EptLoader { static async load( baseUrl: string, fileName: string, - modelDataProvider: ModelDataProvider + modelDataProvider: ModelDataProvider, + styledObjectInfo?: StyledObjectInfo ): Promise { return modelDataProvider.getJsonFile(baseUrl, fileName).then(async (json: any) => { const url = baseUrl + '/'; - const geometry = new PointCloudEptGeometry(url, json, modelDataProvider); + const geometry = new PointCloudEptGeometry(url, json, modelDataProvider, styledObjectInfo); const root = new PointCloudEptGeometryNode(geometry, modelDataProvider); geometry.root = root; diff --git a/viewer/packages/pointclouds/src/potree-three-loader/rendering/PointCloudMaterial.ts b/viewer/packages/pointclouds/src/potree-three-loader/rendering/PointCloudMaterial.ts index 9dffc955789..246c0b7ecf4 100644 --- a/viewer/packages/pointclouds/src/potree-three-loader/rendering/PointCloudMaterial.ts +++ b/viewer/packages/pointclouds/src/potree-three-loader/rendering/PointCloudMaterial.ts @@ -179,8 +179,11 @@ export class PointCloudMaterial extends RawShaderMaterial { private readonly _gradient = SpectralGradient; private gradientTexture: Texture | undefined = generateGradientTexture(this._gradient); - private readonly _objectTexture: THREE.DataTexture = - generateDataTexture(OBJECT_STYLING_TEXTURE_WIDTH, OBJECT_STYLING_TEXTURE_HEIGHT, new Color(0x000000)); + private readonly _objectTexture: THREE.DataTexture = generateDataTexture( + OBJECT_STYLING_TEXTURE_WIDTH, + OBJECT_STYLING_TEXTURE_HEIGHT, + new Color(0x000000) + ); private _classification: IClassification = DEFAULT_CLASSIFICATION; private classificationTexture: Texture | undefined = generateClassificationTexture(this._classification); diff --git a/viewer/packages/pointclouds/src/potree-three-loader/types/IPotree.ts b/viewer/packages/pointclouds/src/potree-three-loader/types/IPotree.ts index 7853d680a2b..99b3e18e4f2 100644 --- a/viewer/packages/pointclouds/src/potree-three-loader/types/IPotree.ts +++ b/viewer/packages/pointclouds/src/potree-three-loader/types/IPotree.ts @@ -2,13 +2,14 @@ import { Camera, WebGLRenderer } from 'three'; import { LRU } from '../utils/lru'; import { PointCloudOctree } from '../tree/PointCloudOctree'; import { IVisibilityUpdateResult } from './IVisibilityUpdateResult'; +import { StyledObjectInfo } from '../../styling/StyledObjectInfo'; export interface IPotree { pointBudget: number; maxNumNodesLoading: number; lru: LRU; - loadPointCloud(baseUrl: string, fileName: string): Promise; + loadPointCloud(baseUrl: string, fileName: string, styledObjectInfo?: StyledObjectInfo): Promise; updatePointClouds(pointClouds: PointCloudOctree[], camera: Camera, renderer: WebGLRenderer): IVisibilityUpdateResult; } diff --git a/viewer/packages/pointclouds/src/potree-three-loader/workers/assignObjects.ts b/viewer/packages/pointclouds/src/potree-three-loader/workers/assignObjects.ts index 866b33691e7..ee20fab9790 100644 --- a/viewer/packages/pointclouds/src/potree-three-loader/workers/assignObjects.ts +++ b/viewer/packages/pointclouds/src/potree-three-loader/workers/assignObjects.ts @@ -2,25 +2,25 @@ * Copyright 2022 Cognite AS */ -import { StyleObject } from '../../styling/StyleObject'; +import { StyledObject } from '../../styling/StyledObject'; import { Vec3, v3Add } from '../../styling/shapes/linalg'; -export function computeObjectIdBuffer(positionBuffer: Float32Array, - objectList: StyleObject[], - pointOffset: Vec3): ArrayBuffer { - const rawArrayBuffer = new ArrayBuffer(2 * positionBuffer.length / 3); +export function computeObjectIdBuffer( + positionBuffer: Float32Array, + objectList: StyledObject[], + pointOffset: Vec3 +): ArrayBuffer { + const rawArrayBuffer = new ArrayBuffer((2 * positionBuffer.length) / 3); const objectIdBuffer = new Uint16Array(rawArrayBuffer); for (let i = 0; i < objectIdBuffer.length; i++) { - // 0 is default / unassigned value objectIdBuffer[i] = 0; - const position: Vec3 = - v3Add([ positionBuffer[3 * i + 0], - positionBuffer[3 * i + 1], - positionBuffer[3 * i + 2] ], - pointOffset); + const position: Vec3 = v3Add( + [positionBuffer[3 * i + 0], positionBuffer[3 * i + 1], positionBuffer[3 * i + 2]], + pointOffset + ); for (const obj of objectList) { if (obj.shape.containsPoint(position)) { diff --git a/viewer/packages/pointclouds/src/potree-three-loader/workers/eptBinaryDecoder.worker.ts b/viewer/packages/pointclouds/src/potree-three-loader/workers/eptBinaryDecoder.worker.ts index 6398b9cb2bf..90571e328bd 100644 --- a/viewer/packages/pointclouds/src/potree-three-loader/workers/eptBinaryDecoder.worker.ts +++ b/viewer/packages/pointclouds/src/potree-three-loader/workers/eptBinaryDecoder.worker.ts @@ -2,32 +2,32 @@ * Copyright 2022 Cognite AS */ -import { RawStyleObject, StyleObject, rawToStyleObject } from '../../styling/StyleObject'; +import { RawStyledObject, StyledObject, rawToStyleObject } from '../../styling/StyledObject'; import { parseEpt, EptInputData } from './parseEpt'; import { Vec3 } from '../../styling/shapes/linalg'; const ctx: Worker = self as any; -let objectList: StyleObject[] = []; +let objectList: StyledObject[] = []; let pointOffset: Vec3 = [0, 0, 0]; type CommandType = 'objects' | 'parse'; export interface ICommand { type: CommandType; -}; +} export type ObjectsCommand = { type: 'objects'; - objects: RawStyleObject[]; + objects: RawStyledObject[]; pointOffset: Vec3; -} +}; export type ParseCommand = { type: 'parse'; data: EptInputData; -} +}; ctx.onmessage = function (event: MessageEvent) { const command = event.data as ICommand; @@ -43,7 +43,7 @@ ctx.onmessage = function (event: MessageEvent) { parseEpt(ctx, parseCommand.data, objectList, pointOffset); break; default: - console.error("Out of switch cases"); + console.error('Out of switch cases'); } }; diff --git a/viewer/packages/pointclouds/src/potree-three-loader/workers/parseEpt.ts b/viewer/packages/pointclouds/src/potree-three-loader/workers/parseEpt.ts index 5092093b467..d69ce1d3a41 100644 --- a/viewer/packages/pointclouds/src/potree-three-loader/workers/parseEpt.ts +++ b/viewer/packages/pointclouds/src/potree-three-loader/workers/parseEpt.ts @@ -1,4 +1,4 @@ -import { StyleObject } from '../../styling/StyleObject'; +import { StyledObject } from '../../styling/StyledObject'; import { Vec3 } from '../../styling/shapes/linalg'; import { computeObjectIdBuffer } from './assignObjects'; @@ -24,10 +24,10 @@ export type SchemaEntry = { }; type RawVector3 = { - x: number, - y: number, - z: number -} + x: number; + y: number; + z: number; +}; export type EptInputData = { buffer: ArrayBuffer; @@ -37,10 +37,7 @@ export type EptInputData = { mins: [number, number, number]; }; -export function parseEpt(worker: Worker, - data: EptInputData, - objects: StyleObject[], - pointOffset: Vec3): void { +export function parseEpt(worker: Worker, data: EptInputData, objects: StyledObject[], pointOffset: Vec3): void { const buffer = data.buffer; const view = new DataView(buffer); const schema: SchemaEntry[] = data.schema; @@ -264,7 +261,7 @@ export function parseEpt(worker: Worker, numberOfReturns: numberOfReturnsBuffer, pointSourceId: pointSourceIdBuffer, indices: indicesBuffer, - objectId: objectIdBuffer, + objectId: objectIdBuffer }; const transferables = [ diff --git a/viewer/packages/pointclouds/src/styling/StyleObject.ts b/viewer/packages/pointclouds/src/styling/StyledObject.ts similarity index 72% rename from viewer/packages/pointclouds/src/styling/StyleObject.ts rename to viewer/packages/pointclouds/src/styling/StyledObject.ts index e8f111ea698..3cd200ed45c 100644 --- a/viewer/packages/pointclouds/src/styling/StyleObject.ts +++ b/viewer/packages/pointclouds/src/styling/StyledObject.ts @@ -7,17 +7,17 @@ import { IRawShape } from './shapes/IRawShape'; import { fromRawShape } from './shapes/fromRawShape'; -export type RawStyleObject = { +export type RawStyledObject = { objectId: number; shape: IRawShape; }; -export type StyleObject = { +export type StyledObject = { objectId: number; shape: IShape; }; -export function rawToStyleObject(obj: RawStyleObject): StyleObject { +export function rawToStyleObject(obj: RawStyledObject): StyledObject { return { objectId: obj.objectId, shape: fromRawShape(obj.shape) diff --git a/viewer/packages/pointclouds/src/styling/StyledObjectInfo.ts b/viewer/packages/pointclouds/src/styling/StyledObjectInfo.ts new file mode 100644 index 00000000000..be19dd34c12 --- /dev/null +++ b/viewer/packages/pointclouds/src/styling/StyledObjectInfo.ts @@ -0,0 +1,9 @@ +/*! + * Copyright 2022 Cognite AS + */ + +import { RawStyledObject } from './StyledObject'; + +export type StyledObjectInfo = { + styledObjects: RawStyledObject[]; +}; diff --git a/viewer/packages/pointclouds/src/styling/shapes/AxisAlignedBox.ts b/viewer/packages/pointclouds/src/styling/shapes/AxisAlignedBox.ts index 09d71dd6a99..6ec339a4a16 100644 --- a/viewer/packages/pointclouds/src/styling/shapes/AxisAlignedBox.ts +++ b/viewer/packages/pointclouds/src/styling/shapes/AxisAlignedBox.ts @@ -40,6 +40,6 @@ export class AxisAlignedBox implements IShape { return { type: 'aabb', box: this._box - } + }; } } diff --git a/viewer/packages/pointclouds/src/styling/shapes/CompositeShape.ts b/viewer/packages/pointclouds/src/styling/shapes/CompositeShape.ts index fdeb8a7e7e7..b40b5bcf44c 100644 --- a/viewer/packages/pointclouds/src/styling/shapes/CompositeShape.ts +++ b/viewer/packages/pointclouds/src/styling/shapes/CompositeShape.ts @@ -42,6 +42,6 @@ export class CompositeShape implements IShape { return { type: 'composite', shapes: this._innerShapes.map(shape => shape.toRawShape()) - } + }; } } diff --git a/viewer/packages/pointclouds/src/styling/shapes/Cylinder.ts b/viewer/packages/pointclouds/src/styling/shapes/Cylinder.ts index 4e179850f25..4a4a1231593 100644 --- a/viewer/packages/pointclouds/src/styling/shapes/Cylinder.ts +++ b/viewer/packages/pointclouds/src/styling/shapes/Cylinder.ts @@ -46,7 +46,7 @@ export class Cylinder implements IShape { return v3Length(v3Sub(this._centerA, this._centerB)); } - private getMiddle(): Vec3{ + private getMiddle(): Vec3 { return v3Middle(this._centerA, this._centerB); } @@ -55,7 +55,6 @@ export class Cylinder implements IShape { } computeBoundingBox(): Box3 { - /* const halfHeight = this.getHalfHeight(); const middle = this.getMiddle(); @@ -72,7 +71,7 @@ export class Cylinder implements IShape { out.applyMatrix4(new THREE.Matrix4().makeRotationFromQuaternion(rotation)); out.translate(middle); return out; */ - throw Error("[Cylinder] Bounding box not yet implemented"); + throw Error('[Cylinder] Bounding box not yet implemented'); } containsPoint(point: Vec3): boolean { diff --git a/viewer/packages/pointclouds/src/styling/shapes/IRawShape.ts b/viewer/packages/pointclouds/src/styling/shapes/IRawShape.ts index 62e2d5be236..3ab37ac481b 100644 --- a/viewer/packages/pointclouds/src/styling/shapes/IRawShape.ts +++ b/viewer/packages/pointclouds/src/styling/shapes/IRawShape.ts @@ -6,4 +6,4 @@ export type ShapeType = 'cylinder' | 'aabb' | 'composite'; export interface IRawShape { type: ShapeType; -}; +} diff --git a/viewer/packages/pointclouds/src/styling/shapes/fromRawShape.ts b/viewer/packages/pointclouds/src/styling/shapes/fromRawShape.ts index a70b243cec5..68fe2eb7684 100644 --- a/viewer/packages/pointclouds/src/styling/shapes/fromRawShape.ts +++ b/viewer/packages/pointclouds/src/styling/shapes/fromRawShape.ts @@ -2,7 +2,6 @@ * Copyright 2022 Cognite AS */ - // import { toThreeBox3, toThreeVector3, assertNever } from '@reveal/utilities'; // import * as THREE from 'three'; @@ -22,9 +21,7 @@ export function fromRawShape(rawShape: IRawShape): IShape { switch (rawShape.type) { case 'cylinder': const rawCylinder = rawShape as RawCylinder; - return new Cylinder(rawCylinder.centerA, - rawCylinder.centerB, - rawCylinder.radius); + return new Cylinder(rawCylinder.centerA, rawCylinder.centerB, rawCylinder.radius); case 'aabb': const rawBox = rawShape as RawAxisAlignedBox; return new AxisAlignedBox(rawBox.box); @@ -33,6 +30,6 @@ export function fromRawShape(rawShape: IRawShape): IShape { return new CompositeShape(rawComposite.shapes.map(fromRawShape)); default: // assertNever(rawShape.type); - console.error("Unsupported RawShape type"); + console.error('Unsupported RawShape type'); } } diff --git a/viewer/packages/pointclouds/src/styling/shapes/linalg.ts b/viewer/packages/pointclouds/src/styling/shapes/linalg.ts index b24f8e724ea..d4959b0f7da 100644 --- a/viewer/packages/pointclouds/src/styling/shapes/linalg.ts +++ b/viewer/packages/pointclouds/src/styling/shapes/linalg.ts @@ -3,7 +3,7 @@ */ export type Vec3 = [number, number, number]; -export type Box3 = { min: Vec3, max: Vec3 }; +export type Box3 = { min: Vec3; max: Vec3 }; export function v3Scale(v: Vec3, f: number): Vec3 { return [v[0] * f, v[1] * f, v[2] * f]; @@ -34,21 +34,22 @@ export function v3Dot(v0: Vec3, v1: Vec3): number { } export function b3ContainsPoint(box: Box3, vec: Vec3): boolean { - return box.min[0] <= vec[0] && vec[0] < box.max[0] - && box.min[1] <= vec[1] && vec[1] < box.max[1] - && box.min[2] <= vec[2] && vec[2] < box.max[2]; + return ( + box.min[0] <= vec[0] && + vec[0] < box.max[0] && + box.min[1] <= vec[1] && + vec[1] < box.max[1] && + box.min[2] <= vec[2] && + vec[2] < box.max[2] + ); } function v3Max(v0: Vec3, v1: Vec3): Vec3 { - return [Math.max(v0[0], v1[0]), - Math.max(v0[1], v1[1]), - Math.max(v0[2], v1[2])]; + return [Math.max(v0[0], v1[0]), Math.max(v0[1], v1[1]), Math.max(v0[2], v1[2])]; } function v3Min(v0: Vec3, v1: Vec3): Vec3 { - return [Math.min(v0[0], v1[0]), - Math.min(v0[1], v1[1]), - Math.min(v0[2], v1[2])]; + return [Math.min(v0[0], v1[0]), Math.min(v0[1], v1[1]), Math.min(v0[2], v1[2])]; } export function b3Union(b0: Box3, b1: Box3): Box3 { diff --git a/viewer/packages/pointclouds/src/styling/staticObjects.ts b/viewer/packages/pointclouds/src/styling/staticObjects.ts index 37fb969c3e6..df0c1e3b78c 100644 --- a/viewer/packages/pointclouds/src/styling/staticObjects.ts +++ b/viewer/packages/pointclouds/src/styling/staticObjects.ts @@ -2,8 +2,7 @@ * Copyright 2022 Cognite AS */ -import { RawStyleObject } from './StyleObject'; -import { RawAxisAlignedBox } from './shapes/AxisAlignedBox'; +import { StyledObjectInfo } from './StyledObjectInfo'; import { RawCylinder } from './shapes/Cylinder'; import { externalObjects } from './data'; @@ -34,8 +33,13 @@ import { Vec3, v3Add, v3Sub, v3Scale } from './shapes/linalg'; } ]; */ - -export const hardCodedObjects: RawStyleObject[] = externalObjects.sort((a, b) => b.Height - a.Height).map((obj, index) => { return { objectId: index + 1, shape: transformObject(obj) } } ); +export const hardCodedObjects: StyledObjectInfo = { + styledObjects: externalObjects + .sort((a, b) => b.Height - a.Height) + .map((obj, index) => { + return { objectId: index + 1, shape: transformObject(obj) }; + }) +}; type ExtVec = { X: number;