UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 7.2 kB
import{_ as t}from"../../../../../chunks/tslib.es6.js";import e from"../../../../../core/Accessor.js";import s from"../../../../../core/Evented.js";import{isSome as i}from"../../../../../core/maybe.js";import{property as r}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/accessorSupport/ensureType.js";import"../../../../../core/arrayUtils.js";import{subclass as a}from"../../../../../core/accessorSupport/decorators/subclass.js";import{f as o,e as n,t as l}from"../../../../../chunks/mat3.js";import{c}from"../../../../../chunks/mat3f64.js";import{m as h}from"../../../../../chunks/mat4.js";import{c as m}from"../../../../../chunks/mat4f64.js";import{s as f}from"../../../../../chunks/vec3.js";import{c as g}from"../../../../../chunks/vec3f64.js";import{BufferViewMat4f64 as d,BufferViewVec3f64 as u,BufferViewMat3f as T,BufferViewVec2f as _,BufferViewVec4f64 as L,BufferViewVec4f as A,BufferViewUint8 as p,BufferViewVec4u8 as E}from"../../../../../geometry/support/buffer/BufferView.js";import{scaleFromMatrix as O}from"../../../support/mathUtils.js";import{newLayout as v}from"../../../support/buffer/InterleavedLayout.js";import{assert as F}from"../Util.js";import{VertexAttribute as S}from"../VertexAttribute.js";var I;function M(t){let e=v().mat4f64(S.LOCALTRANSFORM).mat4f64(S.GLOBALTRANSFORM).vec4f64(S.BOUNDINGSPHERE).vec3f64(S.MODELORIGIN).mat3f(S.MODEL).mat3f(S.MODELNORMAL).vec2f(S.MODELSCALEFACTORS);return t.includes("color")&&(e=e.vec4f(S.COLOR)),t.includes("featureAttribute")&&(e=e.vec4f(S.FEATUREATTRIBUTE)),e=e.u8(S.STATE).u8(S.LODLEVEL),t.includes(S.OBJECTANDLAYERIDCOLOR)&&(e=e.vec4u8(S.OBJECTANDLAYERIDCOLOR)),e.alignTo(8),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"}(I||(I={}));class b{constructor(t){this.localTransform=t.getField(S.LOCALTRANSFORM,d),this.globalTransform=t.getField(S.GLOBALTRANSFORM,d),this.modelOrigin=t.getField(S.MODELORIGIN,u),this.model=t.getField(S.MODEL,T),this.modelNormal=t.getField(S.MODELNORMAL,T),this.modelScaleFactors=t.getField(S.MODELSCALEFACTORS,_),this.boundingSphere=t.getField(S.BOUNDINGSPHERE,L),this.color=t.getField(S.COLOR,A),this.featureAttribute=t.getField(S.FEATUREATTRIBUTE,A),this.state=t.getField(S.STATE,p),this.lodLevel=t.getField(S.LODLEVEL,p),this.objectAndLayerIdColor=t.getField(S.OBJECTANDLAYERIDCOLOR,E)}}let C=class extends e{constructor(t,e){super(t),this.events=new s,this._capacity=0,this._size=0,this._next=0,this._buffer=null,this._view=null,this._layout=M(e)}get capacity(){return this._capacity}get size(){return this._size}get buffer(){return this._buffer.buffer}get view(){return this._view}addInstance(){this._size+1>this._capacity&&this._grow();const t=this._findSlot();return this._view.state.set(t,I.ALLOCATED),this._size++,this.events.emit("instances-changed"),t}removeInstance(t){const e=this._view.state;F(t>=0&&t<this._capacity&&0!=(e.get(t)&I.ALLOCATED),"invalid instance handle"),this._getStateFlag(t,I.ACTIVE)?this._setStateFlags(t,I.REMOVE):this.freeInstance(t),this.events.emit("instances-changed")}freeInstance(t){const e=this._view.state;F(t>=0&&t<this._capacity&&0!=(e.get(t)&I.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=D,i=V;e.localTransform.getMat(t,H),e.globalTransform.getMat(t,G);const r=h(G,G,H);f(s,r[12],r[13],r[14]),e.modelOrigin.setVec(t,s),o(i,r),e.model.setMat(t,i);const a=O(D,r);a.sort(),e.modelScaleFactors.set(t,0,a[1]),e.modelScaleFactors.set(t,1,a[2]),n(i,i),l(i,i),e.modelNormal.setMat(t,i),this._setStateFlags(t,I.TRANSFORM_CHANGED),this.events.emit("instance-transform-changed",{index:t})}getModelTransform(t,e){const s=this._view;s.model.getMat(t,V),s.modelOrigin.getVec(t,D),e[0]=V[0],e[1]=V[1],e[2]=V[2],e[3]=0,e[4]=V[3],e[5]=V[4],e[6]=V[5],e[7]=0,e[8]=V[6],e[9]=V[7],e[10]=V[8],e[11]=0,e[12]=D[0],e[13]=D[1],e[14]=D[2],e[15]=1}applyShaderTransformation(t,e){i(this.shaderTransformation)&&this.shaderTransformation.applyTransform(this,t,e)}getCombinedModelTransform(t,e){return this.getModelTransform(t,e),i(this.shaderTransformation)&&this.shaderTransformation.applyTransform(this,t,e),e}getCombinedLocalTransform(t,e){return this._view.localTransform.getMat(t,e),i(this.shaderTransformation)&&this.shaderTransformation.applyTransform(this,t,e),e}getCombinedMaxScaleFactor(t){let e=this._view.modelScaleFactors.get(t,1);if(i(this.shaderTransformation)){const s=this.shaderTransformation.scaleFactor(D,this,t);e*=Math.max(s[0],s[1],s[2])}return e}getCombinedMedianScaleFactor(t){let e=this._view.modelScaleFactors.get(t,0);if(i(this.shaderTransformation)){const s=this.shaderTransformation.scaleFactor(D,this,t);e*=R(s[0],s[1],s[2])}return 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)}getColor(t,e){this._view.color.getVec(t,e)}setVisible(t,e){e!==this.getVisible(t)&&(this._setStateFlag(t,I.VISIBLE,e),this.events.emit("instance-visibility-changed",{index:t}))}getVisible(t){return this._getStateFlag(t,I.VISIBLE)}setHighlight(t,e){e!==this.getHighlight(t)&&(this._setStateFlag(t,I.HIGHLIGHT,e),this.events.emit("instance-highlight-changed"))}getHighlight(t){return this._getStateFlag(t,I.HIGHLIGHT)}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(){const t=Math.max(w,Math.floor(this._capacity*y)),e=this._layout.createBuffer(t);if(this._buffer){const t=new Uint8Array(this._buffer.buffer);new Uint8Array(e.buffer).set(t)}this._capacity=t,this._buffer=e,this._view=new b(this._buffer)}_findSlot(){const t=this._view.state;let e=this._next;for(;t.get(e)&I.ALLOCATED;)e=e+1===this._capacity?0:e+1;return this._next=e+1===this._capacity?0:e+1,e}};function R(t,e,s){return Math.max(Math.min(t,e),Math.min(Math.max(t,e),s))}t([r({constructOnly:!0})],C.prototype,"shaderTransformation",void 0),t([r()],C.prototype,"_size",void 0),t([r({readOnly:!0})],C.prototype,"size",null),C=t([a("esri.views.3d.webgl-engine.lib.lodRendering.InstanceData")],C);const w=1024,y=2,D=g(),V=c(),H=m(),G=m();export{C as InstanceData,b as InstanceDataView,I as StateFlags};