@loaders.gl/draco 4.0.0-alpha.8 → 4.0.0-alpha.9
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 j=Object.create;var _=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var X=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var Z=t=>_(t,"__esModule",{value:!0});var K=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var ee=(t,e,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of J(e))!H.call(t,o)&&o!=="default"&&_(t,o,{get:()=>e[o],enumerable:!(r=Y(e,o))||r.enumerable});return t},te=t=>ee(Z(_(t!=null?j(X(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var F=K(()=>{});var w="4.0.0-alpha.8";function E(t,e){if(!t)throw new Error(e||"loaders.gl assertion failed.")}var p={self:typeof self!="undefined"&&self,window:typeof window!="undefined"&&window,global:typeof global!="undefined"&&global,document:typeof document!="undefined"&&document},ke=p.self||p.window||p.global||{},Le=p.window||p.self||p.global||{},S=p.global||p.self||p.window||{},Pe=p.document||{};var A=typeof process!="object"||String(process)!=="[object process]"||process.browser,T=typeof importScripts=="function",Ee=typeof window!="undefined"&&typeof window.orientation!="undefined",R=typeof process!="undefined"&&process.version&&/v([0-9]*)/.exec(process.version),Se=R&&parseFloat(R[1])||0;function x(t,e=!0,r){let o=r||new Set;if(t){if(N(t))o.add(t);else if(N(t.buffer))o.add(t.buffer);else if(!ArrayBuffer.isView(t)){if(e&&typeof t=="object")for(let a in t)x(t[a],e,o)}}return r===void 0?Array.from(o):[]}function N(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 f(){let parentPort;try{eval("globalThis.parentPort = require('worker_threads').parentPort"),parentPort=globalThis.parentPort}catch{}return parentPort}var M=new Map,l=class{static inWorkerThread(){return typeof self!="undefined"||Boolean(f())}static set onmessage(e){function r(a){let s=f(),{type:n,payload:i}=s?a:a.data;e(n,i)}let o=f();o?(o.on("message",r),o.on("exit",()=>console.debug("Node worker closing"))):globalThis.onmessage=r}static addEventListener(e){let r=M.get(e);r||(r=a=>{if(!re(a))return;let s=f(),{type:n,payload:i}=s?a:a.data;e(n,i)}),f()?console.error("not implemented"):globalThis.addEventListener("message",r)}static removeEventListener(e){let r=M.get(e);M.delete(e),f()?console.error("not implemented"):globalThis.removeEventListener("message",r)}static postMessage(e,r){let o={source:"loaders.gl",type:e,payload:r},a=x(r),s=f();s?s.postMessage(o,a):globalThis.postMessage(o,a)}};function re(t){let{type:e,data:r}=t;return e==="message"&&r&&typeof r.source=="string"&&r.source.startsWith("loaders.gl")}var b=te(F());var oe="beta",ae=typeof w!="undefined"?w:oe,O={};async function g(t,e=null,r={}){return e&&(t=B(t,e,r)),O[t]=O[t]||se(t),await O[t]}function B(t,e,r){if(t.startsWith("http"))return t;let o=r.modules||{};return o[t]?o[t]:A?r.CDN?(E(r.CDN.startsWith("http")),`${r.CDN}/${e}@${ae}/dist/libs/${t}`):T?`../src/libs/${t}`:`modules/${e}/src/libs/${t}`:`modules/${e}/dist/libs/${t}`}async function se(t){if(t.endsWith("wasm"))return await(await fetch(t)).arrayBuffer();if(!A)try{return b&&b.requireFromFile&&await b.requireFromFile(t)}catch{return null}if(T)return importScripts(t);let r=await(await fetch(t)).text();return ne(r,t)}function ne(t,e){if(!A)return b.requireFromString&&b.requireFromString(t,e);if(T)return eval.call(S,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}var ie=0;function I(t){!l.inWorkerThread()||(l.onmessage=async(e,r)=>{switch(e){case"process":try{let{input:o,options:a={},context:s={}}=r,n=await le({loader:t,arrayBuffer:o,options:a,context:{...s,parse:ce}});l.postMessage("done",{result:n})}catch(o){let a=o instanceof Error?o.message:"";l.postMessage("error",{error:a})}break;default:}})}function ce(t,e){return new Promise((r,o)=>{let a=ie++,s=(i,c)=>{if(c.id===a)switch(i){case"done":l.removeEventListener(s),r(c.result);break;case"error":l.removeEventListener(s),o(c.error);break;default:}};l.addEventListener(s);let n={id:a,input:t,options:e};l.postMessage("process",n)})}async function le({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 W="4.0.0-alpha.8";var de={draco:{decoderType:typeof WebAssembly=="object"?"wasm":"js",libraryPath:"libs/",extraAttributes:{},attributeNameEntry:void 0}},C={name:"Draco",id:"draco",module:"draco",version:W,worker:!0,extensions:["drc"],mimeTypes:["application/octet-stream"],binary:!0,tests:["DRACO"],options:de};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 k(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 d=0;d<c;d+=3){let u=i[d],y=i[d+1],m=i[d+2];e=u<e?u:e,r=y<r?y:r,o=m<o?m:o,a=u>a?u:a,s=y>s?y:s,n=m>n?m:n}return[[e,r,o],[a,s,n]]}function L(t,e,r){let o=v(e.value),a=r||z(e);return{name:t,type:{type:"fixed-size-list",listSize:e.size,children:[{name:"value",type:o}]},nullable:!1,metadata:a}}function z(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 V(t,e,r){let o=q(e.metadata),a=[],s=ue(e.attributes);for(let n in t){let i=t[n],c=U(n,i,s[n]);a.push(c)}if(r){let n=U("indices",r);a.push(n)}return{fields:a,metadata:o}}function ue(t){let e={};for(let r in t){let o=t[r];e[o.name||"undefined"]=o}return e}function U(t,e,r){let o=r?q(r.metadata):void 0;return L(t,e,o)}function q(t){Object.entries(t);let e={};for(let r in t)e[`${r}.string`]=JSON.stringify(t[r]);return e}var G={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},pe={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array},ye=4,D=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 m=`DRACO decompression failed: ${n.error_msg()}`;throw new Error(m)}let i=this._getDracoLoaderData(s,a,r),c=this._getMeshData(s,i,r),d=k(c.attributes),u=V(c.attributes,i,c.indices);return{loader:"draco",loaderData:i,header:{vertexCount:s.num_points(),boundingBox:d},...c,schema:u}}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*ye,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),be(r)}finally{this.draco.destroy(r)}}_getAttributeValues(e,r){let o=pe[r.data_type],a=r.num_components,n=e.num_points()*a,i=n*o.BYTES_PER_ELEMENT,c=fe(this.draco,o),d,u=this.draco._malloc(i);try{let y=this.decoder.GetAttribute(e,r.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(e,y,c,i,u),d=new o(this.draco.HEAPF32.buffer,u,n).slice()}finally{this.draco._free(u)}return{value:d,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 G)if(this.draco[n]===a)return G[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=me(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 fe(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 me(t){let e=t.size(),r=new Int32Array(e);for(let o=0;o<e;o++)r[o]=t.GetValue(o);return r}function be(t){let e=t.size(),r=new Int32Array(e);for(let o=0;o<e;o++)r[o]=t.GetValue(o);return r}var ge="1.5.5",he="1.4.1",P=`https://www.gstatic.com/draco/versioned/decoders/${ge}`,Ae=`${P}/draco_decoder.js`,Te=`${P}/draco_wasm_wrapper.js`,De=`${P}/draco_decoder.wasm`,mt=`https://raw.githubusercontent.com/google/draco/${he}/javascript/draco_encoder.js`,h;async function Q(t){let e=t.modules||{};return e.draco3d?h=h||e.draco3d.createDecoderModule({}).then(r=>({draco:r})):h=h||_e(t),await h}async function _e(t){let e,r;switch(t.draco&&t.draco.decoderType){case"js":e=await g(Ae,"draco",t);break;case"wasm":default:[e,r]=await Promise.all([await g(Te,"draco",t),await g(De,"draco",t)])}return e=e||globalThis.DracoDecoderModule,await we(e,r)}function we(t,e){let r={};return e&&(r.wasmBinary=e),new Promise(o=>{t({...r,onModuleLoaded:a=>o({draco:a})})})}var $={...C,parse:xe};async function xe(t,e){let{draco:r}=await Q(e),o=new D(r);try{return o.parseSync(t,e?.draco)}finally{o.destroy()}}I($);})();
|
|
1
|
+
(()=>{var j=Object.create;var _=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var X=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var Z=t=>_(t,"__esModule",{value:!0});var K=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var ee=(t,e,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of J(e))!H.call(t,o)&&o!=="default"&&_(t,o,{get:()=>e[o],enumerable:!(r=Y(e,o))||r.enumerable});return t},te=t=>ee(Z(_(t!=null?j(X(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var F=K(()=>{});var w="4.0.0-alpha.9";function E(t,e){if(!t)throw new Error(e||"loaders.gl assertion failed.")}var p={self:typeof self!="undefined"&&self,window:typeof window!="undefined"&&window,global:typeof global!="undefined"&&global,document:typeof document!="undefined"&&document},ke=p.self||p.window||p.global||{},Le=p.window||p.self||p.global||{},S=p.global||p.self||p.window||{},Pe=p.document||{};var A=typeof process!="object"||String(process)!=="[object process]"||process.browser,T=typeof importScripts=="function",Ee=typeof window!="undefined"&&typeof window.orientation!="undefined",R=typeof process!="undefined"&&process.version&&/v([0-9]*)/.exec(process.version),Se=R&&parseFloat(R[1])||0;function x(t,e=!0,r){let o=r||new Set;if(t){if(N(t))o.add(t);else if(N(t.buffer))o.add(t.buffer);else if(!ArrayBuffer.isView(t)){if(e&&typeof t=="object")for(let a in t)x(t[a],e,o)}}return r===void 0?Array.from(o):[]}function N(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 f(){let parentPort;try{eval("globalThis.parentPort = require('worker_threads').parentPort"),parentPort=globalThis.parentPort}catch{}return parentPort}var M=new Map,l=class{static inWorkerThread(){return typeof self!="undefined"||Boolean(f())}static set onmessage(e){function r(a){let s=f(),{type:n,payload:i}=s?a:a.data;e(n,i)}let o=f();o?(o.on("message",r),o.on("exit",()=>console.debug("Node worker closing"))):globalThis.onmessage=r}static addEventListener(e){let r=M.get(e);r||(r=a=>{if(!re(a))return;let s=f(),{type:n,payload:i}=s?a:a.data;e(n,i)}),f()?console.error("not implemented"):globalThis.addEventListener("message",r)}static removeEventListener(e){let r=M.get(e);M.delete(e),f()?console.error("not implemented"):globalThis.removeEventListener("message",r)}static postMessage(e,r){let o={source:"loaders.gl",type:e,payload:r},a=x(r),s=f();s?s.postMessage(o,a):globalThis.postMessage(o,a)}};function re(t){let{type:e,data:r}=t;return e==="message"&&r&&typeof r.source=="string"&&r.source.startsWith("loaders.gl")}var b=te(F());var oe="beta",ae=typeof w!="undefined"?w:oe,O={};async function g(t,e=null,r={}){return e&&(t=B(t,e,r)),O[t]=O[t]||se(t),await O[t]}function B(t,e,r){if(t.startsWith("http"))return t;let o=r.modules||{};return o[t]?o[t]:A?r.CDN?(E(r.CDN.startsWith("http")),`${r.CDN}/${e}@${ae}/dist/libs/${t}`):T?`../src/libs/${t}`:`modules/${e}/src/libs/${t}`:`modules/${e}/dist/libs/${t}`}async function se(t){if(t.endsWith("wasm"))return await(await fetch(t)).arrayBuffer();if(!A)try{return b&&b.requireFromFile&&await b.requireFromFile(t)}catch{return null}if(T)return importScripts(t);let r=await(await fetch(t)).text();return ne(r,t)}function ne(t,e){if(!A)return b.requireFromString&&b.requireFromString(t,e);if(T)return eval.call(S,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}var ie=0;function I(t){!l.inWorkerThread()||(l.onmessage=async(e,r)=>{switch(e){case"process":try{let{input:o,options:a={},context:s={}}=r,n=await le({loader:t,arrayBuffer:o,options:a,context:{...s,parse:ce}});l.postMessage("done",{result:n})}catch(o){let a=o instanceof Error?o.message:"";l.postMessage("error",{error:a})}break;default:}})}function ce(t,e){return new Promise((r,o)=>{let a=ie++,s=(i,c)=>{if(c.id===a)switch(i){case"done":l.removeEventListener(s),r(c.result);break;case"error":l.removeEventListener(s),o(c.error);break;default:}};l.addEventListener(s);let n={id:a,input:t,options:e};l.postMessage("process",n)})}async function le({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 W="4.0.0-alpha.9";var de={draco:{decoderType:typeof WebAssembly=="object"?"wasm":"js",libraryPath:"libs/",extraAttributes:{},attributeNameEntry:void 0}},C={name:"Draco",id:"draco",module:"draco",version:W,worker:!0,extensions:["drc"],mimeTypes:["application/octet-stream"],binary:!0,tests:["DRACO"],options:de};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 k(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 d=0;d<c;d+=3){let u=i[d],y=i[d+1],m=i[d+2];e=u<e?u:e,r=y<r?y:r,o=m<o?m:o,a=u>a?u:a,s=y>s?y:s,n=m>n?m:n}return[[e,r,o],[a,s,n]]}function L(t,e,r){let o=v(e.value),a=r||z(e);return{name:t,type:{type:"fixed-size-list",listSize:e.size,children:[{name:"value",type:o}]},nullable:!1,metadata:a}}function z(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 V(t,e,r){let o=q(e.metadata),a=[],s=ue(e.attributes);for(let n in t){let i=t[n],c=U(n,i,s[n]);a.push(c)}if(r){let n=U("indices",r);a.push(n)}return{fields:a,metadata:o}}function ue(t){let e={};for(let r in t){let o=t[r];e[o.name||"undefined"]=o}return e}function U(t,e,r){let o=r?q(r.metadata):void 0;return L(t,e,o)}function q(t){Object.entries(t);let e={};for(let r in t)e[`${r}.string`]=JSON.stringify(t[r]);return e}var G={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},pe={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array},ye=4,D=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 m=`DRACO decompression failed: ${n.error_msg()}`;throw new Error(m)}let i=this._getDracoLoaderData(s,a,r),c=this._getMeshData(s,i,r),d=k(c.attributes),u=V(c.attributes,i,c.indices);return{loader:"draco",loaderData:i,header:{vertexCount:s.num_points(),boundingBox:d},...c,schema:u}}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*ye,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),be(r)}finally{this.draco.destroy(r)}}_getAttributeValues(e,r){let o=pe[r.data_type],a=r.num_components,n=e.num_points()*a,i=n*o.BYTES_PER_ELEMENT,c=fe(this.draco,o),d,u=this.draco._malloc(i);try{let y=this.decoder.GetAttribute(e,r.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(e,y,c,i,u),d=new o(this.draco.HEAPF32.buffer,u,n).slice()}finally{this.draco._free(u)}return{value:d,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 G)if(this.draco[n]===a)return G[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=me(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 fe(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 me(t){let e=t.size(),r=new Int32Array(e);for(let o=0;o<e;o++)r[o]=t.GetValue(o);return r}function be(t){let e=t.size(),r=new Int32Array(e);for(let o=0;o<e;o++)r[o]=t.GetValue(o);return r}var ge="1.5.5",he="1.4.1",P=`https://www.gstatic.com/draco/versioned/decoders/${ge}`,Ae=`${P}/draco_decoder.js`,Te=`${P}/draco_wasm_wrapper.js`,De=`${P}/draco_decoder.wasm`,mt=`https://raw.githubusercontent.com/google/draco/${he}/javascript/draco_encoder.js`,h;async function Q(t){let e=t.modules||{};return e.draco3d?h=h||e.draco3d.createDecoderModule({}).then(r=>({draco:r})):h=h||_e(t),await h}async function _e(t){let e,r;switch(t.draco&&t.draco.decoderType){case"js":e=await g(Ae,"draco",t);break;case"wasm":default:[e,r]=await Promise.all([await g(Te,"draco",t),await g(De,"draco",t)])}return e=e||globalThis.DracoDecoderModule,await we(e,r)}function we(t,e){let r={};return e&&(r.wasmBinary=e),new Promise(o=>{t({...r,onModuleLoaded:a=>o({draco:a})})})}var $={...C,parse:xe};async function xe(t,e){let{draco:r}=await Q(e),o=new D(r);try{return o.parseSync(t,e?.draco)}finally{o.destroy()}}I($);})();
|
|
2
2
|
//# sourceMappingURL=draco-worker.js.map
|