UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 1.42 kB
import{isSome as o,isNone as n}from"../../../../../core/maybe.js";import{isAborted as t,throwIfAborted as e}from"../../../../../core/promiseUtils.js";import{c as r}from"../../../../../chunks/vec3f64.js";import{empty as i,expandWithVec3 as s,center as c,diameter as u}from"../../../../../geometry/support/aaBoundingBox.js";import{LodComponentData as a}from"./LodComponentData.js";class h{static async create(n,r,i){const s=await Promise.allSettled(r.components.map((o=>n.controller.schedule((()=>new a(n,o)),i)))),c=s.map((o=>"fulfilled"===o.status?o.value:null)).filter(o);if(t(i)||c.length!==s.length){c.forEach((o=>o.destroy())),e(i);for(const o of s)if("rejected"===o.status)throw o.reason}return new h(r.minScreenSpaceRadius,c)}constructor(o,n){this.minScreenSpaceRadius=o,this.components=n}destroy(){this.components.forEach((o=>o.destroy()))}intersect(o,n,t,e,r,i,s){this.components.forEach((c=>c.intersect(o,n,t,e,r,i,this.boundingSphere,s)))}get boundingBox(){if(n(this._boundingBox)){const n=i();this.components.forEach((t=>{o(t.boundingInfo)&&(s(n,t.boundingInfo.bbMin),s(n,t.boundingInfo.bbMax))})),this._boundingBox=n}return this._boundingBox}get boundingSphere(){if(n(this._boundingSphere)){const o=this.boundingBox,n=r();c(o,n),this._boundingSphere={center:n,radius:.5*u(o)}}return this._boundingSphere}get triangleCount(){return this.components.reduce(((o,n)=>o+n.triangleCount),0)}}export{h as LodLevel};