@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.58 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import t from"../../../../../core/RandomLCG.js";import{f as o,n as e}from"../../../../../chunks/vec32.js";import{create as i}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{glLayout as r}from"../../../support/buffer/glUtil.js";import{compressNormal as s}from"../Normals.js";import{RegularEdgeInstancesLayout as n,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 i=B.getIntRange(0,255),r=B.getIntRange(0,this.settings.variants-1),s=B.getFloat(),n=255*(.5*y(-(1-Math.min(s/c,1))+Math.max(0,s-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,i),t.variantStroke.set(o,r),t.variantExtension.set(o,n)}}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]=g(t.position0[0]),o[1]=g(t.position0[1]),o[2]=g(t.position0[2]),o[3]=g(t.position1[0]),o[4]=g(t.position1[1]),o[5]=g(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 h=1e4;function g(t){return Math.round(t*h)/h}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 n.createBuffer(t)}write(t,i,r){this._commonWriter.write(t,i,r),o(S,r.faceNormal0,r.faceNormal1),e(S,S);const{typedBuffer:n,typedBufferStride:a}=t.normalCompressed;s(n,i,S[0],S[1],S[2],a)}static{this.Layout=n}static{this.glLayout=r(n,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:i,typedBufferStride:r}=t.normalCompressed;s(i,o,e.faceNormal0[0],e.faceNormal0[1],e.faceNormal0[2],r)}{const{typedBuffer:i,typedBufferStride:r}=t.normal2Compressed;s(i,o,e.faceNormal1[0],e.faceNormal1[1],e.faceNormal1[2],r)}}static{this.Layout=a}static{this.glLayout=r(a,1)}}const S=i(),B=new t;export{w as RegularEdgeBufferWriter,N as SilhouetteEdgeBufferWriter};