@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.5 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{hasScaling as e}from"../../../core/mathUtils.js";import r from"../../../geometry/SpatialReference.js";import{ensurePackedMat4f64 as t,ensurePackedArray as o}from"../../../geometry/support/DoubleArray.js";import n from"../../../geometry/support/MeshGeoreferencedVertexSpace.js";import s from"../../../geometry/support/MeshLocalVertexSpace.js";import{b as i,n as a}from"../../../chunks/vec3.js";import{get as f,cleanup as c}from"../../../libs/i3s/I3SModule.js";import{TransformedGeometry as l,TransformedData as u}from"./SceneLayerWorkerHandle.js";async function m(e){A=await v();const r=[e.geometryBuffer];return{result:x(A,e,r),transferList:r}}async function p(e){A=await v();const r=[e.geometryBuffer],{geometryBuffer:t}=e,o=t.byteLength,n=A._malloc(o),s=new Uint8Array(A.HEAPU8.buffer,n,o);s.set(new Uint8Array(t));const i=A.dracoDecompressPointCloudData(n,s.byteLength);if(A._free(n),i.error.length>0)throw new Error(`i3s.wasm: ${i.error}`);const a=i.featureIds?.length>0?i.featureIds.slice():null,f=i.positions.slice();return a&&r.push(a.buffer),r.push(f.buffer),{result:{positions:f,featureIds:a},transferList:r}}async function y(e){await v(),S(e);const r={buffer:e.buffer};return{result:r,transferList:[r.buffer]}}async function h(e){await v(),L(e)}async function d(e){A=await v(),A.setLegacySchema(e.context,e.jsonSchema)}async function g(e){const{localMatrix:i,origin:a,positions:f,vertexSpace:c}=e,l=r.fromJSON(e.inSpatialReference),u=r.fromJSON(e.outSpatialReference),m=i?t(i):void 0,p=o(a);let y;const[{projectBuffer:h},{initializeProjection:d}]=await Promise.all([import("../../../geometry/projection/projectBuffer.js"),import("../../../geometry/projectionUtils.js")]);await d(l,u);const g=[0,0,0];if(!h(p,l,0,g,u,0))throw new Error("Failed to project");if("georeferenced"===c.type&&null==c.origin){if(y=new Float64Array(f.length),!h(f,l,0,y,u,0,y.length/3))throw new Error("Failed to project")}else{const e="georeferenced"===c.type?n.fromJSON(c):s.fromJSON(c),{projectMeshVertexPositions:r}=await import("../../../geometry/support/meshUtils/projectMeshVertexPositions.js"),t=r({vertexAttributes:{position:f},transform:m?{localMatrix:m}:void 0,vertexSpace:e,spatialReference:l},u);if(!t)throw new Error("Failed to project");y=t}const b=y.length,[w,j,A]=g;for(let r=0;r<b;r+=3)y[r]-=w,y[r+1]-=j,y[r+2]-=A;return{result:{projected:y,original:f,projectedOrigin:g},transferList:[y.buffer,f.buffer]}}async function b({normalMatrix:r,normals:t}){const o=new Float32Array(t.length);return i(o,t,r),e(r)&&a(o,o),{result:{transformed:o,original:t},transferList:[o.buffer,t.buffer]}}function w(e){U(e)}let j,A;function L(e){if(!A)return;const r=e.modifications,t=A._malloc(8*r.length),o=new Float64Array(A.HEAPU8.buffer,t,r.length);for(let n=0;n<r.length;++n)o[n]=r[n];A.setModifications(e.context,t,r.length,e.isGeodetic),A._free(t)}function x(e,r,t){const{context:o,globalTrafo:n,mbs:s,obbData:i,layouts:a,needNormals:f,elevationOffset:c,geometryBuffer:m,geometryDescriptor:p,indexToVertexProjector:y,vertexToRenderProjector:h,normalReferenceFrame:d}=r,g=e._malloc(m.byteLength),b=33,w=e._malloc(b*Float64Array.BYTES_PER_ELEMENT),j=new Uint8Array(e.HEAPU8.buffer,g,m.byteLength);j.set(new Uint8Array(m));const A=new Float64Array(e.HEAPU8.buffer,w,b);P(A,[NaN,NaN,NaN],0);let L=3;P(A,n,L),L+=16,P(A,s.center,L),L+=3,A[L++]=s.radius,i&&P(A,i,L++);const x={isDraco:!1,isLegacy:!1,color:a.some(e=>e.some(e=>"color"===e.name)),normal:f&&a.some(e=>e.some(e=>"normalCompressed"===e.name)),uv0:a.some(e=>e.some(e=>"uv0"===e.name)),uvRegion:a.some(e=>e.some(e=>"uvRegion"===e.name)),featureIndex:p.featureIndex},E=e.process(o,!!i,g,j.byteLength,p,x,w,c,y,h,d);if(e._free(w),e._free(g),E.error.length>0)throw new Error(`i3s.wasm: ${E.error}`);if(E.discarded)return null;const S=E.componentOffsets.length>0?E.componentOffsets.slice():null,U=E.featureIds.length>0?E.featureIds.slice():null,_=E.anchorIds.length>0?Array.from(E.anchorIds):null,v=E.anchors.length>0?Array.from(E.anchors):null,N=E.interleavedVertedData.slice().buffer,F=1===E.indicesType?new Uint16Array(E.indices.buffer,E.indices.byteOffset,E.indices.byteLength/2).slice():new Uint32Array(E.indices.buffer,E.indices.byteOffset,E.indices.byteLength/4).slice(),I=E.positions.slice(),{buffer:M,byteOffset:O,byteLength:B}=E.positionIndices,R=1===E.positionIndicesType?new Uint16Array(M,O,B/2).slice():new Uint32Array(M,O,B/4).slice(),T=new l(r.layouts[0],N,F,E.hasColors,E.hasModifications,{data:I,indices:R});return U&&t.push(U.buffer),S&&t.push(S.buffer),t.push(N),t.push(F.buffer),t.push(I.buffer),t.push(R.buffer),new u(S,U,_,v,T,n,E.obb)}function E(e){return 0===e?0:1===e?1:2===e?2:3}function S(e){if(!A)return;const{context:r,buffer:t}=e,o=A._malloc(t.byteLength),n=t.byteLength/Float64Array.BYTES_PER_ELEMENT,s=new Float64Array(A.HEAPU8.buffer,o,n),i=new Float64Array(t);s.set(i),A.filterOBBs(r,o,n),i.set(s),A._free(o)}function U(e){0===A?.destroy(e)&&(A=null,j=null,c())}function P(e,r,t){for(let o=0;o<r.length;++o)e[o+t]=r[o]}async function _(){A||await v()}async function v(){return A||(A=await(j??=f())),A}const N={transform:(e,r)=>A&&x(A,e,r),destroy:U};export{w as destroyContext,p as dracoDecompressPointCloudData,y as filterObbsForModifications,S as filterObbsForModificationsSync,_ as initialize,E as interpretObbModificationResults,m as process,g as project,d as setLegacySchema,h as setModifications,L as setModificationsSync,N as test,b as transformNormals};