@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 7.18 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../../../../core/Accessor.js";import{reallocGrowthFactor as i}from"../../../../../core/arrayUtils.js";import{EventEmitter as s}from"../../../../../core/Evented.js";import{property as a,subclass as r}from"../../../../../core/accessorSupport/decorators.js";import{fromMat4 as o,invert as n,transpose as l}from"../../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as h}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{set as m}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as f}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{BufferViewVec4f as d,BufferViewVec4u8 as p,BufferViewUint8 as _}from"../../../../../geometry/support/buffer/BufferView.js";import{scaleFromMatrix as u}from"../../../support/mathUtils.js";import{newLayout as v}from"../../../support/buffer/InterleavedLayout.js";import{olidEnabled as b}from"../../effects/geometry/olidUtils.js";import{assert as M}from"../Util.js";class T{constructor(t){this.localTransform=t.localTransform,this.globalTransform=t.globalTransform,this.modelOrigin=t.modelOrigin,this.model=t.instanceModel,this.modelNormal=t.instanceModelNormal,this.modelScaleFactors=t.modelScaleFactors,this.boundingSphere=t.boundingSphere,this.featureAttribute=t.getField("instanceFeatureAttribute",d),this.color=t.getField("instanceColor",p),this.olidColor=t.getField("instanceOlidColor",p),this.state=t.getField("state",_),this.lodLevel=t.getField("lodLevel",_)}}let F=class extends e{constructor(t,e){super(t),this.events=new s,this._capacity=0,this._size=0,this._next=0,this._highlightOptionsMap=new Map,this._highlightOptionsMapPrev=new Map,this._layout=S(e),this._capacity=A,this._buffer=this._layout.createBuffer(this._capacity),this._view=new T(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,1),this._size++,this.events.emit("instances-changed"),t}removeInstance(t){const e=this._view.state;M(t>=0&&t<this._capacity&&!!(1&e.get(t)),"invalid instance handle"),this._getStateFlag(t,18)?this._setStateFlags(t,32):this.freeInstance(t),this.events.emit("instances-changed")}freeInstance(t){const e=this._view.state;M(t>=0&&t<this._capacity&&!!(1&e.get(t)),"invalid instance handle"),e.set(t,0),this._size--}setLocalTransform(t,e,i=!0){this._view.localTransform.setMat(t,e),i&&this.updateModelTransform(t)}getLocalTransform(t,e){this._view.localTransform.getMat(t,e)}setGlobalTransform(t,e,i=!0){this._view.globalTransform.setMat(t,e),i&&this.updateModelTransform(t)}getGlobalTransform(t,e){this._view.globalTransform.getMat(t,e)}updateModelTransform(t){const e=this._view,i=x,s=j;e.localTransform.getMat(t,C),e.globalTransform.getMat(t,L);const a=c(L,L,C);m(i,a[12],a[13],a[14]),e.modelOrigin.setVec(t,i),o(s,a),e.model.setMat(t,s);const r=u(x,a);r.sort(),e.modelScaleFactors.set(t,0,r[1]),e.modelScaleFactors.set(t,1,r[2]),n(s,s),l(s,s),e.modelNormal.setMat(t,s),this._setStateFlags(t,64),this.events.emit("instance-transform-changed",{index:t})}getModelTransform(t,e){const i=this._view;i.model.getMat(t,j),i.modelOrigin.getVec(t,x),e[0]=j[0],e[1]=j[1],e[2]=j[2],e[3]=0,e[4]=j[3],e[5]=j[4],e[6]=j[5],e[7]=0,e[8]=j[6],e[9]=j[7],e[10]=j[8],e[11]=0,e[12]=x[0],e[13]=x[1],e[14]=x[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(x,this,t),e*=Math.max(x[0],x[1],x[2])),e}getCombinedMedianScaleFactor(t){let e=this._view.modelScaleFactors.get(t,0);return null!=this.shaderTransformation&&(this.shaderTransformation.scaleFactor(x,this,t),e*=w(x[0],x[1],x[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.olidColor?.setVec(t,e)}setVisible(t,e){e!==this.getVisible(t)&&(this._setStateFlag(t,4,e),this.events.emit("instance-visibility-changed",{index:t}))}getVisible(t){return this._getStateFlag(t,4)}setHighlight(t,e){const{_highlightOptionsMap:i}=this,s=i.get(t);e?e!==s&&(i.set(t,e),this._setStateFlag(t,8,!0),this.events.emit("instance-highlight-changed")):s&&(i.delete(t),this._setStateFlag(t,8,!1),this.events.emit("instance-highlight-changed"))}get highlightOptionsMap(){return this._highlightOptionsMap}getHighlightStateFlag(t){return this._getStateFlag(t,8)}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 i=0;i<this._capacity;++i){this.getState(i)&t&&++e}return e}_setStateFlags(t,e){const i=this._view.state;e=i.get(t)|e,i.set(t,e)}_clearStateFlags(t,e){const i=this._view.state;e=i.get(t)&~e,i.set(t,e)}_setStateFlag(t,e,i){i?this._setStateFlags(t,e):this._clearStateFlags(t,e)}_getStateFlag(t,e){return!!(this._view.state.get(t)&e)}_grow(){this._capacity=Math.max(A,Math.floor(this._capacity*i)),this._buffer=this._layout.createBuffer(this._capacity).copyFrom(this._buffer),this._view=new T(this._buffer)}_findSlot(){const t=this._view.state;let e=this._next;for(;1&t.get(e);)e=e+1===this._capacity?0:e+1;return this._next=e+1===this._capacity?0:e+1,e}};function w(t,e,i){return Math.max(Math.min(t,e),Math.min(Math.max(t,e),i))}t([a({constructOnly:!0})],F.prototype,"shaderTransformation",void 0),t([a()],F.prototype,"_size",void 0),t([a({readOnly:!0})],F.prototype,"size",null),F=t([r("esri.views.3d.webgl-engine.lib.lodRendering.InstanceData")],F);const y=v().mat4f64("localTransform").mat4f64("globalTransform").vec4f64("boundingSphere").vec3f64("modelOrigin").mat3f("instanceModel").mat3f("instanceModelNormal").vec2f("modelScaleFactors");function S(t){return O(y.clone(),t).u8("state").u8("lodLevel")}function O(t,e){return e.instancedFeatureAttribute&&t.vec4f("instanceFeatureAttribute"),e.instancedColor&&t.vec4u8("instanceColor"),b()&&t.vec4u8("instanceOlidColor"),t}const x=f(),j=h(),C=g(),L=g(),A=64;export{F as InstanceData,T as InstanceDataView,O as addOptionalLayoutFields,A as initialCapacity};