@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 4.06 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{IDENTITY as t,clone as i}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{transformMat4 as e}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{getContinuousIndexArray as s}from"../../../../geometry/support/Indices.js";import{cloneAttributeData as n}from"./AttributeArray.js";import{BoundingInfo as o}from"./BoundingInfo.js";import{GeometryBaseInstance as h}from"./GeometryBaseInstance.js";import{computeAttachmentOriginTriangles as r,computeAttachmentOriginLines as g,computeAttachmentOriginPoints as u}from"./geometryDataUtils.js";import{Object3DHighlightStateID as a}from"./Object3DStateID.js";import{assert as l}from"./Util.js";import{webglDebugEnabled as c}from"../../../webgl/checkWebGLError.js";class m extends h{constructor(t,i,e=null,s=0,n=null,o=-1,h){super(i),this.material=t,this.mapPositions=e,this.type=s,this.olidColor=n,this.edgeIndicesLength=o,this.baseGeometry=h,this._highlights=null,this._highlightOptionsCounts=null,this.visible=!0,this._boundingInfo=null;const r=this.positionAttribute;null!=r&&this.edgeIndicesLength<0&&(this.edgeIndicesLength=r.indices.length)}instantiate(t={}){const i=new m(t.material||this.material,[],this.mapPositions,this.type,this.olidColor,this.edgeIndicesLength,this.baseGeometry);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}getMutableAttribute(t){let i=this._attributes.get(t);return i&&!i.exclusive&&(i={...i,exclusive:!0,data:n(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}):c()&&console.warn(`Setting undefined attribute ${t} data`)}get positionAttribute(){return this.attributes.get("position")??this.baseGeometry?.attributes.get("position")}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!!(0===this.type?this._computeAttachmentOriginTriangles(t):2===this.type?this._computeAttachmentOriginLines(t):this._computeAttachmentOriginPoints(t))&&(null!=this._transformation&&e(t,t,this._transformation),!0)}_computeAttachmentOriginTriangles(t){const i=this.positionAttribute;return r(i,t)}_computeAttachmentOriginLines(t){const i=this.positionAttribute;return g(i,d(this.material.parameters,i),t)}_computeAttachmentOriginPoints(t){const i=this.positionAttribute;return u(i,t)}invalidateBoundingInfo(){this._boundingInfo=null}_calculateBoundingInfo(){const t=this.positionAttribute;if(!t||0===t.indices.length)return null;const i=0===this.type?3:1;l(t.indices.length%i===0,"Indexing error: "+t.indices.length+" not divisible by "+i);const e=s(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 highlights(){return this._highlights||p}get hasHighlights(){return(this._highlightOptionsCounts?.size??0)>0}foreachHighlightOptions(t){this._highlightOptionsCounts?.forEach((i,e)=>t(e))}allocateIdAndHighlight(t){const i=new a(t);return this.addHighlight(i)}addHighlight(t){this._ensureHighlights().add(t);const{highlightName:i}=t,e=(this._highlightOptionsCounts?.get(i)??0)+1;return this._ensureHighlightOptionsCounts().set(i,e),t}_ensureHighlights(){let t=this._highlights;return t||(t=new Set,this._highlights=t),t}_ensureHighlightOptionsCounts(){let t=this._highlightOptionsCounts;return t||(t=new Map,this._highlightOptionsCounts=t),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._ensureHighlightOptionsCounts().set(i,e-1)}}}function d(t,i){return!(!("isClosed"in t)||!t.isClosed)&&i.indices.length>2}const p=new Set;export{m as Geometry};