1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-30 03:38:55 -05:00
sdrangel/plugins/feature/map/Cesium/Workers/decodeDraco.js
2022-02-04 20:41:22 +00:00

2 lines
4.2 KiB
JavaScript

define(["./ComponentDatatype-692a36d3","./when-229515d6","./IndexDatatype-7c683b18","./RuntimeError-608565a6","./createTaskProcessorWorker","./WebGLConstants-f63312fc"],(function(t,e,r,n,o,a){"use strict";let i;function s(t,e){const n=t.num_points(),o=t.num_faces(),a=new i.DracoInt32Array,s=3*o,u=r.IndexDatatype.createTypedArray(n,s);let c=0;for(let r=0;r<o;++r)e.GetFaceFromMesh(t,r,a),u[c+0]=a.GetValue(0),u[c+1]=a.GetValue(1),u[c+2]=a.GetValue(2),c+=3;return i.destroy(a),{typedArray:u,numberOfIndices:s}}function u(r,n,o){const a=r.num_points(),s=o.num_components();let u,c=new i.AttributeQuantizationTransform;if(c.InitFromAttribute(o)){const t=new Array(s);for(let e=0;e<s;++e)t[e]=c.min_value(e);u={quantizationBits:c.quantization_bits(),minValues:t,range:c.range(),octEncoded:!1}}i.destroy(c),c=new i.AttributeOctahedronTransform,c.InitFromAttribute(o)&&(u={quantizationBits:c.quantization_bits(),octEncoded:!0}),i.destroy(c);const d=a*s;let f;f=e.defined(u)?function(t,e,r,n,o){let a,s;n.quantizationBits<=8?(s=new i.DracoUInt8Array,a=new Uint8Array(o),e.GetAttributeUInt8ForAllPoints(t,r,s)):(s=new i.DracoUInt16Array,a=new Uint16Array(o),e.GetAttributeUInt16ForAllPoints(t,r,s));for(let t=0;t<o;++t)a[t]=s.GetValue(t);return i.destroy(s),a}(r,n,o,u,d):function(t,e,r,n){let o,a;switch(r.data_type()){case 1:case 11:a=new i.DracoInt8Array,o=new Int8Array(n),e.GetAttributeInt8ForAllPoints(t,r,a);break;case 2:a=new i.DracoUInt8Array,o=new Uint8Array(n),e.GetAttributeUInt8ForAllPoints(t,r,a);break;case 3:a=new i.DracoInt16Array,o=new Int16Array(n),e.GetAttributeInt16ForAllPoints(t,r,a);break;case 4:a=new i.DracoUInt16Array,o=new Uint16Array(n),e.GetAttributeUInt16ForAllPoints(t,r,a);break;case 5:case 7:a=new i.DracoInt32Array,o=new Int32Array(n),e.GetAttributeInt32ForAllPoints(t,r,a);break;case 6:case 8:a=new i.DracoUInt32Array,o=new Uint32Array(n),e.GetAttributeUInt32ForAllPoints(t,r,a);break;case 9:case 10:a=new i.DracoFloat32Array,o=new Float32Array(n),e.GetAttributeFloatForAllPoints(t,r,a)}for(let t=0;t<n;++t)o[t]=a.GetValue(t);return i.destroy(a),o}(r,n,o,d);const y=t.ComponentDatatype.fromTypedArray(f);return{array:f,data:{componentsPerAttribute:s,componentDatatype:y,byteOffset:o.byte_offset(),byteStride:t.ComponentDatatype.getSizeInBytes(y)*s,normalized:o.normalized(),quantization:u}}}function c(t){return e.defined(t.bufferView)?function(t){const r=new i.Decoder,o=["POSITION","NORMAL"],a=t.compressedAttributes;if(e.defined(a.COLOR_1)||o.push("COLOR"),e.defined(a.TEXCOORD_1)||o.push("TEX_COORD"),t.dequantizeInShader)for(let t=0;t<o.length;++t)r.SkipAttributeTransform(i[o[t]]);const c=t.bufferView,d=new i.DecoderBuffer;if(d.Init(t.array,c.byteLength),r.GetEncodedGeometryType(d)!==i.TRIANGULAR_MESH)throw new n.RuntimeError("Unsupported draco mesh geometry type.");const f=new i.Mesh,y=r.DecodeBufferToMesh(d,f);if(!y.ok()||0===f.ptr)throw new n.RuntimeError("Error decoding draco mesh geometry: "+y.error_msg());i.destroy(d);const A={};for(const t in a)if(a.hasOwnProperty(t)){let e,n=t;if("TEXCOORD_0"===t&&(n="TEX_COORD"),"COLOR_0"===t&&(n="COLOR"),o.includes(n)){const t=r.GetAttributeId(f,i[n]);e=r.GetAttribute(f,t)}else{const n=a[t];e=r.GetAttributeByUniqueId(f,n)}A[t]=u(f,r,e)}const l={indexArray:s(f,r),attributeData:A};return i.destroy(f),i.destroy(r),l}(t):function(t){const e=new i.Decoder;t.dequantizeInShader&&(e.SkipAttributeTransform(i.POSITION),e.SkipAttributeTransform(i.NORMAL));const r=new i.DecoderBuffer;if(r.Init(t.buffer,t.buffer.length),e.GetEncodedGeometryType(r)!==i.POINT_CLOUD)throw new n.RuntimeError("Draco geometry type must be POINT_CLOUD.");const o=new i.PointCloud,a=e.DecodeBufferToPointCloud(r,o);if(!a.ok()||0===o.ptr)throw new n.RuntimeError("Error decoding draco point cloud: "+a.error_msg());i.destroy(r);const s={},c=t.properties;for(const t in c)if(c.hasOwnProperty(t)){let r;if("POSITION"===t||"NORMAL"===t){const n=e.GetAttributeId(o,i[t]);r=e.GetAttribute(o,n)}else{const n=c[t];r=e.GetAttributeByUniqueId(o,n)}s[t]=u(o,e,r)}return i.destroy(o),i.destroy(e),s}(t)}function d(t){i=t,self.onmessage=o(c),self.postMessage(!0)}return function(t){const r=t.data.webAssemblyConfig;if(e.defined(r))return require([r.modulePath],(function(t){e.defined(r.wasmBinaryFile)?(e.defined(t)||(t=self.DracoDecoderModule),t(r).then((function(t){d(t)}))):d(t())}))}}));