@loaders.gl/draco 3.4.11 → 3.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/draco-nodejs-worker.js +1 -1
- package/dist/draco-worker.js +1 -1
- package/dist/draco-writer-nodejs-worker.js +2 -2
- package/dist/draco-writer-worker.js +2 -2
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/package.json +6 -6
- package/dist/bundle.js +0 -5
- package/dist/draco-loader.js +0 -31
- package/dist/draco-writer-nodejs.js +0 -7
- package/dist/draco-writer.js +0 -44
- package/dist/draco3d/draco3d-types.js +0 -51
- package/dist/index.js +0 -48
- package/dist/lib/draco-builder.js +0 -338
- package/dist/lib/draco-module-loader.js +0 -93
- package/dist/lib/draco-parser.js +0 -476
- package/dist/lib/draco-types.js +0 -3
- package/dist/lib/utils/get-draco-schema.js +0 -42
- package/dist/lib/utils/version.js +0 -7
- package/dist/workers/draco-nodejs-worker.js +0 -6
- package/dist/workers/draco-worker.js +0 -5
- package/dist/workers/draco-writer-nodejs-worker.js +0 -26
- package/dist/workers/draco-writer-worker.js +0 -26
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(()=>{var x=Object.create;var w=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var $=t=>w(t,"__esModule",{value:!0});var q=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var j=(t,e,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of v(e))!V.call(t,o)&&o!=="default"&&w(t,o,{get:()=>e[o],enumerable:!(r=N(e,o))||r.enumerable});return t},U=t=>j($(w(t!=null?x(F(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var W=q(()=>{});var b="3.4.
|
|
1
|
+
(()=>{var x=Object.create;var w=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var $=t=>w(t,"__esModule",{value:!0});var q=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var j=(t,e,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of v(e))!V.call(t,o)&&o!=="default"&&w(t,o,{get:()=>e[o],enumerable:!(r=N(e,o))||r.enumerable});return t},U=t=>j($(w(t!=null?x(F(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var W=q(()=>{});var b="3.4.13";function D(t,e){if(!t)throw new Error(e||"loaders.gl assertion failed.")}var c={self:typeof self!="undefined"&&self,window:typeof window!="undefined"&&window,global:typeof global!="undefined"&&global,document:typeof document!="undefined"&&document},ie=c.self||c.window||c.global||{},de=c.window||c.self||c.global||{},k=c.global||c.self||c.window||{},ce=c.document||{};var h=typeof process!="object"||String(process)!=="[object process]"||process.browser,g=typeof importScripts=="function",le=typeof window!="undefined"&&typeof window.orientation!="undefined",T=typeof process!="undefined"&&process.version&&/v([0-9]*)/.exec(process.version),ue=T&&parseFloat(T[1])||0;function M(t,e=!0,r){let o=r||new Set;if(t){if(P(t))o.add(t);else if(P(t.buffer))o.add(t.buffer);else if(!ArrayBuffer.isView(t)){if(e&&typeof t=="object")for(let a in t)M(t[a],e,o)}}return r===void 0?Array.from(o):[]}function P(t){return t?t instanceof ArrayBuffer||typeof MessagePort!="undefined"&&t instanceof MessagePort||typeof ImageBitmap!="undefined"&&t instanceof ImageBitmap||typeof OffscreenCanvas!="undefined"&&t instanceof OffscreenCanvas:!1}function f(){let parentPort;try{eval("globalThis.parentPort = require('worker_threads').parentPort"),parentPort=globalThis.parentPort}catch{}return parentPort}var _=new Map,u=class{static inWorkerThread(){return typeof self!="undefined"||Boolean(f())}static set onmessage(e){function r(a){let s=f(),{type:i,payload:n}=s?a:a.data;e(i,n)}let o=f();o?(o.on("message",r),o.on("exit",()=>console.debug("Node worker closing"))):globalThis.onmessage=r}static addEventListener(e){let r=_.get(e);r||(r=a=>{if(!z(a))return;let s=f(),{type:i,payload:n}=s?a:a.data;e(i,n)}),f()?console.error("not implemented"):globalThis.addEventListener("message",r)}static removeEventListener(e){let r=_.get(e);_.delete(e),f()?console.error("not implemented"):globalThis.removeEventListener("message",r)}static postMessage(e,r){let o={source:"loaders.gl",type:e,payload:r},a=M(r),s=f();s?s.postMessage(o,a):globalThis.postMessage(o,a)}};function z(t){let{type:e,data:r}=t;return e==="message"&&r&&typeof r.source=="string"&&r.source.startsWith("loaders.gl")}var p=U(W());var G="latest",Q=typeof b!="undefined"?b:G,A={};async function E(t,e=null,r={}){return e&&(t=B(t,e,r)),A[t]=A[t]||X(t),await A[t]}function B(t,e,r){if(t.startsWith("http"))return t;let o=r.modules||{};return o[t]?o[t]:h?r.CDN?(D(r.CDN.startsWith("http")),`${r.CDN}/${e}@${Q}/dist/libs/${t}`):g?`../src/libs/${t}`:`modules/${e}/src/libs/${t}`:`modules/${e}/dist/libs/${t}`}async function X(t){if(t.endsWith("wasm"))return await(await fetch(t)).arrayBuffer();if(!h)try{return p&&p.requireFromFile&&await p.requireFromFile(t)}catch{return null}if(g)return importScripts(t);let r=await(await fetch(t)).text();return J(r,t)}function J(t,e){if(!h)return p.requireFromString&&p.requireFromString(t,e);if(g)return eval.call(k,t),null;let r=document.createElement("script");r.id=e;try{r.appendChild(document.createTextNode(t))}catch{r.text=t}return document.body.appendChild(r),null}var I={POSITION:"POSITION",NORMAL:"NORMAL",COLOR_0:"COLOR",TEXCOORD_0:"TEX_COORD"},H=()=>{},m=class{constructor(e){this.draco=e,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(e){e&&this.draco.destroy(e)}encodeSync(e,r={}){return this.log=H,this._setOptions(r),r.pointcloud?this._encodePointCloud(e,r):this._encodeMesh(e,r)}_getAttributesFromMesh(e){let r={...e,...e.attributes};return e.indices&&(r.indices=e.indices),r}_encodePointCloud(e,r){let o=new this.draco.PointCloud;r.metadata&&this._addGeometryMetadata(o,r.metadata);let a=this._getAttributesFromMesh(e);this._createDracoPointCloud(o,a,r);let s=new this.draco.DracoInt8Array;try{let i=this.dracoEncoder.EncodePointCloudToDracoBuffer(o,!1,s);if(!(i>0))throw new Error("Draco encoding failed.");return this.log(`DRACO encoded ${o.num_points()} points
|
|
2
2
|
with ${o.num_attributes()} attributes into ${i} bytes`),R(s)}finally{this.destroyEncodedObject(s),this.destroyEncodedObject(o)}}_encodeMesh(e,r){let o=new this.draco.Mesh;r.metadata&&this._addGeometryMetadata(o,r.metadata);let a=this._getAttributesFromMesh(e);this._createDracoMesh(o,a,r);let s=new this.draco.DracoInt8Array;try{let i=this.dracoEncoder.EncodeMeshToDracoBuffer(o,s);if(i<=0)throw new Error("Draco encoding failed.");return this.log(`DRACO encoded ${o.num_points()} points
|
|
3
|
-
with ${o.num_attributes()} attributes into ${i} bytes`),R(s)}finally{this.destroyEncodedObject(s),this.destroyEncodedObject(o)}}_setOptions(e){if("speed"in e&&this.dracoEncoder.SetSpeedOptions(...e.speed),"method"in e){let r=this.draco[e.method||"MESH_SEQUENTIAL_ENCODING"];this.dracoEncoder.SetEncodingMethod(r)}if("quantization"in e)for(let r in e.quantization){let o=e.quantization[r],a=this.draco[r];this.dracoEncoder.SetAttributeQuantization(a,o)}}_createDracoMesh(e,r,o){let a=o.attributesMetadata||{};try{let s=this._getPositionAttribute(r);if(!s)throw new Error("positions");let i=s.length/3;for(let n in r){let d=r[n];n=I[n]||n;let l=this._addAttributeToMesh(e,n,d,i);l!==-1&&this._addAttributeMetadata(e,l,{name:n,...a[n]||{}})}}catch(s){throw this.destroyEncodedObject(e),s}return e}_createDracoPointCloud(e,r,o){let a=o.attributesMetadata||{};try{let s=this._getPositionAttribute(r);if(!s)throw new Error("positions");let i=s.length/3;for(let n in r){let d=r[n];n=I[n]||n;let l=this._addAttributeToMesh(e,n,d,i);l!==-1&&this._addAttributeMetadata(e,l,{name:n,...a[n]||{}})}}catch(s){throw this.destroyEncodedObject(e),s}return e}_addAttributeToMesh(e,r,o,a){if(!ArrayBuffer.isView(o))return-1;let s=this._getDracoAttributeType(r),i=o.length/a;if(s==="indices"){let l=o.length/3;return this.log(`Adding attribute ${r}, size ${l}`),this.dracoMeshBuilder.AddFacesToMesh(e,l,o),-1}this.log(`Adding attribute ${r}, size ${i}`);let n=this.dracoMeshBuilder,{buffer:d}=o;switch(o.constructor){case Int8Array:return n.AddInt8Attribute(e,s,a,i,new Int8Array(d));case Int16Array:return n.AddInt16Attribute(e,s,a,i,new Int16Array(d));case Int32Array:return n.AddInt32Attribute(e,s,a,i,new Int32Array(d));case Uint8Array:case Uint8ClampedArray:return n.AddUInt8Attribute(e,s,a,i,new Uint8Array(d));case Uint16Array:return n.AddUInt16Attribute(e,s,a,i,new Uint16Array(d));case Uint32Array:return n.AddUInt32Attribute(e,s,a,i,new Uint32Array(d));case Float32Array:default:return n.AddFloatAttribute(e,s,a,i,new Float32Array(d))}}_getDracoAttributeType(e){switch(e.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(e){for(let r in e){let o=e[r];if(this._getDracoAttributeType(r)===this.draco.POSITION)return o}return null}_addGeometryMetadata(e,r){let o=new this.draco.Metadata;this._populateDracoMetadata(o,r),this.dracoMeshBuilder.AddMetadata(e,o)}_addAttributeMetadata(e,r,o){let a=new this.draco.Metadata;this._populateDracoMetadata(a,o),this.dracoMeshBuilder.SetMetadataForAttribute(e,r,a)}_populateDracoMetadata(e,r){for(let[o,a]of K(r))switch(typeof a){case"number":Math.trunc(a)===a?this.dracoMetadataBuilder.AddIntEntry(e,o,a):this.dracoMetadataBuilder.AddDoubleEntry(e,o,a);break;case"object":a instanceof Int32Array&&this.dracoMetadataBuilder.AddIntEntryArray(e,o,a,a.length);break;case"string":default:this.dracoMetadataBuilder.AddStringEntry(e,o,a)}}};function R(t){let e=t.size(),r=new ArrayBuffer(e),o=new Int8Array(r);for(let a=0;a<e;++a)o[a]=t.GetValue(a);return r}function K(t){return t.entries&&!t.hasOwnProperty("entries")?t.entries():Object.entries(t)}var Y="1.5.5",Z="1.4.1",O=`https://www.gstatic.com/draco/versioned/decoders/${Y}`,Te=`${O}/draco_decoder.js`,Pe=`${O}/draco_wasm_wrapper.js`,We=`${O}/draco_decoder.wasm`,ee=`https://raw.githubusercontent.com/google/draco/${Z}/javascript/draco_encoder.js`;var y;async function S(t){let e=t.modules||{};return e.draco3d?y=y||e.draco3d.createEncoderModule({}).then(r=>({draco:r})):y=y||re(t),await y}async function re(t){let e=await E(ee,"draco",t);return e=e||globalThis.DracoEncoderModule,new Promise(r=>{e({onModuleLoaded:o=>r({draco:o})})})}var C="3.4.
|
|
3
|
+
with ${o.num_attributes()} attributes into ${i} bytes`),R(s)}finally{this.destroyEncodedObject(s),this.destroyEncodedObject(o)}}_setOptions(e){if("speed"in e&&this.dracoEncoder.SetSpeedOptions(...e.speed),"method"in e){let r=this.draco[e.method||"MESH_SEQUENTIAL_ENCODING"];this.dracoEncoder.SetEncodingMethod(r)}if("quantization"in e)for(let r in e.quantization){let o=e.quantization[r],a=this.draco[r];this.dracoEncoder.SetAttributeQuantization(a,o)}}_createDracoMesh(e,r,o){let a=o.attributesMetadata||{};try{let s=this._getPositionAttribute(r);if(!s)throw new Error("positions");let i=s.length/3;for(let n in r){let d=r[n];n=I[n]||n;let l=this._addAttributeToMesh(e,n,d,i);l!==-1&&this._addAttributeMetadata(e,l,{name:n,...a[n]||{}})}}catch(s){throw this.destroyEncodedObject(e),s}return e}_createDracoPointCloud(e,r,o){let a=o.attributesMetadata||{};try{let s=this._getPositionAttribute(r);if(!s)throw new Error("positions");let i=s.length/3;for(let n in r){let d=r[n];n=I[n]||n;let l=this._addAttributeToMesh(e,n,d,i);l!==-1&&this._addAttributeMetadata(e,l,{name:n,...a[n]||{}})}}catch(s){throw this.destroyEncodedObject(e),s}return e}_addAttributeToMesh(e,r,o,a){if(!ArrayBuffer.isView(o))return-1;let s=this._getDracoAttributeType(r),i=o.length/a;if(s==="indices"){let l=o.length/3;return this.log(`Adding attribute ${r}, size ${l}`),this.dracoMeshBuilder.AddFacesToMesh(e,l,o),-1}this.log(`Adding attribute ${r}, size ${i}`);let n=this.dracoMeshBuilder,{buffer:d}=o;switch(o.constructor){case Int8Array:return n.AddInt8Attribute(e,s,a,i,new Int8Array(d));case Int16Array:return n.AddInt16Attribute(e,s,a,i,new Int16Array(d));case Int32Array:return n.AddInt32Attribute(e,s,a,i,new Int32Array(d));case Uint8Array:case Uint8ClampedArray:return n.AddUInt8Attribute(e,s,a,i,new Uint8Array(d));case Uint16Array:return n.AddUInt16Attribute(e,s,a,i,new Uint16Array(d));case Uint32Array:return n.AddUInt32Attribute(e,s,a,i,new Uint32Array(d));case Float32Array:default:return n.AddFloatAttribute(e,s,a,i,new Float32Array(d))}}_getDracoAttributeType(e){switch(e.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(e){for(let r in e){let o=e[r];if(this._getDracoAttributeType(r)===this.draco.POSITION)return o}return null}_addGeometryMetadata(e,r){let o=new this.draco.Metadata;this._populateDracoMetadata(o,r),this.dracoMeshBuilder.AddMetadata(e,o)}_addAttributeMetadata(e,r,o){let a=new this.draco.Metadata;this._populateDracoMetadata(a,o),this.dracoMeshBuilder.SetMetadataForAttribute(e,r,a)}_populateDracoMetadata(e,r){for(let[o,a]of K(r))switch(typeof a){case"number":Math.trunc(a)===a?this.dracoMetadataBuilder.AddIntEntry(e,o,a):this.dracoMetadataBuilder.AddDoubleEntry(e,o,a);break;case"object":a instanceof Int32Array&&this.dracoMetadataBuilder.AddIntEntryArray(e,o,a,a.length);break;case"string":default:this.dracoMetadataBuilder.AddStringEntry(e,o,a)}}};function R(t){let e=t.size(),r=new ArrayBuffer(e),o=new Int8Array(r);for(let a=0;a<e;++a)o[a]=t.GetValue(a);return r}function K(t){return t.entries&&!t.hasOwnProperty("entries")?t.entries():Object.entries(t)}var Y="1.5.5",Z="1.4.1",O=`https://www.gstatic.com/draco/versioned/decoders/${Y}`,Te=`${O}/draco_decoder.js`,Pe=`${O}/draco_wasm_wrapper.js`,We=`${O}/draco_decoder.wasm`,ee=`https://raw.githubusercontent.com/google/draco/${Z}/javascript/draco_encoder.js`;var y;async function S(t){let e=t.modules||{};return e.draco3d?y=y||e.draco3d.createEncoderModule({}).then(r=>({draco:r})):y=y||re(t),await y}async function re(t){let e=await E(ee,"draco",t);return e=e||globalThis.DracoEncoderModule,new Promise(r=>{e({onModuleLoaded:o=>r({draco:o})})})}var C="3.4.13";var te={pointcloud:!1,attributeNameEntry:"name"},L={name:"DRACO",id:"draco",module:"draco",version:C,extensions:["drc"],encode:oe,options:{draco:te}};async function oe(t,e={}){let{draco:r}=await S(e),o=new m(r);try{return o.encodeSync(t,e.draco)}finally{o.destroy()}}(()=>{!u.inWorkerThread()||(u.onmessage=async(t,e)=>{switch(t){case"process":try{let{input:r,options:o}=e,a=await L.encode(r,o);u.postMessage("done",{result:a})}catch(r){let o=r instanceof Error?r.message:"";u.postMessage("error",{error:o})}break;default:}})})();})();
|
|
4
4
|
//# sourceMappingURL=draco-writer-worker.js.map
|
|
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.VERSION = void 0;
|
|
7
|
-
var VERSION = typeof "3.4.
|
|
7
|
+
var VERSION = typeof "3.4.13" !== 'undefined' ? "3.4.13" : 'latest';
|
|
8
8
|
exports.VERSION = VERSION;
|
|
9
9
|
//# sourceMappingURL=version.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = typeof "3.4.
|
|
1
|
+
export const VERSION = typeof "3.4.13" !== 'undefined' ? "3.4.13" : 'latest';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/draco",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.13",
|
|
4
4
|
"description": "Framework-independent loader and writer for Draco compressed meshes and point clouds",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@babel/runtime": "^7.3.1",
|
|
45
|
-
"@loaders.gl/loader-utils": "3.4.
|
|
46
|
-
"@loaders.gl/schema": "3.4.
|
|
47
|
-
"@loaders.gl/worker-utils": "3.4.
|
|
45
|
+
"@loaders.gl/loader-utils": "3.4.13",
|
|
46
|
+
"@loaders.gl/schema": "3.4.13",
|
|
47
|
+
"@loaders.gl/worker-utils": "3.4.13",
|
|
48
48
|
"draco3d": "1.5.5"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@loaders.gl/polyfills": "3.4.
|
|
51
|
+
"@loaders.gl/polyfills": "3.4.13"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "be8849c02972ce541e01720d29b976f830d6af92"
|
|
54
54
|
}
|
package/dist/bundle.js
DELETED
package/dist/draco-loader.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._TypecheckDracoLoader = exports.DracoLoader = void 0;
|
|
4
|
-
const worker_utils_1 = require("@loaders.gl/worker-utils");
|
|
5
|
-
// import type {DracoMeshData} from './types';
|
|
6
|
-
const version_1 = require("./lib/utils/version");
|
|
7
|
-
const DEFAULT_DRACO_OPTIONS = {
|
|
8
|
-
draco: {
|
|
9
|
-
decoderType: typeof WebAssembly === 'object' ? 'wasm' : 'js',
|
|
10
|
-
libraryPath: 'libs/',
|
|
11
|
-
extraAttributes: {},
|
|
12
|
-
attributeNameEntry: undefined
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Worker loader for Draco3D compressed geometries
|
|
17
|
-
*/
|
|
18
|
-
exports.DracoLoader = {
|
|
19
|
-
name: 'Draco',
|
|
20
|
-
id: worker_utils_1.isBrowser ? 'draco' : 'draco-nodejs',
|
|
21
|
-
module: 'draco',
|
|
22
|
-
shapes: ['mesh'],
|
|
23
|
-
version: version_1.VERSION,
|
|
24
|
-
worker: true,
|
|
25
|
-
extensions: ['drc'],
|
|
26
|
-
mimeTypes: ['application/octet-stream'],
|
|
27
|
-
binary: true,
|
|
28
|
-
tests: ['DRACO'],
|
|
29
|
-
options: DEFAULT_DRACO_OPTIONS
|
|
30
|
-
};
|
|
31
|
-
exports._TypecheckDracoLoader = exports.DracoLoader;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DracoWriterNodeJS = void 0;
|
|
4
|
-
// Polyfills increases the bundle size significantly. Use it for NodeJS worker only
|
|
5
|
-
require("@loaders.gl/polyfills");
|
|
6
|
-
var draco_writer_1 = require("./draco-writer");
|
|
7
|
-
Object.defineProperty(exports, "DracoWriterNodeJS", { enumerable: true, get: function () { return draco_writer_1.DracoWriter; } });
|
package/dist/draco-writer.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DracoWriter = void 0;
|
|
7
|
-
const draco_builder_1 = __importDefault(require("./lib/draco-builder"));
|
|
8
|
-
const draco_module_loader_1 = require("./lib/draco-module-loader");
|
|
9
|
-
const version_1 = require("./lib/utils/version");
|
|
10
|
-
const DEFAULT_DRACO_OPTIONS = {
|
|
11
|
-
pointcloud: false,
|
|
12
|
-
attributeNameEntry: 'name'
|
|
13
|
-
// Draco Compression Parameters
|
|
14
|
-
// method: 'MESH_EDGEBREAKER_ENCODING',
|
|
15
|
-
// speed: [5, 5],
|
|
16
|
-
// quantization: {
|
|
17
|
-
// POSITION: 10
|
|
18
|
-
// }
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Exporter for Draco3D compressed geometries
|
|
22
|
-
*/
|
|
23
|
-
exports.DracoWriter = {
|
|
24
|
-
name: 'DRACO',
|
|
25
|
-
id: 'draco',
|
|
26
|
-
module: 'draco',
|
|
27
|
-
version: version_1.VERSION,
|
|
28
|
-
extensions: ['drc'],
|
|
29
|
-
encode,
|
|
30
|
-
options: {
|
|
31
|
-
draco: DEFAULT_DRACO_OPTIONS
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
async function encode(data, options = {}) {
|
|
35
|
-
// Dynamically load draco
|
|
36
|
-
const { draco } = await (0, draco_module_loader_1.loadDracoEncoderModule)(options);
|
|
37
|
-
const dracoBuilder = new draco_builder_1.default(draco);
|
|
38
|
-
try {
|
|
39
|
-
return dracoBuilder.encodeSync(data, options.draco);
|
|
40
|
-
}
|
|
41
|
-
finally {
|
|
42
|
-
dracoBuilder.destroy();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// A set of typescript types manually adapted from the Draco web IDL
|
|
3
|
-
// Draco JS is a bit tricky to work with due to the C++ emscripten code base
|
|
4
|
-
// sparse documentation, so these types provide an extra safety net.
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.draco_StatusCode = exports.draco_DataType = exports.draco_EncodedGeometryType = exports.draco_GeometryAttribute_Type = void 0;
|
|
7
|
-
// DRACO WEB DECODER IDL
|
|
8
|
-
/** Draco3D geometry attribute type */
|
|
9
|
-
var draco_GeometryAttribute_Type;
|
|
10
|
-
(function (draco_GeometryAttribute_Type) {
|
|
11
|
-
draco_GeometryAttribute_Type[draco_GeometryAttribute_Type["draco_GeometryAttribute::INVALID"] = 0] = "draco_GeometryAttribute::INVALID";
|
|
12
|
-
draco_GeometryAttribute_Type[draco_GeometryAttribute_Type["draco_GeometryAttribute::POSITION"] = 1] = "draco_GeometryAttribute::POSITION";
|
|
13
|
-
draco_GeometryAttribute_Type[draco_GeometryAttribute_Type["draco_GeometryAttribute::NORMAL"] = 2] = "draco_GeometryAttribute::NORMAL";
|
|
14
|
-
draco_GeometryAttribute_Type[draco_GeometryAttribute_Type["draco_GeometryAttribute::COLOR"] = 3] = "draco_GeometryAttribute::COLOR";
|
|
15
|
-
draco_GeometryAttribute_Type[draco_GeometryAttribute_Type["draco_GeometryAttribute::TEX_COORD"] = 4] = "draco_GeometryAttribute::TEX_COORD";
|
|
16
|
-
draco_GeometryAttribute_Type[draco_GeometryAttribute_Type["draco_GeometryAttribute::GENERIC"] = 5] = "draco_GeometryAttribute::GENERIC";
|
|
17
|
-
})(draco_GeometryAttribute_Type = exports.draco_GeometryAttribute_Type || (exports.draco_GeometryAttribute_Type = {}));
|
|
18
|
-
/** Draco3D encoded geometry type */
|
|
19
|
-
var draco_EncodedGeometryType;
|
|
20
|
-
(function (draco_EncodedGeometryType) {
|
|
21
|
-
draco_EncodedGeometryType[draco_EncodedGeometryType["draco::INVALID_GEOMETRY_TYPE"] = 0] = "draco::INVALID_GEOMETRY_TYPE";
|
|
22
|
-
draco_EncodedGeometryType[draco_EncodedGeometryType["draco::POINT_CLOUD"] = 1] = "draco::POINT_CLOUD";
|
|
23
|
-
draco_EncodedGeometryType[draco_EncodedGeometryType["draco::TRIANGULAR_MESH"] = 2] = "draco::TRIANGULAR_MESH";
|
|
24
|
-
})(draco_EncodedGeometryType = exports.draco_EncodedGeometryType || (exports.draco_EncodedGeometryType = {}));
|
|
25
|
-
/** Draco3D data type */
|
|
26
|
-
var draco_DataType;
|
|
27
|
-
(function (draco_DataType) {
|
|
28
|
-
draco_DataType[draco_DataType["draco::DT_INVALID"] = 0] = "draco::DT_INVALID";
|
|
29
|
-
draco_DataType[draco_DataType["draco::DT_INT8"] = 1] = "draco::DT_INT8";
|
|
30
|
-
draco_DataType[draco_DataType["draco::DT_UINT8"] = 2] = "draco::DT_UINT8";
|
|
31
|
-
draco_DataType[draco_DataType["draco::DT_INT16"] = 3] = "draco::DT_INT16";
|
|
32
|
-
draco_DataType[draco_DataType["draco::DT_UINT16"] = 4] = "draco::DT_UINT16";
|
|
33
|
-
draco_DataType[draco_DataType["draco::DT_INT32"] = 5] = "draco::DT_INT32";
|
|
34
|
-
draco_DataType[draco_DataType["draco::DT_UINT32"] = 6] = "draco::DT_UINT32";
|
|
35
|
-
draco_DataType[draco_DataType["draco::DT_INT64"] = 7] = "draco::DT_INT64";
|
|
36
|
-
draco_DataType[draco_DataType["draco::DT_UINT64"] = 8] = "draco::DT_UINT64";
|
|
37
|
-
draco_DataType[draco_DataType["draco::DT_FLOAT32"] = 9] = "draco::DT_FLOAT32";
|
|
38
|
-
draco_DataType[draco_DataType["draco::DT_FLOAT64"] = 10] = "draco::DT_FLOAT64";
|
|
39
|
-
draco_DataType[draco_DataType["draco::DT_BOOL"] = 11] = "draco::DT_BOOL";
|
|
40
|
-
draco_DataType[draco_DataType["draco::DT_TYPES_COUNT"] = 12] = "draco::DT_TYPES_COUNT";
|
|
41
|
-
})(draco_DataType = exports.draco_DataType || (exports.draco_DataType = {}));
|
|
42
|
-
/** Draco3D status code */
|
|
43
|
-
var draco_StatusCode;
|
|
44
|
-
(function (draco_StatusCode) {
|
|
45
|
-
draco_StatusCode[draco_StatusCode["draco_Status::OK"] = 0] = "draco_Status::OK";
|
|
46
|
-
draco_StatusCode[draco_StatusCode["draco_Status::DRACO_ERROR"] = 1] = "draco_Status::DRACO_ERROR";
|
|
47
|
-
draco_StatusCode[draco_StatusCode["draco_Status::IO_ERROR"] = 2] = "draco_Status::IO_ERROR";
|
|
48
|
-
draco_StatusCode[draco_StatusCode["draco_Status::INVALID_PARAMETER"] = 3] = "draco_Status::INVALID_PARAMETER";
|
|
49
|
-
draco_StatusCode[draco_StatusCode["draco_Status::UNSUPPORTED_VERSION"] = 4] = "draco_Status::UNSUPPORTED_VERSION";
|
|
50
|
-
draco_StatusCode[draco_StatusCode["draco_Status::UNKNOWN_VERSION"] = 5] = "draco_Status::UNKNOWN_VERSION";
|
|
51
|
-
})(draco_StatusCode = exports.draco_StatusCode || (exports.draco_StatusCode = {}));
|
package/dist/index.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports._TypecheckDracoLoader = exports.DracoLoader = exports.DracoWorkerLoader = exports.DracoWriterWorker = exports.DracoWriter = void 0;
|
|
7
|
-
const draco_loader_1 = require("./draco-loader");
|
|
8
|
-
Object.defineProperty(exports, "DracoWorkerLoader", { enumerable: true, get: function () { return draco_loader_1.DracoLoader; } });
|
|
9
|
-
const draco_parser_1 = __importDefault(require("./lib/draco-parser"));
|
|
10
|
-
const draco_module_loader_1 = require("./lib/draco-module-loader");
|
|
11
|
-
const version_1 = require("./lib/utils/version");
|
|
12
|
-
const worker_utils_1 = require("@loaders.gl/worker-utils");
|
|
13
|
-
var draco_writer_1 = require("./draco-writer");
|
|
14
|
-
Object.defineProperty(exports, "DracoWriter", { enumerable: true, get: function () { return draco_writer_1.DracoWriter; } });
|
|
15
|
-
/**
|
|
16
|
-
* Browser worker doesn't work because of issue during "draco_encoder.js" loading.
|
|
17
|
-
* Refused to execute script from 'https://raw.githubusercontent.com/google/draco/1.4.1/javascript/draco_encoder.js' because its MIME type ('') is not executable.
|
|
18
|
-
*/
|
|
19
|
-
exports.DracoWriterWorker = {
|
|
20
|
-
id: worker_utils_1.isBrowser ? 'draco-writer' : 'draco-writer-nodejs',
|
|
21
|
-
name: 'Draco compressed geometry writer',
|
|
22
|
-
module: 'draco',
|
|
23
|
-
version: version_1.VERSION,
|
|
24
|
-
worker: true,
|
|
25
|
-
options: {
|
|
26
|
-
draco: {},
|
|
27
|
-
source: null
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Loader for Draco3D compressed geometries
|
|
32
|
-
*/
|
|
33
|
-
exports.DracoLoader = {
|
|
34
|
-
...draco_loader_1.DracoLoader,
|
|
35
|
-
parse
|
|
36
|
-
};
|
|
37
|
-
async function parse(arrayBuffer, options) {
|
|
38
|
-
const { draco } = await (0, draco_module_loader_1.loadDracoDecoderModule)(options);
|
|
39
|
-
const dracoParser = new draco_parser_1.default(draco);
|
|
40
|
-
try {
|
|
41
|
-
return dracoParser.parseSync(arrayBuffer, options?.draco);
|
|
42
|
-
}
|
|
43
|
-
finally {
|
|
44
|
-
dracoParser.destroy();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
// TYPE TESTS - TODO find a better way than exporting junk
|
|
48
|
-
exports._TypecheckDracoLoader = exports.DracoLoader;
|
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// Native Draco attribute names to GLTF attribute names.
|
|
4
|
-
const GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {
|
|
5
|
-
POSITION: 'POSITION',
|
|
6
|
-
NORMAL: 'NORMAL',
|
|
7
|
-
COLOR_0: 'COLOR',
|
|
8
|
-
TEXCOORD_0: 'TEX_COORD'
|
|
9
|
-
};
|
|
10
|
-
const noop = () => { };
|
|
11
|
-
class DracoBuilder {
|
|
12
|
-
// draco - the draco decoder, either import `draco3d` or load dynamically
|
|
13
|
-
constructor(draco) {
|
|
14
|
-
this.draco = draco;
|
|
15
|
-
this.dracoEncoder = new this.draco.Encoder();
|
|
16
|
-
this.dracoMeshBuilder = new this.draco.MeshBuilder();
|
|
17
|
-
this.dracoMetadataBuilder = new this.draco.MetadataBuilder();
|
|
18
|
-
}
|
|
19
|
-
destroy() {
|
|
20
|
-
this.destroyEncodedObject(this.dracoMeshBuilder);
|
|
21
|
-
this.destroyEncodedObject(this.dracoEncoder);
|
|
22
|
-
this.destroyEncodedObject(this.dracoMetadataBuilder);
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
this.dracoMeshBuilder = null;
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
this.dracoEncoder = null;
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
this.draco = null;
|
|
29
|
-
}
|
|
30
|
-
// TBD - when does this need to be called?
|
|
31
|
-
destroyEncodedObject(object) {
|
|
32
|
-
if (object) {
|
|
33
|
-
this.draco.destroy(object);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Encode mesh or point cloud
|
|
38
|
-
* @param mesh =({})
|
|
39
|
-
* @param options
|
|
40
|
-
*/
|
|
41
|
-
encodeSync(mesh, options = {}) {
|
|
42
|
-
this.log = noop; // TODO
|
|
43
|
-
this._setOptions(options);
|
|
44
|
-
return options.pointcloud
|
|
45
|
-
? this._encodePointCloud(mesh, options)
|
|
46
|
-
: this._encodeMesh(mesh, options);
|
|
47
|
-
}
|
|
48
|
-
// PRIVATE
|
|
49
|
-
_getAttributesFromMesh(mesh) {
|
|
50
|
-
// TODO - Change the encodePointCloud interface instead?
|
|
51
|
-
const attributes = { ...mesh, ...mesh.attributes };
|
|
52
|
-
// Fold indices into the attributes
|
|
53
|
-
if (mesh.indices) {
|
|
54
|
-
attributes.indices = mesh.indices;
|
|
55
|
-
}
|
|
56
|
-
return attributes;
|
|
57
|
-
}
|
|
58
|
-
_encodePointCloud(pointcloud, options) {
|
|
59
|
-
const dracoPointCloud = new this.draco.PointCloud();
|
|
60
|
-
if (options.metadata) {
|
|
61
|
-
this._addGeometryMetadata(dracoPointCloud, options.metadata);
|
|
62
|
-
}
|
|
63
|
-
const attributes = this._getAttributesFromMesh(pointcloud);
|
|
64
|
-
// Build a `DracoPointCloud` from the input data
|
|
65
|
-
this._createDracoPointCloud(dracoPointCloud, attributes, options);
|
|
66
|
-
const dracoData = new this.draco.DracoInt8Array();
|
|
67
|
-
try {
|
|
68
|
-
const encodedLen = this.dracoEncoder.EncodePointCloudToDracoBuffer(dracoPointCloud, false, dracoData);
|
|
69
|
-
if (!(encodedLen > 0)) {
|
|
70
|
-
throw new Error('Draco encoding failed.');
|
|
71
|
-
}
|
|
72
|
-
this.log(`DRACO encoded ${dracoPointCloud.num_points()} points
|
|
73
|
-
with ${dracoPointCloud.num_attributes()} attributes into ${encodedLen} bytes`);
|
|
74
|
-
return dracoInt8ArrayToArrayBuffer(dracoData);
|
|
75
|
-
}
|
|
76
|
-
finally {
|
|
77
|
-
this.destroyEncodedObject(dracoData);
|
|
78
|
-
this.destroyEncodedObject(dracoPointCloud);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
_encodeMesh(mesh, options) {
|
|
82
|
-
const dracoMesh = new this.draco.Mesh();
|
|
83
|
-
if (options.metadata) {
|
|
84
|
-
this._addGeometryMetadata(dracoMesh, options.metadata);
|
|
85
|
-
}
|
|
86
|
-
const attributes = this._getAttributesFromMesh(mesh);
|
|
87
|
-
// Build a `DracoMesh` from the input data
|
|
88
|
-
this._createDracoMesh(dracoMesh, attributes, options);
|
|
89
|
-
const dracoData = new this.draco.DracoInt8Array();
|
|
90
|
-
try {
|
|
91
|
-
const encodedLen = this.dracoEncoder.EncodeMeshToDracoBuffer(dracoMesh, dracoData);
|
|
92
|
-
if (encodedLen <= 0) {
|
|
93
|
-
throw new Error('Draco encoding failed.');
|
|
94
|
-
}
|
|
95
|
-
this.log(`DRACO encoded ${dracoMesh.num_points()} points
|
|
96
|
-
with ${dracoMesh.num_attributes()} attributes into ${encodedLen} bytes`);
|
|
97
|
-
return dracoInt8ArrayToArrayBuffer(dracoData);
|
|
98
|
-
}
|
|
99
|
-
finally {
|
|
100
|
-
this.destroyEncodedObject(dracoData);
|
|
101
|
-
this.destroyEncodedObject(dracoMesh);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Set encoding options.
|
|
106
|
-
* @param {{speed?: any; method?: any; quantization?: any;}} options
|
|
107
|
-
*/
|
|
108
|
-
_setOptions(options) {
|
|
109
|
-
if ('speed' in options) {
|
|
110
|
-
// @ts-ignore
|
|
111
|
-
this.dracoEncoder.SetSpeedOptions(...options.speed);
|
|
112
|
-
}
|
|
113
|
-
if ('method' in options) {
|
|
114
|
-
const dracoMethod = this.draco[options.method || 'MESH_SEQUENTIAL_ENCODING'];
|
|
115
|
-
// assert(dracoMethod)
|
|
116
|
-
this.dracoEncoder.SetEncodingMethod(dracoMethod);
|
|
117
|
-
}
|
|
118
|
-
if ('quantization' in options) {
|
|
119
|
-
for (const attribute in options.quantization) {
|
|
120
|
-
const bits = options.quantization[attribute];
|
|
121
|
-
const dracoPosition = this.draco[attribute];
|
|
122
|
-
this.dracoEncoder.SetAttributeQuantization(dracoPosition, bits);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* @param {Mesh} dracoMesh
|
|
128
|
-
* @param {object} attributes
|
|
129
|
-
* @returns {Mesh}
|
|
130
|
-
*/
|
|
131
|
-
_createDracoMesh(dracoMesh, attributes, options) {
|
|
132
|
-
const optionalMetadata = options.attributesMetadata || {};
|
|
133
|
-
try {
|
|
134
|
-
const positions = this._getPositionAttribute(attributes);
|
|
135
|
-
if (!positions) {
|
|
136
|
-
throw new Error('positions');
|
|
137
|
-
}
|
|
138
|
-
const vertexCount = positions.length / 3;
|
|
139
|
-
for (let attributeName in attributes) {
|
|
140
|
-
const attribute = attributes[attributeName];
|
|
141
|
-
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;
|
|
142
|
-
const uniqueId = this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);
|
|
143
|
-
if (uniqueId !== -1) {
|
|
144
|
-
this._addAttributeMetadata(dracoMesh, uniqueId, {
|
|
145
|
-
name: attributeName,
|
|
146
|
-
...(optionalMetadata[attributeName] || {})
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
this.destroyEncodedObject(dracoMesh);
|
|
153
|
-
throw error;
|
|
154
|
-
}
|
|
155
|
-
return dracoMesh;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* @param {} dracoPointCloud
|
|
159
|
-
* @param {object} attributes
|
|
160
|
-
*/
|
|
161
|
-
_createDracoPointCloud(dracoPointCloud, attributes, options) {
|
|
162
|
-
const optionalMetadata = options.attributesMetadata || {};
|
|
163
|
-
try {
|
|
164
|
-
const positions = this._getPositionAttribute(attributes);
|
|
165
|
-
if (!positions) {
|
|
166
|
-
throw new Error('positions');
|
|
167
|
-
}
|
|
168
|
-
const vertexCount = positions.length / 3;
|
|
169
|
-
for (let attributeName in attributes) {
|
|
170
|
-
const attribute = attributes[attributeName];
|
|
171
|
-
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;
|
|
172
|
-
const uniqueId = this._addAttributeToMesh(dracoPointCloud, attributeName, attribute, vertexCount);
|
|
173
|
-
if (uniqueId !== -1) {
|
|
174
|
-
this._addAttributeMetadata(dracoPointCloud, uniqueId, {
|
|
175
|
-
name: attributeName,
|
|
176
|
-
...(optionalMetadata[attributeName] || {})
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
this.destroyEncodedObject(dracoPointCloud);
|
|
183
|
-
throw error;
|
|
184
|
-
}
|
|
185
|
-
return dracoPointCloud;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* @param mesh
|
|
189
|
-
* @param attributeName
|
|
190
|
-
* @param attribute
|
|
191
|
-
* @param vertexCount
|
|
192
|
-
*/
|
|
193
|
-
_addAttributeToMesh(mesh, attributeName, attribute, vertexCount) {
|
|
194
|
-
if (!ArrayBuffer.isView(attribute)) {
|
|
195
|
-
return -1;
|
|
196
|
-
}
|
|
197
|
-
const type = this._getDracoAttributeType(attributeName);
|
|
198
|
-
// @ts-ignore TODO/fix types
|
|
199
|
-
const size = attribute.length / vertexCount;
|
|
200
|
-
if (type === 'indices') {
|
|
201
|
-
// @ts-ignore TODO/fix types
|
|
202
|
-
const numFaces = attribute.length / 3;
|
|
203
|
-
this.log(`Adding attribute ${attributeName}, size ${numFaces}`);
|
|
204
|
-
// @ts-ignore assumes mesh is a Mesh, not a point cloud
|
|
205
|
-
this.dracoMeshBuilder.AddFacesToMesh(mesh, numFaces, attribute);
|
|
206
|
-
return -1;
|
|
207
|
-
}
|
|
208
|
-
this.log(`Adding attribute ${attributeName}, size ${size}`);
|
|
209
|
-
const builder = this.dracoMeshBuilder;
|
|
210
|
-
const { buffer } = attribute;
|
|
211
|
-
switch (attribute.constructor) {
|
|
212
|
-
case Int8Array:
|
|
213
|
-
return builder.AddInt8Attribute(mesh, type, vertexCount, size, new Int8Array(buffer));
|
|
214
|
-
case Int16Array:
|
|
215
|
-
return builder.AddInt16Attribute(mesh, type, vertexCount, size, new Int16Array(buffer));
|
|
216
|
-
case Int32Array:
|
|
217
|
-
return builder.AddInt32Attribute(mesh, type, vertexCount, size, new Int32Array(buffer));
|
|
218
|
-
case Uint8Array:
|
|
219
|
-
case Uint8ClampedArray:
|
|
220
|
-
return builder.AddUInt8Attribute(mesh, type, vertexCount, size, new Uint8Array(buffer));
|
|
221
|
-
case Uint16Array:
|
|
222
|
-
return builder.AddUInt16Attribute(mesh, type, vertexCount, size, new Uint16Array(buffer));
|
|
223
|
-
case Uint32Array:
|
|
224
|
-
return builder.AddUInt32Attribute(mesh, type, vertexCount, size, new Uint32Array(buffer));
|
|
225
|
-
case Float32Array:
|
|
226
|
-
default:
|
|
227
|
-
return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* DRACO can compress attributes of know type better
|
|
232
|
-
* TODO - expose an attribute type map?
|
|
233
|
-
* @param attributeName
|
|
234
|
-
*/
|
|
235
|
-
_getDracoAttributeType(attributeName) {
|
|
236
|
-
switch (attributeName.toLowerCase()) {
|
|
237
|
-
case 'indices':
|
|
238
|
-
return 'indices';
|
|
239
|
-
case 'position':
|
|
240
|
-
case 'positions':
|
|
241
|
-
case 'vertices':
|
|
242
|
-
return this.draco.POSITION;
|
|
243
|
-
case 'normal':
|
|
244
|
-
case 'normals':
|
|
245
|
-
return this.draco.NORMAL;
|
|
246
|
-
case 'color':
|
|
247
|
-
case 'colors':
|
|
248
|
-
return this.draco.COLOR;
|
|
249
|
-
case 'texcoord':
|
|
250
|
-
case 'texcoords':
|
|
251
|
-
return this.draco.TEX_COORD;
|
|
252
|
-
default:
|
|
253
|
-
return this.draco.GENERIC;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
_getPositionAttribute(attributes) {
|
|
257
|
-
for (const attributeName in attributes) {
|
|
258
|
-
const attribute = attributes[attributeName];
|
|
259
|
-
const dracoType = this._getDracoAttributeType(attributeName);
|
|
260
|
-
if (dracoType === this.draco.POSITION) {
|
|
261
|
-
return attribute;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return null;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Add metadata for the geometry.
|
|
268
|
-
* @param dracoGeometry - WASM Draco Object
|
|
269
|
-
* @param metadata
|
|
270
|
-
*/
|
|
271
|
-
_addGeometryMetadata(dracoGeometry, metadata) {
|
|
272
|
-
const dracoMetadata = new this.draco.Metadata();
|
|
273
|
-
this._populateDracoMetadata(dracoMetadata, metadata);
|
|
274
|
-
this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Add metadata for an attribute to geometry.
|
|
278
|
-
* @param dracoGeometry - WASM Draco Object
|
|
279
|
-
* @param uniqueAttributeId
|
|
280
|
-
* @param metadata
|
|
281
|
-
*/
|
|
282
|
-
_addAttributeMetadata(dracoGeometry, uniqueAttributeId, metadata) {
|
|
283
|
-
// Note: Draco JS IDL doesn't seem to expose draco.AttributeMetadata, however it seems to
|
|
284
|
-
// create such objects automatically from draco.Metadata object.
|
|
285
|
-
const dracoAttributeMetadata = new this.draco.Metadata();
|
|
286
|
-
this._populateDracoMetadata(dracoAttributeMetadata, metadata);
|
|
287
|
-
// Draco3d doc note: Directly add attribute metadata to geometry.
|
|
288
|
-
// You can do this without explicitly adding |GeometryMetadata| to mesh.
|
|
289
|
-
this.dracoMeshBuilder.SetMetadataForAttribute(dracoGeometry, uniqueAttributeId, dracoAttributeMetadata);
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Add contents of object or map to a WASM Draco Metadata Object
|
|
293
|
-
* @param dracoMetadata - WASM Draco Object
|
|
294
|
-
* @param metadata
|
|
295
|
-
*/
|
|
296
|
-
_populateDracoMetadata(dracoMetadata, metadata) {
|
|
297
|
-
for (const [key, value] of getEntries(metadata)) {
|
|
298
|
-
switch (typeof value) {
|
|
299
|
-
case 'number':
|
|
300
|
-
if (Math.trunc(value) === value) {
|
|
301
|
-
this.dracoMetadataBuilder.AddIntEntry(dracoMetadata, key, value);
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
this.dracoMetadataBuilder.AddDoubleEntry(dracoMetadata, key, value);
|
|
305
|
-
}
|
|
306
|
-
break;
|
|
307
|
-
case 'object':
|
|
308
|
-
if (value instanceof Int32Array) {
|
|
309
|
-
this.dracoMetadataBuilder.AddIntEntryArray(dracoMetadata, key, value, value.length);
|
|
310
|
-
}
|
|
311
|
-
break;
|
|
312
|
-
case 'string':
|
|
313
|
-
default:
|
|
314
|
-
this.dracoMetadataBuilder.AddStringEntry(dracoMetadata, key, value);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
exports.default = DracoBuilder;
|
|
320
|
-
// HELPER FUNCTIONS
|
|
321
|
-
/**
|
|
322
|
-
* Copy encoded data to buffer
|
|
323
|
-
* @param dracoData
|
|
324
|
-
*/
|
|
325
|
-
function dracoInt8ArrayToArrayBuffer(dracoData) {
|
|
326
|
-
const byteLength = dracoData.size();
|
|
327
|
-
const outputBuffer = new ArrayBuffer(byteLength);
|
|
328
|
-
const outputData = new Int8Array(outputBuffer);
|
|
329
|
-
for (let i = 0; i < byteLength; ++i) {
|
|
330
|
-
outputData[i] = dracoData.GetValue(i);
|
|
331
|
-
}
|
|
332
|
-
return outputBuffer;
|
|
333
|
-
}
|
|
334
|
-
/** Enable iteration over either an object or a map */
|
|
335
|
-
function getEntries(container) {
|
|
336
|
-
const hasEntriesFunc = container.entries && !container.hasOwnProperty('entries');
|
|
337
|
-
return hasEntriesFunc ? container.entries() : Object.entries(container);
|
|
338
|
-
}
|