/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import e from"../../core/Error.js";import{throwIfAborted as t,whenOrAbort as n,isPromiseLike as r}from"../../core/promiseUtils.js";import s from"../Mesh.js";import o from"./MeshComponent.js";import i from"./MeshGeoreferencedVertexSpace.js";import a from"./MeshTransform.js";import c from"./MeshVertexAttributes.js";import{selectVertexSpace as m}from"./meshVertexSpaceUtils.js";import{merge as l}from"./meshUtils/merge.js";import{Metadata as p}from"./meshUtils/Metadata.js";import{convertUnitGeometry as f,createUnitSizeSphere as u,createUnitSizeBox as w,extractSingleFaceOfBox as h,createUnitSizeCylinder as j,convertPlaneSizeParameter as d,createUnitSizePlane as v}from"./meshUtils/primitives.js";import{polygonToRenderInfoNotElevationAligned as x}from"../../views/3d/support/renderInfoUtils/polygon.js";async function M(e,n,r){const s=await import("./meshUtils/elevation.js");return t(r),s.create(e,n,r)}async function g(e,t){await e.load();const{create:n}=await import("./meshUtils/elevationSampler.js");return n(e,t)}function U(e){const t=l(e);return null!=t?new s(t):null}async function S(e,n,r){const{convertMeshVertexSpace:s}=await import("./meshUtils/convertMeshVertexSpace.js");return t(r),s(e,n,r)}function y(e,t){const n=new s(f(w(),e,t));return t?.imageFace&&"all"!==t.imageFace?h(n,t.imageFace):n}function F(e,t){return new s(f(u(t?.densificationFactor||0),e,t))}function R(e,t){return new s(f(j(t?.densificationFactor||0),e,t))}function V(e,t){const n=t?.facing??"up",r=d(n,t?.size);return new s(f(v(n),e,{...t,size:r}))}async function b(e,t){let n=x(e);r(n)&&(await n,n=x(e));const a=r(n)?null:n,m=a?.positions??[],l=a?.polygonIndices??[];return new s({vertexAttributes:new c({position:m}),components:[new o({faces:l,shading:"flat",material:t?.material??null})],spatialReference:e.spatialReference,vertexSpace:new i})}async function C(e,t,r){const{loadGLTFMesh:o}=await n(import("./meshUtils/loadGLTFMesh.js"),r);return new s((await o(e,t,r)).mesh)}function G(e,t,n){const r=n?.extent??null,{spatialReference:o}=e,i=n?.transform?.clone()??new a,c=m(e,n),l=n?.unitConversionDisabled,f={source:t,extent:r,unitConversionDisabled:l},u=new p;return u.externalSources.push(f),new s({metadata:u,transform:i,vertexSpace:c,spatialReference:o})}function T(t,n){const{spatialReference:r}=t,o=n?.transform?.clone()??new a,i=m(t,n),c=new s({transform:o,vertexSpace:i,spatialReference:r});return c.addResolvingPromise(Promise.reject(new e("mesh-incomplete","Mesh resources are not complete"))),c}export{S as convertVertexSpace,y as createBox,R as createCylinder,g as createElevationSampler,M as createFromElevation,C as createFromGLTF,b as createFromPolygon,T as createIncomplete,V as createPlane,F as createSphere,G as createWithExternalSource,U as merge};
