Newer
Older
smartwell_front_dz / smartwell / mars3d-cesium / Workers / decodeDraco.js
wangxitong on 11 Sep 2023 4 KB first commit
/**
 * @license
 * Cesium - https://github.com/CesiumGS/cesium
 * Version 1.96.6
 *
 * Copyright 2011-2022 Cesium Contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Columbus View (Pat. Pend.)
 *
 * Portions licensed separately.
 * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
 */
define(["./ComponentDatatype-cb7120fd","./defaultValue-ff4e651f","./IndexDatatype-5062f28c","./RuntimeError-ed67c927","./createTaskProcessorWorker","./WebGLConstants-dc5a5fcc"],(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,c=r.IndexDatatype.createTypedArray(n,s);let u=0;for(let r=0;r<o;++r)e.GetFaceFromMesh(t,r,a),c[u+0]=a.GetValue(0),c[u+1]=a.GetValue(1),c[u+2]=a.GetValue(2),u+=3;return i.destroy(a),{typedArray:c,numberOfIndices:s}}function c(r,n,o){const a=r.num_points(),s=o.num_components();let c,u=new i.AttributeQuantizationTransform;if(u.InitFromAttribute(o)){const t=new Array(s);for(let e=0;e<s;++e)t[e]=u.min_value(e);c={quantizationBits:u.quantization_bits(),minValues:t,range:u.range(),octEncoded:!1}}i.destroy(u),u=new i.AttributeOctahedronTransform,u.InitFromAttribute(o)&&(c={quantizationBits:u.quantization_bits(),octEncoded:!0}),i.destroy(u);const d=a*s;let f;f=e.defined(c)?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 i=0;i<o;++i)a[i]=s.GetValue(i);return i.destroy(s),a}(r,n,o,c,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 i=0;i<n;++i)o[i]=a.GetValue(i);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:c}}}function u(t){return e.defined(t.bufferView)?function(t){const e=new i.Decoder,r=["POSITION","NORMAL","COLOR","TEX_COORD"];if(t.dequantizeInShader)for(let n=0;n<r.length;++n)e.SkipAttributeTransform(i[r[n]]);const o=t.bufferView,a=new i.DecoderBuffer;if(a.Init(t.array,o.byteLength),e.GetEncodedGeometryType(a)!==i.TRIANGULAR_MESH)throw new n.RuntimeError("Unsupported draco mesh geometry type.");const u=new i.Mesh,d=e.DecodeBufferToMesh(a,u);if(!d.ok()||0===u.ptr)throw new n.RuntimeError(`Error decoding draco mesh geometry: ${d.error_msg()}`);i.destroy(a);const f={},y=t.compressedAttributes;for(const n in y)if(y.hasOwnProperty(n)){const t=y[n],r=e.GetAttributeByUniqueId(u,t);f[n]=c(u,e,r)}const A={indexArray:s(u,e),attributeData:f};return i.destroy(u),i.destroy(e),A}(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={},u=t.properties;for(const n in u)if(u.hasOwnProperty(n)){let t;if("POSITION"===n||"NORMAL"===n){const r=e.GetAttributeId(o,i[n]);t=e.GetAttribute(o,r)}else{const r=u[n];t=e.GetAttributeByUniqueId(o,r)}s[n]=c(o,e,t)}return i.destroy(o),i.destroy(e),s}(t)}function d(t){i=t,self.onmessage=o(u),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())}))}}));