/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.24/esri/copyright.txt for details. */ import{_ as e}from"../chunks/tslib.es6.js";import t from"../core/Error.js";import{HandleOwnerMixin as o}from"../core/HandleOwner.js";import r from"../core/Loadable.js";import n from"../core/Logger.js";import{isNone as s,isSome as i}from"../core/maybe.js";import{EsriPromiseMixin as a}from"../core/Promise.js";import{whenOrAbort as l}from"../core/promiseUtils.js";import{watch as p}from"../core/reactiveUtils.js";import{property as c}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import"../core/has.js";import"../core/accessorSupport/ensureType.js";import{subclass as m}from"../core/accessorSupport/decorators/subclass.js";import{f as h,c as f}from"../chunks/vec3f64.js";import u from"./Extent.js";import d from"./Geometry.js";import x from"./Point.js";import y from"./Polygon.js";import{fromAxisAndAngle as g,compose as b,create as j}from"./support/axisAngleDegrees.js";import w from"./support/MeshComponent.js";import v from"./support/MeshTransform.js";import{MeshVertexAttributes as M}from"./support/MeshVertexAttributes.js";import{triangulate as P}from"./support/triangulationUtils.js";import{centerAt as R}from"./support/meshUtils/centerAt.js";import{loadExternal as A}from"./support/meshUtils/loadExternal.js";import{offset as z}from"./support/meshUtils/offset.js";import{convertUnitGeometry as F,createUnitSizeBox as C,extractSingleFaceOfBox as O,createUnitSizeSphere as U,createUnitSizeCylinder as L,convertPlaneSizeParameter as T,createUnitSizePlane as E}from"./support/meshUtils/primitives.js";import{rotate as G}from"./support/meshUtils/rotate.js";import{scale as S}from"./support/meshUtils/scale.js";var I;const B=n.getLogger("esri.geometry.Mesh");let k=I=class extends(o(r.LoadableMixin(a(d)))){constructor(e){super(e),this.components=null,this.transform=null,this.external=null,this.hasZ=!0,this.hasM=!1,this.vertexAttributes=new M,this.type="mesh"}initialize(){(s(this.external)||this.vertexAttributes.position.length)&&(this.loadStatus="loaded"),this.when((()=>{this.handles.add(p((()=>({vertexAttributes:this.vertexAttributes,components:this.components?.map((e=>e.clone())),transform:i(this.transform)?this.transform.clone():null})),(()=>this._set("external",null)),{once:!0,sync:!0}))}))}get hasExtent(){return!this.loaded&&i(this.external)&&i(this.external.extent)||this.loaded&&this.vertexAttributes.position.length>0&&(!this.components||this.components.length>0)}get boundingInfo(){const e=this.vertexAttributes.position,t=this.spatialReference;if(0===e.length||this.components&&0===this.components.length)return{extent:new u({xmin:0,ymin:0,zmin:0,xmax:0,ymax:0,zmax:0,spatialReference:t}),center:new x({x:0,y:0,z:0,spatialReference:t})};const o=i(this.transform)?this.transform.project(e,t):e;let r=1/0,n=1/0,s=1/0,a=-1/0,l=-1/0,p=-1/0,c=0,m=0,h=0;const f=o.length,d=1/(f/3);let y=0;for(;yo.cloneWithDeduplication(e,t))):null,spatialReference:this.spatialReference,vertexAttributes:this.vertexAttributes.clone(),transform:i(this.transform)?this.transform.clone():null,external:i(this.external)?{source:this.external.source,extent:i(this.external.extent)?this.external.extent.clone():null}:null};return new I(o)}vertexAttributesChanged(){this.notifyChange("vertexAttributes")}async toBinaryGLTF(e){const{toBinaryGLTF:t}=await import("./support/meshUtils/exporters/gltf/gltfexport.js");return t(this,e)}static createBox(e,t){if(!(e instanceof x))return B.error(".createBox()","expected location to be a Point instance"),null;const o=new I(F(C(),e,t));return t&&t.imageFace&&"all"!==t.imageFace?O(o,t.imageFace):o}static createSphere(e,t){return e instanceof x?new I(F(U(t&&t.densificationFactor||0),e,t)):(B.error(".createSphere()","expected location to be a Point instance"),null)}static createCylinder(e,t){return e instanceof x?new I(F(L(t&&t.densificationFactor||0),e,t)):(B.error(".createCylinder()","expected location to be a Point instance"),null)}static createPlane(e,t){if(!(e instanceof x))return B.error(".createPlane()","expected location to be a Point instance"),null;const o=t?.facing??"up",r=T(o,t?.size);return new I(F(E(o),e,{...t,size:r}))}static createFromPolygon(e,t){if(!(e instanceof y))return B.error(".createFromPolygon()","expected polygon to be a Polygon instance"),null;const o=P(e);return new I({vertexAttributes:new M({position:o.position}),components:[new w({faces:o.faces,shading:"flat",material:t&&t.material||null})],spatialReference:e.spatialReference})}static async createFromGLTF(e,o,r){if(!(e instanceof x))throw B.error(".createfromGLTF()","expected location to be a Point instance"),new t("invalid-input","Expected location to be a Point instance");const{loadGLTFMesh:n}=await l(import("./support/meshUtils/loadGLTFMesh.js"),r);return new I(await n(e,o,r))}static createWithExternalSource(e,t,o){const r=o?.extent??null,n=o?.transform.clone()??new v;n.origin=[e.x,e.y,e.z??0];const s=e.spatialReference;return new I({external:{source:t,extent:r},transform:n,spatialReference:s})}static createIncomplete(e,o){const r=o?.transform.clone()??new v;r.origin=[e.x,e.y,e.z??0];const n=e.spatialReference,s=new I({transform:r,spatialReference:n});return s.addResolvingPromise(Promise.reject(new t("mesh-incomplete","Mesh resources are not complete"))),s}};e([c({type:[w],json:{write:!0}})],k.prototype,"components",void 0),e([c({type:v,json:{write:!0}})],k.prototype,"transform",void 0),e([c({constructOnly:!0})],k.prototype,"external",void 0),e([c({readOnly:!0})],k.prototype,"hasExtent",null),e([c({readOnly:!0})],k.prototype,"boundingInfo",null),e([c({readOnly:!0})],k.prototype,"anchor",null),e([c({readOnly:!0})],k.prototype,"origin",null),e([c({readOnly:!0,json:{read:!1}})],k.prototype,"extent",null),e([c({readOnly:!0,json:{read:!1,write:!0,default:!0}})],k.prototype,"hasZ",void 0),e([c({readOnly:!0,json:{read:!1,write:!0,default:!1}})],k.prototype,"hasM",void 0),e([c({type:M,nonNullable:!0,json:{write:!0}})],k.prototype,"vertexAttributes",void 0),k=I=e([m("esri.geometry.Mesh")],k);const D={x:h(1,0,0),y:h(0,1,0),z:h(0,0,1)},W=j(),Z=j(),_=j(),H=f(),N=k;export{N as default};