Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 3x 3x 3x 11x 6x 7x | /*!
* Copyright 2020 Cognite AS
*/
import { mat4 } from 'gl-matrix';
import { FetchPointCloudDelegate } from '../../../models/pointclouds/delegates';
import { SectorModelTransformation } from '../../../models/cad/types';
import { EptLoader } from '../../../utils/potree/EptLoader';
import { PointCloudModel } from '../../../models/pointclouds/PointCloudModel';
import { CogniteClient } from '@cognite/sdk';
import {
CogniteClient3dExtensions,
CogniteWellknown3dFormat,
CogniteUniformId
} from '../../../utils/CogniteClient3dExtensions';
// @ts-ignore
import * as Potree from '@cognite/potree-core';
const identity = mat4.identity(mat4.create());
export async function createPointCloudModel(
sdk: CogniteClient,
modelRevisionId: CogniteUniformId
): Promise<PointCloudModel> {
initializeXhrRequestHeaders(sdk);
const baseUrl = sdk.getBaseUrl();
const sdkExtensions = new CogniteClient3dExtensions(sdk);
const outputs = await sdkExtensions.getOutputs(modelRevisionId, [CogniteWellknown3dFormat.EptPointCloud]);
const mostRecentEptOutput = outputs.findMostRecentOutput(CogniteWellknown3dFormat.EptPointCloud);
Iif (!mostRecentEptOutput) {
throw new Error(`No point cloud output found for model ${modelRevisionId}`);
}
const url = baseUrl + sdkExtensions.buildBlobBaseUrl(mostRecentEptOutput.blobId) + '/ept.json';
const loaderPromise = EptLoader.load(url);
const fetchPointCloud: FetchPointCloudDelegate = async () => {
const transform: SectorModelTransformation = {
modelMatrix: identity,
inverseModelMatrix: identity
};
return [await loaderPromise, transform];
};
return [fetchPointCloud];
}
function initializeXhrRequestHeaders(sdk: CogniteClient) {
const sdkHeaders = sdk.getDefaultRequestHeaders();
let xhrHeaders: { header: string; value: string }[] = Potree.XHRFactory.config.customHeaders;
for (const [header, value] of Object.entries(sdkHeaders)) {
xhrHeaders = xhrHeaders.filter(x => x.header !== header);
xhrHeaders.push({ header, value });
}
Potree.XHRFactory.config.customHeaders = xhrHeaders.filter(x => x.header);
}
|