@loaders.gl/draco
Advanced tools
Comparing version 4.3.0-beta.2 to 4.3.0-beta.3
@@ -7,3 +7,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
else root['loaders'] = factory();})(globalThis, function () { | ||
"use strict";var __exports__=(()=>{var H=Object.create;var E=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,tt=Object.prototype.hasOwnProperty;var et=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports),rt=(o,t)=>{for(var e in t)E(o,e,{get:t[e],enumerable:!0})},D=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Z(t))!tt.call(o,n)&&n!==e&&E(o,n,{get:()=>t[n],enumerable:!(r=K(t,n))||r.enumerable});return o},w=(o,t,e)=>(D(o,t,"default"),e&&D(e,t,"default")),ot=(o,t,e)=>(e=o!=null?H(J(o)):{},D(t||!o||!o.__esModule?E(e,"default",{value:o,enumerable:!0}):e,o)),nt=o=>D(E({},"__esModule",{value:!0}),o);var F=et((xt,N)=>{N.exports=globalThis.loaders});var g={};rt(g,{DRACO_EXTERNAL_LIBRARIES:()=>u,DRACO_EXTERNAL_LIBRARY_URLS:()=>_,DracoLoader:()=>It,DracoWorkerLoader:()=>I,DracoWriter:()=>Y,DracoWriterWorker:()=>Ot});w(g,ot(F(),1));var y="4.3.0-beta.1";var I={dataType:null,batchType:null,name:"Draco",id:"draco",module:"draco",version:y,worker:!0,extensions:["drc"],mimeTypes:["application/octet-stream"],binary:!0,tests:["DRACO"],options:{draco:{decoderType:typeof WebAssembly=="object"?"wasm":"js",libraryPath:"libs/",extraAttributes:{},attributeNameEntry:void 0}}};function B(o){switch(o.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 M(o){let t=1/0,e=1/0,r=1/0,n=-1/0,a=-1/0,i=-1/0,s=o.POSITION?o.POSITION.value:[],c=s&&s.length;for(let d=0;d<c;d+=3){let l=s[d],h=s[d+1],m=s[d+2];t=l<t?l:t,e=h<e?h:e,r=m<r?m:r,n=l>n?l:n,a=h>a?h:a,i=m>i?m:i}return[[t,e,r],[n,a,i]]}function R(o,t,e){let r=B(t.value),n=e||P(t);return{name:o,type:{type:"fixed-size-list",listSize:t.size,children:[{name:"value",type:r}]},nullable:!1,metadata:n}}function P(o){let t={};return"byteOffset"in o&&(t.byteOffset=o.byteOffset.toString(10)),"byteStride"in o&&(t.byteStride=o.byteStride.toString(10)),"normalized"in o&&(t.normalized=o.normalized.toString()),t}function U(o,t,e){let r=z(t.metadata),n=[],a=at(t.attributes);for(let i in o){let s=o[i],c=k(i,s,a[i]);n.push(c)}if(e){let i=k("indices",e);n.push(i)}return{fields:n,metadata:r}}function at(o){let t={};for(let e in o){let r=o[e];t[r.name||"undefined"]=r}return t}function k(o,t,e){let r=e?z(e.metadata):void 0;return R(o,t,r)}function z(o){Object.entries(o);let t={};for(let e in o)t[`${e}.string`]=JSON.stringify(o[e]);return t}var W={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},it={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array},st=4,b=class{draco;decoder;metadataQuerier;constructor(t){this.draco=t,this.decoder=new this.draco.Decoder,this.metadataQuerier=new this.draco.MetadataQuerier}destroy(){this.draco.destroy(this.decoder),this.draco.destroy(this.metadataQuerier)}parseSync(t,e={}){let r=new this.draco.DecoderBuffer;r.Init(new Int8Array(t),t.byteLength),this._disableAttributeTransforms(e);let n=this.decoder.GetEncodedGeometryType(r),a=n===this.draco.TRIANGULAR_MESH?new this.draco.Mesh:new this.draco.PointCloud;try{let i;switch(n){case this.draco.TRIANGULAR_MESH:i=this.decoder.DecodeBufferToMesh(r,a);break;case this.draco.POINT_CLOUD:i=this.decoder.DecodeBufferToPointCloud(r,a);break;default:throw new Error("DRACO: Unknown geometry type.")}if(!i.ok()||!a.ptr){let m=`DRACO decompression failed: ${i.error_msg()}`;throw new Error(m)}let s=this._getDracoLoaderData(a,n,e),c=this._getMeshData(a,s,e),d=M(c.attributes),l=U(c.attributes,s,c.indices);return{loader:"draco",loaderData:s,header:{vertexCount:a.num_points(),boundingBox:d},...c,schema:l}}finally{this.draco.destroy(r),a&&this.draco.destroy(a)}}_getDracoLoaderData(t,e,r){let n=this._getTopLevelMetadata(t),a=this._getDracoAttributes(t,r);return{geometry_type:e,num_attributes:t.num_attributes(),num_points:t.num_points(),num_faces:t instanceof this.draco.Mesh?t.num_faces():0,metadata:n,attributes:a}}_getDracoAttributes(t,e){let r={};for(let n=0;n<t.num_attributes();n++){let a=this.decoder.GetAttribute(t,n),i=this._getAttributeMetadata(t,n);r[a.unique_id()]={unique_id:a.unique_id(),attribute_type:a.attribute_type(),data_type:a.data_type(),num_components:a.num_components(),byte_offset:a.byte_offset(),byte_stride:a.byte_stride(),normalized:a.normalized(),attribute_index:n,metadata:i};let s=this._getQuantizationTransform(a,e);s&&(r[a.unique_id()].quantization_transform=s);let c=this._getOctahedronTransform(a,e);c&&(r[a.unique_id()].octahedron_transform=c)}return r}_getMeshData(t,e,r){let n=this._getMeshAttributes(e,t,r);if(!n.POSITION)throw new Error("DRACO: No position attribute found.");if(t instanceof this.draco.Mesh)switch(r.topology){case"triangle-strip":return{topology:"triangle-strip",mode:4,attributes:n,indices:{value:this._getTriangleStripIndices(t),size:1}};case"triangle-list":default:return{topology:"triangle-list",mode:5,attributes:n,indices:{value:this._getTriangleListIndices(t),size:1}}}return{topology:"point-list",mode:0,attributes:n}}_getMeshAttributes(t,e,r){let n={};for(let a of Object.values(t.attributes)){let i=this._deduceAttributeName(a,r);a.name=i;let s=this._getAttributeValues(e,a);if(s){let{value:c,size:d}=s;n[i]={value:c,size:d,byteOffset:a.byte_offset,byteStride:a.byte_stride,normalized:a.normalized}}}return n}_getTriangleListIndices(t){let r=t.num_faces()*3,n=r*st,a=this.draco._malloc(n);try{return this.decoder.GetTrianglesUInt32Array(t,n,a),new Uint32Array(this.draco.HEAPF32.buffer,a,r).slice()}finally{this.draco._free(a)}}_getTriangleStripIndices(t){let e=new this.draco.DracoInt32Array;try{return this.decoder.GetTriangleStripsFromMesh(t,e),ut(e)}finally{this.draco.destroy(e)}}_getAttributeValues(t,e){let r=it[e.data_type];if(!r)return console.warn(`DRACO: Unsupported attribute type ${e.data_type}`),null;let n=e.num_components,i=t.num_points()*n,s=i*r.BYTES_PER_ELEMENT,c=ct(this.draco,r),d,l=this.draco._malloc(s);try{let h=this.decoder.GetAttribute(t,e.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(t,h,c,s,l),d=new r(this.draco.HEAPF32.buffer,l,i).slice()}finally{this.draco._free(l)}return{value:d,size:n}}_deduceAttributeName(t,e){let r=t.unique_id;for(let[i,s]of Object.entries(e.extraAttributes||{}))if(s===r)return i;let n=t.attribute_type;for(let i in W)if(this.draco[i]===n)return W[i];let a=e.attributeNameEntry||"name";return t.metadata[a]?t.metadata[a].string:`CUSTOM_ATTRIBUTE_${r}`}_getTopLevelMetadata(t){let e=this.decoder.GetMetadata(t);return this._getDracoMetadata(e)}_getAttributeMetadata(t,e){let r=this.decoder.GetAttributeMetadata(t,e);return this._getDracoMetadata(r)}_getDracoMetadata(t){if(!t||!t.ptr)return{};let e={},r=this.metadataQuerier.NumEntries(t);for(let n=0;n<r;n++){let a=this.metadataQuerier.GetEntryName(t,n);e[a]=this._getDracoMetadataField(t,a)}return e}_getDracoMetadataField(t,e){let r=new this.draco.DracoInt32Array;try{this.metadataQuerier.GetIntEntryArray(t,e,r);let n=dt(r);return{int:this.metadataQuerier.GetIntEntry(t,e),string:this.metadataQuerier.GetStringEntry(t,e),double:this.metadataQuerier.GetDoubleEntry(t,e),intArray:n}}finally{this.draco.destroy(r)}}_disableAttributeTransforms(t){let{quantizedAttributes:e=[],octahedronAttributes:r=[]}=t,n=[...e,...r];for(let a of n)this.decoder.SkipAttributeTransform(this.draco[a])}_getQuantizationTransform(t,e){let{quantizedAttributes:r=[]}=e,n=t.attribute_type();if(r.map(i=>this.decoder[i]).includes(n)){let i=new this.draco.AttributeQuantizationTransform;try{if(i.InitFromAttribute(t))return{quantization_bits:i.quantization_bits(),range:i.range(),min_values:new Float32Array([1,2,3]).map(s=>i.min_value(s))}}finally{this.draco.destroy(i)}}return null}_getOctahedronTransform(t,e){let{octahedronAttributes:r=[]}=e,n=t.attribute_type();if(r.map(i=>this.decoder[i]).includes(n)){let i=new this.draco.AttributeQuantizationTransform;try{if(i.InitFromAttribute(t))return{quantization_bits:i.quantization_bits()}}finally{this.draco.destroy(i)}}return null}};function ct(o,t){switch(t){case Float32Array:return o.DT_FLOAT32;case Int8Array:return o.DT_INT8;case Int16Array:return o.DT_INT16;case Int32Array:return o.DT_INT32;case Uint8Array:return o.DT_UINT8;case Uint16Array:return o.DT_UINT16;case Uint32Array:return o.DT_UINT32;default:return o.DT_INVALID}}function dt(o){let t=o.size(),e=new Int32Array(t);for(let r=0;r<t;r++)e[r]=o.GetValue(r);return e}function ut(o){let t=o.size(),e=new Int32Array(t);for(let r=0;r<t;r++)e[r]=o.GetValue(r);return e}function lt(){return globalThis._loadersgl_?.version||(globalThis._loadersgl_=globalThis._loadersgl_||{},globalThis._loadersgl_.version="4.3.0-beta.1"),globalThis._loadersgl_.version}var $=lt();function v(o,t){if(!o)throw new Error(t||"loaders.gl assertion failed.")}var f={self:typeof self<"u"&&self,window:typeof window<"u"&&window,global:typeof global<"u"&&global,document:typeof document<"u"&&document},Yt=f.self||f.window||f.global||{},Ht=f.window||f.self||f.global||{},Kt=f.global||f.self||f.window||{},Zt=f.document||{};var A=typeof process!="object"||String(process)!=="[object process]"||process.browser,O=typeof importScripts=="function",Jt=typeof window<"u"&&typeof window.orientation<"u",j=typeof process<"u"&&process.version&&/v([0-9]*)/.exec(process.version),te=j&&parseFloat(j[1])||0;var x={};async function p(o,t=null,e={},r=null){return t&&(o=V(o,t,e,r)),x[o]=x[o]||ft(o),await x[o]}function V(o,t,e={},r=null){if(!e.useLocalLibraries&&o.startsWith("http"))return o;r=r||o;let n=e.modules||{};return n[r]?n[r]:A?e.CDN?(v(e.CDN.startsWith("http")),`${e.CDN}/${t}@${$}/dist/libs/${r}`):O?`../src/libs/${r}`:`modules/${t}/src/libs/${r}`:`modules/${t}/dist/libs/${r}`}async function ft(o){if(o.endsWith("wasm"))return await mt(o);if(!A)try{let{requireFromFile:e}=globalThis.loaders||{};return await e?.(o)}catch(e){return console.error(e),null}if(O)return importScripts(o);let t=await yt(o);return ht(t,o)}function ht(o,t){if(!A){let{requireFromString:r}=globalThis.loaders||{};return r?.(o,t)}if(O)return eval.call(globalThis,o),null;let e=document.createElement("script");e.id=t;try{e.appendChild(document.createTextNode(o))}catch{e.text=o}return document.body.appendChild(e),null}async function mt(o){let{readFileAsArrayBuffer:t}=globalThis.loaders||{};return A||!t||o.startsWith("http")?await(await fetch(o)).arrayBuffer():await t(o)}async function yt(o){let{readFileAsText:t}=globalThis.loaders||{};return A||!t||o.startsWith("http")?await(await fetch(o)).text():await t(o)}var At="1.5.6",pt="1.4.1",L=`https://www.gstatic.com/draco/versioned/decoders/${At}`,u={DECODER:"draco_wasm_wrapper.js",DECODER_WASM:"draco_decoder.wasm",FALLBACK_DECODER:"draco_decoder.js",ENCODER:"draco_encoder.js"},_={[u.DECODER]:`${L}/${u.DECODER}`,[u.DECODER_WASM]:`${L}/${u.DECODER_WASM}`,[u.FALLBACK_DECODER]:`${L}/${u.FALLBACK_DECODER}`,[u.ENCODER]:`https://raw.githubusercontent.com/google/draco/${pt}/javascript/${u.ENCODER}`},C,S;async function q(o){let t=o.modules||{};return t.draco3d?C||=t.draco3d.createDecoderModule({}).then(e=>({draco:e})):C||=_t(o),await C}async function G(o){let t=o.modules||{};return t.draco3d?S||=t.draco3d.createEncoderModule({}).then(e=>({draco:e})):S||=Tt(o),await S}async function _t(o){let t,e;switch(o.draco&&o.draco.decoderType){case"js":t=await p(_[u.FALLBACK_DECODER],"draco",o,u.FALLBACK_DECODER);break;case"wasm":default:[t,e]=await Promise.all([await p(_[u.DECODER],"draco",o,u.DECODER),await p(_[u.DECODER_WASM],"draco",o,u.DECODER_WASM)])}return t=t||globalThis.DracoDecoderModule,await bt(t,e)}function bt(o,t){let e={};return t&&(e.wasmBinary=t),new Promise(r=>{o({...e,onModuleLoaded:n=>r({draco:n})})})}async function Tt(o){let t=await p(_[u.ENCODER],"draco",o,u.ENCODER);return t=t||globalThis.DracoEncoderModule,new Promise(e=>{t({onModuleLoaded:r=>e({draco:r})})})}var Q={POSITION:"POSITION",NORMAL:"NORMAL",COLOR_0:"COLOR",TEXCOORD_0:"TEX_COORD"},gt=()=>{},T=class{draco;dracoEncoder;dracoMeshBuilder;dracoMetadataBuilder;log;constructor(t){this.draco=t,this.dracoEncoder=new this.draco.Encoder,this.dracoMeshBuilder=new this.draco.MeshBuilder,this.dracoMetadataBuilder=new this.draco.MetadataBuilder}destroy(){this.destroyEncodedObject(this.dracoMeshBuilder),this.destroyEncodedObject(this.dracoEncoder),this.destroyEncodedObject(this.dracoMetadataBuilder),this.dracoMeshBuilder=null,this.dracoEncoder=null,this.draco=null}destroyEncodedObject(t){t&&this.draco.destroy(t)}encodeSync(t,e={}){return this.log=gt,this._setOptions(e),e.pointcloud?this._encodePointCloud(t,e):this._encodeMesh(t,e)}_getAttributesFromMesh(t){let e={...t,...t.attributes};return t.indices&&(e.indices=t.indices),e}_encodePointCloud(t,e){let r=new this.draco.PointCloud;e.metadata&&this._addGeometryMetadata(r,e.metadata);let n=this._getAttributesFromMesh(t);this._createDracoPointCloud(r,n,e);let a=new this.draco.DracoInt8Array;try{let i=this.dracoEncoder.EncodePointCloudToDracoBuffer(r,!1,a);if(!(i>0))throw new Error("Draco encoding failed.");return this.log(`DRACO encoded ${r.num_points()} points | ||
"use strict";var __exports__=(()=>{var H=Object.create;var E=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,tt=Object.prototype.hasOwnProperty;var et=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports),rt=(o,t)=>{for(var e in t)E(o,e,{get:t[e],enumerable:!0})},D=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Z(t))!tt.call(o,n)&&n!==e&&E(o,n,{get:()=>t[n],enumerable:!(r=K(t,n))||r.enumerable});return o},w=(o,t,e)=>(D(o,t,"default"),e&&D(e,t,"default")),ot=(o,t,e)=>(e=o!=null?H(J(o)):{},D(t||!o||!o.__esModule?E(e,"default",{value:o,enumerable:!0}):e,o)),nt=o=>D(E({},"__esModule",{value:!0}),o);var F=et((xt,N)=>{N.exports=globalThis.loaders});var g={};rt(g,{DRACO_EXTERNAL_LIBRARIES:()=>u,DRACO_EXTERNAL_LIBRARY_URLS:()=>_,DracoLoader:()=>It,DracoWorkerLoader:()=>I,DracoWriter:()=>Y,DracoWriterWorker:()=>Ot});w(g,ot(F(),1));var y="4.3.0-beta.2";var I={dataType:null,batchType:null,name:"Draco",id:"draco",module:"draco",version:y,worker:!0,extensions:["drc"],mimeTypes:["application/octet-stream"],binary:!0,tests:["DRACO"],options:{draco:{decoderType:typeof WebAssembly=="object"?"wasm":"js",libraryPath:"libs/",extraAttributes:{},attributeNameEntry:void 0}}};function B(o){switch(o.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 M(o){let t=1/0,e=1/0,r=1/0,n=-1/0,a=-1/0,i=-1/0,s=o.POSITION?o.POSITION.value:[],c=s&&s.length;for(let d=0;d<c;d+=3){let l=s[d],h=s[d+1],m=s[d+2];t=l<t?l:t,e=h<e?h:e,r=m<r?m:r,n=l>n?l:n,a=h>a?h:a,i=m>i?m:i}return[[t,e,r],[n,a,i]]}function R(o,t,e){let r=B(t.value),n=e||P(t);return{name:o,type:{type:"fixed-size-list",listSize:t.size,children:[{name:"value",type:r}]},nullable:!1,metadata:n}}function P(o){let t={};return"byteOffset"in o&&(t.byteOffset=o.byteOffset.toString(10)),"byteStride"in o&&(t.byteStride=o.byteStride.toString(10)),"normalized"in o&&(t.normalized=o.normalized.toString()),t}function U(o,t,e){let r=z(t.metadata),n=[],a=at(t.attributes);for(let i in o){let s=o[i],c=k(i,s,a[i]);n.push(c)}if(e){let i=k("indices",e);n.push(i)}return{fields:n,metadata:r}}function at(o){let t={};for(let e in o){let r=o[e];t[r.name||"undefined"]=r}return t}function k(o,t,e){let r=e?z(e.metadata):void 0;return R(o,t,r)}function z(o){Object.entries(o);let t={};for(let e in o)t[`${e}.string`]=JSON.stringify(o[e]);return t}var W={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},it={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array},st=4,b=class{draco;decoder;metadataQuerier;constructor(t){this.draco=t,this.decoder=new this.draco.Decoder,this.metadataQuerier=new this.draco.MetadataQuerier}destroy(){this.draco.destroy(this.decoder),this.draco.destroy(this.metadataQuerier)}parseSync(t,e={}){let r=new this.draco.DecoderBuffer;r.Init(new Int8Array(t),t.byteLength),this._disableAttributeTransforms(e);let n=this.decoder.GetEncodedGeometryType(r),a=n===this.draco.TRIANGULAR_MESH?new this.draco.Mesh:new this.draco.PointCloud;try{let i;switch(n){case this.draco.TRIANGULAR_MESH:i=this.decoder.DecodeBufferToMesh(r,a);break;case this.draco.POINT_CLOUD:i=this.decoder.DecodeBufferToPointCloud(r,a);break;default:throw new Error("DRACO: Unknown geometry type.")}if(!i.ok()||!a.ptr){let m=`DRACO decompression failed: ${i.error_msg()}`;throw new Error(m)}let s=this._getDracoLoaderData(a,n,e),c=this._getMeshData(a,s,e),d=M(c.attributes),l=U(c.attributes,s,c.indices);return{loader:"draco",loaderData:s,header:{vertexCount:a.num_points(),boundingBox:d},...c,schema:l}}finally{this.draco.destroy(r),a&&this.draco.destroy(a)}}_getDracoLoaderData(t,e,r){let n=this._getTopLevelMetadata(t),a=this._getDracoAttributes(t,r);return{geometry_type:e,num_attributes:t.num_attributes(),num_points:t.num_points(),num_faces:t instanceof this.draco.Mesh?t.num_faces():0,metadata:n,attributes:a}}_getDracoAttributes(t,e){let r={};for(let n=0;n<t.num_attributes();n++){let a=this.decoder.GetAttribute(t,n),i=this._getAttributeMetadata(t,n);r[a.unique_id()]={unique_id:a.unique_id(),attribute_type:a.attribute_type(),data_type:a.data_type(),num_components:a.num_components(),byte_offset:a.byte_offset(),byte_stride:a.byte_stride(),normalized:a.normalized(),attribute_index:n,metadata:i};let s=this._getQuantizationTransform(a,e);s&&(r[a.unique_id()].quantization_transform=s);let c=this._getOctahedronTransform(a,e);c&&(r[a.unique_id()].octahedron_transform=c)}return r}_getMeshData(t,e,r){let n=this._getMeshAttributes(e,t,r);if(!n.POSITION)throw new Error("DRACO: No position attribute found.");if(t instanceof this.draco.Mesh)switch(r.topology){case"triangle-strip":return{topology:"triangle-strip",mode:4,attributes:n,indices:{value:this._getTriangleStripIndices(t),size:1}};case"triangle-list":default:return{topology:"triangle-list",mode:5,attributes:n,indices:{value:this._getTriangleListIndices(t),size:1}}}return{topology:"point-list",mode:0,attributes:n}}_getMeshAttributes(t,e,r){let n={};for(let a of Object.values(t.attributes)){let i=this._deduceAttributeName(a,r);a.name=i;let s=this._getAttributeValues(e,a);if(s){let{value:c,size:d}=s;n[i]={value:c,size:d,byteOffset:a.byte_offset,byteStride:a.byte_stride,normalized:a.normalized}}}return n}_getTriangleListIndices(t){let r=t.num_faces()*3,n=r*st,a=this.draco._malloc(n);try{return this.decoder.GetTrianglesUInt32Array(t,n,a),new Uint32Array(this.draco.HEAPF32.buffer,a,r).slice()}finally{this.draco._free(a)}}_getTriangleStripIndices(t){let e=new this.draco.DracoInt32Array;try{return this.decoder.GetTriangleStripsFromMesh(t,e),ut(e)}finally{this.draco.destroy(e)}}_getAttributeValues(t,e){let r=it[e.data_type];if(!r)return console.warn(`DRACO: Unsupported attribute type ${e.data_type}`),null;let n=e.num_components,i=t.num_points()*n,s=i*r.BYTES_PER_ELEMENT,c=ct(this.draco,r),d,l=this.draco._malloc(s);try{let h=this.decoder.GetAttribute(t,e.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(t,h,c,s,l),d=new r(this.draco.HEAPF32.buffer,l,i).slice()}finally{this.draco._free(l)}return{value:d,size:n}}_deduceAttributeName(t,e){let r=t.unique_id;for(let[i,s]of Object.entries(e.extraAttributes||{}))if(s===r)return i;let n=t.attribute_type;for(let i in W)if(this.draco[i]===n)return W[i];let a=e.attributeNameEntry||"name";return t.metadata[a]?t.metadata[a].string:`CUSTOM_ATTRIBUTE_${r}`}_getTopLevelMetadata(t){let e=this.decoder.GetMetadata(t);return this._getDracoMetadata(e)}_getAttributeMetadata(t,e){let r=this.decoder.GetAttributeMetadata(t,e);return this._getDracoMetadata(r)}_getDracoMetadata(t){if(!t||!t.ptr)return{};let e={},r=this.metadataQuerier.NumEntries(t);for(let n=0;n<r;n++){let a=this.metadataQuerier.GetEntryName(t,n);e[a]=this._getDracoMetadataField(t,a)}return e}_getDracoMetadataField(t,e){let r=new this.draco.DracoInt32Array;try{this.metadataQuerier.GetIntEntryArray(t,e,r);let n=dt(r);return{int:this.metadataQuerier.GetIntEntry(t,e),string:this.metadataQuerier.GetStringEntry(t,e),double:this.metadataQuerier.GetDoubleEntry(t,e),intArray:n}}finally{this.draco.destroy(r)}}_disableAttributeTransforms(t){let{quantizedAttributes:e=[],octahedronAttributes:r=[]}=t,n=[...e,...r];for(let a of n)this.decoder.SkipAttributeTransform(this.draco[a])}_getQuantizationTransform(t,e){let{quantizedAttributes:r=[]}=e,n=t.attribute_type();if(r.map(i=>this.decoder[i]).includes(n)){let i=new this.draco.AttributeQuantizationTransform;try{if(i.InitFromAttribute(t))return{quantization_bits:i.quantization_bits(),range:i.range(),min_values:new Float32Array([1,2,3]).map(s=>i.min_value(s))}}finally{this.draco.destroy(i)}}return null}_getOctahedronTransform(t,e){let{octahedronAttributes:r=[]}=e,n=t.attribute_type();if(r.map(i=>this.decoder[i]).includes(n)){let i=new this.draco.AttributeQuantizationTransform;try{if(i.InitFromAttribute(t))return{quantization_bits:i.quantization_bits()}}finally{this.draco.destroy(i)}}return null}};function ct(o,t){switch(t){case Float32Array:return o.DT_FLOAT32;case Int8Array:return o.DT_INT8;case Int16Array:return o.DT_INT16;case Int32Array:return o.DT_INT32;case Uint8Array:return o.DT_UINT8;case Uint16Array:return o.DT_UINT16;case Uint32Array:return o.DT_UINT32;default:return o.DT_INVALID}}function dt(o){let t=o.size(),e=new Int32Array(t);for(let r=0;r<t;r++)e[r]=o.GetValue(r);return e}function ut(o){let t=o.size(),e=new Int32Array(t);for(let r=0;r<t;r++)e[r]=o.GetValue(r);return e}function lt(){return globalThis._loadersgl_?.version||(globalThis._loadersgl_=globalThis._loadersgl_||{},globalThis._loadersgl_.version="4.3.0-beta.2"),globalThis._loadersgl_.version}var $=lt();function v(o,t){if(!o)throw new Error(t||"loaders.gl assertion failed.")}var f={self:typeof self<"u"&&self,window:typeof window<"u"&&window,global:typeof global<"u"&&global,document:typeof document<"u"&&document},Yt=f.self||f.window||f.global||{},Ht=f.window||f.self||f.global||{},Kt=f.global||f.self||f.window||{},Zt=f.document||{};var A=typeof process!="object"||String(process)!=="[object process]"||process.browser,O=typeof importScripts=="function",Jt=typeof window<"u"&&typeof window.orientation<"u",j=typeof process<"u"&&process.version&&/v([0-9]*)/.exec(process.version),te=j&&parseFloat(j[1])||0;var x={};async function p(o,t=null,e={},r=null){return t&&(o=V(o,t,e,r)),x[o]=x[o]||ft(o),await x[o]}function V(o,t,e={},r=null){if(!e.useLocalLibraries&&o.startsWith("http"))return o;r=r||o;let n=e.modules||{};return n[r]?n[r]:A?e.CDN?(v(e.CDN.startsWith("http")),`${e.CDN}/${t}@${$}/dist/libs/${r}`):O?`../src/libs/${r}`:`modules/${t}/src/libs/${r}`:`modules/${t}/dist/libs/${r}`}async function ft(o){if(o.endsWith("wasm"))return await mt(o);if(!A)try{let{requireFromFile:e}=globalThis.loaders||{};return await e?.(o)}catch(e){return console.error(e),null}if(O)return importScripts(o);let t=await yt(o);return ht(t,o)}function ht(o,t){if(!A){let{requireFromString:r}=globalThis.loaders||{};return r?.(o,t)}if(O)return eval.call(globalThis,o),null;let e=document.createElement("script");e.id=t;try{e.appendChild(document.createTextNode(o))}catch{e.text=o}return document.body.appendChild(e),null}async function mt(o){let{readFileAsArrayBuffer:t}=globalThis.loaders||{};return A||!t||o.startsWith("http")?await(await fetch(o)).arrayBuffer():await t(o)}async function yt(o){let{readFileAsText:t}=globalThis.loaders||{};return A||!t||o.startsWith("http")?await(await fetch(o)).text():await t(o)}var At="1.5.6",pt="1.4.1",L=`https://www.gstatic.com/draco/versioned/decoders/${At}`,u={DECODER:"draco_wasm_wrapper.js",DECODER_WASM:"draco_decoder.wasm",FALLBACK_DECODER:"draco_decoder.js",ENCODER:"draco_encoder.js"},_={[u.DECODER]:`${L}/${u.DECODER}`,[u.DECODER_WASM]:`${L}/${u.DECODER_WASM}`,[u.FALLBACK_DECODER]:`${L}/${u.FALLBACK_DECODER}`,[u.ENCODER]:`https://raw.githubusercontent.com/google/draco/${pt}/javascript/${u.ENCODER}`},C,S;async function q(o){let t=o.modules||{};return t.draco3d?C||=t.draco3d.createDecoderModule({}).then(e=>({draco:e})):C||=_t(o),await C}async function G(o){let t=o.modules||{};return t.draco3d?S||=t.draco3d.createEncoderModule({}).then(e=>({draco:e})):S||=Tt(o),await S}async function _t(o){let t,e;switch(o.draco&&o.draco.decoderType){case"js":t=await p(_[u.FALLBACK_DECODER],"draco",o,u.FALLBACK_DECODER);break;case"wasm":default:[t,e]=await Promise.all([await p(_[u.DECODER],"draco",o,u.DECODER),await p(_[u.DECODER_WASM],"draco",o,u.DECODER_WASM)])}return t=t||globalThis.DracoDecoderModule,await bt(t,e)}function bt(o,t){let e={};return t&&(e.wasmBinary=t),new Promise(r=>{o({...e,onModuleLoaded:n=>r({draco:n})})})}async function Tt(o){let t=await p(_[u.ENCODER],"draco",o,u.ENCODER);return t=t||globalThis.DracoEncoderModule,new Promise(e=>{t({onModuleLoaded:r=>e({draco:r})})})}var Q={POSITION:"POSITION",NORMAL:"NORMAL",COLOR_0:"COLOR",TEXCOORD_0:"TEX_COORD"},gt=()=>{},T=class{draco;dracoEncoder;dracoMeshBuilder;dracoMetadataBuilder;log;constructor(t){this.draco=t,this.dracoEncoder=new this.draco.Encoder,this.dracoMeshBuilder=new this.draco.MeshBuilder,this.dracoMetadataBuilder=new this.draco.MetadataBuilder}destroy(){this.destroyEncodedObject(this.dracoMeshBuilder),this.destroyEncodedObject(this.dracoEncoder),this.destroyEncodedObject(this.dracoMetadataBuilder),this.dracoMeshBuilder=null,this.dracoEncoder=null,this.draco=null}destroyEncodedObject(t){t&&this.draco.destroy(t)}encodeSync(t,e={}){return this.log=gt,this._setOptions(e),e.pointcloud?this._encodePointCloud(t,e):this._encodeMesh(t,e)}_getAttributesFromMesh(t){let e={...t,...t.attributes};return t.indices&&(e.indices=t.indices),e}_encodePointCloud(t,e){let r=new this.draco.PointCloud;e.metadata&&this._addGeometryMetadata(r,e.metadata);let n=this._getAttributesFromMesh(t);this._createDracoPointCloud(r,n,e);let a=new this.draco.DracoInt8Array;try{let i=this.dracoEncoder.EncodePointCloudToDracoBuffer(r,!1,a);if(!(i>0))throw new Error("Draco encoding failed.");return this.log(`DRACO encoded ${r.num_points()} points | ||
with ${r.num_attributes()} attributes into ${i} bytes`),X(a)}finally{this.destroyEncodedObject(a),this.destroyEncodedObject(r)}}_encodeMesh(t,e){let r=new this.draco.Mesh;e.metadata&&this._addGeometryMetadata(r,e.metadata);let n=this._getAttributesFromMesh(t);this._createDracoMesh(r,n,e);let a=new this.draco.DracoInt8Array;try{let i=this.dracoEncoder.EncodeMeshToDracoBuffer(r,a);if(i<=0)throw new Error("Draco encoding failed.");return this.log(`DRACO encoded ${r.num_points()} points | ||
@@ -10,0 +10,0 @@ with ${r.num_attributes()} attributes into ${i} bytes`),X(a)}finally{this.destroyEncodedObject(a),this.destroyEncodedObject(r)}}_setOptions(t){if("speed"in t&&this.dracoEncoder.SetSpeedOptions(...t.speed),"method"in t){let e=this.draco[t.method||"MESH_SEQUENTIAL_ENCODING"];this.dracoEncoder.SetEncodingMethod(e)}if("quantization"in t)for(let e in t.quantization){let r=t.quantization[e],n=this.draco[e];this.dracoEncoder.SetAttributeQuantization(n,r)}}_createDracoMesh(t,e,r){let n=r.attributesMetadata||{};try{let a=this._getPositionAttribute(e);if(!a)throw new Error("positions");let i=a.length/3;for(let s in e){let c=e[s];s=Q[s]||s;let d=this._addAttributeToMesh(t,s,c,i);d!==-1&&this._addAttributeMetadata(t,d,{name:s,...n[s]||{}})}}catch(a){throw this.destroyEncodedObject(t),a}return t}_createDracoPointCloud(t,e,r){let n=r.attributesMetadata||{};try{let a=this._getPositionAttribute(e);if(!a)throw new Error("positions");let i=a.length/3;for(let s in e){let c=e[s];s=Q[s]||s;let d=this._addAttributeToMesh(t,s,c,i);d!==-1&&this._addAttributeMetadata(t,d,{name:s,...n[s]||{}})}}catch(a){throw this.destroyEncodedObject(t),a}return t}_addAttributeToMesh(t,e,r,n){if(!ArrayBuffer.isView(r))return-1;let a=this._getDracoAttributeType(e),i=r.length/n;if(a==="indices"){let d=r.length/3;return this.log(`Adding attribute ${e}, size ${d}`),this.dracoMeshBuilder.AddFacesToMesh(t,d,r),-1}this.log(`Adding attribute ${e}, size ${i}`);let s=this.dracoMeshBuilder,{buffer:c}=r;switch(r.constructor){case Int8Array:return s.AddInt8Attribute(t,a,n,i,new Int8Array(c));case Int16Array:return s.AddInt16Attribute(t,a,n,i,new Int16Array(c));case Int32Array:return s.AddInt32Attribute(t,a,n,i,new Int32Array(c));case Uint8Array:case Uint8ClampedArray:return s.AddUInt8Attribute(t,a,n,i,new Uint8Array(c));case Uint16Array:return s.AddUInt16Attribute(t,a,n,i,new Uint16Array(c));case Uint32Array:return s.AddUInt32Attribute(t,a,n,i,new Uint32Array(c));case Float32Array:return s.AddFloatAttribute(t,a,n,i,new Float32Array(c));default:return console.warn("Unsupported attribute type",r),-1}}_getDracoAttributeType(t){switch(t.toLowerCase()){case"indices":return"indices";case"position":case"positions":case"vertices":return this.draco.POSITION;case"normal":case"normals":return this.draco.NORMAL;case"color":case"colors":return this.draco.COLOR;case"texcoord":case"texcoords":return this.draco.TEX_COORD;default:return this.draco.GENERIC}}_getPositionAttribute(t){for(let e in t){let r=t[e];if(this._getDracoAttributeType(e)===this.draco.POSITION)return r}return null}_addGeometryMetadata(t,e){let r=new this.draco.Metadata;this._populateDracoMetadata(r,e),this.dracoMeshBuilder.AddMetadata(t,r)}_addAttributeMetadata(t,e,r){let n=new this.draco.Metadata;this._populateDracoMetadata(n,r),this.dracoMeshBuilder.SetMetadataForAttribute(t,e,n)}_populateDracoMetadata(t,e){for(let[r,n]of Dt(e))switch(typeof n){case"number":Math.trunc(n)===n?this.dracoMetadataBuilder.AddIntEntry(t,r,n):this.dracoMetadataBuilder.AddDoubleEntry(t,r,n);break;case"object":n instanceof Int32Array&&this.dracoMetadataBuilder.AddIntEntryArray(t,r,n,n.length);break;case"string":default:this.dracoMetadataBuilder.AddStringEntry(t,r,n)}}};function X(o){let t=o.size(),e=new ArrayBuffer(t),r=new Int8Array(e);for(let n=0;n<t;++n)r[n]=o.GetValue(n);return e}function Dt(o){return o.entries&&!o.hasOwnProperty("entries")?o.entries():Object.entries(o)}var Et={pointcloud:!1,attributeNameEntry:"name"},Y={name:"DRACO",id:"draco",module:"draco",version:y,extensions:["drc"],options:{draco:Et},encode:wt};async function wt(o,t={}){let{draco:e}=await G(t),r=new T(e);try{return r.encodeSync(o,t.draco)}finally{r.destroy()}}var Ot={id:"draco-writer",name:"Draco compressed geometry writer",module:"draco",version:y,worker:!0,options:{draco:{},source:null}};var It={...I,parse:Mt};async function Mt(o,t){let{draco:e}=await q(t),r=new b(e);try{return r.parseSync(o,t?.draco)}finally{r.destroy()}}return nt(g);})(); |
@@ -13,3 +13,3 @@ "use strict"; | ||
} else { | ||
globalThis._loadersgl_.version = "4.3.0-beta.1"; | ||
globalThis._loadersgl_.version = "4.3.0-beta.2"; | ||
} | ||
@@ -334,3 +334,3 @@ } | ||
// src/lib/utils/version.ts | ||
var VERSION2 = true ? "4.3.0-beta.1" : "latest"; | ||
var VERSION2 = true ? "4.3.0-beta.2" : "latest"; | ||
@@ -337,0 +337,0 @@ // src/draco-loader.ts |
@@ -13,3 +13,3 @@ "use strict"; | ||
} else { | ||
globalThis._loadersgl_.version = "4.3.0-beta.1"; | ||
globalThis._loadersgl_.version = "4.3.0-beta.2"; | ||
} | ||
@@ -629,3 +629,3 @@ } | ||
// src/lib/utils/version.ts | ||
var VERSION2 = true ? "4.3.0-beta.1" : "latest"; | ||
var VERSION2 = true ? "4.3.0-beta.2" : "latest"; | ||
@@ -632,0 +632,0 @@ // src/draco-writer.ts |
// Version constant cannot be imported, it needs to correspond to the build version of **this** module. | ||
// __VERSION__ is injected by babel-plugin-version-inline | ||
// @ts-ignore TS2304: Cannot find name '__VERSION__'. | ||
export const VERSION = typeof "4.3.0-beta.1" !== 'undefined' ? "4.3.0-beta.1" : 'latest'; | ||
export const VERSION = typeof "4.3.0-beta.2" !== 'undefined' ? "4.3.0-beta.2" : 'latest'; |
{ | ||
"name": "@loaders.gl/draco", | ||
"version": "4.3.0-beta.2", | ||
"version": "4.3.0-beta.3", | ||
"description": "Framework-independent loader and writer for Draco compressed meshes and point clouds", | ||
@@ -60,5 +60,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"@loaders.gl/loader-utils": "4.3.0-beta.2", | ||
"@loaders.gl/schema": "4.3.0-beta.2", | ||
"@loaders.gl/worker-utils": "4.3.0-beta.2", | ||
"@loaders.gl/loader-utils": "4.3.0-beta.3", | ||
"@loaders.gl/schema": "4.3.0-beta.3", | ||
"@loaders.gl/worker-utils": "4.3.0-beta.3", | ||
"draco3d": "1.5.7" | ||
@@ -72,3 +72,3 @@ }, | ||
}, | ||
"gitHead": "a61003f2bb56acbdaef07a03bc39d4c7830afdcc" | ||
"gitHead": "a63e72f3f325450a883bb2f29d1a8179543ef68c" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
+ Added@loaders.gl/loader-utils@4.3.0-beta.3(transitive)
+ Added@loaders.gl/schema@4.3.0-beta.3(transitive)
+ Added@loaders.gl/worker-utils@4.3.0-beta.3(transitive)
- Removed@loaders.gl/loader-utils@4.3.0-beta.2(transitive)
- Removed@loaders.gl/schema@4.3.0-beta.2(transitive)
- Removed@loaders.gl/worker-utils@4.3.0-beta.2(transitive)