UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 8.7 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as e}from"../chunks/tslib.es6.js";import t from"../core/Error.js";import r from"../core/Loadable.js";import o from"../core/Logger.js";import s from"../core/Promise.js";import{throwIfAborted as n,whenOrAbort as i}from"../core/promiseUtils.js";import{watch as a}from"../core/reactiveUtils.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as c}from"../core/accessorSupport/decorators/subclass.js";import{fromValues as m}from"../core/libs/gl-matrix-2/factories/vec3f64.js";import l from"./Geometry.js";import h from"./Point.js";import u from"./Polygon.js";import{create as d,fromBuffer as f,zero as g}from"./support/aaBoundingBox.js";import{composeAxes as x,create as y}from"./support/axisAngleDegrees.js";import v from"./support/MeshComponent.js";import{componentNotFoundMessage as j,meshNotLoadedMessage as w,invalidLocationMessage as S,invalidPolygonMessage as b,InvalidLocationError as A}from"./support/meshErrors.js";import L from"./support/MeshGeoreferencedVertexSpace.js";import M from"./support/MeshLocalVertexSpace.js";import R from"./support/MeshTransform.js";import{MeshVertexAttributes as C}from"./support/MeshVertexAttributes.js";import{vertexSpaceOriginToPoint as _,isRelativeVertexSpace as F,selectVertexSpace as U}from"./support/meshVertexSpaceUtils.js";import{triangulate as P}from"./support/triangulationUtils.js";import{centerAt as E}from"./support/meshUtils/centerAt.js";import{computeMeshExtent as B}from"./support/meshUtils/extent.js";import{loadExternal as G}from"./support/meshUtils/loadExternal.js";import{Metadata as k}from"./support/meshUtils/Metadata.js";import{convertUnitGeometry as I,createUnitSizeBox as T,extractSingleFaceOfBox as V,createUnitSizeSphere as O,createUnitSizeCylinder as z,convertPlaneSizeParameter as D,createUnitSizePlane as N}from"./support/meshUtils/primitives.js";import{rotate as W}from"./support/meshUtils/rotate.js";import{scale as Z}from"./support/meshUtils/scale.js";var H;const K={base:null,key:"type",defaultKeyValue:"georeferenced",typeMap:{georeferenced:L,local:M}};let q=H=class extends(r.LoadableMixin(s.EsriPromiseMixin(l))){constructor(e){super(e),this.components=null,this.vertexSpace=new L,this.transform=null,this.metadata=new k,this.hasZ=!0,this.hasM=!1,this.vertexAttributes=new C,this.type="mesh"}initialize(){(0===this.metadata.externalSources.length||this.vertexAttributes.position.length)&&(this.loadStatus="loaded"),this.when((()=>{this.addHandles(a((()=>({vertexAttributes:this.vertexAttributes,components:this.components?.map((e=>e.clone()))})),(()=>this._clearSources()),{once:!0,sync:!0}))}))}get hasExtent(){return this.loaded?this.vertexAttributes.position.length>0&&(!this.components||this.components.length>0):null!=this.metadata.displaySource?.extent}get _transformedExtent(){const{spatialReference:e,vertexSpace:t}=this,r=this;return B({get transform(){return r.transform},vertexSpace:t,spatialReference:e,untransformedBounds:this._untransformedBounds})}get _untransformedBounds(){const{vertexAttributes:{position:e},components:t}=this;return 0===e.length||0===t?.length?d(g):f(e)}get origin(){const e=_(this.vertexSpace,this.spatialReference);if(null!=e)return e;const{center:t,zmin:r}=this._transformedExtent;return new h({x:t.x,y:t.y,z:r,spatialReference:this.spatialReference})}get extent(){return this.loaded||null==this.metadata?.displaySource?.extent?this._transformedExtent:this.metadata.displaySource.extent.clone()}addComponent(e){this._checkIfLoaded("addComponent()")&&(this.components||(this.components=[]),this.components.push(v.from(e)),this.notifyChange("components"))}removeComponent(e){if(this._checkIfLoaded("removeComponent()")){if(this.components){const t=this.components.indexOf(e);if(-1!==t)return this.components.splice(t,1),void this.notifyChange("components")}o.getLogger(this).error("removeComponent()",j)}}rotate(e,t,r,o){return x(e,t,r,J),W(this,J,o),this}offset(e,t,r){if(!this._checkIfLoaded("offset()"))return this;const{vertexSpace:o,vertexAttributes:s}=this,n=s?.position;if(!n)return this;if(F(o)){const[s,n,i]=o.origin;o.origin=m(s+e,n+t,i+r)}else{for(let o=0;o<n.length;o+=3)n[o]+=e,n[o+1]+=t,n[o+2]+=r;this.vertexAttributesChanged()}return this}scale(e,t){return this._checkIfLoaded("scale()")?(Z(this,e,t),this):this}centerAt(e,t){return this._checkIfLoaded("centerAt()")?(E(this,e,t),this):this}load(e){const{metadata:{displaySource:t}}=this;return t&&this.addResolvingPromise(G(this,t,e)),Promise.resolve(this)}addExternalSources(e){this.metadata.externalSources.addMany(e)}updateDisplaySource(e){this.metadata.displaySource=e}clone(){return this.cloneAndModifyVertexAttributes(this.vertexAttributes.clone(),this.vertexSpace.clone(),{preserveMetadata:!0})}cloneAndModifyVertexAttributes(e,t,r){let o=null;if(this.components){const e=new Map,t=new Map;o=this.components.map((r=>r.cloneWithDeduplication(e,t)))}const s={components:o,spatialReference:this.spatialReference,vertexAttributes:e,vertexSpace:t,transform:this.transform?.clone()??null,metadata:r?.preserveMetadata?this.metadata.clone():new k};return new H(s)}cloneShallow(){return new H({components:this.components,spatialReference:this.spatialReference,vertexAttributes:this.vertexAttributes,vertexSpace:this.vertexSpace.clone(),transform:this.transform,metadata:this.metadata})}vertexAttributesChanged(){this.notifyChange("vertexAttributes")}async toBinaryGLTF(e){const[{toBinaryGLTF:t}]=await Promise.all([import("./support/meshUtils/exporters/gltf/gltfexport.js"),this.load(e)]);return n(e),await t(this,e)}get usedMemory(){return this.components?this.components.reduce(((e,t)=>e+t.memoryUsage),this.vertexAttributes.usedMemory):this.vertexAttributes.usedMemory}_clearSources(){this.metadata.clearSources()}_checkIfLoaded(e){return!!this.loaded||(o.getLogger(this).error(e,w),!1)}static createBox(e,t){if(!(e instanceof h))return o.getLogger(this.prototype).error(".createBox()",S),null;const r=new H(I(T(),e,t));return t?.imageFace&&"all"!==t.imageFace?V(r,t.imageFace):r}static createSphere(e,t){return e instanceof h?new H(I(O(t?.densificationFactor||0),e,t)):(o.getLogger(this.prototype).error(".createSphere()",S),null)}static createCylinder(e,t){return e instanceof h?new H(I(z(t?.densificationFactor||0),e,t)):(o.getLogger(this.prototype).error(".createCylinder()",S),null)}static createPlane(e,t){if(!(e instanceof h))return o.getLogger(this.prototype).error(".createPlane()",S),null;const r=t?.facing??"up",s=D(r,t?.size);return new H(I(N(r),e,{...t,size:s}))}static createFromPolygon(e,t){if(!(e instanceof u))return o.getLogger(this.prototype).error(".createFromPolygon()",b),null;const r=P(e);return new H({vertexAttributes:new C({position:r.position}),components:[new v({faces:r.faces,shading:"flat",material:t?.material??null})],spatialReference:e.spatialReference,vertexSpace:new L})}static async createFromGLTF(e,t,r){if(!(e instanceof h)){const e=new A;throw o.getLogger(this.prototype).error(".createfromGLTF()",e.message),e}const{loadGLTFMesh:s}=await i(import("./support/meshUtils/loadGLTFMesh.js"),r);return new H(await s(e,t,r))}static createWithExternalSource(e,t,r){const o=r?.extent??null,{spatialReference:s}=e,n=r?.transform?.clone()??new R,i=U(e,r),a=r?.unitConversionDisabled,p={source:t,extent:o,unitConversionDisabled:a},c=new k;return c.externalSources.push(p),new H({metadata:c,transform:n,vertexSpace:i,spatialReference:s})}static createIncomplete(e,r){const{spatialReference:o}=e,s=r?.transform?.clone()??new R,n=U(e,r),i=new H({transform:s,vertexSpace:n,spatialReference:o});return i.addResolvingPromise(Promise.reject(new t("mesh-incomplete","Mesh resources are not complete"))),i}};e([p({type:[v],json:{write:!0}})],q.prototype,"components",void 0),e([p({nonNullable:!0,types:K,constructOnly:!0,json:{write:!0}})],q.prototype,"vertexSpace",void 0),e([p({type:R,json:{write:!0}})],q.prototype,"transform",void 0),e([p({constructOnly:!0})],q.prototype,"metadata",void 0),e([p()],q.prototype,"hasExtent",null),e([p()],q.prototype,"_transformedExtent",null),e([p()],q.prototype,"_untransformedBounds",null),e([p()],q.prototype,"origin",null),e([p({readOnly:!0,json:{read:!1}})],q.prototype,"extent",null),e([p({readOnly:!0,json:{read:!1,write:!0,default:!0}})],q.prototype,"hasZ",void 0),e([p({readOnly:!0,json:{read:!1,write:!0,default:!1}})],q.prototype,"hasM",void 0),e([p({type:C,nonNullable:!0,json:{write:!0}})],q.prototype,"vertexAttributes",void 0),q=H=e([c("esri.geometry.Mesh")],q);const J=y();export{q as default};