@loaders.gl/draco 4.0.0-alpha.22 → 4.0.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/draco-worker.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{var X=Object.create;var w=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty;var ee=t=>w(t,"__esModule",{value:!0});var te=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var re=(t,e,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of K(e))!Z.call(t,o)&&o!=="default"&&w(t,o,{get:()=>e[o],enumerable:!(r=J(e,o))||r.enumerable});return t},oe=t=>re(ee(w(t!=null?X(H(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var N=te(()=>{});var x="4.0.0-alpha.22";function S(t,e){if(!t)throw new Error(e||"loaders.gl assertion failed.")}var f={self:typeof self!="undefined"&&self,window:typeof window!="undefined"&&window,global:typeof global!="undefined"&&global,document:typeof document!="undefined"&&document},Ie=f.self||f.window||f.global||{},Re=f.window||f.self||f.global||{},C=f.global||f.self||f.window||{},ke=f.document||{};var D=typeof process!="object"||String(process)!=="[object process]"||process.browser,T=typeof importScripts=="function",Pe=typeof window!="undefined"&&typeof window.orientation!="undefined",F=typeof process!="undefined"&&process.version&&/v([0-9]*)/.exec(process.version),Se=F&&parseFloat(F[1])||0;function M(t,e=!0,r){let o=r||new Set;if(t){if(B(t))o.add(t);else if(B(t.buffer))o.add(t.buffer);else if(!ArrayBuffer.isView(t)){if(e&&typeof t=="object")for(let a in t)M(t[a],e,o)}}return r===void 0?Array.from(o):[]}function B(t){return t?t instanceof ArrayBuffer||typeof MessagePort!="undefined"&&t instanceof MessagePort||typeof ImageBitmap!="undefined"&&t instanceof ImageBitmap||typeof OffscreenCanvas!="undefined"&&t instanceof OffscreenCanvas:!1}function b(){let parentPort;try{eval("globalThis.parentPort = require('worker_threads').parentPort"),parentPort=globalThis.parentPort}catch{}return parentPort}var O=new Map,p=class{static inWorkerThread(){return typeof self!="undefined"||Boolean(b())}static set onmessage(e){function r(a){let s=b(),{type:n,payload:i}=s?a:a.data;e(n,i)}let o=b();o?(o.on("message",r),o.on("exit",()=>console.debug("Node worker closing"))):globalThis.onmessage=r}static addEventListener(e){let r=O.get(e);r||(r=a=>{if(!ae(a))return;let s=b(),{type:n,payload:i}=s?a:a.data;e(n,i)}),b()?console.error("not implemented"):globalThis.addEventListener("message",r)}static removeEventListener(e){let r=O.get(e);O.delete(e),b()?console.error("not implemented"):globalThis.removeEventListener("message",r)}static postMessage(e,r){let o={source:"loaders.gl",type:e,payload:r},a=M(r),s=b();s?s.postMessage(o,a):globalThis.postMessage(o,a)}};function ae(t){let{type:e,data:r}=t;return e==="message"&&r&&typeof r.source=="string"&&r.source.startsWith("loaders.gl")}var y=oe(N());var se="beta",ne=typeof x!="undefined"?x:se,E={};async function h(t,e=null,r={},o=null){return e&&(t=W(t,e,r,o)),E[t]=E[t]||ie(t),await E[t]}function W(t,e,r={},o=null){if(!r.useLocalLibraries&&t.startsWith("http"))return t;o=o||t;let a=r.modules||{};return a[o]?a[o]:D?r.CDN?(S(r.CDN.startsWith("http")),`${r.CDN}/${e}@${ne}/dist/libs/${o}`):T?`../src/libs/${o}`:`modules/${e}/src/libs/${o}`:`modules/${e}/dist/libs/${o}`}async function ie(t){if(t.endsWith("wasm"))return await le(t);if(!D)try{return y&&y.requireFromFile&&await y.requireFromFile(t)}catch{return null}if(T)return importScripts(t);let e=await de(t);return ce(e,t)}function ce(t,e){if(!D)return y.requireFromString&&y.requireFromString(t,e);if(T)return eval.call(C,t),null;let r=document.createElement("script");r.id=e;try{r.appendChild(document.createTextNode(t))}catch{r.text=t}return document.body.appendChild(r),null}async function le(t){return!y.readFileAsArrayBuffer||t.startsWith("http")?await(await fetch(t)).arrayBuffer():await y.readFileAsArrayBuffer(t)}async function de(t){return!y.readFileAsText||t.startsWith("http")?await(await fetch(t)).text():await y.readFileAsText(t)}var ue=0;function L(t){!p.inWorkerThread()||(p.onmessage=async(e,r)=>{switch(e){case"process":try{let{input:o,options:a={},context:s={}}=r,n=await fe({loader:t,arrayBuffer:o,options:a,context:{...s,_parse:pe}});p.postMessage("done",{result:n})}catch(o){let a=o instanceof Error?o.message:"";p.postMessage("error",{error:a})}break;default:}})}function pe(t,e,r,o){return new Promise((a,s)=>{let n=ue++,i=(u,l)=>{if(l.id===n)switch(u){case"done":p.removeEventListener(i),a(l.result);break;case"error":p.removeEventListener(i),s(l.error);break;default:}};p.addEventListener(i);let c={id:n,input:t,options:r};p.postMessage("process",c)})}async function fe({loader:t,arrayBuffer:e,options:r,context:o}){let a,s;if(t.parseSync||t.parse)a=e,s=t.parseSync||t.parse;else if(t.parseTextSync)a=new TextDecoder().decode(e),s=t.parseTextSync;else throw new Error(`Could not load data with ${t.name} loader`);return r={...r,modules:t&&t.options&&t.options.modules||{},worker:!1},await s(a,{...r},o,t)}var v="4.0.0-alpha.22";var ye={draco:{decoderType:typeof WebAssembly=="object"?"wasm":"js",libraryPath:"libs/",extraAttributes:{},attributeNameEntry:void 0}},z={name:"Draco",id:"draco",module:"draco",version:v,worker:!0,extensions:["drc"],mimeTypes:["application/octet-stream"],binary:!0,tests:["DRACO"],options:ye};function V(t){switch(t.constructor){case Int8Array:return"int8";case Uint8Array:case Uint8ClampedArray:return"uint8";case Int16Array:return"int16";case Uint16Array:return"uint16";case Int32Array:return"int32";case Uint32Array:return"uint32";case Float32Array:return"float32";case Float64Array:return"float64";default:return"null"}}function I(t){let e=1/0,r=1/0,o=1/0,a=-1/0,s=-1/0,n=-1/0,i=t.POSITION?t.POSITION.value:[],c=i&&i.length;for(let u=0;u<c;u+=3){let l=i[u],m=i[u+1],g=i[u+2];e=l<e?l:e,r=m<r?m:r,o=g<o?g:o,a=l>a?l:a,s=m>s?m:s,n=g>n?g:n}return[[e,r,o],[a,s,n]]}function R(t,e,r){let o=V(e.value),a=r||U(e);return{name:t,type:{type:"fixed-size-list",listSize:e.size,children:[{name:"value",type:o}]},nullable:!1,metadata:a}}function U(t){let e={};return"byteOffset"in t&&(e.byteOffset=t.byteOffset.toString(10)),"byteStride"in t&&(e.byteStride=t.byteStride.toString(10)),"normalized"in t&&(e.normalized=t.normalized.toString()),e}function q(t,e,r){let o=$(e.metadata),a=[],s=me(e.attributes);for(let n in t){let i=t[n],c=G(n,i,s[n]);a.push(c)}if(r){let n=G("indices",r);a.push(n)}return{fields:a,metadata:o}}function me(t){let e={};for(let r in t){let o=t[r];e[o.name||"undefined"]=o}return e}function G(t,e,r){let o=r?$(r.metadata):void 0;return R(t,e,o)}function $(t){Object.entries(t);let e={};for(let r in t)e[`${r}.string`]=JSON.stringify(t[r]);return e}var Q={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},be={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array},ge=4,_=class{constructor(e){this.draco=e,this.decoder=new this.draco.Decoder,this.metadataQuerier=new this.draco.MetadataQuerier}destroy(){this.draco.destroy(this.decoder),this.draco.destroy(this.metadataQuerier)}parseSync(e,r={}){let o=new this.draco.DecoderBuffer;o.Init(new Int8Array(e),e.byteLength),this._disableAttributeTransforms(r);let a=this.decoder.GetEncodedGeometryType(o),s=a===this.draco.TRIANGULAR_MESH?new this.draco.Mesh:new this.draco.PointCloud;try{let n;switch(a){case this.draco.TRIANGULAR_MESH:n=this.decoder.DecodeBufferToMesh(o,s);break;case this.draco.POINT_CLOUD:n=this.decoder.DecodeBufferToPointCloud(o,s);break;default:throw new Error("DRACO: Unknown geometry type.")}if(!n.ok()||!s.ptr){let g=`DRACO decompression failed: ${n.error_msg()}`;throw new Error(g)}let i=this._getDracoLoaderData(s,a,r),c=this._getMeshData(s,i,r),u=I(c.attributes),l=q(c.attributes,i,c.indices);return{loader:"draco",loaderData:i,header:{vertexCount:s.num_points(),boundingBox:u},...c,schema:l}}finally{this.draco.destroy(o),s&&this.draco.destroy(s)}}_getDracoLoaderData(e,r,o){let a=this._getTopLevelMetadata(e),s=this._getDracoAttributes(e,o);return{geometry_type:r,num_attributes:e.num_attributes(),num_points:e.num_points(),num_faces:e instanceof this.draco.Mesh?e.num_faces():0,metadata:a,attributes:s}}_getDracoAttributes(e,r){let o={};for(let a=0;a<e.num_attributes();a++){let s=this.decoder.GetAttribute(e,a),n=this._getAttributeMetadata(e,a);o[s.unique_id()]={unique_id:s.unique_id(),attribute_type:s.attribute_type(),data_type:s.data_type(),num_components:s.num_components(),byte_offset:s.byte_offset(),byte_stride:s.byte_stride(),normalized:s.normalized(),attribute_index:a,metadata:n};let i=this._getQuantizationTransform(s,r);i&&(o[s.unique_id()].quantization_transform=i);let c=this._getOctahedronTransform(s,r);c&&(o[s.unique_id()].octahedron_transform=c)}return o}_getMeshData(e,r,o){let a=this._getMeshAttributes(r,e,o);if(!a.POSITION)throw new Error("DRACO: No position attribute found.");if(e instanceof this.draco.Mesh)switch(o.topology){case"triangle-strip":return{topology:"triangle-strip",mode:4,attributes:a,indices:{value:this._getTriangleStripIndices(e),size:1}};case"triangle-list":default:return{topology:"triangle-list",mode:5,attributes:a,indices:{value:this._getTriangleListIndices(e),size:1}}}return{topology:"point-list",mode:0,attributes:a}}_getMeshAttributes(e,r,o){let a={};for(let s of Object.values(e.attributes)){let n=this._deduceAttributeName(s,o);s.name=n;let{value:i,size:c}=this._getAttributeValues(r,s);a[n]={value:i,size:c,byteOffset:s.byte_offset,byteStride:s.byte_stride,normalized:s.normalized}}return a}_getTriangleListIndices(e){let o=e.num_faces()*3,a=o*ge,s=this.draco._malloc(a);try{return this.decoder.GetTrianglesUInt32Array(e,a,s),new Uint32Array(this.draco.HEAPF32.buffer,s,o).slice()}finally{this.draco._free(s)}}_getTriangleStripIndices(e){let r=new this.draco.DracoInt32Array;try{return this.decoder.GetTriangleStripsFromMesh(e,r),De(r)}finally{this.draco.destroy(r)}}_getAttributeValues(e,r){let o=be[r.data_type],a=r.num_components,n=e.num_points()*a,i=n*o.BYTES_PER_ELEMENT,c=he(this.draco,o),u,l=this.draco._malloc(i);try{let m=this.decoder.GetAttribute(e,r.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(e,m,c,i,l),u=new o(this.draco.HEAPF32.buffer,l,n).slice()}finally{this.draco._free(l)}return{value:u,size:a}}_deduceAttributeName(e,r){let o=e.unique_id;for(let[n,i]of Object.entries(r.extraAttributes||{}))if(i===o)return n;let a=e.attribute_type;for(let n in Q)if(this.draco[n]===a)return Q[n];let s=r.attributeNameEntry||"name";return e.metadata[s]?e.metadata[s].string:`CUSTOM_ATTRIBUTE_${o}`}_getTopLevelMetadata(e){let r=this.decoder.GetMetadata(e);return this._getDracoMetadata(r)}_getAttributeMetadata(e,r){let o=this.decoder.GetAttributeMetadata(e,r);return this._getDracoMetadata(o)}_getDracoMetadata(e){if(!e||!e.ptr)return{};let r={},o=this.metadataQuerier.NumEntries(e);for(let a=0;a<o;a++){let s=this.metadataQuerier.GetEntryName(e,a);r[s]=this._getDracoMetadataField(e,s)}return r}_getDracoMetadataField(e,r){let o=new this.draco.DracoInt32Array;try{this.metadataQuerier.GetIntEntryArray(e,r,o);let a=Ae(o);return{int:this.metadataQuerier.GetIntEntry(e,r),string:this.metadataQuerier.GetStringEntry(e,r),double:this.metadataQuerier.GetDoubleEntry(e,r),intArray:a}}finally{this.draco.destroy(o)}}_disableAttributeTransforms(e){let{quantizedAttributes:r=[],octahedronAttributes:o=[]}=e,a=[...r,...o];for(let s of a)this.decoder.SkipAttributeTransform(this.draco[s])}_getQuantizationTransform(e,r){let{quantizedAttributes:o=[]}=r,a=e.attribute_type();if(o.map(n=>this.decoder[n]).includes(a)){let n=new this.draco.AttributeQuantizationTransform;try{if(n.InitFromAttribute(e))return{quantization_bits:n.quantization_bits(),range:n.range(),min_values:new Float32Array([1,2,3]).map(i=>n.min_value(i))}}finally{this.draco.destroy(n)}}return null}_getOctahedronTransform(e,r){let{octahedronAttributes:o=[]}=r,a=e.attribute_type();if(o.map(n=>this.decoder[n]).includes(a)){let n=new this.draco.AttributeQuantizationTransform;try{if(n.InitFromAttribute(e))return{quantization_bits:n.quantization_bits()}}finally{this.draco.destroy(n)}}return null}};function he(t,e){switch(e){case Float32Array:return t.DT_FLOAT32;case Int8Array:return t.DT_INT8;case Int16Array:return t.DT_INT16;case Int32Array:return t.DT_INT32;case Uint8Array:return t.DT_UINT8;case Uint16Array:return t.DT_UINT16;case Uint32Array:return t.DT_UINT32;default:return t.DT_INVALID}}function Ae(t){let e=t.size(),r=new Int32Array(e);for(let o=0;o<e;o++)r[o]=t.GetValue(o);return r}function De(t){let e=t.size(),r=new Int32Array(e);for(let o=0;o<e;o++)r[o]=t.GetValue(o);return r}var Te="1.5.5",_e="1.4.1",k=`https://www.gstatic.com/draco/versioned/decoders/${Te}`,d={DECODER:"draco_wasm_wrapper.js",DECODER_WASM:"draco_decoder.wasm",FALLBACK_DECODER:"draco_decoder.js",ENCODER:"draco_encoder.js"},P={[d.DECODER]:`${k}/${d.DECODER}`,[d.DECODER_WASM]:`${k}/${d.DECODER_WASM}`,[d.FALLBACK_DECODER]:`${k}/${d.FALLBACK_DECODER}`,[d.ENCODER]:`https://raw.githubusercontent.com/google/draco/${_e}/javascript/${d.ENCODER}`},A;async function j(t){let e=t.modules||{};return e.draco3d?A=A||e.draco3d.createDecoderModule({}).then(r=>({draco:r})):A=A||we(t),await A}async function we(t){let e,r;switch(t.draco&&t.draco.decoderType){case"js":e=await h(P[d.FALLBACK_DECODER],"draco",t,d.FALLBACK_DECODER);break;case"wasm":default:[e,r]=await Promise.all([await h(P[d.DECODER],"draco",t,d.DECODER),await h(P[d.DECODER_WASM],"draco",t,d.DECODER_WASM)])}return e=e||globalThis.DracoDecoderModule,await xe(e,r)}function xe(t,e){let r={};return e&&(r.wasmBinary=e),new Promise(o=>{t({...r,onModuleLoaded:a=>o({draco:a})})})}var Y={...z,parse:Me};async function Me(t,e){let{draco:r}=await j(e),o=new _(r);try{return o.parseSync(t,e?.draco)}finally{o.destroy()}}L(Y);})();
|
|
1
|
+
(()=>{var X=Object.create;var w=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty;var ee=t=>w(t,"__esModule",{value:!0});var te=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var re=(t,e,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of H(e))!Z.call(t,o)&&o!=="default"&&w(t,o,{get:()=>e[o],enumerable:!(r=J(e,o))||r.enumerable});return t},oe=t=>re(ee(w(t!=null?X(K(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var N=te(()=>{});var x="4.0.0-alpha.23";function S(t,e){if(!t)throw new Error(e||"loaders.gl assertion failed.")}var f={self:typeof self!="undefined"&&self,window:typeof window!="undefined"&&window,global:typeof global!="undefined"&&global,document:typeof document!="undefined"&&document},Ie=f.self||f.window||f.global||{},Re=f.window||f.self||f.global||{},F=f.global||f.self||f.window||{},Pe=f.document||{};var D=typeof process!="object"||String(process)!=="[object process]"||process.browser,T=typeof importScripts=="function",ke=typeof window!="undefined"&&typeof window.orientation!="undefined",C=typeof process!="undefined"&&process.version&&/v([0-9]*)/.exec(process.version),Se=C&&parseFloat(C[1])||0;function M(t,e=!0,r){let o=r||new Set;if(t){if(B(t))o.add(t);else if(B(t.buffer))o.add(t.buffer);else if(!ArrayBuffer.isView(t)){if(e&&typeof t=="object")for(let a in t)M(t[a],e,o)}}return r===void 0?Array.from(o):[]}function B(t){return t?t instanceof ArrayBuffer||typeof MessagePort!="undefined"&&t instanceof MessagePort||typeof ImageBitmap!="undefined"&&t instanceof ImageBitmap||typeof OffscreenCanvas!="undefined"&&t instanceof OffscreenCanvas:!1}function b(){let parentPort;try{eval("globalThis.parentPort = require('worker_threads').parentPort"),parentPort=globalThis.parentPort}catch{}return parentPort}var O=new Map,p=class{static inWorkerThread(){return typeof self!="undefined"||Boolean(b())}static set onmessage(e){function r(a){let s=b(),{type:n,payload:i}=s?a:a.data;e(n,i)}let o=b();o?(o.on("message",r),o.on("exit",()=>console.debug("Node worker closing"))):globalThis.onmessage=r}static addEventListener(e){let r=O.get(e);r||(r=a=>{if(!ae(a))return;let s=b(),{type:n,payload:i}=s?a:a.data;e(n,i)}),b()?console.error("not implemented"):globalThis.addEventListener("message",r)}static removeEventListener(e){let r=O.get(e);O.delete(e),b()?console.error("not implemented"):globalThis.removeEventListener("message",r)}static postMessage(e,r){let o={source:"loaders.gl",type:e,payload:r},a=M(r),s=b();s?s.postMessage(o,a):globalThis.postMessage(o,a)}};function ae(t){let{type:e,data:r}=t;return e==="message"&&r&&typeof r.source=="string"&&r.source.startsWith("loaders.gl")}var y=oe(N());var se="beta",ne=typeof x!="undefined"?x:se,E={};async function h(t,e=null,r={},o=null){return e&&(t=W(t,e,r,o)),E[t]=E[t]||ie(t),await E[t]}function W(t,e,r={},o=null){if(!r.useLocalLibraries&&t.startsWith("http"))return t;o=o||t;let a=r.modules||{};return a[o]?a[o]:D?r.CDN?(S(r.CDN.startsWith("http")),`${r.CDN}/${e}@${ne}/dist/libs/${o}`):T?`../src/libs/${o}`:`modules/${e}/src/libs/${o}`:`modules/${e}/dist/libs/${o}`}async function ie(t){if(t.endsWith("wasm"))return await ce(t);if(!D)try{return y&&y.requireFromFile&&await y.requireFromFile(t)}catch{return null}if(T)return importScripts(t);let e=await de(t);return le(e,t)}function le(t,e){if(!D)return y.requireFromString&&y.requireFromString(t,e);if(T)return eval.call(F,t),null;let r=document.createElement("script");r.id=e;try{r.appendChild(document.createTextNode(t))}catch{r.text=t}return document.body.appendChild(r),null}async function ce(t){return!y.readFileAsArrayBuffer||t.startsWith("http")?await(await fetch(t)).arrayBuffer():await y.readFileAsArrayBuffer(t)}async function de(t){return!y.readFileAsText||t.startsWith("http")?await(await fetch(t)).text():await y.readFileAsText(t)}var ue=0;function L(t){!p.inWorkerThread()||(p.onmessage=async(e,r)=>{switch(e){case"process":try{let{input:o,options:a={},context:s={}}=r,n=await fe({loader:t,arrayBuffer:o,options:a,context:{...s,_parse:pe}});p.postMessage("done",{result:n})}catch(o){let a=o instanceof Error?o.message:"";p.postMessage("error",{error:a})}break;default:}})}function pe(t,e,r,o){return new Promise((a,s)=>{let n=ue++,i=(u,c)=>{if(c.id===n)switch(u){case"done":p.removeEventListener(i),a(c.result);break;case"error":p.removeEventListener(i),s(c.error);break;default:}};p.addEventListener(i);let l={id:n,input:t,options:r};p.postMessage("process",l)})}async function fe({loader:t,arrayBuffer:e,options:r,context:o}){let a,s;if(t.parseSync||t.parse)a=e,s=t.parseSync||t.parse;else if(t.parseTextSync)a=new TextDecoder().decode(e),s=t.parseTextSync;else throw new Error(`Could not load data with ${t.name} loader`);return r={...r,modules:t&&t.options&&t.options.modules||{},worker:!1},await s(a,{...r},o,t)}var v="4.0.0-alpha.23";var ye={draco:{decoderType:typeof WebAssembly=="object"?"wasm":"js",libraryPath:"libs/",extraAttributes:{},attributeNameEntry:void 0}},z={name:"Draco",id:"draco",module:"draco",version:v,worker:!0,extensions:["drc"],mimeTypes:["application/octet-stream"],binary:!0,tests:["DRACO"],options:ye};function V(t){switch(t.constructor){case Int8Array:return"int8";case Uint8Array:case Uint8ClampedArray:return"uint8";case Int16Array:return"int16";case Uint16Array:return"uint16";case Int32Array:return"int32";case Uint32Array:return"uint32";case Float32Array:return"float32";case Float64Array:return"float64";default:return"null"}}function I(t){let e=1/0,r=1/0,o=1/0,a=-1/0,s=-1/0,n=-1/0,i=t.POSITION?t.POSITION.value:[],l=i&&i.length;for(let u=0;u<l;u+=3){let c=i[u],m=i[u+1],g=i[u+2];e=c<e?c:e,r=m<r?m:r,o=g<o?g:o,a=c>a?c:a,s=m>s?m:s,n=g>n?g:n}return[[e,r,o],[a,s,n]]}function R(t,e,r){let o=V(e.value),a=r||U(e);return{name:t,type:{type:"fixed-size-list",listSize:e.size,children:[{name:"value",type:o}]},nullable:!1,metadata:a}}function U(t){let e={};return"byteOffset"in t&&(e.byteOffset=t.byteOffset.toString(10)),"byteStride"in t&&(e.byteStride=t.byteStride.toString(10)),"normalized"in t&&(e.normalized=t.normalized.toString()),e}function q(t,e,r){let o=$(e.metadata),a=[],s=me(e.attributes);for(let n in t){let i=t[n],l=G(n,i,s[n]);a.push(l)}if(r){let n=G("indices",r);a.push(n)}return{fields:a,metadata:o}}function me(t){let e={};for(let r in t){let o=t[r];e[o.name||"undefined"]=o}return e}function G(t,e,r){let o=r?$(r.metadata):void 0;return R(t,e,o)}function $(t){Object.entries(t);let e={};for(let r in t)e[`${r}.string`]=JSON.stringify(t[r]);return e}var Q={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},be={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array},ge=4,_=class{constructor(e){this.draco=e,this.decoder=new this.draco.Decoder,this.metadataQuerier=new this.draco.MetadataQuerier}destroy(){this.draco.destroy(this.decoder),this.draco.destroy(this.metadataQuerier)}parseSync(e,r={}){let o=new this.draco.DecoderBuffer;o.Init(new Int8Array(e),e.byteLength),this._disableAttributeTransforms(r);let a=this.decoder.GetEncodedGeometryType(o),s=a===this.draco.TRIANGULAR_MESH?new this.draco.Mesh:new this.draco.PointCloud;try{let n;switch(a){case this.draco.TRIANGULAR_MESH:n=this.decoder.DecodeBufferToMesh(o,s);break;case this.draco.POINT_CLOUD:n=this.decoder.DecodeBufferToPointCloud(o,s);break;default:throw new Error("DRACO: Unknown geometry type.")}if(!n.ok()||!s.ptr){let g=`DRACO decompression failed: ${n.error_msg()}`;throw new Error(g)}let i=this._getDracoLoaderData(s,a,r),l=this._getMeshData(s,i,r),u=I(l.attributes),c=q(l.attributes,i,l.indices);return{loader:"draco",loaderData:i,header:{vertexCount:s.num_points(),boundingBox:u},...l,schema:c}}finally{this.draco.destroy(o),s&&this.draco.destroy(s)}}_getDracoLoaderData(e,r,o){let a=this._getTopLevelMetadata(e),s=this._getDracoAttributes(e,o);return{geometry_type:r,num_attributes:e.num_attributes(),num_points:e.num_points(),num_faces:e instanceof this.draco.Mesh?e.num_faces():0,metadata:a,attributes:s}}_getDracoAttributes(e,r){let o={};for(let a=0;a<e.num_attributes();a++){let s=this.decoder.GetAttribute(e,a),n=this._getAttributeMetadata(e,a);o[s.unique_id()]={unique_id:s.unique_id(),attribute_type:s.attribute_type(),data_type:s.data_type(),num_components:s.num_components(),byte_offset:s.byte_offset(),byte_stride:s.byte_stride(),normalized:s.normalized(),attribute_index:a,metadata:n};let i=this._getQuantizationTransform(s,r);i&&(o[s.unique_id()].quantization_transform=i);let l=this._getOctahedronTransform(s,r);l&&(o[s.unique_id()].octahedron_transform=l)}return o}_getMeshData(e,r,o){let a=this._getMeshAttributes(r,e,o);if(!a.POSITION)throw new Error("DRACO: No position attribute found.");if(e instanceof this.draco.Mesh)switch(o.topology){case"triangle-strip":return{topology:"triangle-strip",mode:4,attributes:a,indices:{value:this._getTriangleStripIndices(e),size:1}};case"triangle-list":default:return{topology:"triangle-list",mode:5,attributes:a,indices:{value:this._getTriangleListIndices(e),size:1}}}return{topology:"point-list",mode:0,attributes:a}}_getMeshAttributes(e,r,o){let a={};for(let s of Object.values(e.attributes)){let n=this._deduceAttributeName(s,o);s.name=n;let{value:i,size:l}=this._getAttributeValues(r,s);a[n]={value:i,size:l,byteOffset:s.byte_offset,byteStride:s.byte_stride,normalized:s.normalized}}return a}_getTriangleListIndices(e){let o=e.num_faces()*3,a=o*ge,s=this.draco._malloc(a);try{return this.decoder.GetTrianglesUInt32Array(e,a,s),new Uint32Array(this.draco.HEAPF32.buffer,s,o).slice()}finally{this.draco._free(s)}}_getTriangleStripIndices(e){let r=new this.draco.DracoInt32Array;try{return this.decoder.GetTriangleStripsFromMesh(e,r),De(r)}finally{this.draco.destroy(r)}}_getAttributeValues(e,r){let o=be[r.data_type],a=r.num_components,n=e.num_points()*a,i=n*o.BYTES_PER_ELEMENT,l=he(this.draco,o),u,c=this.draco._malloc(i);try{let m=this.decoder.GetAttribute(e,r.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(e,m,l,i,c),u=new o(this.draco.HEAPF32.buffer,c,n).slice()}finally{this.draco._free(c)}return{value:u,size:a}}_deduceAttributeName(e,r){let o=e.unique_id;for(let[n,i]of Object.entries(r.extraAttributes||{}))if(i===o)return n;let a=e.attribute_type;for(let n in Q)if(this.draco[n]===a)return Q[n];let s=r.attributeNameEntry||"name";return e.metadata[s]?e.metadata[s].string:`CUSTOM_ATTRIBUTE_${o}`}_getTopLevelMetadata(e){let r=this.decoder.GetMetadata(e);return this._getDracoMetadata(r)}_getAttributeMetadata(e,r){let o=this.decoder.GetAttributeMetadata(e,r);return this._getDracoMetadata(o)}_getDracoMetadata(e){if(!e||!e.ptr)return{};let r={},o=this.metadataQuerier.NumEntries(e);for(let a=0;a<o;a++){let s=this.metadataQuerier.GetEntryName(e,a);r[s]=this._getDracoMetadataField(e,s)}return r}_getDracoMetadataField(e,r){let o=new this.draco.DracoInt32Array;try{this.metadataQuerier.GetIntEntryArray(e,r,o);let a=Ae(o);return{int:this.metadataQuerier.GetIntEntry(e,r),string:this.metadataQuerier.GetStringEntry(e,r),double:this.metadataQuerier.GetDoubleEntry(e,r),intArray:a}}finally{this.draco.destroy(o)}}_disableAttributeTransforms(e){let{quantizedAttributes:r=[],octahedronAttributes:o=[]}=e,a=[...r,...o];for(let s of a)this.decoder.SkipAttributeTransform(this.draco[s])}_getQuantizationTransform(e,r){let{quantizedAttributes:o=[]}=r,a=e.attribute_type();if(o.map(n=>this.decoder[n]).includes(a)){let n=new this.draco.AttributeQuantizationTransform;try{if(n.InitFromAttribute(e))return{quantization_bits:n.quantization_bits(),range:n.range(),min_values:new Float32Array([1,2,3]).map(i=>n.min_value(i))}}finally{this.draco.destroy(n)}}return null}_getOctahedronTransform(e,r){let{octahedronAttributes:o=[]}=r,a=e.attribute_type();if(o.map(n=>this.decoder[n]).includes(a)){let n=new this.draco.AttributeQuantizationTransform;try{if(n.InitFromAttribute(e))return{quantization_bits:n.quantization_bits()}}finally{this.draco.destroy(n)}}return null}};function he(t,e){switch(e){case Float32Array:return t.DT_FLOAT32;case Int8Array:return t.DT_INT8;case Int16Array:return t.DT_INT16;case Int32Array:return t.DT_INT32;case Uint8Array:return t.DT_UINT8;case Uint16Array:return t.DT_UINT16;case Uint32Array:return t.DT_UINT32;default:return t.DT_INVALID}}function Ae(t){let e=t.size(),r=new Int32Array(e);for(let o=0;o<e;o++)r[o]=t.GetValue(o);return r}function De(t){let e=t.size(),r=new Int32Array(e);for(let o=0;o<e;o++)r[o]=t.GetValue(o);return r}var Te="1.5.5",_e="1.4.1",P=`https://www.gstatic.com/draco/versioned/decoders/${Te}`,d={DECODER:"draco_wasm_wrapper.js",DECODER_WASM:"draco_decoder.wasm",FALLBACK_DECODER:"draco_decoder.js",ENCODER:"draco_encoder.js"},k={[d.DECODER]:`${P}/${d.DECODER}`,[d.DECODER_WASM]:`${P}/${d.DECODER_WASM}`,[d.FALLBACK_DECODER]:`${P}/${d.FALLBACK_DECODER}`,[d.ENCODER]:`https://raw.githubusercontent.com/google/draco/${_e}/javascript/${d.ENCODER}`},A;async function j(t){let e=t.modules||{};return e.draco3d?A=A||e.draco3d.createDecoderModule({}).then(r=>({draco:r})):A=A||we(t),await A}async function we(t){let e,r;switch(t.draco&&t.draco.decoderType){case"js":e=await h(k[d.FALLBACK_DECODER],"draco",t,d.FALLBACK_DECODER);break;case"wasm":default:[e,r]=await Promise.all([await h(k[d.DECODER],"draco",t,d.DECODER),await h(k[d.DECODER_WASM],"draco",t,d.DECODER_WASM)])}return e=e||globalThis.DracoDecoderModule,await xe(e,r)}function xe(t,e){let r={};return e&&(r.wasmBinary=e),new Promise(o=>{t({...r,onModuleLoaded:a=>o({draco:a})})})}var Y={...z,parse:Me};async function Me(t,e){let{draco:r}=await j(e),o=new _(r);try{return o.parseSync(t,e?.draco)}finally{o.destroy()}}L(Y);})();
|
|
2
2
|
//# sourceMappingURL=draco-worker.js.map
|