Agriculture-front-end/public/Cesium/Workers/decodeI3S.js

2 lines
10 KiB
JavaScript
Raw Normal View History

2023-04-23 09:41:12 +08:00
define(["./createTaskProcessorWorker","./defaultValue-f6d5e6da","./WebMercatorProjection-943e2226","./Matrix3-81054f0f","./Math-2ce22ee9"],(function(e,t,n,r,o){"use strict";let i;function a(e,t,n,r){return r[e+t*n]}function s(e,t,n){const r=n.nativeExtent;let o=(e-r.west)/(r.east-r.west)*(n.width-1),i=(t-r.south)/(r.north-r.south)*(n.height-1);const s=Math.floor(o);let u=Math.floor(i);o-=s,i-=u;const c=s<n.width?s+1:s;let f=u<n.height?u+1:u;u=n.height-1-u,f=n.height-1-f;let l=function(e,t,n,r,o,i){return(n*(1-e)+r*e)*(1-t)+(o*(1-e)+i*e)*t}(o,i,a(s,u,n.width,n.buffer),a(c,u,n.width,n.buffer),a(s,f,n.width,n.buffer),a(c,f,n.width,n.buffer));return l=l*n.scale+n.offset,l}function u(e,t,o){for(let i=0;i<o.length;i++){const a=o[i].nativeExtent;let u=new r.Cartesian3;if("WebMercator"===o[i].projectionType){const a=o[i].projection._ellipsoid._radii;u=new n.WebMercatorProjection(new r.Ellipsoid(a.x,a.y,a.z)).project(new r.Cartographic(e,t,0))}else u.x=e,u.y=t;if(u.x>a.west&&u.x<a.east&&u.y>a.south&&u.y<a.north)return s(u.x,u.y,o[i])}return 0}function c(e,n,r,o){const a=new Uint8Array(e,0,5);return a[0]==="D".charCodeAt()&&a[1]==="R".charCodeAt()&&a[2]==="A".charCodeAt()&&a[3]==="C".charCodeAt()&&a[4]==="O".charCodeAt()?function(e){const n=i,r=new n.DecoderBuffer,o=new Uint8Array(e);r.Init(o,o.length);const a=new n.Decoder,s=a.GetEncodedGeometryType(r),u=new n.MetadataQuerier;let c,l;s===n.TRIANGULAR_MESH&&(c=new n.Mesh,l=a.DecodeBufferToMesh(r,c));const d={vertexCount:[0],featureCount:0};if(t.defined(l)&&l.ok()&&0!==c.ptr){const e=c.num_faces(),r=c.num_attributes(),o=c.num_points();d.indices=new Uint32Array(3*e);const i=d.indices;d.vertexCount[0]=o,d.scale_x=1,d.scale_y=1;const s=new n.DracoInt32Array(3);for(let t=0;t<e;++t)a.GetFaceFromMesh(c,t,s),i[3*t]=s.GetValue(0),i[3*t+1]=s.GetValue(1),i[3*t+2]=s.GetValue(2);n.destroy(s);for(let e=0;e<r;++e){const r=a.GetAttribute(c,e),i=f(n,a,c,r,o),s=r.attribute_type();let l="unknown";s===n.POSITION?l="positions":s===n.NORMAL?l="normals":s===n.COLOR?l="colors":s===n.TEX_COORD&&(l="uv0s");const y=a.GetAttributeMetadata(c,e);if(0!==y.ptr){const e=u.NumEntries(y);for(let t=0;t<e;++t){const e=u.GetEntryName(y,t);"i3s-scale_x"===e?d.scale_x=u.GetDoubleEntry(y,"i3s-scale_x"):"i3s-scale_y"===e?d.scale_y=u.GetDoubleEntry(y,"i3s-scale_y"):"i3s-attribute-type"===e&&(l=u.GetStringEntry(y,"i3s-attribute-type"))}}t.defined(d[l])&&console.log("Attribute already exists",l),d[l]=i,"feature-index"===l&&d.featureCount++}n.destroy(c)}return n.destroy(u),n.destroy(a),d}(e):function(e,n,r,o){const i={vertexCount:0},a=new DataView(e);try{let s=0;if(i.vertexCount=a.getUint32(s,1),s+=4,i.featureCount=a.getUint32(s,1),s+=4,t.defined(r))for(let n=0;n<r.attributes.length;n++)t.defined(l[r.attributes[n]])?s=l[r.attributes[n]](i,e,s):console.error("Unknown decoder for",r.attributes[n]);else{let r=n.ordering,a=n.featureAttributeOrder;t.defined(o)&&t.defined(o.geometryData)&&t.defined(o.geometryData[0])&&t.defined(o.geometryData[0].params)&&(r=Object.keys(o.geometryData[0].params.vertexAttributes),a=Object.keys(o.geometryData[0].params.featureAttributes));for(let n=0;n<r.length;n++){const o=l[r[n]];t.defined(o)||console.log(r[n]),s=o(i,e,s)}for(let n=0;n<a.length;n++){const r=l[a[n]];t.defined(r)||console.log(a[n]),s=r(i,e,s)}}}catch(e){console.error(e)}return i.scale_x=1,i.scale_y=1,i}(e,n,r,o)}function f(e,n,r,o,i){const a=o.num_components()*i;let s;const u=[function(){},function(){s=new e.DracoInt8Array(a);n.GetAttributeInt8ForAllPoints(r,o,s)||console.error("Bad stream");const t=new Int8Array(a);for(let e=0;e<a;++e)t[e]=s.GetValue(e);return t},function(){s=new e.DracoInt8Array(a);n.GetAttributeUInt8ForAllPoints(r,o,s)||console.error("Bad stream");const t=new Uint8Array(a);for(let e=0;e<a;++e)t[e]=s.GetValue(e);return t},function(){s=new e.DracoInt16Array(a);n.GetAttributeInt16ForAllPoints(r,o,s)||console.error("Bad stream");const t=new Int16Array(a);for(let e=0;e<a;++e)t[e]=s.GetValue(e);return t},function(){s=new e.DracoInt16Array(a);n.GetAttributeUInt16ForAllPoints(r,o,s)||console.error("Bad stream");const t=ne