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