/* COPYRIGHT Esri - https://js.arcgis.com/5.0/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 s}from"../../core/mathUtils.js";import{throwIfAborted as i}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 u from"../../symbols/FillSymbol3DLayer.js";import l from"../../symbols/MeshSymbol3D.js";import{defaultImageSphereCenter as p,defaultImageSphereSize as f}from"./constants.js";import{loadRasterFactory as h,loadPanoramicTilePyramid as y}from"./support/importUtils.js";function w({data:t,center:r=p,size:e=f,horizonPitch:o=0,horizonYaw:n=0,horizonRoll:s=0}){const i=r.clone();i.z=-e/2;const u=a.createSphere(i,{size:e,densificationFactor:2,vertexSpace:"georeferenced",material:new m({colorTexture:new c({data:t})})});if(u.components[0].trustSourceNormals=!0,u.vertexAttributes.uv){const t=u.vertexAttributes.uv.length??0;for(let r=0;r<t;r++)u.vertexAttributes.uv[2*r+0]=1-u.vertexAttributes.uv[2*r+0]}return u.rotate(o,s,n,{origin:u.extent.center}),u.centerAt(i),u}function j(r){return new t({geometry:r,symbol:new l({symbolLayers:new e([new u])})})}function d(t,r){return 2*n(Math.atan(Math.tan(s(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 i(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){const e=await y();return i(r),new e({raster:t})}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 i(e),o?.getHeader?.("Content-Type")}catch{return null}}export{w as createImageSphere,d as findDiagonalFOV,M as getContentType,v as loadMeshes,b as loadPyramid,g as loadRaster,j as meshToGraphic};
