UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.09 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{generateUID as t}from"../../../../core/uid.js";import{IDENTITY as i,clone as e}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{t as s}from"../../../../chunks/vec32.js";import{compactIndices as n,getContinuousIndexArray as h}from"../../../../geometry/support/Indices.js";import{cloneAttributeData as r}from"./AttributeArray.js";import{BoundingInfo as o}from"./BoundingInfo.js";import{computeAttachmentOriginTriangles as a,computeAttachmentOriginLines as g,computeAttachmentOriginPoints as u}from"./geometryDataUtils.js";import{GeometryType as l}from"./IntersectableGeometry.js";import{Object3DHighlightStateID as c}from"./Object3DStateID.js";import{assert as m}from"./Util.js";import{VertexAttribute as d}from"./VertexAttribute.js";import{webglDebugEnabled as f}from"../../../webgl/checkWebGLError.js";class p{constructor(i,e,s=null,h=l.Mesh,r=null,o=-1){this.material=i,this.mapPositions=s,this.type=h,this.objectAndLayerIdColor=r,this.edgeIndicesLength=o,this.highlights=new Set,this._highlightOptionsCounts=new Map,this.id=t(),this.visible=!0,this._attributes=new Map,this._boundingInfo=null;for(const[t,a]of e)this._attributes.set(t,{...a,indices:n(a.indices)}),t===d.POSITION&&(this.edgeIndicesLength=this.edgeIndicesLength<0?this._attributes.get(t).indices.length:this.edgeIndicesLength)}instantiate(t={}){const i=new p(t.material||this.material,[],this.mapPositions,this.type,this.objectAndLayerIdColor,this.edgeIndicesLength);return this._attributes.forEach(((t,e)=>{t.exclusive=!1,i._attributes.set(e,t)})),i._boundingInfo=this._boundingInfo,i.transformation=t.transformation||this.transformation,i}get attributes(){return this._attributes}getMutableAttribute(t){let i=this._attributes.get(t);return i&&!i.exclusive&&(i={...i,exclusive:!0,data:r(i.data)},this._attributes.set(t,i)),i}setAttributeData(t,i){const e=this._attributes.get(t);e?this._attributes.set(t,{...e,exclusive:!0,data:i}):f()&&console.warn(`Setting undefined attribute ${t} data`)}get indexCount(){const t=this._attributes.values().next().value?.indices;return t?.length??0}get faceCount(){return this.indexCount/3}get boundingInfo(){return this._boundingInfo??=this._calculateBoundingInfo(),this._boundingInfo}computeAttachmentOrigin(t){return!!(this.type===l.Mesh?this._computeAttachmentOriginTriangles(t):this.type===l.Line?this._computeAttachmentOriginLines(t):this._computeAttachmentOriginPoints(t))&&(null!=this._transformation&&s(t,t,this._transformation),!0)}_computeAttachmentOriginTriangles(t){const i=this.attributes.get(d.POSITION);return a(i,t)}_computeAttachmentOriginLines(t){const i=this.attributes.get(d.POSITION);return g(i,b(this.material.parameters,i),t)}_computeAttachmentOriginPoints(t){const i=this.attributes.get(d.POSITION);return u(i,t)}invalidateBoundingInfo(){this._boundingInfo=null}_calculateBoundingInfo(){const t=this.attributes.get(d.POSITION);if(!t||0===t.indices.length)return null;const i=this.type===l.Mesh?3:1;m(t.indices.length%i===0,"Indexing error: "+t.indices.length+" not divisible by "+i);const e=h(t.indices.length/i);return new o(e,i,t)}get transformation(){return this._transformation??i}set transformation(t){this._transformation=t&&t!==i?e(t):null}get highlightNames(){return this._highlightOptionsCounts}get hasHighlights(){return this._highlightOptionsCounts.size>0}foreachHighlightOptions(t){this._highlightOptionsCounts.forEach(((i,e)=>t(e)))}allocateIdAndHighlight(t){const i=new c(t);return this.addHighlight(i)}addHighlight(t){this.highlights.add(t);const{highlightName:i}=t,e=(this._highlightOptionsCounts.get(i)??0)+1;return this._highlightOptionsCounts.set(i,e),t}removeHighlight(t){if(this.highlights.delete(t)){const{highlightName:i}=t,e=this._highlightOptionsCounts.get(i)??0;e<=1?this._highlightOptionsCounts.delete(i):this._highlightOptionsCounts.set(i,e-1)}}}function b(t,i){return!(!("isClosed"in t)||!t.isClosed)&&i.indices.length>2}export{p as Geometry,l as GeometryType};