@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 4.25 kB
JavaScript
import{isSome as e}from"../../../core/maybe.js";import{IndexType as t}from"../../../libs/i3s/enums.js";import{get as r}from"../../../libs/i3s/I3SModule.js";import{NodeIMModificationImpact as n}from"./i3s/I3SNode.js";async function o(e){await p();const t=[e.geometryBuffer];return{result:b(e,t),transferList:t}}async function s(e){await p();const t=[e.geometryBuffer],{geometryBuffer:r}=e,n=r.byteLength,o=u._malloc(n),s=new Uint8Array(u.HEAPU8.buffer,o,n);s.set(new Uint8Array(r));const i=u.dracoDecompressPointCloudData(o,s.byteLength);if(u._free(o),i.error.length>0)throw new Error(`i3s.wasm: ${i.error}`);const f=i.featureIds?.length>0?i.featureIds.slice():null,a=i.positions.slice();return f&&t.push(f.buffer),t.push(a.buffer),{result:{positions:a,featureIds:f},transferList:t}}async function i(e){await p(),d(e);const t={buffer:e.buffer};return{result:t,transferList:[t.buffer]}}async function f(e){await p(),y(e)}async function a(e){await p(),u.setLegacySchema(e.context,e.jsonSchema)}function l(e){E(e)}let c,u;function y(e){const t=e.modifications,r=u._malloc(8*t.length),n=new Float64Array(u.HEAPU8.buffer,r,t.length);for(let o=0;o<t.length;++o)n[o]=t[o];u.setModifications(e.context,r,t.length,e.isGeodetic),u._free(r)}function b(r,n){if(!u)return null;const{context:o,localOrigin:s,globalTrafo:i,mbs:f,obb:a,elevationOffset:l,geometryBuffer:c,geometryDescriptor:y,indexToVertexProjector:b,vertexToRenderProjector:m}=r,d=u._malloc(c.byteLength),E=33,p=u._malloc(E*Float64Array.BYTES_PER_ELEMENT),g=new Uint8Array(u.HEAPU8.buffer,d,c.byteLength);g.set(new Uint8Array(c));const w=new Float64Array(u.HEAPU8.buffer,p,E);h(w,s);let A=w.byteOffset+3*w.BYTES_PER_ELEMENT,_=new Float64Array(w.buffer,A);h(_,i),A+=16*w.BYTES_PER_ELEMENT,_=new Float64Array(w.buffer,A),h(_,f),A+=4*w.BYTES_PER_ELEMENT,e(a)&&(_=new Float64Array(w.buffer,A),h(_,a.center),A+=3*w.BYTES_PER_ELEMENT,_=new Float64Array(w.buffer,A),h(_,a.halfSize),A+=3*w.BYTES_PER_ELEMENT,_=new Float64Array(w.buffer,A),h(_,a.quaternion));const L=y,I={isDraco:!1,isLegacy:!1,color:r.layouts.some((e=>e.some((e=>"color"===e.name)))),normal:r.needNormals&&r.layouts.some((e=>e.some((e=>"normalCompressed"===e.name)))),uv0:r.layouts.some((e=>e.some((e=>"uv0"===e.name)))),uvRegion:r.layouts.some((e=>e.some((e=>"uvRegion"===e.name)))),featureIndex:L.featureIndex},T=u.process(o,!!r.obb,d,g.byteLength,L,I,p,l,b,m,r.normalReferenceFrame);if(u._free(p),u._free(d),T.error.length>0)throw new Error(`i3s.wasm: ${T.error}`);if(T.discarded)return null;const P=T.componentOffsets.length>0?T.componentOffsets.slice():null,U=T.featureIds.length>0?T.featureIds.slice():null,B=T.interleavedVertedData.slice().buffer,F=T.indicesType===t.Int16?new Uint16Array(T.indices.buffer,T.indices.byteOffset,T.indices.byteLength/2).slice():new Uint32Array(T.indices.buffer,T.indices.byteOffset,T.indices.byteLength/4).slice(),M=T.positions.slice(),S=T.positionIndicesType===t.Int16?new Uint16Array(T.positionIndices.buffer,T.positionIndices.byteOffset,T.positionIndices.byteLength/2).slice():new Uint32Array(T.positionIndices.buffer,T.positionIndices.byteOffset,T.positionIndices.byteLength/4).slice(),x={layout:r.layouts[0],interleavedVertexData:B,indices:F,hasColors:T.hasColors,hasModifications:T.hasModifications,positionData:{data:M,indices:S}};return U&&n.push(U.buffer),P&&n.push(P.buffer),n.push(B),n.push(F.buffer),n.push(M.buffer),n.push(S.buffer),{componentOffsets:P,featureIds:U,transformedGeometry:x,obb:T.obb}}function m(e){return 0===e?n.Unmodified:1===e?n.PotentiallyModified:2===e?n.Culled:n.Unknown}function d(e){const{context:t,buffer:r}=e,n=u._malloc(r.byteLength),o=r.byteLength/Float64Array.BYTES_PER_ELEMENT,s=new Float64Array(u.HEAPU8.buffer,n,o),i=new Float64Array(r);s.set(i),u.filterOBBs(t,n,o),i.set(s),u._free(n)}function E(e){u&&u.destroy(e)}function h(e,t){for(let r=0;r<t.length;++r)e[r]=t[r]}function p(){return u?Promise.resolve():(c||(c=r().then((e=>{u=e,c=null}))),c)}const g={transform:b,destroy:E};export{l as destroyContext,s as dracoDecompressPointCloudData,i as filterObbsForModifications,d as filterObbsForModificationsSync,p as initialize,m as interpretObbModificationResults,o as process,a as setLegacySchema,f as setModifications,y as setModificationsSync,g as test};