UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 2.23 kB
import t from"../../../../../core/RandomLCG.js";import{a as o,n as e}from"../../../../../chunks/vec3.js";import{c as n}from"../../../../../chunks/vec3f64.js";import{glLayout as i}from"../../../support/buffer/glUtil.js";import{RegularEdgeInstancesLayout as r,SilhouetteEdgeInstancesLayout as s}from"./bufferLayouts.js";class a{updateSettings(t){this.settings=t,this._edgeHashFunction=t.reducedPrecision?f:p}write(t,o,e){const n=this._edgeHashFunction(e);y.seed=n;const i=y.getIntRange(0,255),r=y.getIntRange(0,this.settings.variants-1),s=.7,a=y.getFloat(),c=255*(.5*g(-(1-Math.min(a/s,1))+Math.max(0,a-s)/(1-s),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,c)}trim(t,o){return t.slice(0,o)}}const c=new Float32Array(6),m=new Uint32Array(c.buffer),u=new Uint32Array(1);function p(t){const o=c;o[0]=t.position0[0],o[1]=t.position0[1],o[2]=t.position0[2],o[3]=t.position1[0],o[4]=t.position1[1],o[5]=t.position1[2],u[0]=5381;for(let e=0;e<m.length;e++)u[0]=31*u[0]+m[e];return u[0]}function f(t){const o=c;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<m.length;e++)u[0]=31*u[0]+m[e];return u[0]}const l=1e4;function h(t){return Math.round(t*l)/l}function g(t,o){const e=t<0?-1:1;return Math.abs(t)**o*e}class d{constructor(){this._commonWriter=new a}updateSettings(t){this._commonWriter.updateSettings(t)}allocate(t){return r.createBuffer(t)}write(t,n,i){this._commonWriter.write(t,n,i),o(_,i.faceNormal0,i.faceNormal1),e(_,_),t.normal.setVec(n,_)}trim(t,o){return this._commonWriter.trim(t,o)}}d.Layout=r,d.glLayout=i(r,1);class w{constructor(){this._commonWriter=new a}updateSettings(t){this._commonWriter.updateSettings(t)}allocate(t){return s.createBuffer(t)}write(t,o,e){this._commonWriter.write(t,o,e),t.normalA.setVec(o,e.faceNormal0),t.normalB.setVec(o,e.faceNormal1)}trim(t,o){return this._commonWriter.trim(t,o)}}w.Layout=s,w.glLayout=i(s,1);const _=n(),y=new t;export{a as CommonBufferWriter,d as RegularEdgeBufferWriter,w as SilhouetteEdgeBufferWriter};