@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.54 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import t from"../../../../../core/RandomLCG.js";import{g as o,n as e}from"../../../../../chunks/vec32.js";import{create as r}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{glLayout as n}from"../../../support/buffer/glUtil.js";import{compressNormal as i}from"../Normals.js";import{RegularEdgeInstancesLayout as s,SilhouetteEdgeInstancesLayout as a}from"./bufferLayouts.js";const c=.7;class f{updateSettings(t){this.settings=t,this._edgeHashFunction=t.reducedPrecision?d:l}write(t,o,e){B.seed=this._edgeHashFunction(e);const r=B.getIntRange(0,255),n=B.getIntRange(0,this.settings.variants-1),i=B.getFloat(),s=255*(.5*y(-(1-Math.min(i/c,1))+Math.max(0,i-c)/(1-c),1.2)+.5);t.position0.setVec(o,e.position0),t.position1.setVec(o,e.position1),t.componentIndex.set(o,e.componentIndex),t.variantOffset.set(o,r),t.variantStroke.set(o,n),t.variantExtension.set(o,s)}}const m=new Float32Array(6),p=new Uint32Array(m.buffer),u=new Uint32Array(1);function l(t){return m[0]=t.position0[0],m[1]=t.position0[1],m[2]=t.position0[2],m[3]=t.position1[0],m[4]=t.position1[1],m[5]=t.position1[2],u[0]=31*(31*(31*(31*(31*(166811+p[0])+p[1])+p[2])+p[3])+p[4])+p[5],u[0]}function d(t){const o=m;o[0]=h(t.position0[0]),o[1]=h(t.position0[1]),o[2]=h(t.position0[2]),o[3]=h(t.position1[0]),o[4]=h(t.position1[1]),o[5]=h(t.position1[2]),u[0]=5381;for(let e=0;e<p.length;e++)u[0]=31*u[0]+p[e];return u[0]}const g=1e4;function h(t){return Math.round(t*g)/g}function y(t,o){return Math.abs(t)**o*Math.sign(t)}class w{constructor(){this._commonWriter=new f}updateSettings(t){this._commonWriter.updateSettings(t)}allocate(t){return s.createBuffer(t)}write(t,r,n){this._commonWriter.write(t,r,n),o(S,n.faceNormal0,n.faceNormal1),e(S,S);const{typedBuffer:s,typedBufferStride:a}=t.normalCompressed;i(s,r,S[0],S[1],S[2],a)}}w.Layout=s,w.glLayout=n(s,1);class N{constructor(){this._commonWriter=new f}updateSettings(t){this._commonWriter.updateSettings(t)}allocate(t){return a.createBuffer(t)}write(t,o,e){this._commonWriter.write(t,o,e);{const{typedBuffer:r,typedBufferStride:n}=t.normalCompressed;i(r,o,e.faceNormal0[0],e.faceNormal0[1],e.faceNormal0[2],n)}{const{typedBuffer:r,typedBufferStride:n}=t.normal2Compressed;i(r,o,e.faceNormal1[0],e.faceNormal1[1],e.faceNormal1[2],n)}}}N.Layout=a,N.glLayout=n(a,1);const S=r(),B=new t;export{w as RegularEdgeBufferWriter,N as SilhouetteEdgeBufferWriter};