All files / src/views/threejs/pointcloud createThreeJsPointCloudNode.ts

100% Statements 15/15
100% Branches 2/2
100% Functions 1/1
100% Lines 15/15

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          1x     1x 1x 1x   1x       3x 3x   2x 1x     2x 2x 2x 2x 2x   2x    
/*!
 * Copyright 2020 Cognite AS
 */
 
// @ts-ignore
import * as Potree from '@cognite/potree-core';
 
import { PointCloudModel } from '../../../models/pointclouds/PointCloudModel';
import { toThreeMatrix4 } from '../utilities';
import { PotreeGroupWrapper } from './PotreeGroupWrapper';
import { PotreeNodeWrapper } from './PotreeNodeWrapper';
 
export async function createThreeJsPointCloudNode(
  model: PointCloudModel,
  potreeGroup?: Potree.Group
): Promise<[PotreeGroupWrapper, PotreeNodeWrapper]> {
  const [fetchPointcloud] = model;
  const [geometry, transform] = await fetchPointcloud();
 
  if (!potreeGroup) {
    potreeGroup = new PotreeGroupWrapper();
  }
 
  const octtree = new Potree.PointCloudOctree(geometry);
  octtree.name = 'PointCloudOctree';
  octtree.applyMatrix(toThreeMatrix4(transform.modelMatrix));
  const node = new PotreeNodeWrapper(octtree);
  potreeGroup.addPointCloud(node);
 
  return [potreeGroup, node];
}