@loaders.gl/draco
Advanced tools
Comparing version 4.2.0-alpha.6 to 4.2.0-beta.1
@@ -48,9 +48,2 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
// (disabled):../worker-utils/src/lib/node/require-utils.node | ||
var require_require_utils = __commonJS({ | ||
"(disabled):../worker-utils/src/lib/node/require-utils.node"() { | ||
"use strict"; | ||
} | ||
}); | ||
// bundle.ts | ||
@@ -73,2 +66,4 @@ var bundle_exports = {}; | ||
var DracoLoader = { | ||
dataType: null, | ||
batchType: null, | ||
name: "Draco", | ||
@@ -228,3 +223,7 @@ id: "draco", | ||
6: Uint32Array, | ||
// 7: BigInt64Array, | ||
// 8: BigUint64Array, | ||
9: Float32Array | ||
// 10: Float64Array | ||
// 11: BOOL - What array type do we use for this? | ||
}; | ||
@@ -402,10 +401,13 @@ var INDEX_ITEM_SIZE = 4; | ||
loaderAttribute.name = attributeName; | ||
const { value, size } = this._getAttributeValues(dracoGeometry, loaderAttribute); | ||
attributes[attributeName] = { | ||
value, | ||
size, | ||
byteOffset: loaderAttribute.byte_offset, | ||
byteStride: loaderAttribute.byte_stride, | ||
normalized: loaderAttribute.normalized | ||
}; | ||
const values = this._getAttributeValues(dracoGeometry, loaderAttribute); | ||
if (values) { | ||
const { value, size } = values; | ||
attributes[attributeName] = { | ||
value, | ||
size, | ||
byteOffset: loaderAttribute.byte_offset, | ||
byteStride: loaderAttribute.byte_stride, | ||
normalized: loaderAttribute.normalized | ||
}; | ||
} | ||
} | ||
@@ -452,2 +454,6 @@ return attributes; | ||
const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type]; | ||
if (!TypedArrayCtor) { | ||
console.warn(`DRACO: Unsupported attribute type ${attribute.data_type}`); | ||
return null; | ||
} | ||
const numComponents = attribute.num_components; | ||
@@ -705,3 +711,2 @@ const numPoints = dracoGeometry.num_points(); | ||
// ../worker-utils/src/lib/library-utils/library-utils.ts | ||
var node = __toESM(require_require_utils(), 1); | ||
var loadLibraryPromises = {}; | ||
@@ -743,3 +748,4 @@ async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) { | ||
try { | ||
return node && void 0 && await (void 0)(libraryUrl); | ||
const { requireFromFile } = globalThis.loaders || {}; | ||
return await requireFromFile?.(libraryUrl); | ||
} catch (error) { | ||
@@ -758,3 +764,4 @@ console.error(error); | ||
if (!isBrowser) { | ||
return void 0 && (void 0)(scriptSource, id); | ||
const { requireFromString } = globalThis.loaders || {}; | ||
return requireFromString?.(scriptSource, id); | ||
} | ||
@@ -776,14 +783,16 @@ if (isWorker) { | ||
async function loadAsArrayBuffer(url) { | ||
if (isBrowser || !void 0 || url.startsWith("http")) { | ||
const { readFileAsArrayBuffer } = globalThis.loaders || {}; | ||
if (isBrowser || !readFileAsArrayBuffer || url.startsWith("http")) { | ||
const response = await fetch(url); | ||
return await response.arrayBuffer(); | ||
} | ||
return await (void 0)(url); | ||
return await readFileAsArrayBuffer(url); | ||
} | ||
async function loadAsText(url) { | ||
if (isBrowser || !void 0 || url.startsWith("http")) { | ||
const { readFileAsText } = globalThis.loaders || {}; | ||
if (isBrowser || !readFileAsText || url.startsWith("http")) { | ||
const response = await fetch(url); | ||
return await response.text(); | ||
} | ||
return await (void 0)(url); | ||
return await readFileAsText(url); | ||
} | ||
@@ -816,7 +825,7 @@ | ||
if (modules.draco3d) { | ||
loadDecoderPromise = loadDecoderPromise || modules.draco3d.createDecoderModule({}).then((draco) => { | ||
loadDecoderPromise ||= modules.draco3d.createDecoderModule({}).then((draco) => { | ||
return { draco }; | ||
}); | ||
} else { | ||
loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options); | ||
loadDecoderPromise ||= loadDracoDecoder(options); | ||
} | ||
@@ -828,7 +837,7 @@ return await loadDecoderPromise; | ||
if (modules.draco3d) { | ||
loadEncoderPromise = loadEncoderPromise || modules.draco3d.createEncoderModule({}).then((draco) => { | ||
loadEncoderPromise ||= modules.draco3d.createEncoderModule({}).then((draco) => { | ||
return { draco }; | ||
}); | ||
} else { | ||
loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options); | ||
loadEncoderPromise ||= loadDracoEncoder(options); | ||
} | ||
@@ -1118,4 +1127,6 @@ return await loadEncoderPromise; | ||
case Float32Array: | ||
return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer)); | ||
default: | ||
return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer)); | ||
console.warn("Unsupported attribute type", attribute); | ||
return -1; | ||
} | ||
@@ -1122,0 +1133,0 @@ } |
@@ -7,6 +7,6 @@ (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.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 | ||
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);})(); | ||
"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 T={};rt(T,{DRACO_EXTERNAL_LIBRARIES:()=>u,DRACO_EXTERNAL_LIBRARY_URLS:()=>_,DracoLoader:()=>It,DracoWorkerLoader:()=>I,DracoWriter:()=>Y,DracoWriterWorker:()=>Ot});w(T,ot(F(),1));var A="4.2.0-alpha.6";var I={dataType:null,batchType:null,name:"Draco",id:"draco",module:"draco",version:A,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.2.0-alpha.6"),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 y=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]:y?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(!y)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 At(o);return ht(t,o)}function ht(o,t){if(!y){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 y||!t||o.startsWith("http")?await(await fetch(o)).arrayBuffer():await t(o)}async function At(o){let{readFileAsText:t}=globalThis.loaders||{};return y||!t||o.startsWith("http")?await(await fetch(o)).text():await t(o)}var yt="1.5.6",pt="1.4.1",L=`https://www.gstatic.com/draco/versioned/decoders/${yt}`,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||=gt(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 gt(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"},Tt=()=>{},g=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=Tt,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 | ||
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:A,extensions:["drc"],options:{draco:Et},encode:wt};async function wt(o,t={}){let{draco:e}=await G(t),r=new g(e);try{return r.encodeSync(o,t.draco)}finally{r.destroy()}}var Ot={id:"draco-writer",name:"Draco compressed geometry writer",module:"draco",version:A,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(T);})(); | ||
return __exports__; | ||
}); |
@@ -1,2 +0,2 @@ | ||
import type { Loader, LoaderOptions } from '@loaders.gl/loader-utils'; | ||
import type { LoaderOptions } from '@loaders.gl/loader-utils'; | ||
import type { DracoMesh } from "./lib/draco-types.js"; | ||
@@ -6,6 +6,7 @@ import type { DracoParseOptions } from "./lib/draco-parser.js"; | ||
draco?: DracoParseOptions & { | ||
/** @deprecated WASM decoding is faster but JS is more backwards compatible */ | ||
decoderType?: 'wasm' | 'js'; | ||
/** @deprecated Specify where to load the Draco decoder library */ | ||
libraryPath?: string; | ||
extraAttributes?: any; | ||
attributeNameEntry?: string; | ||
/** Override the URL to the worker bundle (by default loads from unpkg.com) */ | ||
workerUrl?: string; | ||
@@ -17,3 +18,23 @@ }; | ||
*/ | ||
export declare const DracoLoader: Loader<DracoMesh, never, DracoLoaderOptions>; | ||
export declare const DracoLoader: { | ||
readonly dataType: DracoMesh; | ||
readonly batchType: never; | ||
readonly name: "Draco"; | ||
readonly id: "draco"; | ||
readonly module: "draco"; | ||
readonly version: any; | ||
readonly worker: true; | ||
readonly extensions: ["drc"]; | ||
readonly mimeTypes: ["application/octet-stream"]; | ||
readonly binary: true; | ||
readonly tests: ["DRACO"]; | ||
readonly options: { | ||
readonly draco: { | ||
readonly decoderType: "wasm" | "js"; | ||
readonly libraryPath: "libs/"; | ||
readonly extraAttributes: {}; | ||
readonly attributeNameEntry: undefined; | ||
}; | ||
}; | ||
}; | ||
//# sourceMappingURL=draco-loader.d.ts.map |
@@ -9,2 +9,4 @@ // loaders.gl | ||
export const DracoLoader = { | ||
dataType: null, | ||
batchType: null, | ||
name: 'Draco', | ||
@@ -11,0 +13,0 @@ id: 'draco', |
"use strict"; | ||
(() => { | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __commonJS = (cb, mod) => function __require() { | ||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
// (disabled):../worker-utils/src/lib/node/require-utils.node | ||
var require_require_utils = __commonJS({ | ||
"(disabled):../worker-utils/src/lib/node/require-utils.node"() { | ||
"use strict"; | ||
} | ||
}); | ||
// ../worker-utils/src/lib/env-utils/version.ts | ||
@@ -46,3 +13,3 @@ function getVersion() { | ||
} else { | ||
globalThis._loadersgl_.version = "4.2.0-alpha.5"; | ||
globalThis._loadersgl_.version = "4.2.0-alpha.6"; | ||
} | ||
@@ -200,3 +167,2 @@ } | ||
// ../worker-utils/src/lib/library-utils/library-utils.ts | ||
var node = __toESM(require_require_utils(), 1); | ||
var loadLibraryPromises = {}; | ||
@@ -238,3 +204,4 @@ async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) { | ||
try { | ||
return node && void 0 && await (void 0)(libraryUrl); | ||
const { requireFromFile } = globalThis.loaders || {}; | ||
return await requireFromFile?.(libraryUrl); | ||
} catch (error) { | ||
@@ -253,3 +220,4 @@ console.error(error); | ||
if (!isBrowser) { | ||
return void 0 && (void 0)(scriptSource, id); | ||
const { requireFromString } = globalThis.loaders || {}; | ||
return requireFromString?.(scriptSource, id); | ||
} | ||
@@ -271,14 +239,16 @@ if (isWorker) { | ||
async function loadAsArrayBuffer(url) { | ||
if (isBrowser || !void 0 || url.startsWith("http")) { | ||
const { readFileAsArrayBuffer } = globalThis.loaders || {}; | ||
if (isBrowser || !readFileAsArrayBuffer || url.startsWith("http")) { | ||
const response = await fetch(url); | ||
return await response.arrayBuffer(); | ||
} | ||
return await (void 0)(url); | ||
return await readFileAsArrayBuffer(url); | ||
} | ||
async function loadAsText(url) { | ||
if (isBrowser || !void 0 || url.startsWith("http")) { | ||
const { readFileAsText } = globalThis.loaders || {}; | ||
if (isBrowser || !readFileAsText || url.startsWith("http")) { | ||
const response = await fetch(url); | ||
return await response.text(); | ||
} | ||
return await (void 0)(url); | ||
return await readFileAsText(url); | ||
} | ||
@@ -368,6 +338,8 @@ | ||
// src/lib/utils/version.ts | ||
var VERSION2 = true ? "4.2.0-alpha.5" : "latest"; | ||
var VERSION2 = true ? "4.2.0-alpha.6" : "latest"; | ||
// src/draco-loader.ts | ||
var DracoLoader = { | ||
dataType: null, | ||
batchType: null, | ||
name: "Draco", | ||
@@ -527,3 +499,7 @@ id: "draco", | ||
6: Uint32Array, | ||
// 7: BigInt64Array, | ||
// 8: BigUint64Array, | ||
9: Float32Array | ||
// 10: Float64Array | ||
// 11: BOOL - What array type do we use for this? | ||
}; | ||
@@ -701,10 +677,13 @@ var INDEX_ITEM_SIZE = 4; | ||
loaderAttribute.name = attributeName; | ||
const { value, size } = this._getAttributeValues(dracoGeometry, loaderAttribute); | ||
attributes[attributeName] = { | ||
value, | ||
size, | ||
byteOffset: loaderAttribute.byte_offset, | ||
byteStride: loaderAttribute.byte_stride, | ||
normalized: loaderAttribute.normalized | ||
}; | ||
const values = this._getAttributeValues(dracoGeometry, loaderAttribute); | ||
if (values) { | ||
const { value, size } = values; | ||
attributes[attributeName] = { | ||
value, | ||
size, | ||
byteOffset: loaderAttribute.byte_offset, | ||
byteStride: loaderAttribute.byte_stride, | ||
normalized: loaderAttribute.normalized | ||
}; | ||
} | ||
} | ||
@@ -751,2 +730,6 @@ return attributes; | ||
const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type]; | ||
if (!TypedArrayCtor) { | ||
console.warn(`DRACO: Unsupported attribute type ${attribute.data_type}`); | ||
return null; | ||
} | ||
const numComponents = attribute.num_components; | ||
@@ -982,7 +965,7 @@ const numPoints = dracoGeometry.num_points(); | ||
if (modules.draco3d) { | ||
loadDecoderPromise = loadDecoderPromise || modules.draco3d.createDecoderModule({}).then((draco) => { | ||
loadDecoderPromise ||= modules.draco3d.createDecoderModule({}).then((draco) => { | ||
return { draco }; | ||
}); | ||
} else { | ||
loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options); | ||
loadDecoderPromise ||= loadDracoDecoder(options); | ||
} | ||
@@ -989,0 +972,0 @@ return await loadDecoderPromise; |
"use strict"; | ||
(() => { | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __commonJS = (cb, mod) => function __require() { | ||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
// (disabled):../worker-utils/src/lib/node/require-utils.node | ||
var require_require_utils = __commonJS({ | ||
"(disabled):../worker-utils/src/lib/node/require-utils.node"() { | ||
"use strict"; | ||
} | ||
}); | ||
// ../worker-utils/src/lib/env-utils/version.ts | ||
@@ -46,3 +13,3 @@ function getVersion() { | ||
} else { | ||
globalThis._loadersgl_.version = "4.2.0-alpha.5"; | ||
globalThis._loadersgl_.version = "4.2.0-alpha.6"; | ||
} | ||
@@ -200,3 +167,2 @@ } | ||
// ../worker-utils/src/lib/library-utils/library-utils.ts | ||
var node = __toESM(require_require_utils(), 1); | ||
var loadLibraryPromises = {}; | ||
@@ -238,3 +204,4 @@ async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) { | ||
try { | ||
return node && void 0 && await (void 0)(libraryUrl); | ||
const { requireFromFile } = globalThis.loaders || {}; | ||
return await requireFromFile?.(libraryUrl); | ||
} catch (error) { | ||
@@ -253,3 +220,4 @@ console.error(error); | ||
if (!isBrowser) { | ||
return void 0 && (void 0)(scriptSource, id); | ||
const { requireFromString } = globalThis.loaders || {}; | ||
return requireFromString?.(scriptSource, id); | ||
} | ||
@@ -271,14 +239,16 @@ if (isWorker) { | ||
async function loadAsArrayBuffer(url) { | ||
if (isBrowser || !void 0 || url.startsWith("http")) { | ||
const { readFileAsArrayBuffer } = globalThis.loaders || {}; | ||
if (isBrowser || !readFileAsArrayBuffer || url.startsWith("http")) { | ||
const response = await fetch(url); | ||
return await response.arrayBuffer(); | ||
} | ||
return await (void 0)(url); | ||
return await readFileAsArrayBuffer(url); | ||
} | ||
async function loadAsText(url) { | ||
if (isBrowser || !void 0 || url.startsWith("http")) { | ||
const { readFileAsText } = globalThis.loaders || {}; | ||
if (isBrowser || !readFileAsText || url.startsWith("http")) { | ||
const response = await fetch(url); | ||
return await response.text(); | ||
} | ||
return await (void 0)(url); | ||
return await readFileAsText(url); | ||
} | ||
@@ -506,4 +476,6 @@ | ||
case Float32Array: | ||
return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer)); | ||
default: | ||
return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer)); | ||
console.warn("Unsupported attribute type", attribute); | ||
return -1; | ||
} | ||
@@ -637,7 +609,7 @@ } | ||
if (modules.draco3d) { | ||
loadEncoderPromise = loadEncoderPromise || modules.draco3d.createEncoderModule({}).then((draco) => { | ||
loadEncoderPromise ||= modules.draco3d.createEncoderModule({}).then((draco) => { | ||
return { draco }; | ||
}); | ||
} else { | ||
loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options); | ||
loadEncoderPromise ||= loadDracoEncoder(options); | ||
} | ||
@@ -663,3 +635,3 @@ return await loadEncoderPromise; | ||
// src/lib/utils/version.ts | ||
var VERSION2 = true ? "4.2.0-alpha.5" : "latest"; | ||
var VERSION2 = true ? "4.2.0-alpha.6" : "latest"; | ||
@@ -666,0 +638,0 @@ // src/draco-writer.ts |
@@ -1,2 +0,2 @@ | ||
import type { WriterWithEncoder, WriterOptions } from '@loaders.gl/loader-utils'; | ||
import type { WriterOptions } from '@loaders.gl/loader-utils'; | ||
import type { DracoMesh } from "./lib/draco-types.js"; | ||
@@ -16,3 +16,18 @@ import type { DracoBuildOptions } from "./lib/draco-builder.js"; | ||
*/ | ||
export declare const DracoWriter: WriterWithEncoder<DracoMesh, unknown, DracoWriterOptions>; | ||
export declare const DracoWriter: { | ||
readonly name: "DRACO"; | ||
readonly id: "draco"; | ||
readonly module: "draco"; | ||
readonly version: any; | ||
readonly extensions: ["drc"]; | ||
readonly options: { | ||
readonly draco: { | ||
pointcloud: boolean; | ||
attributeNameEntry: string; | ||
}; | ||
}; | ||
readonly encode: typeof encode; | ||
}; | ||
declare function encode(data: DracoMesh, options?: DracoWriterOptions): Promise<ArrayBuffer>; | ||
export {}; | ||
//# sourceMappingURL=draco-writer.d.ts.map |
@@ -1,2 +0,1 @@ | ||
import type { LoaderWithParser } from '@loaders.gl/loader-utils'; | ||
import type { DracoMesh, DracoLoaderData } from "./lib/draco-types.js"; | ||
@@ -29,3 +28,25 @@ import type { DracoLoaderOptions } from "./draco-loader.js"; | ||
*/ | ||
export declare const DracoLoader: LoaderWithParser<DracoMesh, never, DracoLoaderOptions>; | ||
export declare const DracoLoader: { | ||
readonly parse: typeof parse; | ||
readonly dataType: DracoMesh; | ||
readonly batchType: never; | ||
readonly name: "Draco"; | ||
readonly id: "draco"; | ||
readonly module: "draco"; | ||
readonly version: any; | ||
readonly worker: true; | ||
readonly extensions: ["drc"]; | ||
readonly mimeTypes: ["application/octet-stream"]; | ||
readonly binary: true; | ||
readonly tests: ["DRACO"]; | ||
readonly options: { | ||
readonly draco: { | ||
readonly decoderType: "wasm" | "js"; | ||
readonly libraryPath: "libs/"; | ||
readonly extraAttributes: {}; | ||
readonly attributeNameEntry: undefined; | ||
}; | ||
}; | ||
}; | ||
declare function parse(arrayBuffer: ArrayBuffer, options?: DracoLoaderOptions): Promise<DracoMesh>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -73,3 +73,3 @@ import type { Draco3D, Encoder, Mesh, MeshBuilder, PointCloud, Metadata, MetadataBuilder, draco_GeometryAttribute_Type } from "../draco3d/draco3d-types.js"; | ||
*/ | ||
_addAttributeToMesh(mesh: PointCloud, attributeName: string, attribute: TypedArray, vertexCount: number): any; | ||
_addAttributeToMesh(mesh: PointCloud, attributeName: string, attribute: TypedArray, vertexCount: number): number; | ||
/** | ||
@@ -76,0 +76,0 @@ * DRACO can compress attributes of know type better |
@@ -229,4 +229,10 @@ // Native Draco attribute names to GLTF attribute names. | ||
case Float32Array: | ||
return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer)); | ||
// case Float64Array: | ||
// Add attribute does not seem to be exposed | ||
// return builder.AddAttribute(mesh, type, vertexCount, size, new Float32Array(buffer)); | ||
default: | ||
return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer)); | ||
// eslint-disable-next-line no-console | ||
console.warn('Unsupported attribute type', attribute); | ||
return -1; | ||
} | ||
@@ -233,0 +239,0 @@ } |
@@ -30,11 +30,9 @@ // Dynamic DRACO module loading inspired by THREE.DRACOLoader | ||
if (modules.draco3d) { | ||
loadDecoderPromise = | ||
loadDecoderPromise || | ||
modules.draco3d.createDecoderModule({}).then((draco) => { | ||
return { draco }; | ||
}); | ||
loadDecoderPromise ||= modules.draco3d.createDecoderModule({}).then((draco) => { | ||
return { draco }; | ||
}); | ||
} | ||
else { | ||
// If not, dynamically load the WASM script from our CDN | ||
loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options); | ||
loadDecoderPromise ||= loadDracoDecoder(options); | ||
} | ||
@@ -47,11 +45,9 @@ return await loadDecoderPromise; | ||
if (modules.draco3d) { | ||
loadEncoderPromise = | ||
loadEncoderPromise || | ||
modules.draco3d.createEncoderModule({}).then((draco) => { | ||
return { draco }; | ||
}); | ||
loadEncoderPromise ||= modules.draco3d.createEncoderModule({}).then((draco) => { | ||
return { draco }; | ||
}); | ||
} | ||
else { | ||
// If not, dynamically load the WASM script from our CDN | ||
loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options); | ||
loadEncoderPromise ||= loadDracoEncoder(options); | ||
} | ||
@@ -58,0 +54,0 @@ return await loadEncoderPromise; |
import type { TypedArray, MeshAttribute, MeshGeometry } from '@loaders.gl/schema'; | ||
import type { Draco3D, Decoder, Mesh, PointCloud, PointAttribute, Metadata, MetadataQuerier } from "../draco3d/draco3d-types.js"; | ||
import type { DracoMesh, DracoLoaderData, DracoAttribute, DracoMetadataEntry, DracoQuantizationTransform, DracoOctahedronTransform } from "./draco-types.js"; | ||
/** | ||
* @param topology - How triangle indices should be generated (mesh only) | ||
* @param attributeNameEntry | ||
* @param extraAttributes | ||
* @param quantizedAttributes | ||
* @param octahedronAttributes | ||
*/ | ||
/** Options to control draco parsing */ | ||
export type DracoParseOptions = { | ||
/** How triangle indices should be generated (mesh only) */ | ||
topology?: 'triangle-list' | 'triangle-strip'; | ||
/** Specify which attribute metadata entry stores the attribute name */ | ||
attributeNameEntry?: string; | ||
/** Names and ids of extra attributes to include in the output */ | ||
extraAttributes?: { | ||
[uniqueId: string]: number; | ||
}; | ||
/** Skip transforms specific quantized attributes */ | ||
quantizedAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[]; | ||
/** Skip transforms specific octahedron encoded attributes */ | ||
octahedronAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[]; | ||
@@ -81,3 +80,3 @@ }; | ||
size: number; | ||
}; | ||
} | null; | ||
/** | ||
@@ -84,0 +83,0 @@ * DRACO does not store attribute names - We need to deduce an attribute name |
@@ -24,3 +24,7 @@ /* eslint-disable camelcase */ | ||
6: Uint32Array, | ||
// 7: BigInt64Array, | ||
// 8: BigUint64Array, | ||
9: Float32Array | ||
// 10: Float64Array | ||
// 11: BOOL - What array type do we use for this? | ||
}; | ||
@@ -204,10 +208,13 @@ const INDEX_ITEM_SIZE = 4; | ||
loaderAttribute.name = attributeName; | ||
const { value, size } = this._getAttributeValues(dracoGeometry, loaderAttribute); | ||
attributes[attributeName] = { | ||
value, | ||
size, | ||
byteOffset: loaderAttribute.byte_offset, | ||
byteStride: loaderAttribute.byte_stride, | ||
normalized: loaderAttribute.normalized | ||
}; | ||
const values = this._getAttributeValues(dracoGeometry, loaderAttribute); | ||
if (values) { | ||
const { value, size } = values; | ||
attributes[attributeName] = { | ||
value, | ||
size, | ||
byteOffset: loaderAttribute.byte_offset, | ||
byteStride: loaderAttribute.byte_stride, | ||
normalized: loaderAttribute.normalized | ||
}; | ||
} | ||
} | ||
@@ -257,2 +264,7 @@ return attributes; | ||
const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type]; | ||
if (!TypedArrayCtor) { | ||
// eslint-disable-next-line no-console | ||
console.warn(`DRACO: Unsupported attribute type ${attribute.data_type}`); | ||
return null; | ||
} | ||
const numComponents = attribute.num_components; | ||
@@ -259,0 +271,0 @@ const numPoints = dracoGeometry.num_points(); |
// 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.5" !== 'undefined' ? "4.2.0-alpha.5" : 'latest'; | ||
export const VERSION = typeof "4.2.0-alpha.6" !== 'undefined' ? "4.2.0-alpha.6" : 'latest'; |
{ | ||
"name": "@loaders.gl/draco", | ||
"version": "4.2.0-alpha.6", | ||
"version": "4.2.0-beta.1", | ||
"description": "Framework-independent loader and writer for Draco compressed meshes and point clouds", | ||
@@ -60,11 +60,14 @@ "license": "MIT", | ||
"dependencies": { | ||
"@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" | ||
"@loaders.gl/loader-utils": "4.2.0-beta.1", | ||
"@loaders.gl/schema": "4.2.0-beta.1", | ||
"@loaders.gl/worker-utils": "4.2.0-beta.1", | ||
"draco3d": "1.5.7" | ||
}, | ||
"devDependencies": { | ||
"@types/draco3d": "^1.4.9" | ||
}, | ||
"peerDependencies": { | ||
"@loaders.gl/core": "^4.0.0" | ||
}, | ||
"gitHead": "37bd8ca71763529f18727ee4bf29dd176aa914ca" | ||
"gitHead": "c386a9196516fe3ff24847b40e6c77be039cf905" | ||
} |
@@ -12,6 +12,7 @@ // loaders.gl | ||
draco?: DracoParseOptions & { | ||
/** @deprecated WASM decoding is faster but JS is more backwards compatible */ | ||
decoderType?: 'wasm' | 'js'; | ||
/** @deprecated Specify where to load the Draco decoder library */ | ||
libraryPath?: string; | ||
extraAttributes?; | ||
attributeNameEntry?: string; | ||
/** Override the URL to the worker bundle (by default loads from unpkg.com) */ | ||
workerUrl?: string; | ||
@@ -24,3 +25,5 @@ }; | ||
*/ | ||
export const DracoLoader: Loader<DracoMesh, never, DracoLoaderOptions> = { | ||
export const DracoLoader = { | ||
dataType: null as unknown as DracoMesh, | ||
batchType: null as never, | ||
name: 'Draco', | ||
@@ -44,2 +47,2 @@ id: 'draco', | ||
} | ||
}; | ||
} as const satisfies Loader<DracoMesh, never, DracoLoaderOptions>; |
@@ -32,3 +32,3 @@ import type {WriterWithEncoder, WriterOptions} from '@loaders.gl/loader-utils'; | ||
*/ | ||
export const DracoWriter: WriterWithEncoder<DracoMesh, unknown, DracoWriterOptions> = { | ||
export const DracoWriter = { | ||
name: 'DRACO', | ||
@@ -43,3 +43,3 @@ id: 'draco', | ||
encode | ||
}; | ||
} as const satisfies WriterWithEncoder<DracoMesh, unknown, DracoWriterOptions>; | ||
@@ -46,0 +46,0 @@ async function encode(data: DracoMesh, options: DracoWriterOptions = {}): Promise<ArrayBuffer> { |
@@ -48,6 +48,6 @@ // loaders.gl | ||
*/ | ||
export const DracoLoader: LoaderWithParser<DracoMesh, never, DracoLoaderOptions> = { | ||
export const DracoLoader = { | ||
...DracoWorkerLoader, | ||
parse | ||
}; | ||
} as const satisfies LoaderWithParser<DracoMesh, never, DracoLoaderOptions>; | ||
@@ -54,0 +54,0 @@ async function parse(arrayBuffer: ArrayBuffer, options?: DracoLoaderOptions): Promise<DracoMesh> { |
@@ -276,3 +276,3 @@ /* eslint-disable camelcase */ | ||
vertexCount: number | ||
) { | ||
): number { | ||
if (!ArrayBuffer.isView(attribute)) { | ||
@@ -321,4 +321,12 @@ return -1; | ||
case Float32Array: | ||
return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer)); | ||
// case Float64Array: | ||
// Add attribute does not seem to be exposed | ||
// return builder.AddAttribute(mesh, type, vertexCount, size, new Float32Array(buffer)); | ||
default: | ||
return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer)); | ||
// eslint-disable-next-line no-console | ||
console.warn('Unsupported attribute type', attribute); | ||
return -1; | ||
} | ||
@@ -325,0 +333,0 @@ } |
@@ -38,10 +38,8 @@ // Dynamic DRACO module loading inspired by THREE.DRACOLoader | ||
if (modules.draco3d) { | ||
loadDecoderPromise = | ||
loadDecoderPromise || | ||
modules.draco3d.createDecoderModule({}).then((draco) => { | ||
return {draco}; | ||
}); | ||
loadDecoderPromise ||= modules.draco3d.createDecoderModule({}).then((draco) => { | ||
return {draco}; | ||
}); | ||
} else { | ||
// If not, dynamically load the WASM script from our CDN | ||
loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options); | ||
loadDecoderPromise ||= loadDracoDecoder(options); | ||
} | ||
@@ -56,10 +54,8 @@ return await loadDecoderPromise; | ||
if (modules.draco3d) { | ||
loadEncoderPromise = | ||
loadEncoderPromise || | ||
modules.draco3d.createEncoderModule({}).then((draco) => { | ||
return {draco}; | ||
}); | ||
loadEncoderPromise ||= modules.draco3d.createEncoderModule({}).then((draco) => { | ||
return {draco}; | ||
}); | ||
} else { | ||
// If not, dynamically load the WASM script from our CDN | ||
loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options); | ||
loadEncoderPromise ||= loadDracoEncoder(options); | ||
} | ||
@@ -66,0 +62,0 @@ return await loadEncoderPromise; |
@@ -31,14 +31,13 @@ /* eslint-disable camelcase */ | ||
/** | ||
* @param topology - How triangle indices should be generated (mesh only) | ||
* @param attributeNameEntry | ||
* @param extraAttributes | ||
* @param quantizedAttributes | ||
* @param octahedronAttributes | ||
*/ | ||
/** Options to control draco parsing */ | ||
export type DracoParseOptions = { | ||
/** How triangle indices should be generated (mesh only) */ | ||
topology?: 'triangle-list' | 'triangle-strip'; | ||
/** Specify which attribute metadata entry stores the attribute name */ | ||
attributeNameEntry?: string; | ||
/** Names and ids of extra attributes to include in the output */ | ||
extraAttributes?: {[uniqueId: string]: number}; | ||
/** Skip transforms specific quantized attributes */ | ||
quantizedAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[]; | ||
/** Skip transforms specific octahedron encoded attributes */ | ||
octahedronAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[]; | ||
@@ -69,3 +68,7 @@ }; | ||
6: Uint32Array, | ||
// 7: BigInt64Array, | ||
// 8: BigUint64Array, | ||
9: Float32Array | ||
// 10: Float64Array | ||
// 11: BOOL - What array type do we use for this? | ||
}; | ||
@@ -298,10 +301,13 @@ | ||
loaderAttribute.name = attributeName; | ||
const {value, size} = this._getAttributeValues(dracoGeometry, loaderAttribute); | ||
attributes[attributeName] = { | ||
value, | ||
size, | ||
byteOffset: loaderAttribute.byte_offset, | ||
byteStride: loaderAttribute.byte_stride, | ||
normalized: loaderAttribute.normalized | ||
}; | ||
const values = this._getAttributeValues(dracoGeometry, loaderAttribute); | ||
if (values) { | ||
const {value, size} = values; | ||
attributes[attributeName] = { | ||
value, | ||
size, | ||
byteOffset: loaderAttribute.byte_offset, | ||
byteStride: loaderAttribute.byte_stride, | ||
normalized: loaderAttribute.normalized | ||
}; | ||
} | ||
} | ||
@@ -356,4 +362,9 @@ | ||
attribute: DracoAttribute | ||
): {value: TypedArray; size: number} { | ||
): {value: TypedArray; size: number} | null { | ||
const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type]; | ||
if (!TypedArrayCtor) { | ||
// eslint-disable-next-line no-console | ||
console.warn(`DRACO: Unsupported attribute type ${attribute.data_type}`); | ||
return null; | ||
} | ||
const numComponents = attribute.num_components; | ||
@@ -360,0 +371,0 @@ const numPoints = dracoGeometry.num_points(); |
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 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
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
Sorry, the diff of this file is not supported yet
14301006
1
146358
+ Added@loaders.gl/loader-utils@4.2.0-beta.1(transitive)
+ Added@loaders.gl/schema@4.2.0-beta.1(transitive)
+ Added@loaders.gl/worker-utils@4.2.0-beta.1(transitive)
+ Addeddraco3d@1.5.7(transitive)
- Removed@loaders.gl/loader-utils@4.2.0-alpha.6(transitive)
- Removed@loaders.gl/schema@4.2.0-alpha.6(transitive)
- Removed@loaders.gl/worker-utils@4.2.0-alpha.6(transitive)
- Removeddraco3d@1.5.5(transitive)
Updateddraco3d@1.5.7