/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../geometry","../../../Ground","../../../core/Logger","../../../core/maybe","../../../core/promiseUtils","../../../core/unitUtils","../../Mesh","../../projection","../MeshComponent","../MeshVertexAttributes","../../Point"],(function(e,t,n,o,r,i,l,a,s,u,c,p,d){"use strict";const m=r.getLogger("esri.geometry.support.meshUtils.elevation");function f(e,t,n){return y.apply(this,arguments)}function y(){return(y=t._asyncToGenerator((function*(e,t,n){let r;if(g(e)||e instanceof o){var i;const o=yield v(e);return r=yield o.createElevationSampler(t,{demResolution:null!=(i=null==n?void 0:n.demResolution)?i:"finest-contiguous"}),h(r,t,{material:null==n?void 0:n.material})}return"string"==typeof(null==n?void 0:n.demResolution)?(m.error("create()","demResolution must be a number when used directly with a sampler"),null):h(e,t,{material:null==n?void 0:n.material,demResolution:null==n?void 0:n.demResolution})}))).apply(this,arguments)}function h(e,t,n){var o,r;const l=a.getMetersPerUnitForSR(t.spatialReference),d=(null!=(o=n.demResolution)?o:e.demResolution.min)/l,m=Math.round(t.width/d),f=Math.round(t.height/d),y=m+1,h=f+1,v=new Float64Array(y*h*3),R=new Float32Array(y*h*2);let g=0,b=0;const A=new Uint32Array(m*f*2*3);let M=0,x=0;const U=!e.spatialReference.equals(t.spatialReference);w.spatialReference=t.spatialReference;const{xmin:_,ymin:P,height:S,width:j}=t;for(let a=0;a<h;a++){const t=P+S*(a/f);for(let n=0;n<y;n++){const o=_+j*(n/m);if(v[g++]=o,v[g++]=t,U){w.x=o,w.y=t;const n=u.project(w,e.spatialReference);v[g++]=i.unwrapOr(e.elevationAt(n.x,n.y),0)}else v[g++]=i.unwrapOr(e.elevationAt(o,t),0);const r=n/m,l=a/f;R[b++]=r,R[b++]=l,a!==f&&n!==m&&(A[x++]=M+1,A[x++]=M+y+1,A[x++]=M+y,A[x++]=M,A[x++]=M+1,A[x++]=M+y),M++}}return new s({vertexAttributes:new p.MeshVertexAttributes({position:v,uv:R}),components:[new c({faces:A,shading:"smooth",material:null!=(r=null==n?void 0:n.material)?r:null})],spatialReference:t.spatialReference})}function v(e){return R.apply(this,arguments)}function R(){return(R=t._asyncToGenerator((function*(e){return g(e)?e.load():(yield e.load(),yield l.eachAlways(e.layers.map((e=>e.load()))),e)}))).apply(this,arguments)}function g(e){return"type"in e&&("elevation"===e.type||"base-elevation"===e.type)}const w=new d;e.create=f,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
