@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 5.42 kB
JavaScript
import{_ as t}from"../../../chunks/tslib.es6.js";import{fetchAsset as e}from"../../../assets.js";import r from"../../../core/Accessor.js";import{createTask as s}from"../../../core/asyncUtils.js";import i from"../../../core/Error.js";import a from"../../../core/Logger.js";import{isSome as o,abortMaybe as n,releaseMaybe as c,disposeMaybe as f,isNone as u}from"../../../core/maybe.js";import{isAbortError as h}from"../../../core/promiseUtils.js";import{initial as d}from"../../../core/reactiveUtils.js";import{property as p}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as m}from"../../../core/accessorSupport/decorators/subclass.js";import{c as l,o as g,m as _}from"../../../chunks/mat4.js";import{f as b}from"../../../chunks/mat4f64.js";import{WatchUpdatingTracking as y}from"../../../core/support/WatchUpdatingTracking.js";import{StarPassParameters as v,StarsTechnique as j}from"./StarsTechnique.js";import{glLayout as w}from"../support/buffer/glUtil.js";import{newLayout as T}from"../support/buffer/InterleavedLayout.js";import{Default3D as k}from"../webgl-engine/lib/DefaultVertexAttributeLocations.js";import{VertexArrayObject as D}from"../webgl-engine/lib/VertexArrayObject.js";import{VertexAttribute as P}from"../webgl-engine/lib/VertexAttribute.js";import{BufferObject as A}from"../../webgl/BufferObject.js";import{PrimitiveType as x,Usage as q}from"../../webgl/enums.js";let O=class extends r{get updating(){return this._updatingTracking.updating||this.loading}get loading(){return o(this._loadDataTask)&&!this._loadDataTask.finished}constructor(t){super(t),this._loadDataTask=null,this._numPoints=0,this._renderParameter=new v,this._updatingTracking=new y}initialize(){this._loadDataTask=this._createLoadDataTask()}destroy(){this._loadDataTask=n(this._loadDataTask),this._updatingTracking.destroy(),this._numPoints=0,this._technique=c(this._technique),this._vao=f(this._vao)}render(t){const{rctx:e}=t;if(this._ensureResources(e),u(this._technique)||u(this._vao))return;if(!this._technique.compiled)return void this.requestRender();const r=e.bindTechnique(this._technique,this._renderParameter,t.bindParameters);e.bindVAO(this._vao),r.assertCompatibleVertexAttributeLocations(this._vao),e.drawArrays(x.POINTS,0,this._numPoints)}_ensureResources(t){if(o(this._technique)||u(U))return;this._technique=new j({rctx:t,viewingMode:this.view.state.viewingMode}),this._numPoints=U.byteLength/L;const e=new Float32Array(U,0,2*this._numPoints),r=new Uint8Array(U,2*this._numPoints*4,this._numPoints);this._vao=this._createVertexArrayObject(t,e,r,this._numPoints),this._updatingTracking.add((()=>"virtual"!==this.view.environment.lighting.type?this.view.environment.lighting.date:null),(t=>this._update(t)),d)}_computeDayDuration(t){const e=t,r=new Date(t.getFullYear(),0,1,11,58,56);return(+e-+r)/(+new Date(t.getFullYear()+1,0,1,11,58,55)-+r)}_update(t){if(!t)return;const e=(t.getHours()/12+t.getMinutes()/60*(2/24)+t.getSeconds()/60*(2/1440)-.9972222)%2,r=2*this._computeDayDuration(t),s=l(this._renderParameter.modelMatrix,M);g(s,s,-r*Math.PI),_(s,I,s),g(s,s,-e*Math.PI),this.requestRender()}_hexToRGB(t){return[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)]}_unpackUint8Attributes(t){return t>=192?[2.9,t-192]:t>=160?[2.5,t-160]:t>=128?[2,t-128]:t>=96?[1.5,t-96]:t>=64?[1,t-64]:t>=32?[.7,t-32]:[.4,t]}_createVertexArrayObject(t,e,r,s){const i=R.createBuffer(s),a=i.position,o=i.color,n=i.size;for(let c=0;c<s;c++){const t=e[2*c+0],s=e[2*c+1];a.set(c,0,-Math.cos(t)*Math.sin(s)),a.set(c,1,-Math.sin(t)*Math.sin(s)),a.set(c,2,-Math.cos(s));const i=this._unpackUint8Attributes(r[c]),f=this._hexToRGB(S[i[1]]);o.set(c,0,255*f[0]),o.set(c,1,255*f[1]),o.set(c,2,255*f[2]),o.set(c,3,255),n.set(c,i[0])}return new D(t,k,{geometry:w(R)},{geometry:A.createVertex(t,q.STATIC_DRAW,i.buffer)})}_createLoadDataTask(){if(o(U))return null;const t=s((async t=>{const{data:r}=await e("esri/views/3d/environment/resources/stars.wsv",{responseType:"array-buffer",signal:t});this._verifyStarData(r),U=r}));return t.promise.catch((t=>{h(t)||a.getLogger(this.declaredClass).error(t)})).then((()=>{this.destroyed||(this.requestRender(),this.notifyChange("updating"))})),t}_verifyStarData(t){if(!t)throw new i("stars:no-data-received","Failed to create stars because star catalogue is missing");const e=t.byteLength/L;if(e%1!=0||e>5e4||e<5e3)throw new i("stars:invalid-data","Failed to create stars because star catalogue data is invalid")}};t([p({constructOnly:!0})],O.prototype,"view",void 0),t([p({constructOnly:!0})],O.prototype,"requestRender",void 0),t([p({readOnly:!0})],O.prototype,"updating",null),t([p()],O.prototype,"_loadDataTask",void 0),t([p()],O.prototype,"_updatingTracking",void 0),O=t([m("esri.views.3d.environment.Stars")],O);const S=["9bb2ff","9eb5ff","aabfff","bbccff","ccd8ff ","dae2ff","e4e9ff","eeefff","f8f6ff","fff9fb","fff5ef","fff1e5","ffeddb","ffe9d2","ffe6ca","ffe3c3","ffe0bb","ffddb4","ffdaad","ffd6a5","ffd29c","ffcc8f","ffc178","ffa94b","ff7b00"],I=b(1,0,0,0,0,.9174771405229186,.39778850739794974,0,0,-.39778850739794974,.9174771405229186,0,0,0,0,1),M=b(1,0,0,0,0,.9174771405229186,-.39778850739794974,0,0,.39778850739794974,.9174771405229186,0,0,0,0,1),L=9,R=T().vec3f(P.POSITION).vec4u8(P.COLOR).f32(P.SIZE);let U=null;export{O as Stars};