/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{isSome as o}from"../../../../../core/arrayUtils.js";import{isAborted as e,throwIfAborted as n}from"../../../../../core/promiseUtils.js";import{create as t}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{empty as s,expandWithVec3 as i,center as r,diameter as c}from"../../../../../geometry/support/aaBoundingBox.js";import{getEmissions as u}from"../../effects/emissive/emissions.js";import{LodComponentData as a}from"./LodComponentData.js";class m{static async create(t,s,i){const r=await Promise.allSettled(s.components.map(o=>t.controller.schedule(()=>new a(t,o.geometry),i))),c=r.map(o=>"fulfilled"===o.status?o.value:null).filter(o);if(e(i)||c.length!==r.length){c.forEach(o=>o.destroy()),n(i);for(const o of r)if("rejected"===o.status)throw o.reason}return new m(s.minScreenSpaceRadius,c)}constructor(o,e){this.minScreenSpaceRadius=o,this.components=e}destroy(){this.components.forEach(o=>o.destroy())}intersect(o,e,n,t,s,i,r){this.components.forEach(c=>c.intersect(o,e,n,t,s,i,this.boundingSphere,r))}get boundingBox(){if(null==this._boundingBox){const o=s();this.components.forEach(e=>{null!=e.boundingInfo&&(i(o,e.boundingInfo.bbMin),i(o,e.boundingInfo.bbMax))}),this._boundingBox=o}return this._boundingBox}get boundingSphere(){if(null==this._boundingSphere){const o=this.boundingBox,e=t();r(o,e),this._boundingSphere={center:e,radius:.5*c(o)}}return this._boundingSphere}get triangleCount(){return this.components.reduce((o,e)=>o+e.numTriangles,0)}get emissions(){return u(this.components)}}export{m as LodLevel};
