/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import t from"../../Graphic.js";import r from"../../request.js";import e from"../../core/Collection.js";import o from"../../core/Error.js";import{rad2deg as n,deg2rad as i}from"../../core/mathUtils.js";import{throwIfAborted as s}from"../../core/promiseUtils.js";import a from"../../geometry/Mesh.js";import m from"../../geometry/support/MeshMaterial.js";import c from"../../geometry/support/MeshTexture.js";import l from"../../symbols/FillSymbol3DLayer.js";import u from"../../symbols/MeshSymbol3D.js";import{defaultImageSphereCenter as p,defaultImageSphereSize as f}from"./constants.js";import{loadRasterFactory as h,loadPanoramicTilePyramid as w}from"./support/importUtils.js";function y({data:t,center:r=p,size:e=f,horizonPitch:o=0,horizonYaw:n=0,horizonRoll:i=0}){const s=r.clone();s.z=-e/2;const l=a.createSphere(s,{size:e,densificationFactor:2,vertexSpace:"georeferenced",material:new m({colorTexture:new c({data:t})})});if(l.components[0].trustSourceNormals=!0,l.vertexAttributes.uv){const t=l.vertexAttributes.uv.length??0;for(let r=0;r<t;r++)l.vertexAttributes.uv[2*r+0]=1-l.vertexAttributes.uv[2*r+0]}return l.rotate(o,i,n,{origin:l.extent.center}),l.centerAt(s),l}function j(r){return new t({geometry:r,symbol:new u({symbolLayers:new e([new l])})})}function d(t,r){return 2*n(Math.atan(Math.tan(i(t/2))*Math.sqrt((1/r)**2+1)))}async function g(t,r){const e=await h(),o=await e.open({url:t,ioConfig:{skipExtensions:["jgw","aux.xml"],skipMapInfo:!0},...r});return s(r),x(o,{url:t})}const x=(t,r)=>{if(!t)throw new o("panoramic-viewer:missing-raster","Raster data could not be loaded",r);return t};async function b(t,r,e){const o=await w();return s(e),new o({raster:t,horizonPitch:r.pitch,horizonYaw:r.yaw,horizonRoll:r.roll})}async function v(t,r){return t?.length?await Promise.all(t.map(t=>t.loadMesh(r))):[]}async function M(t,e){try{const o=await r(t,{...e,method:"head"});return s(e),o?.getHeader?.("Content-Type")}catch{return null}}export{y as createImageSphere,d as findDiagonalFOV,M as getContentType,v as loadMeshes,b as loadPyramid,g as loadRaster,j as meshToGraphic};
