UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 5.24 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{_ as t}from"../../../../../chunks/tslib.es6.js";import{fetchAsset as e}from"../../../../../assets.js";import{createTask as s}from"../../../../../core/asyncUtils.js";import r from"../../../../../core/Error.js";import a from"../../../../../core/Logger.js";import{abortMaybe as i,disposeMaybe as o}from"../../../../../core/maybe.js";import{isAbortError as n}from"../../../../../core/promiseUtils.js";import{watch as f,initial as c,syncAndInitial as m}from"../../../../../core/reactiveUtils.js";import"../../../../../core/has.js";import"../../../../../core/RandomLCG.js";import{subclass as u}from"../../../../../core/accessorSupport/decorators/subclass.js";import{copy as l,rotateZ as h,multiply as d}from"../../../../../core/libs/gl-matrix-2/math/mat4.js";import{fromValues as p}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{InternalRenderCategory as b}from"../../../webgl.js";import{glLayout as _}from"../../../support/buffer/glUtil.js";import{newLayout as g}from"../../../support/buffer/InterleavedLayout.js";import{OpaqueEnvironment as j}from"../OpaqueEnvironment.js";import{StarPassParameters as w,StarsTechnique as v}from"./StarsTechnique.js";import{RenderRequestType as D}from"../../lib/basicInterfaces.js";import{Default3D as P}from"../../lib/DefaultVertexAttributeLocations.js";import{VertexArrayObject as T}from"../../lib/VertexArrayObject.js";import{VertexAttribute as y}from"../../lib/VertexAttribute.js";import{BufferObject as A}from"../../../../webgl/BufferObject.js";import{PrimitiveType as I,Usage as M}from"../../../../webgl/enums.js";let E=class extends j{constructor(){super(...arguments),this._starData=null,this._loadDataTask=null,this._numPoints=0,this._passParameters=new w}initialize(){this.addHandles([f((()=>this.view.environment.starsEnabled),(t=>t?this._enable():this._disable()),c),f((()=>"virtual"===this.view.environment.lighting.type?null:this.view.environment.lighting.date),(t=>this._update(t)),m)])}_enable(){super._enable(),this._loadDataTask=this._createLoadDataTask()}get loading(){return!!this._loadDataTask&&!this._loadDataTask.finished}destroy(){this._loadDataTask=i(this._loadDataTask),this._numPoints=0,this._vao=o(this._vao),this._starData=null}precompile(){this.techniques.precompile(v)}render(t){const e=t.find((({name:t})=>t===b.OPAQUE_ENVIRONMENT)),s=this.renderingContext;if(this.loading)return this.requestRender(D.UPDATE),e;if(!this._starData)return e;this._vao??=this._ensureResources(this._starData,s);const r=this.techniques.get(v);return r.compiled?(s.bindTechnique(r,this.bindParameters,this._passParameters),s.bindVAO(this._vao),s.drawArrays(I.POINTS,0,this._numPoints),e):(this.requestRender(D.UPDATE),e)}_ensureResources(t,e){this._numPoints=t.byteLength/V;return O(e,new Float32Array(t,0,2*this._numPoints),new Uint8Array(t,2*this._numPoints*4,this._numPoints),this._numPoints)}_update(t){if(!t)return;const e=(t.getHours()/12+t.getMinutes()/60*(2/24)+t.getSeconds()/60*(2/1440)-.9972222)%2,s=2*x(t),r=l(this._passParameters.modelMatrix,S);h(r,r,-s*Math.PI),d(r,q,r),h(r,r,-e*Math.PI),this.requestRender(D.UPDATE)}_createLoadDataTask(){if(this._starData)return null;const t=s((async t=>{const{data:s}=await e("esri/views/3d/environment/resources/stars.wsv",{responseType:"array-buffer",signal:t});L(s),this._starData=s}));return t.promise.catch((t=>{n(t)||a.getLogger(this).error(t)})).then((()=>{this.destroyed||this.requestRender(D.UPDATE)})),t}};function O(t,e,s,r){const a=F.createBuffer(r),i=a.position,o=a.color,n=a.size;for(let f=0;f<r;f++){const t=e[2*f],r=e[2*f+1];i.set(f,0,-Math.cos(t)*Math.sin(r)),i.set(f,1,-Math.sin(t)*Math.sin(r)),i.set(f,2,-Math.cos(r));const a=U(s[f]),c=R(k[a[1]]);o.set(f,0,255*c[0]),o.set(f,1,255*c[1]),o.set(f,2,255*c[2]),o.set(f,3,255),n.set(f,a[0])}return new T(t,P,new Map([["geometry",_(F)]]),new Map([["geometry",A.createVertex(t,M.STATIC_DRAW,a.buffer)]]))}function x(t){const e=t,s=new Date(t.getFullYear(),0,1,11,58,56);return(+e-+s)/(+new Date(t.getFullYear()+1,0,1,11,58,55)-+s)}function L(t){if(!t)throw new r("stars:no-data-received","Failed to create stars because star catalogue is missing");const e=t.byteLength/V;if(e%1!=0||e>5e4||e<5e3)throw new r("stars:invalid-data","Failed to create stars because star catalogue data is invalid")}function R(t){return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}function U(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]}E=t([u("esri.views.3d.webgl-engine.effects.stars.Stars")],E);const k=["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"],q=p(1,0,0,0,0,.9174771405229186,.39778850739794974,0,0,-.39778850739794974,.9174771405229186,0,0,0,0,1),S=p(1,0,0,0,0,.9174771405229186,-.39778850739794974,0,0,.39778850739794974,.9174771405229186,0,0,0,0,1),V=9,F=g().vec3f(y.POSITION).vec4u8(y.COLOR).f32(y.SIZE);export{E as Stars};