@loaders.gl/draco
Advanced tools
Comparing version 4.2.0-alpha.5 to 4.2.0-alpha.6
@@ -230,2 +230,5 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var DracoParser = class { | ||
draco; | ||
decoder; | ||
metadataQuerier; | ||
// draco - the draco decoder, either import `draco3d` or load dynamically | ||
@@ -895,2 +898,7 @@ constructor(draco) { | ||
var DracoBuilder = class { | ||
draco; | ||
dracoEncoder; | ||
dracoMeshBuilder; | ||
dracoMetadataBuilder; | ||
log; | ||
// draco - the draco decoder, either import `draco3d` or load dynamically | ||
@@ -897,0 +905,0 @@ constructor(draco) { |
@@ -7,3 +7,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
else root['loaders'] = factory();})(globalThis, function () { | ||
"use strict";var __exports__=(()=>{var K=Object.create;var I=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var tt=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty;var rt=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports),ot=(o,t)=>{for(var e in t)I(o,e,{get:t[e],enumerable:!0})},O=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of J(t))!et.call(o,n)&&n!==e&&I(o,n,{get:()=>t[n],enumerable:!(r=Z(t,n))||r.enumerable});return o},M=(o,t,e)=>(O(o,t,"default"),e&&O(e,t,"default")),nt=(o,t,e)=>(e=o!=null?K(tt(o)):{},O(t||!o||!o.__esModule?I(e,"default",{value:o,enumerable:!0}):e,o)),at=o=>O(I({},"__esModule",{value:!0}),o);var B=rt((Lt,N)=>{N.exports=globalThis.loaders});var w={};ot(w,{DRACO_EXTERNAL_LIBRARIES:()=>u,DRACO_EXTERNAL_LIBRARY_URLS:()=>b,DracoLoader:()=>Mt,DracoWorkerLoader:()=>x,DracoWriter:()=>H,DracoWriterWorker:()=>It});M(w,nt(B(),1));var y="4.2.0-alpha.4";var x={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 P(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 L(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 f=s[d],m=s[d+1],A=s[d+2];t=f<t?f:t,e=m<e?m:e,r=A<r?A:r,n=f>n?f:n,a=m>a?m:a,i=A>i?A:i}return[[t,e,r],[n,a,i]]}function C(o,t,e){let r=P(t.value),n=e||k(t);return{name:o,type:{type:"fixed-size-list",listSize:t.size,children:[{name:"value",type:r}]},nullable:!1,metadata:n}}function k(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=W(t.metadata),n=[],a=it(t.attributes);for(let i in o){let s=o[i],c=z(i,s,a[i]);n.push(c)}if(e){let i=z("indices",e);n.push(i)}return{fields:n,metadata:r}}function it(o){let t={};for(let e in o){let r=o[e];t[r.name||"undefined"]=r}return t}function z(o,t,e){let r=e?W(e.metadata):void 0;return C(o,t,r)}function W(o){Object.entries(o);let t={};for(let e in o)t[`${e}.string`]=JSON.stringify(o[e]);return t}var $={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},st={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array},ct=4,g=class{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 A=`DRACO decompression failed: ${i.error_msg()}`;throw new Error(A)}let s=this._getDracoLoaderData(a,n,e),c=this._getMeshData(a,s,e),d=L(c.attributes),f=U(c.attributes,s,c.indices);return{loader:"draco",loaderData:s,header:{vertexCount:a.num_points(),boundingBox:d},...c,schema:f}}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{value:s,size:c}=this._getAttributeValues(e,a);n[i]={value:s,size:c,byteOffset:a.byte_offset,byteStride:a.byte_stride,normalized:a.normalized}}return n}_getTriangleListIndices(t){let r=t.num_faces()*3,n=r*ct,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),lt(e)}finally{this.draco.destroy(e)}}_getAttributeValues(t,e){let r=st[e.data_type],n=e.num_components,i=t.num_points()*n,s=i*r.BYTES_PER_ELEMENT,c=dt(this.draco,r),d,f=this.draco._malloc(s);try{let m=this.decoder.GetAttribute(t,e.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(t,m,c,s,f),d=new r(this.draco.HEAPF32.buffer,f,i).slice()}finally{this.draco._free(f)}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 $)if(this.draco[i]===n)return $[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=ut(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 dt(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 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(o){let t=o.size(),e=new Int32Array(t);for(let r=0;r<t;r++)e[r]=o.GetValue(r);return e}function ft(){return globalThis._loadersgl_?.version||(globalThis._loadersgl_=globalThis._loadersgl_||{},globalThis._loadersgl_.version="4.2.0-alpha.4"),globalThis._loadersgl_.version}var v=ft();function j(o,t){if(!o)throw new Error(t||"loaders.gl assertion failed.")}var h={self:typeof self<"u"&&self,window:typeof window<"u"&&window,global:typeof global<"u"&&global,document:typeof document<"u"&&document},Ht=h.self||h.window||h.global||{},Kt=h.window||h.self||h.global||{},Zt=h.global||h.self||h.window||{},Jt=h.document||{};var p=typeof process!="object"||String(process)!=="[object process]"||process.browser,R=typeof importScripts=="function",te=typeof window<"u"&&typeof window.orientation<"u",q=typeof process<"u"&&process.version&&/v([0-9]*)/.exec(process.version),ee=q&&parseFloat(q[1])||0;var l={};var S={};async function _(o,t=null,e={},r=null){return t&&(o=V(o,t,e,r)),S[o]=S[o]||ht(o),await S[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]:p?e.CDN?(j(e.CDN.startsWith("http")),`${e.CDN}/${t}@${v}/dist/libs/${r}`):R?`../src/libs/${r}`:`modules/${t}/src/libs/${r}`:`modules/${t}/dist/libs/${r}`}async function ht(o){if(o.endsWith("wasm"))return await At(o);if(!p)try{return l&&void 0&&await(void 0)(o)}catch(e){return console.error(e),null}if(R)return importScripts(o);let t=await yt(o);return mt(t,o)}function mt(o,t){if(!p)return void 0&&(void 0)(o,t);if(R)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 At(o){return p||!void 0||o.startsWith("http")?await(await fetch(o)).arrayBuffer():await(void 0)(o)}async function yt(o){return p||!void 0||o.startsWith("http")?await(await fetch(o)).text():await(void 0)(o)}var pt="1.5.6",_t="1.4.1",F=`https://www.gstatic.com/draco/versioned/decoders/${pt}`,u={DECODER:"draco_wasm_wrapper.js",DECODER_WASM:"draco_decoder.wasm",FALLBACK_DECODER:"draco_decoder.js",ENCODER:"draco_encoder.js"},b={[u.DECODER]:`${F}/${u.DECODER}`,[u.DECODER_WASM]:`${F}/${u.DECODER_WASM}`,[u.FALLBACK_DECODER]:`${F}/${u.FALLBACK_DECODER}`,[u.ENCODER]:`https://raw.githubusercontent.com/google/draco/${_t}/javascript/${u.ENCODER}`},T,D;async function G(o){let t=o.modules||{};return t.draco3d?T=T||t.draco3d.createDecoderModule({}).then(e=>({draco:e})):T=T||bt(o),await T}async function Q(o){let t=o.modules||{};return t.draco3d?D=D||t.draco3d.createEncoderModule({}).then(e=>({draco:e})):D=D||Tt(o),await D}async function bt(o){let t,e;switch(o.draco&&o.draco.decoderType){case"js":t=await _(b[u.FALLBACK_DECODER],"draco",o,u.FALLBACK_DECODER);break;case"wasm":default:[t,e]=await Promise.all([await _(b[u.DECODER],"draco",o,u.DECODER),await _(b[u.DECODER_WASM],"draco",o,u.DECODER_WASM)])}return t=t||globalThis.DracoDecoderModule,await gt(t,e)}function gt(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 _(b[u.ENCODER],"draco",o,u.ENCODER);return t=t||globalThis.DracoEncoderModule,new Promise(e=>{t({onModuleLoaded:r=>e({draco:r})})})}var X={POSITION:"POSITION",NORMAL:"NORMAL",COLOR_0:"COLOR",TEXCOORD_0:"TEX_COORD"},Dt=()=>{},E=class{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=Dt,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 K=Object.create;var I=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var tt=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty;var rt=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports),ot=(o,t)=>{for(var e in t)I(o,e,{get:t[e],enumerable:!0})},O=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of J(t))!et.call(o,n)&&n!==e&&I(o,n,{get:()=>t[n],enumerable:!(r=Z(t,n))||r.enumerable});return o},M=(o,t,e)=>(O(o,t,"default"),e&&O(e,t,"default")),nt=(o,t,e)=>(e=o!=null?K(tt(o)):{},O(t||!o||!o.__esModule?I(e,"default",{value:o,enumerable:!0}):e,o)),at=o=>O(I({},"__esModule",{value:!0}),o);var B=rt((Lt,N)=>{N.exports=globalThis.loaders});var w={};ot(w,{DRACO_EXTERNAL_LIBRARIES:()=>u,DRACO_EXTERNAL_LIBRARY_URLS:()=>b,DracoLoader:()=>Mt,DracoWorkerLoader:()=>x,DracoWriter:()=>H,DracoWriterWorker:()=>It});M(w,nt(B(),1));var y="4.2.0-alpha.5";var x={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 P(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 L(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 f=s[d],m=s[d+1],A=s[d+2];t=f<t?f:t,e=m<e?m:e,r=A<r?A:r,n=f>n?f:n,a=m>a?m:a,i=A>i?A:i}return[[t,e,r],[n,a,i]]}function C(o,t,e){let r=P(t.value),n=e||k(t);return{name:o,type:{type:"fixed-size-list",listSize:t.size,children:[{name:"value",type:r}]},nullable:!1,metadata:n}}function k(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=W(t.metadata),n=[],a=it(t.attributes);for(let i in o){let s=o[i],c=z(i,s,a[i]);n.push(c)}if(e){let i=z("indices",e);n.push(i)}return{fields:n,metadata:r}}function it(o){let t={};for(let e in o){let r=o[e];t[r.name||"undefined"]=r}return t}function z(o,t,e){let r=e?W(e.metadata):void 0;return C(o,t,r)}function W(o){Object.entries(o);let t={};for(let e in o)t[`${e}.string`]=JSON.stringify(o[e]);return t}var $={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},st={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array},ct=4,g=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 A=`DRACO decompression failed: ${i.error_msg()}`;throw new Error(A)}let s=this._getDracoLoaderData(a,n,e),c=this._getMeshData(a,s,e),d=L(c.attributes),f=U(c.attributes,s,c.indices);return{loader:"draco",loaderData:s,header:{vertexCount:a.num_points(),boundingBox:d},...c,schema:f}}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{value:s,size:c}=this._getAttributeValues(e,a);n[i]={value:s,size:c,byteOffset:a.byte_offset,byteStride:a.byte_stride,normalized:a.normalized}}return n}_getTriangleListIndices(t){let r=t.num_faces()*3,n=r*ct,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),lt(e)}finally{this.draco.destroy(e)}}_getAttributeValues(t,e){let r=st[e.data_type],n=e.num_components,i=t.num_points()*n,s=i*r.BYTES_PER_ELEMENT,c=dt(this.draco,r),d,f=this.draco._malloc(s);try{let m=this.decoder.GetAttribute(t,e.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(t,m,c,s,f),d=new r(this.draco.HEAPF32.buffer,f,i).slice()}finally{this.draco._free(f)}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 $)if(this.draco[i]===n)return $[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=ut(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 dt(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 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(o){let t=o.size(),e=new Int32Array(t);for(let r=0;r<t;r++)e[r]=o.GetValue(r);return e}function ft(){return globalThis._loadersgl_?.version||(globalThis._loadersgl_=globalThis._loadersgl_||{},globalThis._loadersgl_.version="4.2.0-alpha.5"),globalThis._loadersgl_.version}var v=ft();function j(o,t){if(!o)throw new Error(t||"loaders.gl assertion failed.")}var h={self:typeof self<"u"&&self,window:typeof window<"u"&&window,global:typeof global<"u"&&global,document:typeof document<"u"&&document},Ht=h.self||h.window||h.global||{},Kt=h.window||h.self||h.global||{},Zt=h.global||h.self||h.window||{},Jt=h.document||{};var p=typeof process!="object"||String(process)!=="[object process]"||process.browser,R=typeof importScripts=="function",te=typeof window<"u"&&typeof window.orientation<"u",q=typeof process<"u"&&process.version&&/v([0-9]*)/.exec(process.version),ee=q&&parseFloat(q[1])||0;var l={};var S={};async function _(o,t=null,e={},r=null){return t&&(o=V(o,t,e,r)),S[o]=S[o]||ht(o),await S[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]:p?e.CDN?(j(e.CDN.startsWith("http")),`${e.CDN}/${t}@${v}/dist/libs/${r}`):R?`../src/libs/${r}`:`modules/${t}/src/libs/${r}`:`modules/${t}/dist/libs/${r}`}async function ht(o){if(o.endsWith("wasm"))return await At(o);if(!p)try{return l&&void 0&&await(void 0)(o)}catch(e){return console.error(e),null}if(R)return importScripts(o);let t=await yt(o);return mt(t,o)}function mt(o,t){if(!p)return void 0&&(void 0)(o,t);if(R)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 At(o){return p||!void 0||o.startsWith("http")?await(await fetch(o)).arrayBuffer():await(void 0)(o)}async function yt(o){return p||!void 0||o.startsWith("http")?await(await fetch(o)).text():await(void 0)(o)}var pt="1.5.6",_t="1.4.1",F=`https://www.gstatic.com/draco/versioned/decoders/${pt}`,u={DECODER:"draco_wasm_wrapper.js",DECODER_WASM:"draco_decoder.wasm",FALLBACK_DECODER:"draco_decoder.js",ENCODER:"draco_encoder.js"},b={[u.DECODER]:`${F}/${u.DECODER}`,[u.DECODER_WASM]:`${F}/${u.DECODER_WASM}`,[u.FALLBACK_DECODER]:`${F}/${u.FALLBACK_DECODER}`,[u.ENCODER]:`https://raw.githubusercontent.com/google/draco/${_t}/javascript/${u.ENCODER}`},T,D;async function G(o){let t=o.modules||{};return t.draco3d?T=T||t.draco3d.createDecoderModule({}).then(e=>({draco:e})):T=T||bt(o),await T}async function Q(o){let t=o.modules||{};return t.draco3d?D=D||t.draco3d.createEncoderModule({}).then(e=>({draco:e})):D=D||Tt(o),await D}async function bt(o){let t,e;switch(o.draco&&o.draco.decoderType){case"js":t=await _(b[u.FALLBACK_DECODER],"draco",o,u.FALLBACK_DECODER);break;case"wasm":default:[t,e]=await Promise.all([await _(b[u.DECODER],"draco",o,u.DECODER),await _(b[u.DECODER_WASM],"draco",o,u.DECODER_WASM)])}return t=t||globalThis.DracoDecoderModule,await gt(t,e)}function gt(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 _(b[u.ENCODER],"draco",o,u.ENCODER);return t=t||globalThis.DracoEncoderModule,new Promise(e=>{t({onModuleLoaded:r=>e({draco:r})})})}var X={POSITION:"POSITION",NORMAL:"NORMAL",COLOR_0:"COLOR",TEXCOORD_0:"TEX_COORD"},Dt=()=>{},E=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=Dt,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`),Y(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`),Y(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=X[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=X[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:default:return s.AddFloatAttribute(t,a,n,i,new Float32Array(c))}}_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 Et(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 Y(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 Et(o){return o.entries&&!o.hasOwnProperty("entries")?o.entries():Object.entries(o)}var wt={pointcloud:!1,attributeNameEntry:"name"},H={name:"DRACO",id:"draco",module:"draco",version:y,extensions:["drc"],options:{draco:wt},encode:Ot};async function Ot(o,t={}){let{draco:e}=await Q(t),r=new E(e);try{return r.encodeSync(o,t.draco)}finally{r.destroy()}}var It={id:"draco-writer",name:"Draco compressed geometry writer",module:"draco",version:y,worker:!0,options:{draco:{},source:null}};var Mt={...x,parse:Rt};async function Rt(o,t){let{draco:e}=await G(t),r=new g(e);try{return r.parseSync(o,t?.draco)}finally{r.destroy()}}return at(w);})(); |
@@ -46,3 +46,3 @@ "use strict"; | ||
} else { | ||
globalThis._loadersgl_.version = "4.2.0-alpha.4"; | ||
globalThis._loadersgl_.version = "4.2.0-alpha.5"; | ||
} | ||
@@ -140,3 +140,5 @@ } | ||
if (parentPort2) { | ||
parentPort2.on("message", handleMessage); | ||
parentPort2.on("message", (message) => { | ||
handleMessage(message); | ||
}); | ||
parentPort2.on("exit", () => console.debug("Node worker closing")); | ||
@@ -363,3 +365,3 @@ } else { | ||
// src/lib/utils/version.ts | ||
var VERSION2 = true ? "4.2.0-alpha.4" : "latest"; | ||
var VERSION2 = true ? "4.2.0-alpha.5" : "latest"; | ||
@@ -366,0 +368,0 @@ // src/draco-loader.ts |
@@ -46,3 +46,3 @@ "use strict"; | ||
} else { | ||
globalThis._loadersgl_.version = "4.2.0-alpha.4"; | ||
globalThis._loadersgl_.version = "4.2.0-alpha.5"; | ||
} | ||
@@ -140,3 +140,5 @@ } | ||
if (parentPort2) { | ||
parentPort2.on("message", handleMessage); | ||
parentPort2.on("message", (message) => { | ||
handleMessage(message); | ||
}); | ||
parentPort2.on("exit", () => console.debug("Node worker closing")); | ||
@@ -656,3 +658,3 @@ } else { | ||
// src/lib/utils/version.ts | ||
var VERSION2 = true ? "4.2.0-alpha.4" : "latest"; | ||
var VERSION2 = true ? "4.2.0-alpha.5" : "latest"; | ||
@@ -659,0 +661,0 @@ // src/draco-writer.ts |
@@ -10,2 +10,7 @@ // Native Draco attribute names to GLTF attribute names. | ||
export default class DracoBuilder { | ||
draco; | ||
dracoEncoder; | ||
dracoMeshBuilder; | ||
dracoMetadataBuilder; | ||
log; | ||
// draco - the draco decoder, either import `draco3d` or load dynamically | ||
@@ -12,0 +17,0 @@ constructor(draco) { |
@@ -28,2 +28,5 @@ /* eslint-disable camelcase */ | ||
export default class DracoParser { | ||
draco; | ||
decoder; | ||
metadataQuerier; | ||
// draco - the draco decoder, either import `draco3d` or load dynamically | ||
@@ -30,0 +33,0 @@ constructor(draco) { |
// 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.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest'; | ||
export const VERSION = typeof "4.2.0-alpha.5" !== 'undefined' ? "4.2.0-alpha.5" : 'latest'; |
{ | ||
"name": "@loaders.gl/draco", | ||
"version": "4.2.0-alpha.5", | ||
"version": "4.2.0-alpha.6", | ||
"description": "Framework-independent loader and writer for Draco compressed meshes and point clouds", | ||
@@ -60,14 +60,11 @@ "license": "MIT", | ||
"dependencies": { | ||
"@loaders.gl/loader-utils": "4.2.0-alpha.5", | ||
"@loaders.gl/schema": "4.2.0-alpha.5", | ||
"@loaders.gl/worker-utils": "4.2.0-alpha.5", | ||
"@loaders.gl/loader-utils": "4.2.0-alpha.6", | ||
"@loaders.gl/schema": "4.2.0-alpha.6", | ||
"@loaders.gl/worker-utils": "4.2.0-alpha.6", | ||
"draco3d": "1.5.5" | ||
}, | ||
"devDependencies": { | ||
"@loaders.gl/polyfills": "4.2.0-alpha.5" | ||
}, | ||
"peerDependencies": { | ||
"@loaders.gl/core": "^4.0.0" | ||
}, | ||
"gitHead": "32d95a81971f104e4dfeb88ab57065f05321a76a" | ||
"gitHead": "37bd8ca71763529f18727ee4bf29dd176aa914ca" | ||
} |
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
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
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
14306942
0
146375
+ Added@loaders.gl/loader-utils@4.2.0-alpha.6(transitive)
+ Added@loaders.gl/schema@4.2.0-alpha.6(transitive)
+ Added@loaders.gl/worker-utils@4.2.0-alpha.6(transitive)
- Removed@loaders.gl/loader-utils@4.2.0-alpha.5(transitive)
- Removed@loaders.gl/schema@4.2.0-alpha.5(transitive)
- Removed@loaders.gl/worker-utils@4.2.0-alpha.5(transitive)