@loaders.gl/draco 3.1.3 → 4.0.0-alpha.5
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/bundle.js +2 -2
- package/dist/bundle.js.map +1 -0
- package/dist/dist.min.js +2 -2
- package/dist/dist.min.js.map +2 -2
- package/dist/draco-loader.js +21 -27
- package/dist/draco-loader.js.map +1 -0
- package/dist/draco-worker.js +1 -1
- package/dist/draco-worker.js.map +2 -2
- package/dist/draco-writer.js +27 -39
- package/dist/draco-writer.js.map +1 -0
- package/dist/draco3d/draco3d-types.js +44 -47
- package/dist/draco3d/draco3d-types.js.map +1 -0
- package/dist/index.js +21 -28
- package/dist/index.js.map +1 -0
- package/dist/lib/draco-builder.js +329 -313
- package/dist/lib/draco-builder.js.map +1 -0
- package/dist/lib/draco-module-loader.js +72 -78
- package/dist/lib/draco-module-loader.js.map +1 -0
- package/dist/lib/draco-parser.js +416 -440
- package/dist/lib/draco-parser.js.map +1 -0
- package/dist/lib/draco-types.js +2 -3
- package/dist/{es5/lib → lib}/draco-types.js.map +0 -0
- package/dist/lib/utils/get-draco-schema.js +41 -35
- package/dist/lib/utils/get-draco-schema.js.map +1 -0
- package/dist/lib/utils/version.js +2 -7
- package/dist/lib/utils/version.js.map +1 -0
- package/dist/workers/draco-worker.js +4 -5
- package/dist/workers/draco-worker.js.map +1 -0
- package/package.json +8 -8
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/draco-loader.js +0 -38
- package/dist/es5/draco-loader.js.map +0 -1
- package/dist/es5/draco-writer.js +0 -78
- package/dist/es5/draco-writer.js.map +0 -1
- package/dist/es5/draco3d/draco3d-types.js +0 -58
- package/dist/es5/draco3d/draco3d-types.js.map +0 -1
- package/dist/es5/index.js +0 -85
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/draco-builder.js +0 -409
- package/dist/es5/lib/draco-builder.js.map +0 -1
- package/dist/es5/lib/draco-module-loader.js +0 -229
- package/dist/es5/lib/draco-module-loader.js.map +0 -1
- package/dist/es5/lib/draco-parser.js +0 -528
- package/dist/es5/lib/draco-parser.js.map +0 -1
- package/dist/es5/lib/draco-types.js +0 -2
- package/dist/es5/lib/utils/get-draco-schema.js +0 -55
- package/dist/es5/lib/utils/get-draco-schema.js.map +0 -1
- package/dist/es5/lib/utils/version.js +0 -9
- package/dist/es5/lib/utils/version.js.map +0 -1
- package/dist/es5/workers/draco-worker.js +0 -8
- package/dist/es5/workers/draco-worker.js.map +0 -1
- package/dist/esm/bundle.js +0 -5
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/draco-loader.js +0 -24
- package/dist/esm/draco-loader.js.map +0 -1
- package/dist/esm/draco-writer.js +0 -32
- package/dist/esm/draco-writer.js.map +0 -1
- package/dist/esm/draco3d/draco3d-types.js +0 -48
- package/dist/esm/draco3d/draco3d-types.js.map +0 -1
- package/dist/esm/index.js +0 -24
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/draco-builder.js +0 -354
- package/dist/esm/lib/draco-builder.js.map +0 -1
- package/dist/esm/lib/draco-module-loader.js +0 -85
- package/dist/esm/lib/draco-module-loader.js.map +0 -1
- package/dist/esm/lib/draco-parser.js +0 -452
- package/dist/esm/lib/draco-parser.js.map +0 -1
- package/dist/esm/lib/draco-types.js +0 -2
- package/dist/esm/lib/draco-types.js.map +0 -1
- package/dist/esm/lib/utils/get-draco-schema.js +0 -48
- package/dist/esm/lib/utils/get-draco-schema.js.map +0 -1
- package/dist/esm/lib/utils/version.js +0 -2
- package/dist/esm/lib/utils/version.js.map +0 -1
- package/dist/esm/workers/draco-worker.js +0 -4
- package/dist/esm/workers/draco-worker.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/utils/version.ts"],"names":["VERSION"],"mappings":";;;;;;AAGO,IAAMA,OAAO,GAAG,mBAAuB,WAAvB,aAAmD,QAAnE","sourcesContent":["// Version constant cannot be imported, it needs to correspond to the build version of **this** module.\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nexport const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n"],"file":"version.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/workers/draco-worker.ts"],"names":["DracoLoader"],"mappings":";;AAAA;;AACA;;AAEA,qCAAmBA,kBAAnB","sourcesContent":["import {createLoaderWorker} from '@loaders.gl/loader-utils';\nimport {DracoLoader} from '../index';\n\ncreateLoaderWorker(DracoLoader);\n"],"file":"draco-worker.js"}
|
package/dist/esm/bundle.js
DELETED
package/dist/esm/bundle.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|
package/dist/esm/draco-loader.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { VERSION } from './lib/utils/version';
|
|
2
|
-
const DEFAULT_DRACO_OPTIONS = {
|
|
3
|
-
draco: {
|
|
4
|
-
decoderType: typeof WebAssembly === 'object' ? 'wasm' : 'js',
|
|
5
|
-
libraryPath: 'libs/',
|
|
6
|
-
extraAttributes: {},
|
|
7
|
-
attributeNameEntry: undefined
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
export const DracoLoader = {
|
|
11
|
-
name: 'Draco',
|
|
12
|
-
id: 'draco',
|
|
13
|
-
module: 'draco',
|
|
14
|
-
shapes: ['mesh'],
|
|
15
|
-
version: VERSION,
|
|
16
|
-
worker: true,
|
|
17
|
-
extensions: ['drc'],
|
|
18
|
-
mimeTypes: ['application/octet-stream'],
|
|
19
|
-
binary: true,
|
|
20
|
-
tests: ['DRACO'],
|
|
21
|
-
options: DEFAULT_DRACO_OPTIONS
|
|
22
|
-
};
|
|
23
|
-
export const _TypecheckDracoLoader = DracoLoader;
|
|
24
|
-
//# sourceMappingURL=draco-loader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/draco-loader.ts"],"names":["VERSION","DEFAULT_DRACO_OPTIONS","draco","decoderType","WebAssembly","libraryPath","extraAttributes","attributeNameEntry","undefined","DracoLoader","name","id","module","shapes","version","worker","extensions","mimeTypes","binary","tests","options","_TypecheckDracoLoader"],"mappings":"AAGA,SAAQA,OAAR,QAAsB,qBAAtB;AAWA,MAAMC,qBAAyC,GAAG;AAChDC,EAAAA,KAAK,EAAE;AACLC,IAAAA,WAAW,EAAE,OAAOC,WAAP,KAAuB,QAAvB,GAAkC,MAAlC,GAA2C,IADnD;AAELC,IAAAA,WAAW,EAAE,OAFR;AAGLC,IAAAA,eAAe,EAAE,EAHZ;AAILC,IAAAA,kBAAkB,EAAEC;AAJf;AADyC,CAAlD;AAYA,OAAO,MAAMC,WAAW,GAAG;AACzBC,EAAAA,IAAI,EAAE,OADmB;AAEzBC,EAAAA,EAAE,EAAE,OAFqB;AAGzBC,EAAAA,MAAM,EAAE,OAHiB;AAIzBC,EAAAA,MAAM,EAAE,CAAC,MAAD,CAJiB;AAKzBC,EAAAA,OAAO,EAAEd,OALgB;AAMzBe,EAAAA,MAAM,EAAE,IANiB;AAOzBC,EAAAA,UAAU,EAAE,CAAC,KAAD,CAPa;AAQzBC,EAAAA,SAAS,EAAE,CAAC,0BAAD,CARc;AASzBC,EAAAA,MAAM,EAAE,IATiB;AAUzBC,EAAAA,KAAK,EAAE,CAAC,OAAD,CAVkB;AAWzBC,EAAAA,OAAO,EAAEnB;AAXgB,CAApB;AAcP,OAAO,MAAMoB,qBAA6B,GAAGZ,WAAtC","sourcesContent":["import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {DracoParseOptions} from './lib/draco-parser';\n// import type {DracoMeshData} from './types';\nimport {VERSION} from './lib/utils/version';\n\nexport type DracoLoaderOptions = LoaderOptions & {\n draco?: DracoParseOptions & {\n decoderType?: 'wasm' | 'js';\n libraryPath?: string;\n extraAttributes?;\n attributeNameEntry?: string;\n };\n};\n\nconst DEFAULT_DRACO_OPTIONS: DracoLoaderOptions = {\n draco: {\n decoderType: typeof WebAssembly === 'object' ? 'wasm' : 'js', // 'js' for IE11\n libraryPath: 'libs/',\n extraAttributes: {},\n attributeNameEntry: undefined\n }\n};\n\n/**\n * Worker loader for Draco3D compressed geometries\n */\nexport const DracoLoader = {\n name: 'Draco',\n id: 'draco',\n module: 'draco',\n shapes: ['mesh'],\n version: VERSION,\n worker: true,\n extensions: ['drc'],\n mimeTypes: ['application/octet-stream'],\n binary: true,\n tests: ['DRACO'],\n options: DEFAULT_DRACO_OPTIONS\n};\n\nexport const _TypecheckDracoLoader: Loader = DracoLoader;\n"],"file":"draco-loader.js"}
|
package/dist/esm/draco-writer.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import DRACOBuilder from './lib/draco-builder';
|
|
2
|
-
import { loadDracoEncoderModule } from './lib/draco-module-loader';
|
|
3
|
-
import { VERSION } from './lib/utils/version';
|
|
4
|
-
const DEFAULT_DRACO_OPTIONS = {
|
|
5
|
-
pointcloud: false,
|
|
6
|
-
attributeNameEntry: 'name'
|
|
7
|
-
};
|
|
8
|
-
export const DracoWriter = {
|
|
9
|
-
name: 'DRACO',
|
|
10
|
-
id: 'draco',
|
|
11
|
-
module: 'draco',
|
|
12
|
-
version: VERSION,
|
|
13
|
-
extensions: ['drc'],
|
|
14
|
-
encode,
|
|
15
|
-
options: {
|
|
16
|
-
draco: DEFAULT_DRACO_OPTIONS
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
async function encode(data, options = {}) {
|
|
21
|
-
const {
|
|
22
|
-
draco
|
|
23
|
-
} = await loadDracoEncoderModule(options);
|
|
24
|
-
const dracoBuilder = new DRACOBuilder(draco);
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
return dracoBuilder.encodeSync(data, options.draco);
|
|
28
|
-
} finally {
|
|
29
|
-
dracoBuilder.destroy();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=draco-writer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/draco-writer.ts"],"names":["DRACOBuilder","loadDracoEncoderModule","VERSION","DEFAULT_DRACO_OPTIONS","pointcloud","attributeNameEntry","DracoWriter","name","id","module","version","extensions","encode","options","draco","data","dracoBuilder","encodeSync","destroy"],"mappings":"AAGA,OAAOA,YAAP,MAAyB,qBAAzB;AACA,SAAQC,sBAAR,QAAqC,2BAArC;AACA,SAAQC,OAAR,QAAsB,qBAAtB;AAIA,MAAMC,qBAAqB,GAAG;AAC5BC,EAAAA,UAAU,EAAE,KADgB;AAE5BC,EAAAA,kBAAkB,EAAE;AAFQ,CAA9B;AAcA,OAAO,MAAMC,WAAmB,GAAG;AACjCC,EAAAA,IAAI,EAAE,OAD2B;AAEjCC,EAAAA,EAAE,EAAE,OAF6B;AAGjCC,EAAAA,MAAM,EAAE,OAHyB;AAIjCC,EAAAA,OAAO,EAAER,OAJwB;AAKjCS,EAAAA,UAAU,EAAE,CAAC,KAAD,CALqB;AAMjCC,EAAAA,MANiC;AAOjCC,EAAAA,OAAO,EAAE;AACPC,IAAAA,KAAK,EAAEX;AADA;AAPwB,CAA5B;;AAYP,eAAeS,MAAf,CACEG,IADF,EAEEF,OAAqC,GAAG,EAF1C,EAGwB;AAEtB,QAAM;AAACC,IAAAA;AAAD,MAAU,MAAMb,sBAAsB,CAACY,OAAD,CAA5C;AACA,QAAMG,YAAY,GAAG,IAAIhB,YAAJ,CAAiBc,KAAjB,CAArB;;AAEA,MAAI;AACF,WAAOE,YAAY,CAACC,UAAb,CAAwBF,IAAxB,EAA8BF,OAAO,CAACC,KAAtC,CAAP;AACD,GAFD,SAEU;AACRE,IAAAA,YAAY,CAACE,OAAb;AACD;AACF","sourcesContent":["import type {Writer} from '@loaders.gl/loader-utils';\nimport type {DracoMesh} from './lib/draco-types';\nimport type {DracoBuildOptions} from './lib/draco-builder';\nimport DRACOBuilder from './lib/draco-builder';\nimport {loadDracoEncoderModule} from './lib/draco-module-loader';\nimport {VERSION} from './lib/utils/version';\n\nexport type DracoWriterOptions = DracoBuildOptions & {};\n\nconst DEFAULT_DRACO_OPTIONS = {\n pointcloud: false, // Set to true if pointcloud (mode: 0, no indices)\n attributeNameEntry: 'name'\n // Draco Compression Parameters\n // method: 'MESH_EDGEBREAKER_ENCODING',\n // speed: [5, 5],\n // quantization: {\n // POSITION: 10\n // }\n};\n\n/**\n * Exporter for Draco3D compressed geometries\n */\nexport const DracoWriter: Writer = {\n name: 'DRACO',\n id: 'draco',\n module: 'draco',\n version: VERSION,\n extensions: ['drc'],\n encode,\n options: {\n draco: DEFAULT_DRACO_OPTIONS\n }\n};\n\nasync function encode(\n data: DracoMesh,\n options: {draco?: DracoWriterOptions} = {}\n): Promise<ArrayBuffer> {\n // Dynamically load draco\n const {draco} = await loadDracoEncoderModule(options);\n const dracoBuilder = new DRACOBuilder(draco);\n\n try {\n return dracoBuilder.encodeSync(data, options.draco);\n } finally {\n dracoBuilder.destroy();\n }\n}\n"],"file":"draco-writer.js"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export let draco_GeometryAttribute_Type;
|
|
2
|
-
|
|
3
|
-
(function (draco_GeometryAttribute_Type) {
|
|
4
|
-
draco_GeometryAttribute_Type[draco_GeometryAttribute_Type["draco_GeometryAttribute::INVALID"] = 0] = "draco_GeometryAttribute::INVALID";
|
|
5
|
-
draco_GeometryAttribute_Type[draco_GeometryAttribute_Type["draco_GeometryAttribute::POSITION"] = 1] = "draco_GeometryAttribute::POSITION";
|
|
6
|
-
draco_GeometryAttribute_Type[draco_GeometryAttribute_Type["draco_GeometryAttribute::NORMAL"] = 2] = "draco_GeometryAttribute::NORMAL";
|
|
7
|
-
draco_GeometryAttribute_Type[draco_GeometryAttribute_Type["draco_GeometryAttribute::COLOR"] = 3] = "draco_GeometryAttribute::COLOR";
|
|
8
|
-
draco_GeometryAttribute_Type[draco_GeometryAttribute_Type["draco_GeometryAttribute::TEX_COORD"] = 4] = "draco_GeometryAttribute::TEX_COORD";
|
|
9
|
-
draco_GeometryAttribute_Type[draco_GeometryAttribute_Type["draco_GeometryAttribute::GENERIC"] = 5] = "draco_GeometryAttribute::GENERIC";
|
|
10
|
-
})(draco_GeometryAttribute_Type || (draco_GeometryAttribute_Type = {}));
|
|
11
|
-
|
|
12
|
-
export let draco_EncodedGeometryType;
|
|
13
|
-
|
|
14
|
-
(function (draco_EncodedGeometryType) {
|
|
15
|
-
draco_EncodedGeometryType[draco_EncodedGeometryType["draco::INVALID_GEOMETRY_TYPE"] = 0] = "draco::INVALID_GEOMETRY_TYPE";
|
|
16
|
-
draco_EncodedGeometryType[draco_EncodedGeometryType["draco::POINT_CLOUD"] = 1] = "draco::POINT_CLOUD";
|
|
17
|
-
draco_EncodedGeometryType[draco_EncodedGeometryType["draco::TRIANGULAR_MESH"] = 2] = "draco::TRIANGULAR_MESH";
|
|
18
|
-
})(draco_EncodedGeometryType || (draco_EncodedGeometryType = {}));
|
|
19
|
-
|
|
20
|
-
export let draco_DataType;
|
|
21
|
-
|
|
22
|
-
(function (draco_DataType) {
|
|
23
|
-
draco_DataType[draco_DataType["draco::DT_INVALID"] = 0] = "draco::DT_INVALID";
|
|
24
|
-
draco_DataType[draco_DataType["draco::DT_INT8"] = 1] = "draco::DT_INT8";
|
|
25
|
-
draco_DataType[draco_DataType["draco::DT_UINT8"] = 2] = "draco::DT_UINT8";
|
|
26
|
-
draco_DataType[draco_DataType["draco::DT_INT16"] = 3] = "draco::DT_INT16";
|
|
27
|
-
draco_DataType[draco_DataType["draco::DT_UINT16"] = 4] = "draco::DT_UINT16";
|
|
28
|
-
draco_DataType[draco_DataType["draco::DT_INT32"] = 5] = "draco::DT_INT32";
|
|
29
|
-
draco_DataType[draco_DataType["draco::DT_UINT32"] = 6] = "draco::DT_UINT32";
|
|
30
|
-
draco_DataType[draco_DataType["draco::DT_INT64"] = 7] = "draco::DT_INT64";
|
|
31
|
-
draco_DataType[draco_DataType["draco::DT_UINT64"] = 8] = "draco::DT_UINT64";
|
|
32
|
-
draco_DataType[draco_DataType["draco::DT_FLOAT32"] = 9] = "draco::DT_FLOAT32";
|
|
33
|
-
draco_DataType[draco_DataType["draco::DT_FLOAT64"] = 10] = "draco::DT_FLOAT64";
|
|
34
|
-
draco_DataType[draco_DataType["draco::DT_BOOL"] = 11] = "draco::DT_BOOL";
|
|
35
|
-
draco_DataType[draco_DataType["draco::DT_TYPES_COUNT"] = 12] = "draco::DT_TYPES_COUNT";
|
|
36
|
-
})(draco_DataType || (draco_DataType = {}));
|
|
37
|
-
|
|
38
|
-
export let draco_StatusCode;
|
|
39
|
-
|
|
40
|
-
(function (draco_StatusCode) {
|
|
41
|
-
draco_StatusCode[draco_StatusCode["draco_Status::OK"] = 0] = "draco_Status::OK";
|
|
42
|
-
draco_StatusCode[draco_StatusCode["draco_Status::DRACO_ERROR"] = 1] = "draco_Status::DRACO_ERROR";
|
|
43
|
-
draco_StatusCode[draco_StatusCode["draco_Status::IO_ERROR"] = 2] = "draco_Status::IO_ERROR";
|
|
44
|
-
draco_StatusCode[draco_StatusCode["draco_Status::INVALID_PARAMETER"] = 3] = "draco_Status::INVALID_PARAMETER";
|
|
45
|
-
draco_StatusCode[draco_StatusCode["draco_Status::UNSUPPORTED_VERSION"] = 4] = "draco_Status::UNSUPPORTED_VERSION";
|
|
46
|
-
draco_StatusCode[draco_StatusCode["draco_Status::UNKNOWN_VERSION"] = 5] = "draco_Status::UNKNOWN_VERSION";
|
|
47
|
-
})(draco_StatusCode || (draco_StatusCode = {}));
|
|
48
|
-
//# sourceMappingURL=draco3d-types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/draco3d/draco3d-types.ts"],"names":["draco_GeometryAttribute_Type","draco_EncodedGeometryType","draco_DataType","draco_StatusCode"],"mappings":"AAiBA,WAAYA,4BAAZ;;WAAYA,4B;AAAAA,EAAAA,4B,CAAAA,4B;AAAAA,EAAAA,4B,CAAAA,4B;AAAAA,EAAAA,4B,CAAAA,4B;AAAAA,EAAAA,4B,CAAAA,4B;AAAAA,EAAAA,4B,CAAAA,4B;AAAAA,EAAAA,4B,CAAAA,4B;GAAAA,4B,KAAAA,4B;;AAUZ,WAAYC,yBAAZ;;WAAYA,yB;AAAAA,EAAAA,yB,CAAAA,yB;AAAAA,EAAAA,yB,CAAAA,yB;AAAAA,EAAAA,yB,CAAAA,yB;GAAAA,yB,KAAAA,yB;;AAOZ,WAAYC,cAAZ;;WAAYA,c;AAAAA,EAAAA,c,CAAAA,c;AAAAA,EAAAA,c,CAAAA,c;AAAAA,EAAAA,c,CAAAA,c;AAAAA,EAAAA,c,CAAAA,c;AAAAA,EAAAA,c,CAAAA,c;AAAAA,EAAAA,c,CAAAA,c;AAAAA,EAAAA,c,CAAAA,c;AAAAA,EAAAA,c,CAAAA,c;AAAAA,EAAAA,c,CAAAA,c;AAAAA,EAAAA,c,CAAAA,c;AAAAA,EAAAA,c,CAAAA,c;AAAAA,EAAAA,c,CAAAA,c;AAAAA,EAAAA,c,CAAAA,c;GAAAA,c,KAAAA,c;;AAiBZ,WAAYC,gBAAZ;;WAAYA,gB;AAAAA,EAAAA,gB,CAAAA,gB;AAAAA,EAAAA,gB,CAAAA,gB;AAAAA,EAAAA,gB,CAAAA,gB;AAAAA,EAAAA,gB,CAAAA,gB;AAAAA,EAAAA,gB,CAAAA,gB;AAAAA,EAAAA,gB,CAAAA,gB;GAAAA,gB,KAAAA,gB","sourcesContent":["// A set of typescript types manually adapted from the Draco web IDL\n// Draco JS is a bit tricky to work with due to the C++ emscripten code base\n// sparse documentation, so these types provide an extra safety net.\n\n// Typescript defs adapted from draco3d emscripten IDL\n// https://raw.githubusercontent.com/google/draco/master/src/draco/javascript/emscripten/draco_web_decoder.idl\n// Interface exposed to emscripten's WebIDL Binder.\n// http://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.html\n\n/* eslint-disable camelcase */\n\n/** Draco3D untyped memory pointer */\ntype VoidPtr = any;\n\n// DRACO WEB DECODER IDL\n\n/** Draco3D geometry attribute type */\nexport enum draco_GeometryAttribute_Type {\n 'draco_GeometryAttribute::INVALID',\n 'draco_GeometryAttribute::POSITION',\n 'draco_GeometryAttribute::NORMAL',\n 'draco_GeometryAttribute::COLOR',\n 'draco_GeometryAttribute::TEX_COORD',\n 'draco_GeometryAttribute::GENERIC'\n}\n\n/** Draco3D encoded geometry type */\nexport enum draco_EncodedGeometryType {\n 'draco::INVALID_GEOMETRY_TYPE',\n 'draco::POINT_CLOUD',\n 'draco::TRIANGULAR_MESH'\n}\n\n/** Draco3D data type */\nexport enum draco_DataType {\n 'draco::DT_INVALID',\n 'draco::DT_INT8',\n 'draco::DT_UINT8',\n 'draco::DT_INT16',\n 'draco::DT_UINT16',\n 'draco::DT_INT32',\n 'draco::DT_UINT32',\n 'draco::DT_INT64',\n 'draco::DT_UINT64',\n 'draco::DT_FLOAT32',\n 'draco::DT_FLOAT64',\n 'draco::DT_BOOL',\n 'draco::DT_TYPES_COUNT'\n}\n\n/** Draco3D status code */\nexport enum draco_StatusCode {\n 'draco_Status::OK',\n 'draco_Status::DRACO_ERROR',\n 'draco_Status::IO_ERROR',\n 'draco_Status::INVALID_PARAMETER',\n 'draco_Status::UNSUPPORTED_VERSION',\n 'draco_Status::UNKNOWN_VERSION'\n}\n\n/** Draco3D decoder buffer allocated on emscripten heap */\nexport declare class DecoderBuffer {\n constructor();\n Init(data: Int8Array, data_size: number): void;\n}\n\n/** Draco3D attribute transform data */\nexport declare class AttributeTransformData {\n constructor();\n transform_type(): number;\n}\n\n/** Draco3D geometry attribute */\nexport declare class GeometryAttribute {\n constructor();\n}\n\n/** Draco3D point attribute */\nexport declare class PointAttribute {\n ptr: VoidPtr;\n\n constructor();\n size(): number;\n GetAttributeTransformData(): AttributeTransformData;\n\n // From GeometryAttribute\n attribute_type(): number;\n data_type(): number;\n num_components(): number;\n normalized(): boolean;\n byte_stride(): number;\n byte_offset(): number;\n unique_id(): number;\n}\n\n/** Draco3D attribute transform */\nexport declare class AttributeQuantizationTransform {\n constructor();\n InitFromAttribute(att: PointAttribute): boolean;\n quantization_bits(): number;\n min_value(axis: number): number;\n range(): number;\n}\n\n/** Draco3D attribute transform */\nexport declare class AttributeOctahedronTransform {\n constructor();\n InitFromAttribute(att: PointAttribute): boolean;\n quantization_bits(): number;\n}\n\n/** Draco3D point cloud */\nexport declare class PointCloud {\n ptr: VoidPtr;\n\n constructor();\n num_attributes(): number;\n num_points(): number;\n}\n\n/** Draco3D mesh */\nexport declare class Mesh extends PointCloud {\n constructor();\n num_faces(): number;\n}\n\n/** Draco3D metadata */\nexport declare class Metadata {\n ptr: VoidPtr;\n\n constructor();\n}\n\n/** Draco3D status */\nexport declare class Status {\n constructor();\n code(): draco_StatusCode;\n ok(): boolean;\n error_msg(): string;\n}\n\n/** Draco3D Float32Array allocated on the emscripten heap */\nexport declare class DracoFloat32Array {\n constructor();\n GetValue(index: number): number;\n size(): number;\n}\n\n/** Draco3D Int8Array allocated on the emscripten heap */\nexport declare class DracoInt8Array {\n constructor();\n GetValue(index: number): number;\n size(): number;\n}\n\n/** Draco3D Uint8Array allocated on the emscripten heap */\nexport declare class DracoUInt8Array {\n GetValue(index: number): number;\n size(): number;\n}\n\n/** Draco3D Int16Array allocated on the emscripten heap */\nexport declare class DracoInt16Array {\n constructor();\n GetValue(index: number): number;\n size(): number;\n}\n\n/** Draco3D Uint16Array allocated on the emscripten heap */\nexport declare class DracoUInt16Array {\n constructor();\n GetValue(index: number): number;\n size(): number;\n}\n\n/** Draco3D Int32Array allocated on the emscripten heap */\nexport declare class DracoInt32Array {\n constructor();\n GetValue(index: number): number;\n size(): number;\n}\n\n/** Draco3D Uint32Array allocated on the emscripten heap */\nexport declare class DracoUInt32Array {\n constructor();\n GetValue(index: number): number;\n size(): number;\n}\n\n/** Draco3D metadata querier */\nexport declare class MetadataQuerier {\n constructor();\n\n HasEntry(metadata: Metadata, entry_name: string): string;\n GetIntEntry(metadata: Metadata, entry_name: string);\n GetIntEntryArray(metadata: Metadata, entry_name: string, out_values: DracoInt32Array);\n GetDoubleEntry(metadata: Metadata, entry_name: string): number;\n GetStringEntry(metadata: Metadata, entry_name: string): string;\n\n NumEntries(metadata: Metadata): number;\n GetEntryName(metadata: Metadata, entry_id: number): string;\n}\n\n/**\n * Draco3D Decoder class\n */\nexport declare class Decoder {\n constructor();\n\n GetEncodedGeometryType(in_buffer: DecoderBuffer): draco_EncodedGeometryType;\n\n DecodeBufferToPointCloud(in_buffer: DecoderBuffer, out_point_cloud: PointCloud): Status;\n DecodeBufferToMesh(in_buffer: DecoderBuffer, out_mesh: Mesh): Status;\n\n GetAttributeId(pc: PointCloud, type: draco_GeometryAttribute_Type): number;\n GetAttributeIdByName(pc: PointCloud, name: string): number;\n GetAttributeIdByMetadataEntry(pc: PointCloud, name: string, value: string): number;\n\n GetAttribute(pc: PointCloud, att_id: number): PointAttribute;\n GetAttributeByUniqueId(pc: PointCloud, unique_id: number): PointAttribute;\n\n GetMetadata(pc: PointCloud): Metadata;\n GetAttributeMetadata(pc: PointCloud, att_id: number): Metadata;\n\n GetFaceFromMesh(m: Mesh, face_id: number, out_values: DracoInt32Array): boolean;\n GetTriangleStripsFromMesh(m: Mesh, strip_values: DracoInt32Array);\n\n GetTrianglesUInt16Array(m: Mesh, out_size: number, out_values: VoidPtr): boolean;\n GetTrianglesUInt32Array(m: Mesh, out_size: number, out_values: VoidPtr): boolean;\n\n GetAttributeFloat(pa: PointAttribute, att_index: number, out_values: DracoFloat32Array): boolean;\n\n GetAttributeFloatForAllPoints(\n pc: PointCloud,\n pa: PointAttribute,\n out_values: DracoFloat32Array\n ): boolean;\n\n // Deprecated, use GetAttributeInt32ForAllPoints instead.\n GetAttributeIntForAllPoints(\n pc: PointCloud,\n pa: PointAttribute,\n out_values: DracoInt32Array\n ): boolean;\n\n GetAttributeInt8ForAllPoints(\n pc: PointCloud,\n pa: PointAttribute,\n out_values: DracoInt8Array\n ): boolean;\n GetAttributeUInt8ForAllPoints(\n pc: PointCloud,\n pa: PointAttribute,\n out_values: DracoUInt8Array\n ): boolean;\n GetAttributeInt16ForAllPoints(\n pc: PointCloud,\n pa: PointAttribute,\n out_values: DracoInt16Array\n ): boolean;\n GetAttributeUInt16ForAllPoints(\n pc: PointCloud,\n pa: PointAttribute,\n out_values: DracoUInt16Array\n ): boolean;\n GetAttributeInt32ForAllPoints(\n pc: PointCloud,\n pa: PointAttribute,\n out_values: DracoInt32Array\n ): boolean;\n GetAttributeUInt32ForAllPoints(\n pc: PointCloud,\n pa: PointAttribute,\n out_values: DracoUInt32Array\n ): boolean;\n\n GetAttributeDataArrayForAllPoints(\n pc: PointCloud,\n pa: PointAttribute,\n data_type: draco_DataType,\n out_size: number,\n out_values: VoidPtr\n ): boolean;\n\n SkipAttributeTransform(att_type: draco_GeometryAttribute_Type): void;\n}\n\n// DRACO WEB ENCODER IDL\n\n/** Draco3D metadata builder */\nexport declare class MetadataBuilder {\n constructor();\n AddStringEntry(metadata: Metadata, entry_name: string, entry_value: string);\n AddIntEntry(metadata: Metadata, entry_name: string, entry_value: number);\n AddDoubleEntry(metadata: Metadata, entry_name: string, entry_value: number);\n AddIntEntryArray(\n metadata: Metadata,\n entry_name: string,\n entry_value: Int32Array,\n num_values: number\n );\n}\n\n/** Draco3D point cloud builder */\n\nexport declare class PointCloudBuilder {\n constructor();\n PointCloudBuilder(): void;\n AddFloatAttribute(\n pc: PointCloud,\n type: draco_GeometryAttribute_Type,\n num_vertices: number,\n num_components: number,\n att_values: Float32Array\n );\n AddInt8Attribute(\n pc: PointCloud,\n type: draco_GeometryAttribute_Type,\n num_vertices: number,\n num_components: number,\n att_values: Int8Array\n );\n AddUInt8Attribute(\n pc: PointCloud,\n type: draco_GeometryAttribute_Type,\n num_vertices: number,\n num_components: number,\n att_values: Uint8Array\n );\n AddInt16Attribute(\n pc: PointCloud,\n type: draco_GeometryAttribute_Type,\n num_vertices: number,\n num_components: number,\n att_values: Int16Array\n );\n AddUInt16Attribute(\n pc: PointCloud,\n type: draco_GeometryAttribute_Type,\n num_vertices: number,\n num_components: number,\n att_values: Uint16Array\n );\n AddInt32Attribute(\n pc: PointCloud,\n type: draco_GeometryAttribute_Type,\n num_vertices: number,\n num_components: number,\n att_values: Int32Array\n );\n AddUInt32Attribute(\n pc: PointCloud,\n type: draco_GeometryAttribute_Type,\n num_vertices: number,\n num_components: number,\n att_values: Uint32Array\n );\n\n AddMetadata(pc: PointCloud, metadata: Metadata): boolean;\n SetMetadataForAttribute(pc: PointCloud, attribute_id: number, metadata: Metadata);\n}\n\n/** Draco3D mesh builder */\nexport declare class MeshBuilder extends PointCloudBuilder {\n constructor();\n AddFacesToMesh(mesh: Mesh, num_faces: number, faces: number[]): boolean;\n}\n\n/** Draco3D encoder */\nexport declare class Encoder {\n constructor();\n Encoder(): void;\n SetEncodingMethod(method: number): void;\n SetAttributeQuantization(type: draco_GeometryAttribute_Type, quantization_bits: number);\n SetAttributeExplicitQuantization(\n type: draco_GeometryAttribute_Type,\n quantization_bits: number,\n num_components: number,\n origin: number[],\n range: number\n );\n SetSpeedOptions(encoding_speed: number, decoding_speed: number): void;\n SetTrackEncodedProperties(flag: boolean): void;\n\n EncodeMeshToDracoBuffer(mesh: Mesh, encoded_data: DracoInt8Array);\n EncodePointCloudToDracoBuffer(\n pc: PointCloud,\n deduplicate_values: boolean,\n encoded_data: DracoInt8Array\n );\n\n // Returns the number of encoded points or faces from the last Encode\n // operation. Returns 0 if SetTrackEncodedProperties was not set to true.\n GetNumberOfEncodedPoints(): number;\n GetNumberOfEncodedFaces(): number;\n}\n\n/** Draco3D expert encoder */\nexport declare class ExpertEncoder {\n constructor();\n ExpertEncoder(pc: PointCloud): void;\n SetEncodingMethod(method: number): void;\n SetAttributeQuantization(att_id: number, quantization_bits: number);\n SetAttributeExplicitQuantization(\n att_id: number,\n quantization_bits: number,\n num_components: number,\n origin: number[],\n range: number\n );\n SetSpeedOptions(encoding_speed: number, decoding_speed: number): void;\n SetTrackEncodedProperties(flag: boolean): void;\n\n EncodeToDracoBuffer(deduplicate_values: boolean, encoded_data: DracoInt8Array);\n\n // Returns the number of encoded points or faces from the last Encode\n // operation. Returns 0 if SetTrackEncodedProperties was not set to true.\n GetNumberOfEncodedPoints(): number;\n GetNumberOfEncodedFaces(): number;\n}\n\n/** Draco3D module interface */\nexport interface Draco3D {\n // ENUMS\n\n // draco_EncodedGeometryType\n readonly INVALID_GEOMETRY_TYPE: draco_EncodedGeometryType;\n readonly POINT_CLOUD: draco_EncodedGeometryType;\n readonly TRIANGULAR_MESH: draco_EncodedGeometryType;\n\n // enum draco_GeometryAttribute_Type\n readonly INVALID: draco_GeometryAttribute_Type;\n readonly POSITION: draco_GeometryAttribute_Type;\n readonly NORMAL: draco_GeometryAttribute_Type;\n readonly COLOR: draco_GeometryAttribute_Type;\n readonly TEX_COORD: draco_GeometryAttribute_Type;\n readonly GENERIC: draco_GeometryAttribute_Type;\n\n // enum draco_DataType\n readonly DT_INVALID: draco_DataType;\n readonly DT_INT8: draco_DataType;\n readonly DT_UINT8: draco_DataType;\n readonly DT_INT16: draco_DataType;\n readonly DT_UINT16: draco_DataType;\n readonly DT_INT32: draco_DataType;\n readonly DT_UINT32: draco_DataType;\n readonly DT_INT64: draco_DataType;\n readonly DT_UINT64: draco_DataType;\n readonly DT_FLOAT32: draco_DataType;\n readonly DT_FLOAT64: draco_DataType;\n readonly DT_BOOL: draco_DataType;\n readonly DT_TYPES_COUNT: draco_DataType;\n\n readonly Mesh: typeof Mesh;\n readonly PointCloud: typeof PointCloud;\n readonly Metadata: typeof Metadata;\n\n readonly Encoder: typeof Encoder;\n readonly MeshBuilder: typeof MeshBuilder;\n readonly MetadataBuilder: typeof MetadataBuilder;\n\n readonly MetadataQuerier: typeof MetadataQuerier;\n readonly Decoder: typeof Decoder;\n readonly DecoderBuffer: typeof DecoderBuffer;\n\n readonly DracoFloat32Array: typeof DracoFloat32Array;\n readonly DracoInt8Array: typeof DracoInt8Array;\n readonly DracoUInt8Array: typeof DracoUInt8Array;\n readonly DracoInt16Array: typeof DracoInt16Array;\n readonly DracoUInt16Array: typeof DracoUInt16Array;\n readonly DracoInt32Array: typeof DracoInt32Array;\n readonly DracoUInt32Array: typeof DracoUInt32Array;\n\n readonly AttributeQuantizationTransform: typeof AttributeQuantizationTransform;\n\n // createEncoderModule(): Encoder;\n // createDecoderModule(): Decoder;\n destroy(resource: any): void;\n _malloc(byteLength: number): number;\n _free(ptr: number): void;\n\n HEAPF32: {\n buffer: ArrayBuffer;\n };\n}\n"],"file":"draco3d-types.js"}
|
package/dist/esm/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { DracoLoader as DracoWorkerLoader } from './draco-loader';
|
|
2
|
-
import DracoParser from './lib/draco-parser';
|
|
3
|
-
import { loadDracoDecoderModule } from './lib/draco-module-loader';
|
|
4
|
-
export { DracoWriter } from './draco-writer';
|
|
5
|
-
export { DracoWorkerLoader };
|
|
6
|
-
export const DracoLoader = { ...DracoWorkerLoader,
|
|
7
|
-
parse
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
async function parse(arrayBuffer, options) {
|
|
11
|
-
const {
|
|
12
|
-
draco
|
|
13
|
-
} = await loadDracoDecoderModule(options);
|
|
14
|
-
const dracoParser = new DracoParser(draco);
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
return dracoParser.parseSync(arrayBuffer, options === null || options === void 0 ? void 0 : options.draco);
|
|
18
|
-
} finally {
|
|
19
|
-
dracoParser.destroy();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const _TypecheckDracoLoader = DracoLoader;
|
|
24
|
-
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":["DracoLoader","DracoWorkerLoader","DracoParser","loadDracoDecoderModule","DracoWriter","parse","arrayBuffer","options","draco","dracoParser","parseSync","destroy","_TypecheckDracoLoader"],"mappings":"AAGA,SAAQA,WAAW,IAAIC,iBAAvB,QAA+C,gBAA/C;AACA,OAAOC,WAAP,MAAwB,oBAAxB;AACA,SAAQC,sBAAR,QAAqC,2BAArC;AASA,SAAQC,WAAR,QAA0B,gBAA1B;AAKA,SAAQH,iBAAR;AAKA,OAAO,MAAMD,WAAW,GAAG,EACzB,GAAGC,iBADsB;AAEzBI,EAAAA;AAFyB,CAApB;;AAKP,eAAeA,KAAf,CAAqBC,WAArB,EAA+CC,OAA/C,EAAiG;AAC/F,QAAM;AAACC,IAAAA;AAAD,MAAU,MAAML,sBAAsB,CAACI,OAAD,CAA5C;AACA,QAAME,WAAW,GAAG,IAAIP,WAAJ,CAAgBM,KAAhB,CAApB;;AACA,MAAI;AACF,WAAOC,WAAW,CAACC,SAAZ,CAAsBJ,WAAtB,EAAmCC,OAAnC,aAAmCA,OAAnC,uBAAmCA,OAAO,CAAEC,KAA5C,CAAP;AACD,GAFD,SAEU;AACRC,IAAAA,WAAW,CAACE,OAAZ;AACD;AACF;;AAGD,OAAO,MAAMC,qBAAuC,GAAGZ,WAAhD","sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {DracoMesh, DracoLoaderData} from './lib/draco-types';\nimport type {DracoLoaderOptions} from './draco-loader';\nimport {DracoLoader as DracoWorkerLoader} from './draco-loader';\nimport DracoParser from './lib/draco-parser';\nimport {loadDracoDecoderModule} from './lib/draco-module-loader';\n\n// Draco data types\n\nexport type {DracoMesh, DracoLoaderData};\n\n// Draco Writer\n\nexport type {DracoWriterOptions} from './draco-writer';\nexport {DracoWriter} from './draco-writer';\n\n// Draco Loader\n\nexport type {DracoLoaderOptions};\nexport {DracoWorkerLoader};\n\n/**\n * Loader for Draco3D compressed geometries\n */\nexport const DracoLoader = {\n ...DracoWorkerLoader,\n parse\n};\n\nasync function parse(arrayBuffer: ArrayBuffer, options?: DracoLoaderOptions): Promise<DracoMesh> {\n const {draco} = await loadDracoDecoderModule(options);\n const dracoParser = new DracoParser(draco);\n try {\n return dracoParser.parseSync(arrayBuffer, options?.draco);\n } finally {\n dracoParser.destroy();\n }\n}\n\n// TYPE TESTS - TODO find a better way than exporting junk\nexport const _TypecheckDracoLoader: LoaderWithParser = DracoLoader;\n"],"file":"index.js"}
|
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
const GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {
|
|
3
|
-
POSITION: 'POSITION',
|
|
4
|
-
NORMAL: 'NORMAL',
|
|
5
|
-
COLOR_0: 'COLOR',
|
|
6
|
-
TEXCOORD_0: 'TEX_COORD'
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const noop = () => {};
|
|
10
|
-
|
|
11
|
-
export default class DracoBuilder {
|
|
12
|
-
constructor(draco) {
|
|
13
|
-
_defineProperty(this, "draco", void 0);
|
|
14
|
-
|
|
15
|
-
_defineProperty(this, "dracoEncoder", void 0);
|
|
16
|
-
|
|
17
|
-
_defineProperty(this, "dracoMeshBuilder", void 0);
|
|
18
|
-
|
|
19
|
-
_defineProperty(this, "dracoMetadataBuilder", void 0);
|
|
20
|
-
|
|
21
|
-
_defineProperty(this, "log", void 0);
|
|
22
|
-
|
|
23
|
-
this.draco = draco;
|
|
24
|
-
this.dracoEncoder = new this.draco.Encoder();
|
|
25
|
-
this.dracoMeshBuilder = new this.draco.MeshBuilder();
|
|
26
|
-
this.dracoMetadataBuilder = new this.draco.MetadataBuilder();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
destroy() {
|
|
30
|
-
this.destroyEncodedObject(this.dracoMeshBuilder);
|
|
31
|
-
this.destroyEncodedObject(this.dracoEncoder);
|
|
32
|
-
this.destroyEncodedObject(this.dracoMetadataBuilder);
|
|
33
|
-
this.dracoMeshBuilder = null;
|
|
34
|
-
this.dracoEncoder = null;
|
|
35
|
-
this.draco = null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
destroyEncodedObject(object) {
|
|
39
|
-
if (object) {
|
|
40
|
-
this.draco.destroy(object);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
encodeSync(mesh, options = {}) {
|
|
45
|
-
this.log = noop;
|
|
46
|
-
|
|
47
|
-
this._setOptions(options);
|
|
48
|
-
|
|
49
|
-
return options.pointcloud ? this._encodePointCloud(mesh, options) : this._encodeMesh(mesh, options);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
_getAttributesFromMesh(mesh) {
|
|
53
|
-
const attributes = { ...mesh,
|
|
54
|
-
...mesh.attributes
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
if (mesh.indices) {
|
|
58
|
-
attributes.indices = mesh.indices;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return attributes;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
_encodePointCloud(pointcloud, options) {
|
|
65
|
-
const dracoPointCloud = new this.draco.PointCloud();
|
|
66
|
-
|
|
67
|
-
if (options.metadata) {
|
|
68
|
-
this._addGeometryMetadata(dracoPointCloud, options.metadata);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const attributes = this._getAttributesFromMesh(pointcloud);
|
|
72
|
-
|
|
73
|
-
this._createDracoPointCloud(dracoPointCloud, attributes, options);
|
|
74
|
-
|
|
75
|
-
const dracoData = new this.draco.DracoInt8Array();
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
const encodedLen = this.dracoEncoder.EncodePointCloudToDracoBuffer(dracoPointCloud, false, dracoData);
|
|
79
|
-
|
|
80
|
-
if (!(encodedLen > 0)) {
|
|
81
|
-
throw new Error('Draco encoding failed.');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
this.log("DRACO encoded ".concat(dracoPointCloud.num_points(), " points\n with ").concat(dracoPointCloud.num_attributes(), " attributes into ").concat(encodedLen, " bytes"));
|
|
85
|
-
return dracoInt8ArrayToArrayBuffer(dracoData);
|
|
86
|
-
} finally {
|
|
87
|
-
this.destroyEncodedObject(dracoData);
|
|
88
|
-
this.destroyEncodedObject(dracoPointCloud);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
_encodeMesh(mesh, options) {
|
|
93
|
-
const dracoMesh = new this.draco.Mesh();
|
|
94
|
-
|
|
95
|
-
if (options.metadata) {
|
|
96
|
-
this._addGeometryMetadata(dracoMesh, options.metadata);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const attributes = this._getAttributesFromMesh(mesh);
|
|
100
|
-
|
|
101
|
-
this._createDracoMesh(dracoMesh, attributes, options);
|
|
102
|
-
|
|
103
|
-
const dracoData = new this.draco.DracoInt8Array();
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
const encodedLen = this.dracoEncoder.EncodeMeshToDracoBuffer(dracoMesh, dracoData);
|
|
107
|
-
|
|
108
|
-
if (encodedLen <= 0) {
|
|
109
|
-
throw new Error('Draco encoding failed.');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
this.log("DRACO encoded ".concat(dracoMesh.num_points(), " points\n with ").concat(dracoMesh.num_attributes(), " attributes into ").concat(encodedLen, " bytes"));
|
|
113
|
-
return dracoInt8ArrayToArrayBuffer(dracoData);
|
|
114
|
-
} finally {
|
|
115
|
-
this.destroyEncodedObject(dracoData);
|
|
116
|
-
this.destroyEncodedObject(dracoMesh);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
_setOptions(options) {
|
|
121
|
-
if ('speed' in options) {
|
|
122
|
-
this.dracoEncoder.SetSpeedOptions(...options.speed);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if ('method' in options) {
|
|
126
|
-
const dracoMethod = this.draco[options.method || 'MESH_SEQUENTIAL_ENCODING'];
|
|
127
|
-
this.dracoEncoder.SetEncodingMethod(dracoMethod);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if ('quantization' in options) {
|
|
131
|
-
for (const attribute in options.quantization) {
|
|
132
|
-
const bits = options.quantization[attribute];
|
|
133
|
-
const dracoPosition = this.draco[attribute];
|
|
134
|
-
this.dracoEncoder.SetAttributeQuantization(dracoPosition, bits);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
_createDracoMesh(dracoMesh, attributes, options) {
|
|
140
|
-
const optionalMetadata = options.attributesMetadata || {};
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
const positions = this._getPositionAttribute(attributes);
|
|
144
|
-
|
|
145
|
-
if (!positions) {
|
|
146
|
-
throw new Error('positions');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const vertexCount = positions.length / 3;
|
|
150
|
-
|
|
151
|
-
for (let attributeName in attributes) {
|
|
152
|
-
const attribute = attributes[attributeName];
|
|
153
|
-
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;
|
|
154
|
-
|
|
155
|
-
const uniqueId = this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);
|
|
156
|
-
|
|
157
|
-
if (uniqueId !== -1) {
|
|
158
|
-
this._addAttributeMetadata(dracoMesh, uniqueId, {
|
|
159
|
-
name: attributeName,
|
|
160
|
-
...(optionalMetadata[attributeName] || {})
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
} catch (error) {
|
|
165
|
-
this.destroyEncodedObject(dracoMesh);
|
|
166
|
-
throw error;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return dracoMesh;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
_createDracoPointCloud(dracoPointCloud, attributes, options) {
|
|
173
|
-
const optionalMetadata = options.attributesMetadata || {};
|
|
174
|
-
|
|
175
|
-
try {
|
|
176
|
-
const positions = this._getPositionAttribute(attributes);
|
|
177
|
-
|
|
178
|
-
if (!positions) {
|
|
179
|
-
throw new Error('positions');
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const vertexCount = positions.length / 3;
|
|
183
|
-
|
|
184
|
-
for (let attributeName in attributes) {
|
|
185
|
-
const attribute = attributes[attributeName];
|
|
186
|
-
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;
|
|
187
|
-
|
|
188
|
-
const uniqueId = this._addAttributeToMesh(dracoPointCloud, attributeName, attribute, vertexCount);
|
|
189
|
-
|
|
190
|
-
if (uniqueId !== -1) {
|
|
191
|
-
this._addAttributeMetadata(dracoPointCloud, uniqueId, {
|
|
192
|
-
name: attributeName,
|
|
193
|
-
...(optionalMetadata[attributeName] || {})
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
} catch (error) {
|
|
198
|
-
this.destroyEncodedObject(dracoPointCloud);
|
|
199
|
-
throw error;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return dracoPointCloud;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
_addAttributeToMesh(mesh, attributeName, attribute, vertexCount) {
|
|
206
|
-
if (!ArrayBuffer.isView(attribute)) {
|
|
207
|
-
return -1;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const type = this._getDracoAttributeType(attributeName);
|
|
211
|
-
|
|
212
|
-
const size = attribute.length / vertexCount;
|
|
213
|
-
|
|
214
|
-
if (type === 'indices') {
|
|
215
|
-
const numFaces = attribute.length / 3;
|
|
216
|
-
this.log("Adding attribute ".concat(attributeName, ", size ").concat(numFaces));
|
|
217
|
-
this.dracoMeshBuilder.AddFacesToMesh(mesh, numFaces, attribute);
|
|
218
|
-
return -1;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
this.log("Adding attribute ".concat(attributeName, ", size ").concat(size));
|
|
222
|
-
const builder = this.dracoMeshBuilder;
|
|
223
|
-
const {
|
|
224
|
-
buffer
|
|
225
|
-
} = attribute;
|
|
226
|
-
|
|
227
|
-
switch (attribute.constructor) {
|
|
228
|
-
case Int8Array:
|
|
229
|
-
return builder.AddInt8Attribute(mesh, type, vertexCount, size, new Int8Array(buffer));
|
|
230
|
-
|
|
231
|
-
case Int16Array:
|
|
232
|
-
return builder.AddInt16Attribute(mesh, type, vertexCount, size, new Int16Array(buffer));
|
|
233
|
-
|
|
234
|
-
case Int32Array:
|
|
235
|
-
return builder.AddInt32Attribute(mesh, type, vertexCount, size, new Int32Array(buffer));
|
|
236
|
-
|
|
237
|
-
case Uint8Array:
|
|
238
|
-
case Uint8ClampedArray:
|
|
239
|
-
return builder.AddUInt8Attribute(mesh, type, vertexCount, size, new Uint8Array(buffer));
|
|
240
|
-
|
|
241
|
-
case Uint16Array:
|
|
242
|
-
return builder.AddUInt16Attribute(mesh, type, vertexCount, size, new Uint16Array(buffer));
|
|
243
|
-
|
|
244
|
-
case Uint32Array:
|
|
245
|
-
return builder.AddUInt32Attribute(mesh, type, vertexCount, size, new Uint32Array(buffer));
|
|
246
|
-
|
|
247
|
-
case Float32Array:
|
|
248
|
-
default:
|
|
249
|
-
return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
_getDracoAttributeType(attributeName) {
|
|
254
|
-
switch (attributeName.toLowerCase()) {
|
|
255
|
-
case 'indices':
|
|
256
|
-
return 'indices';
|
|
257
|
-
|
|
258
|
-
case 'position':
|
|
259
|
-
case 'positions':
|
|
260
|
-
case 'vertices':
|
|
261
|
-
return this.draco.POSITION;
|
|
262
|
-
|
|
263
|
-
case 'normal':
|
|
264
|
-
case 'normals':
|
|
265
|
-
return this.draco.NORMAL;
|
|
266
|
-
|
|
267
|
-
case 'color':
|
|
268
|
-
case 'colors':
|
|
269
|
-
return this.draco.COLOR;
|
|
270
|
-
|
|
271
|
-
case 'texcoord':
|
|
272
|
-
case 'texcoords':
|
|
273
|
-
return this.draco.TEX_COORD;
|
|
274
|
-
|
|
275
|
-
default:
|
|
276
|
-
return this.draco.GENERIC;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
_getPositionAttribute(attributes) {
|
|
281
|
-
for (const attributeName in attributes) {
|
|
282
|
-
const attribute = attributes[attributeName];
|
|
283
|
-
|
|
284
|
-
const dracoType = this._getDracoAttributeType(attributeName);
|
|
285
|
-
|
|
286
|
-
if (dracoType === this.draco.POSITION) {
|
|
287
|
-
return attribute;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
_addGeometryMetadata(dracoGeometry, metadata) {
|
|
295
|
-
const dracoMetadata = new this.draco.Metadata();
|
|
296
|
-
|
|
297
|
-
this._populateDracoMetadata(dracoMetadata, metadata);
|
|
298
|
-
|
|
299
|
-
this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
_addAttributeMetadata(dracoGeometry, uniqueAttributeId, metadata) {
|
|
303
|
-
const dracoAttributeMetadata = new this.draco.Metadata();
|
|
304
|
-
|
|
305
|
-
this._populateDracoMetadata(dracoAttributeMetadata, metadata);
|
|
306
|
-
|
|
307
|
-
this.dracoMeshBuilder.SetMetadataForAttribute(dracoGeometry, uniqueAttributeId, dracoAttributeMetadata);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
_populateDracoMetadata(dracoMetadata, metadata) {
|
|
311
|
-
for (const [key, value] of getEntries(metadata)) {
|
|
312
|
-
switch (typeof value) {
|
|
313
|
-
case 'number':
|
|
314
|
-
if (Math.trunc(value) === value) {
|
|
315
|
-
this.dracoMetadataBuilder.AddIntEntry(dracoMetadata, key, value);
|
|
316
|
-
} else {
|
|
317
|
-
this.dracoMetadataBuilder.AddDoubleEntry(dracoMetadata, key, value);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
break;
|
|
321
|
-
|
|
322
|
-
case 'object':
|
|
323
|
-
if (value instanceof Int32Array) {
|
|
324
|
-
this.dracoMetadataBuilder.AddIntEntryArray(dracoMetadata, key, value, value.length);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
break;
|
|
328
|
-
|
|
329
|
-
case 'string':
|
|
330
|
-
default:
|
|
331
|
-
this.dracoMetadataBuilder.AddStringEntry(dracoMetadata, key, value);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
function dracoInt8ArrayToArrayBuffer(dracoData) {
|
|
339
|
-
const byteLength = dracoData.size();
|
|
340
|
-
const outputBuffer = new ArrayBuffer(byteLength);
|
|
341
|
-
const outputData = new Int8Array(outputBuffer);
|
|
342
|
-
|
|
343
|
-
for (let i = 0; i < byteLength; ++i) {
|
|
344
|
-
outputData[i] = dracoData.GetValue(i);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
return outputBuffer;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
function getEntries(container) {
|
|
351
|
-
const hasEntriesFunc = container.entries && !container.hasOwnProperty('entries');
|
|
352
|
-
return hasEntriesFunc ? container.entries() : Object.entries(container);
|
|
353
|
-
}
|
|
354
|
-
//# sourceMappingURL=draco-builder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/draco-builder.ts"],"names":["GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP","POSITION","NORMAL","COLOR_0","TEXCOORD_0","noop","DracoBuilder","constructor","draco","dracoEncoder","Encoder","dracoMeshBuilder","MeshBuilder","dracoMetadataBuilder","MetadataBuilder","destroy","destroyEncodedObject","object","encodeSync","mesh","options","log","_setOptions","pointcloud","_encodePointCloud","_encodeMesh","_getAttributesFromMesh","attributes","indices","dracoPointCloud","PointCloud","metadata","_addGeometryMetadata","_createDracoPointCloud","dracoData","DracoInt8Array","encodedLen","EncodePointCloudToDracoBuffer","Error","num_points","num_attributes","dracoInt8ArrayToArrayBuffer","dracoMesh","Mesh","_createDracoMesh","EncodeMeshToDracoBuffer","SetSpeedOptions","speed","dracoMethod","method","SetEncodingMethod","attribute","quantization","bits","dracoPosition","SetAttributeQuantization","optionalMetadata","attributesMetadata","positions","_getPositionAttribute","vertexCount","length","attributeName","uniqueId","_addAttributeToMesh","_addAttributeMetadata","name","error","ArrayBuffer","isView","type","_getDracoAttributeType","size","numFaces","AddFacesToMesh","builder","buffer","Int8Array","AddInt8Attribute","Int16Array","AddInt16Attribute","Int32Array","AddInt32Attribute","Uint8Array","Uint8ClampedArray","AddUInt8Attribute","Uint16Array","AddUInt16Attribute","Uint32Array","AddUInt32Attribute","Float32Array","AddFloatAttribute","toLowerCase","COLOR","TEX_COORD","GENERIC","dracoType","dracoGeometry","dracoMetadata","Metadata","_populateDracoMetadata","AddMetadata","uniqueAttributeId","dracoAttributeMetadata","SetMetadataForAttribute","key","value","getEntries","Math","trunc","AddIntEntry","AddDoubleEntry","AddIntEntryArray","AddStringEntry","byteLength","outputBuffer","outputData","i","GetValue","container","hasEntriesFunc","entries","hasOwnProperty","Object"],"mappings":";AA8BA,MAAMA,gCAAgC,GAAG;AACvCC,EAAAA,QAAQ,EAAE,UAD6B;AAEvCC,EAAAA,MAAM,EAAE,QAF+B;AAGvCC,EAAAA,OAAO,EAAE,OAH8B;AAIvCC,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aAAzC,EAAwDO,GAAxD,EAA6DC,KAA7D;AAfJ;AAiBD;AACF;;AAlY+B;;AA2YlC,SAASjE,2BAAT,CAAqCP,SAArC,EAAgE;AAC9D,QAAMgF,UAAU,GAAGhF,SAAS,CAACsC,IAAV,EAAnB;AACA,QAAM2C,YAAY,GAAG,IAAI/C,WAAJ,CAAgB8C,UAAhB,CAArB;AACA,QAAME,UAAU,GAAG,IAAIvC,SAAJ,CAAcsC,YAAd,CAAnB;;AACA,OAAK,IAAIE,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGH,UAApB,EAAgC,EAAEG,CAAlC,EAAqC;AACnCD,IAAAA,UAAU,CAACC,CAAD,CAAV,GAAgBnF,SAAS,CAACoF,QAAV,CAAmBD,CAAnB,CAAhB;AACD;;AACD,SAAOF,YAAP;AACD;;AAGD,SAASR,UAAT,CAAoBY,SAApB,EAA+B;AAC7B,QAAMC,cAAc,GAAGD,SAAS,CAACE,OAAV,IAAqB,CAACF,SAAS,CAACG,cAAV,CAAyB,SAAzB,CAA7C;AACA,SAAOF,cAAc,GAAGD,SAAS,CAACE,OAAV,EAAH,GAAyBE,MAAM,CAACF,OAAP,CAAeF,SAAf,CAA9C;AACD","sourcesContent":["/* eslint-disable camelcase */\n// This code is inspired by example code in the DRACO repository\nimport type {\n Draco3D,\n DracoInt8Array,\n Encoder,\n Mesh,\n MeshBuilder,\n PointCloud,\n Metadata,\n MetadataBuilder,\n draco_GeometryAttribute_Type\n} from '../draco3d/draco3d-types';\n\nimport type {TypedArray} from '@loaders.gl/schema';\nimport type {DracoMesh} from './draco-types';\n\nexport type DracoBuildOptions = {\n pointcloud?: boolean;\n metadata?: {[key: string]: string};\n attributesMetadata?: {};\n log?: any;\n\n // draco encoding options\n speed?: [number, number];\n method?: string;\n quantization?: {[attributeName: string]: number};\n};\n\n// Native Draco attribute names to GLTF attribute names.\nconst GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {\n POSITION: 'POSITION',\n NORMAL: 'NORMAL',\n COLOR_0: 'COLOR',\n TEXCOORD_0: 'TEX_COORD'\n};\n\nconst noop = () => {};\n\nexport default class DracoBuilder {\n draco: Draco3D;\n dracoEncoder: Encoder;\n dracoMeshBuilder: MeshBuilder;\n dracoMetadataBuilder: MetadataBuilder;\n log: any;\n\n // draco - the draco decoder, either import `draco3d` or load dynamically\n constructor(draco: Draco3D) {\n this.draco = draco;\n this.dracoEncoder = new this.draco.Encoder();\n this.dracoMeshBuilder = new this.draco.MeshBuilder();\n this.dracoMetadataBuilder = new this.draco.MetadataBuilder();\n }\n\n destroy(): void {\n this.destroyEncodedObject(this.dracoMeshBuilder);\n this.destroyEncodedObject(this.dracoEncoder);\n this.destroyEncodedObject(this.dracoMetadataBuilder);\n // @ts-ignore\n this.dracoMeshBuilder = null;\n // @ts-ignore\n this.dracoEncoder = null;\n // @ts-ignore\n this.draco = null;\n }\n\n // TBD - when does this need to be called?\n destroyEncodedObject(object): void {\n if (object) {\n this.draco.destroy(object);\n }\n }\n\n /**\n * Encode mesh or point cloud\n * @param mesh =({})\n * @param options\n */\n encodeSync(mesh: DracoMesh, options: DracoBuildOptions = {}): ArrayBuffer {\n this.log = noop; // TODO\n this._setOptions(options);\n\n return options.pointcloud\n ? this._encodePointCloud(mesh, options)\n : this._encodeMesh(mesh, options);\n }\n\n // PRIVATE\n\n _getAttributesFromMesh(mesh: DracoMesh) {\n // TODO - Change the encodePointCloud interface instead?\n const attributes = {...mesh, ...mesh.attributes};\n // Fold indices into the attributes\n if (mesh.indices) {\n attributes.indices = mesh.indices;\n }\n return attributes;\n }\n\n _encodePointCloud(pointcloud: DracoMesh, options: DracoBuildOptions): ArrayBuffer {\n const dracoPointCloud = new this.draco.PointCloud();\n\n if (options.metadata) {\n this._addGeometryMetadata(dracoPointCloud, options.metadata);\n }\n\n const attributes = this._getAttributesFromMesh(pointcloud);\n\n // Build a `DracoPointCloud` from the input data\n this._createDracoPointCloud(dracoPointCloud, attributes, options);\n\n const dracoData = new this.draco.DracoInt8Array();\n\n try {\n const encodedLen = this.dracoEncoder.EncodePointCloudToDracoBuffer(\n dracoPointCloud,\n false,\n dracoData\n );\n\n if (!(encodedLen > 0)) {\n throw new Error('Draco encoding failed.');\n }\n\n this.log(`DRACO encoded ${dracoPointCloud.num_points()} points\n with ${dracoPointCloud.num_attributes()} attributes into ${encodedLen} bytes`);\n\n return dracoInt8ArrayToArrayBuffer(dracoData);\n } finally {\n this.destroyEncodedObject(dracoData);\n this.destroyEncodedObject(dracoPointCloud);\n }\n }\n\n _encodeMesh(mesh: DracoMesh, options: DracoBuildOptions): ArrayBuffer {\n const dracoMesh = new this.draco.Mesh();\n\n if (options.metadata) {\n this._addGeometryMetadata(dracoMesh, options.metadata);\n }\n\n const attributes = this._getAttributesFromMesh(mesh);\n\n // Build a `DracoMesh` from the input data\n this._createDracoMesh(dracoMesh, attributes, options);\n\n const dracoData = new this.draco.DracoInt8Array();\n\n try {\n const encodedLen = this.dracoEncoder.EncodeMeshToDracoBuffer(dracoMesh, dracoData);\n if (encodedLen <= 0) {\n throw new Error('Draco encoding failed.');\n }\n\n this.log(`DRACO encoded ${dracoMesh.num_points()} points\n with ${dracoMesh.num_attributes()} attributes into ${encodedLen} bytes`);\n\n return dracoInt8ArrayToArrayBuffer(dracoData);\n } finally {\n this.destroyEncodedObject(dracoData);\n this.destroyEncodedObject(dracoMesh);\n }\n }\n\n /**\n * Set encoding options.\n * @param {{speed?: any; method?: any; quantization?: any;}} options\n */\n _setOptions(options: DracoBuildOptions): void {\n if ('speed' in options) {\n // @ts-ignore\n this.dracoEncoder.SetSpeedOptions(...options.speed);\n }\n if ('method' in options) {\n const dracoMethod = this.draco[options.method || 'MESH_SEQUENTIAL_ENCODING'];\n // assert(dracoMethod)\n this.dracoEncoder.SetEncodingMethod(dracoMethod);\n }\n if ('quantization' in options) {\n for (const attribute in options.quantization) {\n const bits = options.quantization[attribute];\n const dracoPosition = this.draco[attribute];\n this.dracoEncoder.SetAttributeQuantization(dracoPosition, bits);\n }\n }\n }\n\n /**\n * @param {Mesh} dracoMesh\n * @param {object} attributes\n * @returns {Mesh}\n */\n _createDracoMesh(dracoMesh: Mesh, attributes, options: DracoBuildOptions): Mesh {\n const optionalMetadata = options.attributesMetadata || {};\n\n try {\n const positions = this._getPositionAttribute(attributes);\n if (!positions) {\n throw new Error('positions');\n }\n const vertexCount = positions.length / 3;\n\n for (let attributeName in attributes) {\n const attribute = attributes[attributeName];\n attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;\n const uniqueId = this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);\n\n if (uniqueId !== -1) {\n this._addAttributeMetadata(dracoMesh, uniqueId, {\n name: attributeName,\n ...(optionalMetadata[attributeName] || {})\n });\n }\n }\n } catch (error) {\n this.destroyEncodedObject(dracoMesh);\n throw error;\n }\n\n return dracoMesh;\n }\n\n /**\n * @param {} dracoPointCloud\n * @param {object} attributes\n */\n _createDracoPointCloud(\n dracoPointCloud: PointCloud,\n attributes: object,\n options: DracoBuildOptions\n ): PointCloud {\n const optionalMetadata = options.attributesMetadata || {};\n\n try {\n const positions = this._getPositionAttribute(attributes);\n if (!positions) {\n throw new Error('positions');\n }\n const vertexCount = positions.length / 3;\n\n for (let attributeName in attributes) {\n const attribute = attributes[attributeName];\n attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;\n const uniqueId = this._addAttributeToMesh(\n dracoPointCloud,\n attributeName,\n attribute,\n vertexCount\n );\n if (uniqueId !== -1) {\n this._addAttributeMetadata(dracoPointCloud, uniqueId, {\n name: attributeName,\n ...(optionalMetadata[attributeName] || {})\n });\n }\n }\n } catch (error) {\n this.destroyEncodedObject(dracoPointCloud);\n throw error;\n }\n\n return dracoPointCloud;\n }\n\n /**\n * @param mesh\n * @param attributeName\n * @param attribute\n * @param vertexCount\n */\n _addAttributeToMesh(\n mesh: PointCloud,\n attributeName: string,\n attribute: TypedArray,\n vertexCount: number\n ) {\n if (!ArrayBuffer.isView(attribute)) {\n return -1;\n }\n\n const type = this._getDracoAttributeType(attributeName);\n // @ts-ignore TODO/fix types\n const size = attribute.length / vertexCount;\n\n if (type === 'indices') {\n // @ts-ignore TODO/fix types\n const numFaces = attribute.length / 3;\n this.log(`Adding attribute ${attributeName}, size ${numFaces}`);\n\n // @ts-ignore assumes mesh is a Mesh, not a point cloud\n this.dracoMeshBuilder.AddFacesToMesh(mesh, numFaces, attribute);\n return -1;\n }\n\n this.log(`Adding attribute ${attributeName}, size ${size}`);\n\n const builder = this.dracoMeshBuilder;\n const {buffer} = attribute;\n\n switch (attribute.constructor) {\n case Int8Array:\n return builder.AddInt8Attribute(mesh, type, vertexCount, size, new Int8Array(buffer));\n\n case Int16Array:\n return builder.AddInt16Attribute(mesh, type, vertexCount, size, new Int16Array(buffer));\n\n case Int32Array:\n return builder.AddInt32Attribute(mesh, type, vertexCount, size, new Int32Array(buffer));\n case Uint8Array:\n case Uint8ClampedArray:\n return builder.AddUInt8Attribute(mesh, type, vertexCount, size, new Uint8Array(buffer));\n\n case Uint16Array:\n return builder.AddUInt16Attribute(mesh, type, vertexCount, size, new Uint16Array(buffer));\n\n case Uint32Array:\n return builder.AddUInt32Attribute(mesh, type, vertexCount, size, new Uint32Array(buffer));\n\n case Float32Array:\n default:\n return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));\n }\n }\n\n /**\n * DRACO can compress attributes of know type better\n * TODO - expose an attribute type map?\n * @param attributeName\n */\n _getDracoAttributeType(attributeName: string): draco_GeometryAttribute_Type | 'indices' {\n switch (attributeName.toLowerCase()) {\n case 'indices':\n return 'indices';\n case 'position':\n case 'positions':\n case 'vertices':\n return this.draco.POSITION;\n case 'normal':\n case 'normals':\n return this.draco.NORMAL;\n case 'color':\n case 'colors':\n return this.draco.COLOR;\n case 'texcoord':\n case 'texcoords':\n return this.draco.TEX_COORD;\n default:\n return this.draco.GENERIC;\n }\n }\n\n _getPositionAttribute(attributes) {\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const dracoType = this._getDracoAttributeType(attributeName);\n if (dracoType === this.draco.POSITION) {\n return attribute;\n }\n }\n return null;\n }\n\n /**\n * Add metadata for the geometry.\n * @param dracoGeometry - WASM Draco Object\n * @param metadata\n */\n _addGeometryMetadata(dracoGeometry: PointCloud, metadata: {[key: string]: string}) {\n const dracoMetadata = new this.draco.Metadata();\n this._populateDracoMetadata(dracoMetadata, metadata);\n this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);\n }\n\n /**\n * Add metadata for an attribute to geometry.\n * @param dracoGeometry - WASM Draco Object\n * @param uniqueAttributeId\n * @param metadata\n */\n _addAttributeMetadata(\n dracoGeometry: PointCloud,\n uniqueAttributeId: number,\n metadata: Map<string, string> | {[key: string]: string}\n ) {\n // Note: Draco JS IDL doesn't seem to expose draco.AttributeMetadata, however it seems to\n // create such objects automatically from draco.Metadata object.\n const dracoAttributeMetadata = new this.draco.Metadata();\n this._populateDracoMetadata(dracoAttributeMetadata, metadata);\n // Draco3d doc note: Directly add attribute metadata to geometry.\n // You can do this without explicitly adding |GeometryMetadata| to mesh.\n this.dracoMeshBuilder.SetMetadataForAttribute(\n dracoGeometry,\n uniqueAttributeId,\n dracoAttributeMetadata\n );\n }\n\n /**\n * Add contents of object or map to a WASM Draco Metadata Object\n * @param dracoMetadata - WASM Draco Object\n * @param metadata\n */\n _populateDracoMetadata(\n dracoMetadata: Metadata,\n metadata: Map<string, string> | {[key: string]: string}\n ) {\n for (const [key, value] of getEntries(metadata)) {\n switch (typeof value) {\n case 'number':\n if (Math.trunc(value) === value) {\n this.dracoMetadataBuilder.AddIntEntry(dracoMetadata, key, value);\n } else {\n this.dracoMetadataBuilder.AddDoubleEntry(dracoMetadata, key, value);\n }\n break;\n case 'object':\n if (value instanceof Int32Array) {\n this.dracoMetadataBuilder.AddIntEntryArray(dracoMetadata, key, value, value.length);\n }\n break;\n case 'string':\n default:\n this.dracoMetadataBuilder.AddStringEntry(dracoMetadata, key, value);\n }\n }\n }\n}\n\n// HELPER FUNCTIONS\n\n/**\n * Copy encoded data to buffer\n * @param dracoData\n */\nfunction dracoInt8ArrayToArrayBuffer(dracoData: DracoInt8Array) {\n const byteLength = dracoData.size();\n const outputBuffer = new ArrayBuffer(byteLength);\n const outputData = new Int8Array(outputBuffer);\n for (let i = 0; i < byteLength; ++i) {\n outputData[i] = dracoData.GetValue(i);\n }\n return outputBuffer;\n}\n\n/** Enable iteration over either an object or a map */\nfunction getEntries(container) {\n const hasEntriesFunc = container.entries && !container.hasOwnProperty('entries');\n return hasEntriesFunc ? container.entries() : Object.entries(container);\n}\n"],"file":"draco-builder.js"}
|