@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.98 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{IDENTITY as t,clone as i}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{t as e}from"../../../../chunks/vec32.js";import{compactIndices as s,getContinuousIndexArray as n}from"../../../../geometry/support/Indices.js";import{cloneAttributeData as h}from"./AttributeArray.js";import{BoundingInfo as o}from"./BoundingInfo.js";import{ContentObject as r}from"./ContentObject.js";import{ContentObjectType as g}from"./ContentObjectType.js";import{computeAttachmentOriginTriangles as a,computeAttachmentOriginLines as u,computeAttachmentOriginPoints as l}from"./geometryDataUtils.js";import{Object3DHighlightStateID as c}from"./Object3DStateID.js";import{assert as m}from"./Util.js";import{VertexAttribute as d}from"./VertexAttribute.js";class f extends r{constructor(t,i,e=null,n=g.Mesh,h=null,o=-1){super(),this.material=t,this.mapPositions=e,this.type=n,this.objectAndLayerIdColor=h,this.edgeIndicesLength=o,this.highlights=new Set,this._highlightOptionsCounts=new Map,this.visible=!0,this._attributes=new Map,this._boundingInfo=null;for(const[r,g]of i)this._attributes.set(r,{...g,indices:s(g.indices)}),r===d.POSITION&&(this.edgeIndicesLength=this.edgeIndicesLength<0?this._attributes.get(r).indices.length:this.edgeIndicesLength)}instantiate(t={}){const i=new f(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:h(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})}get indexCount(){const t=this._attributes.values().next().value?.indices;return t?.length??0}get faceCount(){return this.indexCount/3}get boundingInfo(){return null==this._boundingInfo&&(this._boundingInfo=this._calculateBoundingInfo()),this._boundingInfo}computeAttachmentOrigin(t){return!!(this.type===g.Mesh?this._computeAttachmentOriginTriangles(t):this.type===g.Line?this._computeAttachmentOriginLines(t):this._computeAttachmentOriginPoints(t))&&(null!=this._transformation&&e(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 u(i,p(this.material.parameters,i),t)}_computeAttachmentOriginPoints(t){const i=this.attributes.get(d.POSITION);return l(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===g.Mesh?3:1;m(t.indices.length%i==0,"Indexing error: "+t.indices.length+" not divisible by "+i);const e=n(t.indices.length/i);return new o(e,i,t)}get transformation(){return this._transformation??t}set transformation(e){this._transformation=e&&e!==t?i(e):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 p(t,i){return!(!("isClosed"in t)||!t.isClosed)&&i.indices.length>2}export{f as Geometry};