@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 8 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as t}from"../../../../../chunks/tslib.es6.js";import e from"../../../../../core/Accessor.js";import{reallocGrowthFactor as s}from"../../../../../core/arrayUtils.js";import i from"../../../../../core/Evented.js";import{property as a}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/Logger.js";import{subclass as r}from"../../../../../core/accessorSupport/decorators/subclass.js";import{fromMat4 as o,invert as n,transpose as h}from"../../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as l}from"../../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{multiply as c}from"../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as g}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{i as m}from"../../../../../chunks/vec32.js";import{create as f}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{BufferViewMat4f64 as d,BufferViewVec3f64 as p,BufferViewMat3f as _,BufferViewVec2f as T,BufferViewVec4f64 as u,BufferViewVec4f as L,BufferViewVec4u8 as O,BufferViewUint8 as A}from"../../../../../geometry/support/buffer/BufferView.js";import{scaleFromMatrix as E}from"../../../support/mathUtils.js";import{newLayout as v}from"../../../support/buffer/InterleavedLayout.js";import{assert as M}from"../Util.js";import{VertexAttribute as I}from"../VertexAttribute.js";import{initialCapacity as F}from"./RenderInstanceData.js";var S;function b(t){let e=v().mat4f64(I.LOCALTRANSFORM).mat4f64(I.GLOBALTRANSFORM).vec4f64(I.BOUNDINGSPHERE).vec3f64(I.MODELORIGIN).mat3f(I.INSTANCEMODEL).mat3f(I.INSTANCEMODELNORMAL).vec2f(I.MODELSCALEFACTORS);return t.includes(I.FEATUREATTRIBUTE)&&(e=e.vec4f(I.FEATUREATTRIBUTE)),t.includes(I.COLOR)&&(e=e.vec4u8(I.COLOR)),t.includes(I.OLIDCOLOR)&&(e=e.vec4u8(I.OLIDCOLOR)),e=e.u8(I.STATE).u8(I.LODLEVEL),e}!function(t){t[t.ALLOCATED=1]="ALLOCATED",t[t.DEFAULT_ACTIVE=2]="DEFAULT_ACTIVE",t[t.VISIBLE=4]="VISIBLE",t[t.HIGHLIGHT=8]="HIGHLIGHT",t[t.HIGHLIGHT_ACTIVE=16]="HIGHLIGHT_ACTIVE",t[t.REMOVE=32]="REMOVE",t[t.TRANSFORM_CHANGED=64]="TRANSFORM_CHANGED",t[t.ACTIVE=18]="ACTIVE"}(S||(S={}));class C{constructor(t){this.localTransform=t.getField(I.LOCALTRANSFORM,d),this.globalTransform=t.getField(I.GLOBALTRANSFORM,d),this.modelOrigin=t.getField(I.MODELORIGIN,p),this.model=t.getField(I.INSTANCEMODEL,_),this.modelNormal=t.getField(I.INSTANCEMODELNORMAL,_),this.modelScaleFactors=t.getField(I.MODELSCALEFACTORS,T),this.boundingSphere=t.getField(I.BOUNDINGSPHERE,u),this.featureAttribute=t.getField(I.FEATUREATTRIBUTE,L),this.color=t.getField(I.COLOR,O),this.objectAndLayerIdColor=t.getField(I.OLIDCOLOR,O),this.state=t.getField(I.STATE,A),this.lodLevel=t.getField(I.LODLEVEL,A)}}let R=class extends e{constructor(t,e){super(t),this.events=new i,this._capacity=0,this._size=0,this._next=0,this._highlightOptionsMap=new Map,this._highlightOptionsMapPrev=new Map,this._layout=b(e),this._capacity=F,this._buffer=this._layout.createBuffer(this._capacity),this._view=new C(this._buffer)}get capacity(){return this._capacity}get size(){return this._size}get view(){return this._view}addInstance(){this._size+1>this._capacity&&this._grow();const t=this._findSlot();return this._view.state.set(t,S.ALLOCATED),this._size++,this.events.emit("instances-changed"),t}removeInstance(t){const e=this._view.state;M(t>=0&&t<this._capacity&&0!==(e.get(t)&S.ALLOCATED),"invalid instance handle"),this._getStateFlag(t,S.ACTIVE)?this._setStateFlags(t,S.REMOVE):this.freeInstance(t),this.events.emit("instances-changed")}freeInstance(t){const e=this._view.state;M(t>=0&&t<this._capacity&&0!==(e.get(t)&S.ALLOCATED),"invalid instance handle"),e.set(t,0),this._size--}setLocalTransform(t,e,s=!0){this._view.localTransform.setMat(t,e),s&&this.updateModelTransform(t)}getLocalTransform(t,e){this._view.localTransform.getMat(t,e)}setGlobalTransform(t,e,s=!0){this._view.globalTransform.setMat(t,e),s&&this.updateModelTransform(t)}getGlobalTransform(t,e){this._view.globalTransform.getMat(t,e)}updateModelTransform(t){const e=this._view,s=y,i=H;e.localTransform.getMat(t,N),e.globalTransform.getMat(t,D);const a=c(D,D,N);m(s,a[12],a[13],a[14]),e.modelOrigin.setVec(t,s),o(i,a),e.model.setMat(t,i);const r=E(y,a);r.sort(),e.modelScaleFactors.set(t,0,r[1]),e.modelScaleFactors.set(t,1,r[2]),n(i,i),h(i,i),e.modelNormal.setMat(t,i),this._setStateFlags(t,S.TRANSFORM_CHANGED),this.events.emit("instance-transform-changed",{index:t})}getModelTransform(t,e){const s=this._view;s.model.getMat(t,H),s.modelOrigin.getVec(t,y),e[0]=H[0],e[1]=H[1],e[2]=H[2],e[3]=0,e[4]=H[3],e[5]=H[4],e[6]=H[5],e[7]=0,e[8]=H[6],e[9]=H[7],e[10]=H[8],e[11]=0,e[12]=y[0],e[13]=y[1],e[14]=y[2],e[15]=1}applyShaderTransformation(t,e){null!=this.shaderTransformation&&this.shaderTransformation.applyTransform(this,t,e)}getCombinedModelTransform(t,e){return this.getModelTransform(t,e),null!=this.shaderTransformation&&this.shaderTransformation.applyTransform(this,t,e),e}getCombinedLocalTransform(t,e){this._view.localTransform.getMat(t,e),null!=this.shaderTransformation&&this.shaderTransformation.applyTransform(this,t,e)}getCombinedMaxScaleFactor(t){let e=this._view.modelScaleFactors.get(t,1);return null!=this.shaderTransformation&&(this.shaderTransformation.scaleFactor(y,this,t),e*=Math.max(y[0],y[1],y[2])),e}getCombinedMedianScaleFactor(t){let e=this._view.modelScaleFactors.get(t,0);return null!=this.shaderTransformation&&(this.shaderTransformation.scaleFactor(y,this,t),e*=w(y[0],y[1],y[2])),e}getModel(t,e){this._view.model.getMat(t,e)}setFeatureAttribute(t,e){this._view.featureAttribute.setVec(t,e)}getFeatureAttribute(t,e){this._view.featureAttribute.getVec(t,e)}setColor(t,e){this._view.color.setVec(t,e)}setObjectAndLayerIdColor(t,e){this._view.objectAndLayerIdColor.setVec(t,e)}setVisible(t,e){e!==this.getVisible(t)&&(this._setStateFlag(t,S.VISIBLE,e),this.events.emit("instance-visibility-changed",{index:t}))}getVisible(t){return this._getStateFlag(t,S.VISIBLE)}setHighlight(t,e){const{_highlightOptionsMap:s}=this,i=s.get(t);e?e!==i&&(s.set(t,e),this._setStateFlag(t,S.HIGHLIGHT,!0),this.events.emit("instance-highlight-changed")):i&&(s.delete(t),this._setStateFlag(t,S.HIGHLIGHT,!1),this.events.emit("instance-highlight-changed"))}get highlightOptionsMap(){return this._highlightOptionsMap}getHighlightStateFlag(t){return this._getStateFlag(t,S.HIGHLIGHT)}geHighlightOptionsPrev(t){const e=this._highlightOptionsMapPrev.get(t)??null;return this._highlightOptionsMapPrev.delete(t),e}getHighlightName(t){const e=this.highlightOptionsMap.get(t)??null;return e?this._highlightOptionsMapPrev.set(t,e):this._highlightOptionsMapPrev.delete(t),e}getState(t){return this._view.state.get(t)}getLodLevel(t){return this._view.lodLevel.get(t)}countFlags(t){let e=0;for(let s=0;s<this._capacity;++s){this.getState(s)&t&&++e}return e}_setStateFlags(t,e){const s=this._view.state;e=s.get(t)|e,s.set(t,e)}_clearStateFlags(t,e){const s=this._view.state;e=s.get(t)&~e,s.set(t,e)}_setStateFlag(t,e,s){s?this._setStateFlags(t,e):this._clearStateFlags(t,e)}_getStateFlag(t,e){return!!(this._view.state.get(t)&e)}_grow(){this._capacity=Math.max(F,Math.floor(this._capacity*s)),this._buffer=this._layout.createBuffer(this._capacity).copyFrom(this._buffer),this._view=new C(this._buffer)}_findSlot(){const t=this._view.state;let e=this._next;for(;t.get(e)&S.ALLOCATED;)e=e+1===this._capacity?0:e+1;return this._next=e+1===this._capacity?0:e+1,e}};function w(t,e,s){return Math.max(Math.min(t,e),Math.min(Math.max(t,e),s))}t([a({constructOnly:!0})],R.prototype,"shaderTransformation",void 0),t([a()],R.prototype,"_size",void 0),t([a({readOnly:!0})],R.prototype,"size",null),R=t([r("esri.views.3d.webgl-engine.lib.lodRendering.InstanceData")],R);const y=f(),H=l(),N=g(),D=g();export{R as InstanceData,C as InstanceDataView,S as StateFlags};