"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var THREE = _interopRequireWildcard(require("three"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
class PointCloudNode extends THREE.EventDispatcher {
  constructor() {
    let numPoints = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
    let layer = arguments.length > 1 ? arguments[1] : undefined;
    super();
    this.numPoints = numPoints;
    this.layer = layer;
    this.children = [];
    this.bbox = new THREE.Box3();
    this.sse = -1;
  }
  add(node, indexChild) {
    this.children.push(node);
    node.parent = this;
    this.createChildAABB(node, indexChild);
  }
  load() {
    // Query octree/HRC if we don't have children potreeNode yet.
    if (!this.octreeIsLoaded) {
      this.loadOctree();
    }
    return this.layer.source.fetcher(this.url, this.layer.source.networkOptions).then(file => this.layer.source.parse(file, {
      out: this.layer,
      in: this.layer.source
    }));
  }
  findCommonAncestor(node) {
    if (node.depth == this.depth) {
      if (node.id == this.id) {
        return node;
      } else if (node.depth != 0) {
        return this.parent.findCommonAncestor(node.parent);
      }
    } else if (node.depth < this.depth) {
      return this.parent.findCommonAncestor(node);
    } else {
      return this.findCommonAncestor(node.parent);
    }
  }
}
var _default = PointCloudNode;
exports.default = _default;