All files / src/views/threejs/cad discardSector.ts

100% Statements 17/17
90% Branches 9/10
100% Functions 4/4
100% Lines 14/14

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        2x 2x   2x 5x 4x 2x 2x   2x 1x   2x 1x 2x       5x 4x    
/*!
 * Copyright 2020 Cognite AS
 */
 
import { SectorNode } from './SectorNode';
import * as THREE from 'three';
 
export function discardSector(_sectorId: number, sectorNode: SectorNode) {
  const meshes: THREE.Mesh[] = sectorNode.children.filter(x => x instanceof THREE.Mesh).map(x => x as THREE.Mesh);
  for (const mesh of meshes) {
    Eif (mesh.geometry) {
      mesh.geometry.dispose();
    }
    if (mesh.material && mesh.material instanceof THREE.Material) {
      mesh.material.dispose();
    }
    if (mesh.material && mesh.material instanceof Array) {
      for (const material of mesh.material) {
        material.dispose();
      }
    }
  }
  const sectorChildren = sectorNode.children.filter(x => !(x instanceof SectorNode));
  sectorNode.remove(...sectorChildren);
}