@loaders.gl/draco 4.0.0-beta.4 → 4.0.0-beta.6
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
|
-
"use strict";(()=>{var Y=Object.create;var R=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var Z=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var ee=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of J(e))!K.call(t,a)&&a!==r&&R(t,a,{get:()=>e[a],enumerable:!(o=X(e,a))||o.enumerable});return t};var te=(t,e,r)=>(r=t!=null?Y(H(t)):{},ee(e||!t||!t.__esModule?R(r,"default",{value:t,enumerable:!0}):r,t));var N=Z(()=>{"use strict"});function re(){return globalThis._loadersgl_?.version||(globalThis._loadersgl_=globalThis._loadersgl_||{},globalThis._loadersgl_.version="4.0.0-beta.4"),globalThis._loadersgl_.version}var S=re();function F(t,e){if(!t)throw new Error(e||"loaders.gl assertion failed.")}var y={self:typeof self<"u"&&self,window:typeof window<"u"&&window,global:typeof global<"u"&&global,document:typeof document<"u"&&document},Ee=y.self||y.window||y.global||{},we=y.window||y.self||y.global||{},Le=y.global||y.self||y.window||{},Ie=y.document||{};var D=typeof process!="object"||String(process)!=="[object process]"||process.browser,_=typeof importScripts=="function",Pe=typeof window<"u"&&typeof window.orientation<"u",C=typeof process<"u"&&process.version&&/v([0-9]*)/.exec(process.version),Re=C&&parseFloat(C[1])||0;function x(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)x(t[a],e,o)}}return r===void 0?Array.from(o):[]}function B(t){return t?t instanceof ArrayBuffer||typeof MessagePort<"u"&&t instanceof MessagePort||typeof ImageBitmap<"u"&&t instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&t instanceof OffscreenCanvas:!1}function g(){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<"u"||Boolean(g())}static set onmessage(e){function r(a){let n=g(),{type:s,payload:i}=n?a:a.data;e(s,i)}let o=g();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(!oe(a))return;let n=g(),{type:s,payload:i}=n?a:a.data;e(s,i)}),g()?console.error("not implemented"):globalThis.addEventListener("message",r)}static removeEventListener(e){let r=M.get(e);M.delete(e),g()?console.error("not implemented"):globalThis.removeEventListener("message",r)}static postMessage(e,r){let o={source:"loaders.gl",type:e,payload:r},a=x(r),n=g();n?n.postMessage(o,a):globalThis.postMessage(o,a)}};function oe(t){let{type:e,data:r}=t;return e==="message"&&r&&typeof r.source=="string"&&r.source.startsWith("loaders.gl")}var p=te(N(),1);var O={};async function h(t,e=null,r={},o=null){return e&&(t=k(t,e,r,o)),O[t]=O[t]||ae(t),await O[t]}function k(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?(F(r.CDN.startsWith("http")),`${r.CDN}/${e}@${S}/dist/libs/${o}`):_?`../src/libs/${o}`:`modules/${e}/src/libs/${o}`:`modules/${e}/dist/libs/${o}`}async function ae(t){if(t.endsWith("wasm"))return await se(t);if(!D)try{return p&&void 0&&await(void 0)(t)}catch(r){return console.error(r),null}if(_)return importScripts(t);let e=await ie(t);return ne(e,t)}function ne(t,e){if(!D)return void 0&&(void 0)(t,e);if(_)return eval.call(globalThis,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 se(t){return!void 0||t.startsWith("http")?await(await fetch(t)).arrayBuffer():await(void 0)(t)}async function ie(t){return!void 0||t.startsWith("http")?await(await fetch(t)).text():await(void 0)(t)}var ce=0;function E(t){l.inWorkerThread()&&(l.onmessage=async(e,r)=>{switch(e){case"process":try{let{input:o,options:a={},context:n={}}=r,s=await ue({loader:t,arrayBuffer:o,options:a,context:{...n,_parse:de}});l.postMessage("done",{result:s})}catch(o){let a=o instanceof Error?o.message:"";l.postMessage("error",{error:a})}break;default:}})}function de(t,e,r,o){return new Promise((a,n)=>{let s=ce++,i=(f,d)=>{if(d.id===s)switch(f){case"done":l.removeEventListener(i),a(d.result);break;case"error":l.removeEventListener(i),n(d.error);break;default:}};l.addEventListener(i);let c={id:s,input:t,options:r};l.postMessage("process",c)})}async function ue({loader:t,arrayBuffer:e,options:r,context:o}){let a,n;if(t.parseSync||t.parse)a=e,n=t.parseSync||t.parse;else if(t.parseTextSync)a=new TextDecoder().decode(e),n=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 n(a,{...r},o,t)}var W="4.0.0-beta.4";var le={draco:{decoderType:typeof WebAssembly=="object"?"wasm":"js",libraryPath:"libs/",extraAttributes:{},attributeNameEntry:void 0}},v={name:"Draco",id:"draco",module:"draco",version:W,worker:!0,extensions:["drc"],mimeTypes:["application/octet-stream"],binary:!0,tests:["DRACO"],options:le};function z(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 w(t){let e=1/0,r=1/0,o=1/0,a=-1/0,n=-1/0,s=-1/0,i=t.POSITION?t.POSITION.value:[],c=i&&i.length;for(let f=0;f<c;f+=3){let d=i[f],m=i[f+1],A=i[f+2];e=d<e?d:e,r=m<r?m:r,o=A<o?A:o,a=d>a?d:a,n=m>n?m:n,s=A>s?A:s}return[[e,r,o],[a,n,s]]}function L(t,e,r){let o=z(e.value),a=r||V(e);return{name:t,type:{type:"fixed-size-list",listSize:e.size,children:[{name:"value",type:o}]},nullable:!1,metadata:a}}function V(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 U(t,e,r){let o=q(e.metadata),a=[],n=pe(e.attributes);for(let s in t){let i=t[s],c=G(s,i,n[s]);a.push(c)}if(r){let s=G("indices",r);a.push(s)}return{fields:a,metadata:o}}function pe(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?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 $={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},fe={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array},ye=4,b=class{draco;decoder;metadataQuerier;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),n=a===this.draco.TRIANGULAR_MESH?new this.draco.Mesh:new this.draco.PointCloud;try{let s;switch(a){case this.draco.TRIANGULAR_MESH:s=this.decoder.DecodeBufferToMesh(o,n);break;case this.draco.POINT_CLOUD:s=this.decoder.DecodeBufferToPointCloud(o,n);break;default:throw new Error("DRACO: Unknown geometry type.")}if(!s.ok()||!n.ptr){let A=`DRACO decompression failed: ${s.error_msg()}`;throw new Error(A)}let i=this._getDracoLoaderData(n,a,r),c=this._getMeshData(n,i,r),f=w(c.attributes),d=U(c.attributes,i,c.indices);return{loader:"draco",loaderData:i,header:{vertexCount:n.num_points(),boundingBox:f},...c,schema:d}}finally{this.draco.destroy(o),n&&this.draco.destroy(n)}}_getDracoLoaderData(e,r,o){let a=this._getTopLevelMetadata(e),n=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:n}}_getDracoAttributes(e,r){let o={};for(let a=0;a<e.num_attributes();a++){let n=this.decoder.GetAttribute(e,a),s=this._getAttributeMetadata(e,a);o[n.unique_id()]={unique_id:n.unique_id(),attribute_type:n.attribute_type(),data_type:n.data_type(),num_components:n.num_components(),byte_offset:n.byte_offset(),byte_stride:n.byte_stride(),normalized:n.normalized(),attribute_index:a,metadata:s};let i=this._getQuantizationTransform(n,r);i&&(o[n.unique_id()].quantization_transform=i);let c=this._getOctahedronTransform(n,r);c&&(o[n.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 n of Object.values(e.attributes)){let s=this._deduceAttributeName(n,o);n.name=s;let{value:i,size:c}=this._getAttributeValues(r,n);a[s]={value:i,size:c,byteOffset:n.byte_offset,byteStride:n.byte_stride,normalized:n.normalized}}return a}_getTriangleListIndices(e){let o=e.num_faces()*3,a=o*ye,n=this.draco._malloc(a);try{return this.decoder.GetTrianglesUInt32Array(e,a,n),new Uint32Array(this.draco.HEAPF32.buffer,n,o).slice()}finally{this.draco._free(n)}}_getTriangleStripIndices(e){let r=new this.draco.DracoInt32Array;try{return this.decoder.GetTriangleStripsFromMesh(e,r),Ae(r)}finally{this.draco.destroy(r)}}_getAttributeValues(e,r){let o=fe[r.data_type],a=r.num_components,s=e.num_points()*a,i=s*o.BYTES_PER_ELEMENT,c=me(this.draco,o),f,d=this.draco._malloc(i);try{let m=this.decoder.GetAttribute(e,r.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(e,m,c,i,d),f=new o(this.draco.HEAPF32.buffer,d,s).slice()}finally{this.draco._free(d)}return{value:f,size:a}}_deduceAttributeName(e,r){let o=e.unique_id;for(let[s,i]of Object.entries(r.extraAttributes||{}))if(i===o)return s;let a=e.attribute_type;for(let s in $)if(this.draco[s]===a)return $[s];let n=r.attributeNameEntry||"name";return e.metadata[n]?e.metadata[n].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 n=this.metadataQuerier.GetEntryName(e,a);r[n]=this._getDracoMetadataField(e,n)}return r}_getDracoMetadataField(e,r){let o=new this.draco.DracoInt32Array;try{this.metadataQuerier.GetIntEntryArray(e,r,o);let a=ge(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 n of a)this.decoder.SkipAttributeTransform(this.draco[n])}_getQuantizationTransform(e,r){let{quantizedAttributes:o=[]}=r,a=e.attribute_type();if(o.map(s=>this.decoder[s]).includes(a)){let s=new this.draco.AttributeQuantizationTransform;try{if(s.InitFromAttribute(e))return{quantization_bits:s.quantization_bits(),range:s.range(),min_values:new Float32Array([1,2,3]).map(i=>s.min_value(i))}}finally{this.draco.destroy(s)}}return null}_getOctahedronTransform(e,r){let{octahedronAttributes:o=[]}=r,a=e.attribute_type();if(o.map(s=>this.decoder[s]).includes(a)){let s=new this.draco.AttributeQuantizationTransform;try{if(s.InitFromAttribute(e))return{quantization_bits:s.quantization_bits()}}finally{this.draco.destroy(s)}}return null}};function me(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 ge(t){let e=t.size(),r=new Int32Array(e);for(let o=0;o<e;o++)r[o]=t.GetValue(o);return r}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}var he="1.5.6",be="1.4.1",I=`https://www.gstatic.com/draco/versioned/decoders/${he}`,u={DECODER:"draco_wasm_wrapper.js",DECODER_WASM:"draco_decoder.wasm",FALLBACK_DECODER:"draco_decoder.js",ENCODER:"draco_encoder.js"},P={[u.DECODER]:`${I}/${u.DECODER}`,[u.DECODER_WASM]:`${I}/${u.DECODER_WASM}`,[u.FALLBACK_DECODER]:`${I}/${u.FALLBACK_DECODER}`,[u.ENCODER]:`https://raw.githubusercontent.com/google/draco/${be}/javascript/${u.ENCODER}`},T;async function Q(t){let e=t.modules||{};return e.draco3d?T=T||e.draco3d.createDecoderModule({}).then(r=>({draco:r})):T=T||Te(t),await T}async function Te(t){let e,r;switch(t.draco&&t.draco.decoderType){case"js":e=await h(P[u.FALLBACK_DECODER],"draco",t,u.FALLBACK_DECODER);break;case"wasm":default:[e,r]=await Promise.all([await h(P[u.DECODER],"draco",t,u.DECODER),await h(P[u.DECODER_WASM],"draco",t,u.DECODER_WASM)])}return e=e||globalThis.DracoDecoderModule,await De(e,r)}function De(t,e){let r={};return e&&(r.wasmBinary=e),new Promise(o=>{t({...r,onModuleLoaded:a=>o({draco:a})})})}var j={...v,parse:_e};async function _e(t,e){let{draco:r}=await Q(e),o=new b(r);try{return o.parseSync(t,e?.draco)}finally{o.destroy()}}E(j);})();
|
|
1
|
+
"use strict";(()=>{var Y=Object.create;var R=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var Z=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var ee=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of J(e))!K.call(t,a)&&a!==r&&R(t,a,{get:()=>e[a],enumerable:!(o=X(e,a))||o.enumerable});return t};var te=(t,e,r)=>(r=t!=null?Y(H(t)):{},ee(e||!t||!t.__esModule?R(r,"default",{value:t,enumerable:!0}):r,t));var N=Z(()=>{"use strict"});function re(){return globalThis._loadersgl_?.version||(globalThis._loadersgl_=globalThis._loadersgl_||{},globalThis._loadersgl_.version="4.0.0-beta.6"),globalThis._loadersgl_.version}var S=re();function F(t,e){if(!t)throw new Error(e||"loaders.gl assertion failed.")}var y={self:typeof self<"u"&&self,window:typeof window<"u"&&window,global:typeof global<"u"&&global,document:typeof document<"u"&&document},Ee=y.self||y.window||y.global||{},we=y.window||y.self||y.global||{},Le=y.global||y.self||y.window||{},Ie=y.document||{};var D=typeof process!="object"||String(process)!=="[object process]"||process.browser,_=typeof importScripts=="function",Pe=typeof window<"u"&&typeof window.orientation<"u",C=typeof process<"u"&&process.version&&/v([0-9]*)/.exec(process.version),Re=C&&parseFloat(C[1])||0;function x(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)x(t[a],e,o)}}return r===void 0?Array.from(o):[]}function B(t){return t?t instanceof ArrayBuffer||typeof MessagePort<"u"&&t instanceof MessagePort||typeof ImageBitmap<"u"&&t instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&t instanceof OffscreenCanvas:!1}function g(){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<"u"||Boolean(g())}static set onmessage(e){function r(a){let n=g(),{type:s,payload:i}=n?a:a.data;e(s,i)}let o=g();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(!oe(a))return;let n=g(),{type:s,payload:i}=n?a:a.data;e(s,i)}),g()?console.error("not implemented"):globalThis.addEventListener("message",r)}static removeEventListener(e){let r=M.get(e);M.delete(e),g()?console.error("not implemented"):globalThis.removeEventListener("message",r)}static postMessage(e,r){let o={source:"loaders.gl",type:e,payload:r},a=x(r),n=g();n?n.postMessage(o,a):globalThis.postMessage(o,a)}};function oe(t){let{type:e,data:r}=t;return e==="message"&&r&&typeof r.source=="string"&&r.source.startsWith("loaders.gl")}var p=te(N(),1);var O={};async function h(t,e=null,r={},o=null){return e&&(t=k(t,e,r,o)),O[t]=O[t]||ae(t),await O[t]}function k(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?(F(r.CDN.startsWith("http")),`${r.CDN}/${e}@${S}/dist/libs/${o}`):_?`../src/libs/${o}`:`modules/${e}/src/libs/${o}`:`modules/${e}/dist/libs/${o}`}async function ae(t){if(t.endsWith("wasm"))return await se(t);if(!D)try{return p&&void 0&&await(void 0)(t)}catch(r){return console.error(r),null}if(_)return importScripts(t);let e=await ie(t);return ne(e,t)}function ne(t,e){if(!D)return void 0&&(void 0)(t,e);if(_)return eval.call(globalThis,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 se(t){return!void 0||t.startsWith("http")?await(await fetch(t)).arrayBuffer():await(void 0)(t)}async function ie(t){return!void 0||t.startsWith("http")?await(await fetch(t)).text():await(void 0)(t)}var ce=0;function E(t){l.inWorkerThread()&&(l.onmessage=async(e,r)=>{switch(e){case"process":try{let{input:o,options:a={},context:n={}}=r,s=await ue({loader:t,arrayBuffer:o,options:a,context:{...n,_parse:de}});l.postMessage("done",{result:s})}catch(o){let a=o instanceof Error?o.message:"";l.postMessage("error",{error:a})}break;default:}})}function de(t,e,r,o){return new Promise((a,n)=>{let s=ce++,i=(f,d)=>{if(d.id===s)switch(f){case"done":l.removeEventListener(i),a(d.result);break;case"error":l.removeEventListener(i),n(d.error);break;default:}};l.addEventListener(i);let c={id:s,input:t,options:r};l.postMessage("process",c)})}async function ue({loader:t,arrayBuffer:e,options:r,context:o}){let a,n;if(t.parseSync||t.parse)a=e,n=t.parseSync||t.parse;else if(t.parseTextSync)a=new TextDecoder().decode(e),n=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 n(a,{...r},o,t)}var W="4.0.0-beta.6";var le={draco:{decoderType:typeof WebAssembly=="object"?"wasm":"js",libraryPath:"libs/",extraAttributes:{},attributeNameEntry:void 0}},v={name:"Draco",id:"draco",module:"draco",version:W,worker:!0,extensions:["drc"],mimeTypes:["application/octet-stream"],binary:!0,tests:["DRACO"],options:le};function z(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 w(t){let e=1/0,r=1/0,o=1/0,a=-1/0,n=-1/0,s=-1/0,i=t.POSITION?t.POSITION.value:[],c=i&&i.length;for(let f=0;f<c;f+=3){let d=i[f],m=i[f+1],A=i[f+2];e=d<e?d:e,r=m<r?m:r,o=A<o?A:o,a=d>a?d:a,n=m>n?m:n,s=A>s?A:s}return[[e,r,o],[a,n,s]]}function L(t,e,r){let o=z(e.value),a=r||V(e);return{name:t,type:{type:"fixed-size-list",listSize:e.size,children:[{name:"value",type:o}]},nullable:!1,metadata:a}}function V(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 U(t,e,r){let o=q(e.metadata),a=[],n=pe(e.attributes);for(let s in t){let i=t[s],c=G(s,i,n[s]);a.push(c)}if(r){let s=G("indices",r);a.push(s)}return{fields:a,metadata:o}}function pe(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?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 $={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},fe={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array},ye=4,b=class{draco;decoder;metadataQuerier;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),n=a===this.draco.TRIANGULAR_MESH?new this.draco.Mesh:new this.draco.PointCloud;try{let s;switch(a){case this.draco.TRIANGULAR_MESH:s=this.decoder.DecodeBufferToMesh(o,n);break;case this.draco.POINT_CLOUD:s=this.decoder.DecodeBufferToPointCloud(o,n);break;default:throw new Error("DRACO: Unknown geometry type.")}if(!s.ok()||!n.ptr){let A=`DRACO decompression failed: ${s.error_msg()}`;throw new Error(A)}let i=this._getDracoLoaderData(n,a,r),c=this._getMeshData(n,i,r),f=w(c.attributes),d=U(c.attributes,i,c.indices);return{loader:"draco",loaderData:i,header:{vertexCount:n.num_points(),boundingBox:f},...c,schema:d}}finally{this.draco.destroy(o),n&&this.draco.destroy(n)}}_getDracoLoaderData(e,r,o){let a=this._getTopLevelMetadata(e),n=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:n}}_getDracoAttributes(e,r){let o={};for(let a=0;a<e.num_attributes();a++){let n=this.decoder.GetAttribute(e,a),s=this._getAttributeMetadata(e,a);o[n.unique_id()]={unique_id:n.unique_id(),attribute_type:n.attribute_type(),data_type:n.data_type(),num_components:n.num_components(),byte_offset:n.byte_offset(),byte_stride:n.byte_stride(),normalized:n.normalized(),attribute_index:a,metadata:s};let i=this._getQuantizationTransform(n,r);i&&(o[n.unique_id()].quantization_transform=i);let c=this._getOctahedronTransform(n,r);c&&(o[n.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 n of Object.values(e.attributes)){let s=this._deduceAttributeName(n,o);n.name=s;let{value:i,size:c}=this._getAttributeValues(r,n);a[s]={value:i,size:c,byteOffset:n.byte_offset,byteStride:n.byte_stride,normalized:n.normalized}}return a}_getTriangleListIndices(e){let o=e.num_faces()*3,a=o*ye,n=this.draco._malloc(a);try{return this.decoder.GetTrianglesUInt32Array(e,a,n),new Uint32Array(this.draco.HEAPF32.buffer,n,o).slice()}finally{this.draco._free(n)}}_getTriangleStripIndices(e){let r=new this.draco.DracoInt32Array;try{return this.decoder.GetTriangleStripsFromMesh(e,r),Ae(r)}finally{this.draco.destroy(r)}}_getAttributeValues(e,r){let o=fe[r.data_type],a=r.num_components,s=e.num_points()*a,i=s*o.BYTES_PER_ELEMENT,c=me(this.draco,o),f,d=this.draco._malloc(i);try{let m=this.decoder.GetAttribute(e,r.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(e,m,c,i,d),f=new o(this.draco.HEAPF32.buffer,d,s).slice()}finally{this.draco._free(d)}return{value:f,size:a}}_deduceAttributeName(e,r){let o=e.unique_id;for(let[s,i]of Object.entries(r.extraAttributes||{}))if(i===o)return s;let a=e.attribute_type;for(let s in $)if(this.draco[s]===a)return $[s];let n=r.attributeNameEntry||"name";return e.metadata[n]?e.metadata[n].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 n=this.metadataQuerier.GetEntryName(e,a);r[n]=this._getDracoMetadataField(e,n)}return r}_getDracoMetadataField(e,r){let o=new this.draco.DracoInt32Array;try{this.metadataQuerier.GetIntEntryArray(e,r,o);let a=ge(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 n of a)this.decoder.SkipAttributeTransform(this.draco[n])}_getQuantizationTransform(e,r){let{quantizedAttributes:o=[]}=r,a=e.attribute_type();if(o.map(s=>this.decoder[s]).includes(a)){let s=new this.draco.AttributeQuantizationTransform;try{if(s.InitFromAttribute(e))return{quantization_bits:s.quantization_bits(),range:s.range(),min_values:new Float32Array([1,2,3]).map(i=>s.min_value(i))}}finally{this.draco.destroy(s)}}return null}_getOctahedronTransform(e,r){let{octahedronAttributes:o=[]}=r,a=e.attribute_type();if(o.map(s=>this.decoder[s]).includes(a)){let s=new this.draco.AttributeQuantizationTransform;try{if(s.InitFromAttribute(e))return{quantization_bits:s.quantization_bits()}}finally{this.draco.destroy(s)}}return null}};function me(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 ge(t){let e=t.size(),r=new Int32Array(e);for(let o=0;o<e;o++)r[o]=t.GetValue(o);return r}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}var he="1.5.6",be="1.4.1",I=`https://www.gstatic.com/draco/versioned/decoders/${he}`,u={DECODER:"draco_wasm_wrapper.js",DECODER_WASM:"draco_decoder.wasm",FALLBACK_DECODER:"draco_decoder.js",ENCODER:"draco_encoder.js"},P={[u.DECODER]:`${I}/${u.DECODER}`,[u.DECODER_WASM]:`${I}/${u.DECODER_WASM}`,[u.FALLBACK_DECODER]:`${I}/${u.FALLBACK_DECODER}`,[u.ENCODER]:`https://raw.githubusercontent.com/google/draco/${be}/javascript/${u.ENCODER}`},T;async function Q(t){let e=t.modules||{};return e.draco3d?T=T||e.draco3d.createDecoderModule({}).then(r=>({draco:r})):T=T||Te(t),await T}async function Te(t){let e,r;switch(t.draco&&t.draco.decoderType){case"js":e=await h(P[u.FALLBACK_DECODER],"draco",t,u.FALLBACK_DECODER);break;case"wasm":default:[e,r]=await Promise.all([await h(P[u.DECODER],"draco",t,u.DECODER),await h(P[u.DECODER_WASM],"draco",t,u.DECODER_WASM)])}return e=e||globalThis.DracoDecoderModule,await De(e,r)}function De(t,e){let r={};return e&&(r.wasmBinary=e),new Promise(o=>{t({...r,onModuleLoaded:a=>o({draco:a})})})}var j={...v,parse:_e};async function _e(t,e){let{draco:r}=await Q(e),o=new b(r);try{return o.parseSync(t,e?.draco)}finally{o.destroy()}}E(j);})();
|
|
2
2
|
//# sourceMappingURL=draco-worker.js.map
|