@loaders.gl/gltf 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 +13 -13
- package/dist/glb-loader.js +28 -33
- package/dist/glb-loader.js.map +1 -0
- package/dist/glb-writer.js +26 -34
- package/dist/glb-writer.js.map +1 -0
- package/dist/gltf-loader.js +43 -46
- package/dist/gltf-loader.js.map +1 -0
- package/dist/gltf-writer.js +26 -29
- package/dist/gltf-writer.js.map +1 -0
- package/dist/index.js +7 -21
- package/dist/index.js.map +1 -0
- package/dist/lib/api/gltf-extensions.js +31 -71
- package/dist/lib/api/gltf-extensions.js.map +1 -0
- package/dist/lib/api/gltf-scenegraph.js +512 -550
- package/dist/lib/api/gltf-scenegraph.js.map +1 -0
- package/dist/lib/api/normalize-gltf-v1.js +229 -274
- package/dist/lib/api/normalize-gltf-v1.js.map +1 -0
- package/dist/lib/api/post-process-gltf.js +376 -324
- package/dist/lib/api/post-process-gltf.js.map +1 -0
- package/dist/lib/encoders/encode-glb.js +58 -56
- package/dist/lib/encoders/encode-glb.js.map +1 -0
- package/dist/lib/encoders/encode-gltf.js +12 -25
- package/dist/lib/encoders/encode-gltf.js.map +1 -0
- package/dist/lib/extensions/EXT_meshopt_compression.js +49 -47
- package/dist/lib/extensions/EXT_meshopt_compression.js.map +1 -0
- package/dist/lib/extensions/EXT_texture_webp.js +28 -34
- package/dist/lib/extensions/EXT_texture_webp.js.map +1 -0
- package/dist/lib/extensions/KHR_binary_gltf.js +23 -39
- package/dist/lib/extensions/KHR_binary_gltf.js.map +1 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +111 -126
- package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
- package/dist/lib/extensions/KHR_texture_basisu.js +19 -28
- package/dist/lib/extensions/KHR_texture_basisu.js.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +44 -57
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +32 -42
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +62 -75
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
- package/dist/lib/gltf-utils/get-typed-array.js +14 -39
- package/dist/lib/gltf-utils/get-typed-array.js.map +1 -0
- package/dist/lib/gltf-utils/gltf-attribute-utils.js +65 -65
- package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +1 -0
- package/dist/lib/gltf-utils/gltf-constants.js +30 -36
- package/dist/lib/gltf-utils/gltf-constants.js.map +1 -0
- package/dist/lib/gltf-utils/gltf-utils.js +45 -52
- package/dist/lib/gltf-utils/gltf-utils.js.map +1 -0
- package/dist/lib/gltf-utils/resolve-url.js +15 -17
- package/dist/lib/gltf-utils/resolve-url.js.map +1 -0
- package/dist/lib/parsers/parse-glb.js +107 -120
- package/dist/lib/parsers/parse-glb.js.map +1 -0
- package/dist/lib/parsers/parse-gltf.js +154 -173
- package/dist/lib/parsers/parse-gltf.js.map +1 -0
- package/dist/lib/types/glb-types.js +2 -2
- package/dist/{es5/lib → lib}/types/glb-types.js.map +0 -0
- package/dist/lib/types/gltf-json-schema.js +2 -4
- package/dist/{es5/lib → lib}/types/gltf-json-schema.js.map +0 -0
- package/dist/lib/types/gltf-postprocessed-schema.js +2 -4
- package/dist/{es5/lib → lib}/types/gltf-postprocessed-schema.js.map +0 -0
- package/dist/lib/types/gltf-types.js +2 -3
- package/dist/{es5/lib → lib}/types/gltf-types.js.map +0 -0
- package/dist/lib/utils/assert.js +5 -11
- package/dist/lib/utils/assert.js.map +1 -0
- package/dist/lib/utils/version.js +2 -7
- package/dist/lib/utils/version.js.map +1 -0
- package/dist/meshopt/meshopt-decoder.js +82 -97
- package/dist/meshopt/meshopt-decoder.js.map +1 -0
- package/dist/{es5/meshopt → meshopt}/meshopt-encoder.ts.disabled +0 -0
- package/dist/webp/webp.js +23 -32
- package/dist/webp/webp.js.map +1 -0
- package/package.json +8 -11
- package/src/lib/parsers/parse-gltf.ts +1 -1
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/glb-loader.js +0 -70
- package/dist/es5/glb-loader.js.map +0 -1
- package/dist/es5/glb-writer.js +0 -41
- package/dist/es5/glb-writer.js.map +0 -1
- package/dist/es5/gltf-loader.js +0 -97
- package/dist/es5/gltf-loader.js.map +0 -1
- package/dist/es5/gltf-writer.js +0 -40
- package/dist/es5/gltf-writer.js.map +0 -1
- package/dist/es5/index.js +0 -56
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/api/gltf-extensions.js +0 -146
- package/dist/es5/lib/api/gltf-extensions.js.map +0 -1
- package/dist/es5/lib/api/gltf-scenegraph.js +0 -623
- package/dist/es5/lib/api/gltf-scenegraph.js.map +0 -1
- package/dist/es5/lib/api/normalize-gltf-v1.js +0 -392
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +0 -1
- package/dist/es5/lib/api/post-process-gltf.js +0 -502
- package/dist/es5/lib/api/post-process-gltf.js.map +0 -1
- package/dist/es5/lib/encoders/encode-glb.js +0 -75
- package/dist/es5/lib/encoders/encode-glb.js.map +0 -1
- package/dist/es5/lib/encoders/encode-gltf.js +0 -26
- package/dist/es5/lib/encoders/encode-gltf.js.map +0 -1
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +0 -137
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +0 -1
- package/dist/es5/lib/extensions/EXT_texture_webp.js +0 -60
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +0 -1
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +0 -53
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +0 -1
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +0 -331
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +0 -49
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +0 -1
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +0 -129
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +0 -97
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +0 -139
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
- package/dist/es5/lib/gltf-utils/get-typed-array.js +0 -26
- package/dist/es5/lib/gltf-utils/get-typed-array.js.map +0 -1
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +0 -85
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
- package/dist/es5/lib/gltf-utils/gltf-constants.js +0 -48
- package/dist/es5/lib/gltf-utils/gltf-constants.js.map +0 -1
- package/dist/es5/lib/gltf-utils/gltf-utils.js +0 -69
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +0 -1
- package/dist/es5/lib/gltf-utils/resolve-url.js +0 -23
- package/dist/es5/lib/gltf-utils/resolve-url.js.map +0 -1
- package/dist/es5/lib/parsers/parse-glb.js +0 -142
- package/dist/es5/lib/parsers/parse-glb.js.map +0 -1
- package/dist/es5/lib/parsers/parse-gltf.js +0 -353
- package/dist/es5/lib/parsers/parse-gltf.js.map +0 -1
- package/dist/es5/lib/types/glb-types.js +0 -2
- package/dist/es5/lib/types/gltf-json-schema.js +0 -2
- package/dist/es5/lib/types/gltf-postprocessed-schema.js +0 -2
- package/dist/es5/lib/types/gltf-types.js +0 -2
- package/dist/es5/lib/utils/assert.js +0 -13
- package/dist/es5/lib/utils/assert.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/meshopt/meshopt-decoder.js +0 -270
- package/dist/es5/meshopt/meshopt-decoder.js.map +0 -1
- package/dist/es5/webp/webp.js +0 -104
- package/dist/es5/webp/webp.js.map +0 -1
- package/dist/esm/bundle.js +0 -5
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/glb-loader.js +0 -34
- package/dist/esm/glb-loader.js.map +0 -1
- package/dist/esm/glb-writer.js +0 -29
- package/dist/esm/glb-writer.js.map +0 -1
- package/dist/esm/gltf-loader.js +0 -47
- package/dist/esm/gltf-loader.js.map +0 -1
- package/dist/esm/gltf-writer.js +0 -29
- package/dist/esm/gltf-writer.js.map +0 -1
- package/dist/esm/index.js +0 -7
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/api/gltf-extensions.js +0 -35
- package/dist/esm/lib/api/gltf-extensions.js.map +0 -1
- package/dist/esm/lib/api/gltf-scenegraph.js +0 -515
- package/dist/esm/lib/api/gltf-scenegraph.js.map +0 -1
- package/dist/esm/lib/api/normalize-gltf-v1.js +0 -250
- package/dist/esm/lib/api/normalize-gltf-v1.js.map +0 -1
- package/dist/esm/lib/api/post-process-gltf.js +0 -422
- package/dist/esm/lib/api/post-process-gltf.js.map +0 -1
- package/dist/esm/lib/encoders/encode-glb.js +0 -63
- package/dist/esm/lib/encoders/encode-glb.js.map +0 -1
- package/dist/esm/lib/encoders/encode-gltf.js +0 -14
- package/dist/esm/lib/encoders/encode-gltf.js.map +0 -1
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js +0 -56
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +0 -1
- package/dist/esm/lib/extensions/EXT_texture_webp.js +0 -32
- package/dist/esm/lib/extensions/EXT_texture_webp.js.map +0 -1
- package/dist/esm/lib/extensions/KHR_binary_gltf.js +0 -26
- package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +0 -1
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +0 -126
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
- package/dist/esm/lib/extensions/KHR_texture_basisu.js +0 -22
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +0 -1
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +0 -49
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +0 -37
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +0 -68
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
- package/dist/esm/lib/gltf-utils/get-typed-array.js +0 -16
- package/dist/esm/lib/gltf-utils/get-typed-array.js.map +0 -1
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js +0 -73
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
- package/dist/esm/lib/gltf-utils/gltf-constants.js +0 -37
- package/dist/esm/lib/gltf-utils/gltf-constants.js.map +0 -1
- package/dist/esm/lib/gltf-utils/gltf-utils.js +0 -56
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +0 -1
- package/dist/esm/lib/gltf-utils/resolve-url.js +0 -16
- package/dist/esm/lib/gltf-utils/resolve-url.js.map +0 -1
- package/dist/esm/lib/parsers/parse-glb.js +0 -128
- package/dist/esm/lib/parsers/parse-glb.js.map +0 -1
- package/dist/esm/lib/parsers/parse-gltf.js +0 -170
- package/dist/esm/lib/parsers/parse-gltf.js.map +0 -1
- package/dist/esm/lib/types/glb-types.js +0 -2
- package/dist/esm/lib/types/glb-types.js.map +0 -1
- package/dist/esm/lib/types/gltf-json-schema.js +0 -2
- package/dist/esm/lib/types/gltf-json-schema.js.map +0 -1
- package/dist/esm/lib/types/gltf-postprocessed-schema.js +0 -2
- package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +0 -1
- package/dist/esm/lib/types/gltf-types.js +0 -2
- package/dist/esm/lib/types/gltf-types.js.map +0 -1
- package/dist/esm/lib/utils/assert.js +0 -6
- package/dist/esm/lib/utils/assert.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/meshopt/meshopt-decoder.js +0 -103
- package/dist/esm/meshopt/meshopt-decoder.js.map +0 -1
- package/dist/esm/meshopt/meshopt-encoder.ts.disabled +0 -409
- package/dist/esm/webp/webp.js +0 -29
- package/dist/esm/webp/webp.js.map +0 -1
package/dist/esm/gltf-loader.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { VERSION } from './lib/utils/version';
|
|
2
|
-
import { parseGLTF } from './lib/parsers/parse-gltf';
|
|
3
|
-
export const GLTFLoader = {
|
|
4
|
-
name: 'glTF',
|
|
5
|
-
id: 'gltf',
|
|
6
|
-
module: 'gltf',
|
|
7
|
-
version: VERSION,
|
|
8
|
-
extensions: ['gltf', 'glb'],
|
|
9
|
-
mimeTypes: ['model/gltf+json', 'model/gltf-binary'],
|
|
10
|
-
text: true,
|
|
11
|
-
binary: true,
|
|
12
|
-
tests: ['glTF'],
|
|
13
|
-
parse,
|
|
14
|
-
options: {
|
|
15
|
-
gltf: {
|
|
16
|
-
normalize: true,
|
|
17
|
-
loadBuffers: true,
|
|
18
|
-
loadImages: true,
|
|
19
|
-
decompressMeshes: true,
|
|
20
|
-
postProcess: true
|
|
21
|
-
},
|
|
22
|
-
log: console
|
|
23
|
-
},
|
|
24
|
-
deprecatedOptions: {
|
|
25
|
-
fetchImages: 'gltf.loadImages',
|
|
26
|
-
createImages: 'gltf.loadImages',
|
|
27
|
-
decompress: 'gltf.decompressMeshes',
|
|
28
|
-
postProcess: 'gltf.postProcess',
|
|
29
|
-
gltf: {
|
|
30
|
-
decompress: 'gltf.decompressMeshes'
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
export async function parse(arrayBuffer, options = {}, context) {
|
|
35
|
-
options = { ...GLTFLoader.options,
|
|
36
|
-
...options
|
|
37
|
-
};
|
|
38
|
-
options.gltf = { ...GLTFLoader.options.gltf,
|
|
39
|
-
...options.gltf
|
|
40
|
-
};
|
|
41
|
-
const {
|
|
42
|
-
byteOffset = 0
|
|
43
|
-
} = options;
|
|
44
|
-
const gltf = {};
|
|
45
|
-
return await parseGLTF(gltf, arrayBuffer, byteOffset, options, context);
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=gltf-loader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/gltf-loader.ts"],"names":["VERSION","parseGLTF","GLTFLoader","name","id","module","version","extensions","mimeTypes","text","binary","tests","parse","options","gltf","normalize","loadBuffers","loadImages","decompressMeshes","postProcess","log","console","deprecatedOptions","fetchImages","createImages","decompress","arrayBuffer","context","byteOffset"],"mappings":"AAEA,SAAQA,OAAR,QAAsB,qBAAtB;AAKA,SAAQC,SAAR,QAAwB,0BAAxB;AAiBA,OAAO,MAAMC,UAA4B,GAAG;AAC1CC,EAAAA,IAAI,EAAE,MADoC;AAE1CC,EAAAA,EAAE,EAAE,MAFsC;AAG1CC,EAAAA,MAAM,EAAE,MAHkC;AAI1CC,EAAAA,OAAO,EAAEN,OAJiC;AAK1CO,EAAAA,UAAU,EAAE,CAAC,MAAD,EAAS,KAAT,CAL8B;AAM1CC,EAAAA,SAAS,EAAE,CAAC,iBAAD,EAAoB,mBAApB,CAN+B;AAQ1CC,EAAAA,IAAI,EAAE,IARoC;AAS1CC,EAAAA,MAAM,EAAE,IATkC;AAU1CC,EAAAA,KAAK,EAAE,CAAC,MAAD,CAVmC;AAW1CC,EAAAA,KAX0C;AAa1CC,EAAAA,OAAO,EAAE;AACPC,IAAAA,IAAI,EAAE;AACJC,MAAAA,SAAS,EAAE,IADP;AAEJC,MAAAA,WAAW,EAAE,IAFT;AAGJC,MAAAA,UAAU,EAAE,IAHR;AAIJC,MAAAA,gBAAgB,EAAE,IAJd;AAKJC,MAAAA,WAAW,EAAE;AALT,KADC;AAUPC,IAAAA,GAAG,EAAEC;AAVE,GAbiC;AAyB1CC,EAAAA,iBAAiB,EAAE;AACjBC,IAAAA,WAAW,EAAE,iBADI;AAEjBC,IAAAA,YAAY,EAAE,iBAFG;AAGjBC,IAAAA,UAAU,EAAE,uBAHK;AAIjBN,IAAAA,WAAW,EAAE,kBAJI;AAKjBL,IAAAA,IAAI,EAAE;AACJW,MAAAA,UAAU,EAAE;AADR;AALW;AAzBuB,CAArC;AAoCP,OAAO,eAAeb,KAAf,CAAqBc,WAArB,EAAkCb,OAA0B,GAAG,EAA/D,EAAmEc,OAAnE,EAA4E;AAEjFd,EAAAA,OAAO,GAAG,EAAC,GAAGX,UAAU,CAACW,OAAf;AAAwB,OAAGA;AAA3B,GAAV;AAEAA,EAAAA,OAAO,CAACC,IAAR,GAAe,EAAC,GAAGZ,UAAU,CAACW,OAAX,CAAmBC,IAAvB;AAA6B,OAAGD,OAAO,CAACC;AAAxC,GAAf;AAEA,QAAM;AAACc,IAAAA,UAAU,GAAG;AAAd,MAAmBf,OAAzB;AACA,QAAMC,IAAI,GAAG,EAAb;AACA,SAAO,MAAMb,SAAS,CAACa,IAAD,EAA0BY,WAA1B,EAAuCE,UAAvC,EAAmDf,OAAnD,EAA4Dc,OAA5D,CAAtB;AACD","sourcesContent":["import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {DracoLoaderOptions} from '@loaders.gl/draco';\nimport {VERSION} from './lib/utils/version';\nimport type {ImageLoaderOptions} from '@loaders.gl/images';\nimport type {TextureLoaderOptions} from '@loaders.gl/textures';\nimport type {GLTFParseOptions} from './lib/parsers/parse-gltf';\nimport type {GLTFWithBuffers} from './lib/types/gltf-types';\nimport {parseGLTF} from './lib/parsers/parse-gltf';\nimport {GLBLoaderOptions} from './glb-loader';\n\n/**\n * GLTF loader options\n */\nexport type GLTFLoaderOptions = LoaderOptions &\n ImageLoaderOptions &\n TextureLoaderOptions &\n GLBLoaderOptions &\n DracoLoaderOptions & {\n gltf?: GLTFParseOptions;\n };\n\n/**\n * GLTF loader\n */\nexport const GLTFLoader: LoaderWithParser = {\n name: 'glTF',\n id: 'gltf',\n module: 'gltf',\n version: VERSION,\n extensions: ['gltf', 'glb'],\n mimeTypes: ['model/gltf+json', 'model/gltf-binary'],\n\n text: true,\n binary: true,\n tests: ['glTF'],\n parse,\n\n options: {\n gltf: {\n normalize: true, // Normalize glTF v1 to glTF v2 format (not yet stable)\n loadBuffers: true, // Fetch any linked .BIN buffers, decode base64\n loadImages: true, // Create image objects\n decompressMeshes: true, // Decompress Draco encoded meshes\n postProcess: true // Postprocess glTF and return json structure directly\n },\n\n // common?\n log: console // eslint-disable-line\n },\n deprecatedOptions: {\n fetchImages: 'gltf.loadImages',\n createImages: 'gltf.loadImages',\n decompress: 'gltf.decompressMeshes',\n postProcess: 'gltf.postProcess',\n gltf: {\n decompress: 'gltf.decompressMeshes'\n }\n }\n};\n\nexport async function parse(arrayBuffer, options: GLTFLoaderOptions = {}, context) {\n // Apps can call the parse method directly, we so apply default options here\n options = {...GLTFLoader.options, ...options};\n // @ts-ignore\n options.gltf = {...GLTFLoader.options.gltf, ...options.gltf};\n\n const {byteOffset = 0} = options;\n const gltf = {};\n return await parseGLTF(gltf as GLTFWithBuffers, arrayBuffer, byteOffset, options, context);\n}\n"],"file":"gltf-loader.js"}
|
package/dist/esm/gltf-writer.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { VERSION } from './lib/utils/version';
|
|
2
|
-
import { encodeGLTFSync } from './lib/encoders/encode-gltf';
|
|
3
|
-
export const GLTFWriter = {
|
|
4
|
-
name: 'glTF',
|
|
5
|
-
id: 'gltf',
|
|
6
|
-
module: 'gltf',
|
|
7
|
-
version: VERSION,
|
|
8
|
-
extensions: ['glb'],
|
|
9
|
-
mimeTypes: ['model/gltf-binary'],
|
|
10
|
-
binary: true,
|
|
11
|
-
encodeSync,
|
|
12
|
-
options: {
|
|
13
|
-
gltf: {}
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
function encodeSync(gltf, options = {}) {
|
|
18
|
-
const {
|
|
19
|
-
byteOffset = 0
|
|
20
|
-
} = options;
|
|
21
|
-
const byteLength = encodeGLTFSync(gltf, null, byteOffset, options);
|
|
22
|
-
const arrayBuffer = new ArrayBuffer(byteLength);
|
|
23
|
-
const dataView = new DataView(arrayBuffer);
|
|
24
|
-
encodeGLTFSync(gltf, dataView, byteOffset, options);
|
|
25
|
-
return arrayBuffer;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const _TypecheckGLBLoader = GLTFWriter;
|
|
29
|
-
//# sourceMappingURL=gltf-writer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/gltf-writer.ts"],"names":["VERSION","encodeGLTFSync","GLTFWriter","name","id","module","version","extensions","mimeTypes","binary","encodeSync","options","gltf","byteOffset","byteLength","arrayBuffer","ArrayBuffer","dataView","DataView","_TypecheckGLBLoader"],"mappings":"AACA,SAAQA,OAAR,QAAsB,qBAAtB;AACA,SAAQC,cAAR,QAA6B,4BAA7B;AAUA,OAAO,MAAMC,UAAU,GAAG;AACxBC,EAAAA,IAAI,EAAE,MADkB;AAExBC,EAAAA,EAAE,EAAE,MAFoB;AAGxBC,EAAAA,MAAM,EAAE,MAHgB;AAIxBC,EAAAA,OAAO,EAAEN,OAJe;AAMxBO,EAAAA,UAAU,EAAE,CAAC,KAAD,CANY;AAOxBC,EAAAA,SAAS,EAAE,CAAC,mBAAD,CAPa;AAQxBC,EAAAA,MAAM,EAAE,IARgB;AAUxBC,EAAAA,UAVwB;AAYxBC,EAAAA,OAAO,EAAE;AACPC,IAAAA,IAAI,EAAE;AADC;AAZe,CAAnB;;AAiBP,SAASF,UAAT,CAAoBE,IAApB,EAA0BD,OAA0B,GAAG,EAAvD,EAA2D;AACzD,QAAM;AAACE,IAAAA,UAAU,GAAG;AAAd,MAAmBF,OAAzB;AAGA,QAAMG,UAAU,GAAGb,cAAc,CAACW,IAAD,EAAO,IAAP,EAAaC,UAAb,EAAyBF,OAAzB,CAAjC;AACA,QAAMI,WAAW,GAAG,IAAIC,WAAJ,CAAgBF,UAAhB,CAApB;AACA,QAAMG,QAAQ,GAAG,IAAIC,QAAJ,CAAaH,WAAb,CAAjB;AACAd,EAAAA,cAAc,CAACW,IAAD,EAAOK,QAAP,EAAiBJ,UAAjB,EAA6BF,OAA7B,CAAd;AAEA,SAAOI,WAAP;AACD;;AAGD,OAAO,MAAMI,mBAA2B,GAAGjB,UAApC","sourcesContent":["import type {Writer} from '@loaders.gl/loader-utils';\nimport {VERSION} from './lib/utils/version';\nimport {encodeGLTFSync} from './lib/encoders/encode-gltf';\n\nexport type GLTFWriterOptions = {\n gltf?: {};\n byteOffset?: number;\n};\n\n/**\n * GLTF exporter\n */\nexport const GLTFWriter = {\n name: 'glTF',\n id: 'gltf',\n module: 'gltf',\n version: VERSION,\n\n extensions: ['glb'], // We only support encoding to binary GLB, not to JSON GLTF\n mimeTypes: ['model/gltf-binary'], // 'model/gltf+json',\n binary: true,\n\n encodeSync,\n\n options: {\n gltf: {}\n }\n};\n\nfunction encodeSync(gltf, options: GLTFWriterOptions = {}) {\n const {byteOffset = 0} = options;\n\n // Calculate length, then create arraybuffer and encode\n const byteLength = encodeGLTFSync(gltf, null, byteOffset, options);\n const arrayBuffer = new ArrayBuffer(byteLength);\n const dataView = new DataView(arrayBuffer);\n encodeGLTFSync(gltf, dataView, byteOffset, options);\n\n return arrayBuffer;\n}\n\n// TYPE TESTS - TODO find a better way than exporting junk\nexport const _TypecheckGLBLoader: Writer = GLTFWriter;\n"],"file":"gltf-writer.js"}
|
package/dist/esm/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { GLTFLoader } from './gltf-loader';
|
|
2
|
-
export { GLTFWriter } from './gltf-writer';
|
|
3
|
-
export { GLBLoader } from './glb-loader';
|
|
4
|
-
export { GLBWriter } from './glb-writer';
|
|
5
|
-
export { default as GLTFScenegraph } from './lib/api/gltf-scenegraph';
|
|
6
|
-
export { postProcessGLTF } from './lib/api/post-process-gltf';
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":["GLTFLoader","GLTFWriter","GLBLoader","GLBWriter","default","GLTFScenegraph","postProcessGLTF"],"mappings":"AA0BA,SAAQA,UAAR,QAAyB,eAAzB;AACA,SAAQC,UAAR,QAAyB,eAAzB;AAGA,SAAQC,SAAR,QAAwB,cAAxB;AACA,SAAQC,SAAR,QAAwB,cAAxB;AAGA,SAAQC,OAAO,IAAIC,cAAnB,QAAwC,2BAAxC;AACA,SAAQC,eAAR,QAA8B,6BAA9B","sourcesContent":["/* eslint-disable camelcase, indent */\nexport type {GLB} from './lib/types/glb-types';\nexport type {\n GLTF,\n GLTFAccessor,\n GLTFBuffer,\n GLTFBufferView,\n GLTFMeshPrimitive,\n GLTFMesh,\n GLTFNode,\n GLTFMaterial,\n GLTFSampler,\n GLTFScene,\n GLTFSkin,\n GLTFTexture,\n GLTFImage,\n GLTFImagePostprocessed,\n // The following extensions are handled by the GLTFLoader and removed from the parsed glTF (disable via options.gltf.excludeExtensions)\n GLTF_KHR_binary_glTF,\n GLTF_KHR_draco_mesh_compression,\n GLTF_KHR_texture_basisu,\n GLTF_EXT_meshopt_compression,\n GLTF_EXT_texture_webp\n} from './lib/types/gltf-types';\n\n// glTF loader/writer definition objects\nexport {GLTFLoader} from './gltf-loader';\nexport {GLTFWriter} from './gltf-writer';\n\n// GLB Loader & Writer (for custom formats that want to leverage the GLB binary \"envelope\")\nexport {GLBLoader} from './glb-loader';\nexport {GLBWriter} from './glb-writer';\n\n// glTF Data Access Helper Class\nexport {default as GLTFScenegraph} from './lib/api/gltf-scenegraph';\nexport {postProcessGLTF} from './lib/api/post-process-gltf';\nexport type {Mesh} from './lib/types/gltf-json-schema';\nexport type {GLTFObject} from './lib/types/gltf-types';\n"],"file":"index.js"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import * as EXT_meshopt_compression from '../extensions/EXT_meshopt_compression';
|
|
2
|
-
import * as EXT_texture_webp from '../extensions/EXT_texture_webp';
|
|
3
|
-
import * as KHR_texture_basisu from '../extensions/KHR_texture_basisu';
|
|
4
|
-
import * as KHR_draco_mesh_compression from '../extensions/KHR_draco_mesh_compression';
|
|
5
|
-
import * as KHR_lights_punctual from '../extensions/deprecated/KHR_lights_punctual';
|
|
6
|
-
import * as KHR_materials_unlit from '../extensions/deprecated/KHR_materials_unlit';
|
|
7
|
-
import * as KHR_techniques_webgl from '../extensions/deprecated/KHR_techniques_webgl';
|
|
8
|
-
export const EXTENSIONS = [EXT_meshopt_compression, EXT_texture_webp, KHR_texture_basisu, KHR_draco_mesh_compression, KHR_lights_punctual, KHR_materials_unlit, KHR_techniques_webgl];
|
|
9
|
-
export function preprocessExtensions(gltf, options = {}, context) {
|
|
10
|
-
const extensions = EXTENSIONS.filter(extension => useExtension(extension.name, options));
|
|
11
|
-
|
|
12
|
-
for (const extension of extensions) {
|
|
13
|
-
var _extension$preprocess;
|
|
14
|
-
|
|
15
|
-
(_extension$preprocess = extension.preprocess) === null || _extension$preprocess === void 0 ? void 0 : _extension$preprocess.call(extension, gltf, options, context);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export async function decodeExtensions(gltf, options = {}, context) {
|
|
19
|
-
const extensions = EXTENSIONS.filter(extension => useExtension(extension.name, options));
|
|
20
|
-
|
|
21
|
-
for (const extension of extensions) {
|
|
22
|
-
var _extension$decode;
|
|
23
|
-
|
|
24
|
-
await ((_extension$decode = extension.decode) === null || _extension$decode === void 0 ? void 0 : _extension$decode.call(extension, gltf, options, context));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function useExtension(extensionName, options) {
|
|
29
|
-
var _options$gltf;
|
|
30
|
-
|
|
31
|
-
const excludes = (options === null || options === void 0 ? void 0 : (_options$gltf = options.gltf) === null || _options$gltf === void 0 ? void 0 : _options$gltf.excludeExtensions) || {};
|
|
32
|
-
const exclude = extensionName in excludes && !excludes[extensionName];
|
|
33
|
-
return !exclude;
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=gltf-extensions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/api/gltf-extensions.ts"],"names":["EXT_meshopt_compression","EXT_texture_webp","KHR_texture_basisu","KHR_draco_mesh_compression","KHR_lights_punctual","KHR_materials_unlit","KHR_techniques_webgl","EXTENSIONS","preprocessExtensions","gltf","options","context","extensions","filter","extension","useExtension","name","preprocess","decodeExtensions","decode","extensionName","excludes","excludeExtensions","exclude"],"mappings":"AAQA,OAAO,KAAKA,uBAAZ,MAAyC,uCAAzC;AACA,OAAO,KAAKC,gBAAZ,MAAkC,gCAAlC;AACA,OAAO,KAAKC,kBAAZ,MAAoC,kCAApC;AACA,OAAO,KAAKC,0BAAZ,MAA4C,0CAA5C;AAGA,OAAO,KAAKC,mBAAZ,MAAqC,8CAArC;AACA,OAAO,KAAKC,mBAAZ,MAAqC,8CAArC;AACA,OAAO,KAAKC,oBAAZ,MAAsC,+CAAtC;AAgBA,OAAO,MAAMC,UAAiC,GAAG,CAM/CP,uBAN+C,EAO/CC,gBAP+C,EAS/CC,kBAT+C,EAU/CC,0BAV+C,EAW/CC,mBAX+C,EAY/CC,mBAZ+C,EAa/CC,oBAb+C,CAA1C;AAiBP,OAAO,SAASE,oBAAT,CAA8BC,IAA9B,EAAoCC,OAA0B,GAAG,EAAjE,EAAqEC,OAArE,EAA+E;AACpF,QAAMC,UAAU,GAAGL,UAAU,CAACM,MAAX,CAAmBC,SAAD,IAAeC,YAAY,CAACD,SAAS,CAACE,IAAX,EAAiBN,OAAjB,CAA7C,CAAnB;;AACA,OAAK,MAAMI,SAAX,IAAwBF,UAAxB,EAAoC;AAAA;;AAClC,6BAAAE,SAAS,CAACG,UAAV,qFAAAH,SAAS,EAAcL,IAAd,EAAoBC,OAApB,EAA6BC,OAA7B,CAAT;AACD;AACF;AAGD,OAAO,eAAeO,gBAAf,CAAgCT,IAAhC,EAAsCC,OAA0B,GAAG,EAAnE,EAAuEC,OAAvE,EAAiF;AACtF,QAAMC,UAAU,GAAGL,UAAU,CAACM,MAAX,CAAmBC,SAAD,IAAeC,YAAY,CAACD,SAAS,CAACE,IAAX,EAAiBN,OAAjB,CAA7C,CAAnB;;AACA,OAAK,MAAMI,SAAX,IAAwBF,UAAxB,EAAoC;AAAA;;AAGlC,gCAAME,SAAS,CAACK,MAAhB,sDAAM,uBAAAL,SAAS,EAAUL,IAAV,EAAgBC,OAAhB,EAAyBC,OAAzB,CAAf;AACD;AACF;;AAED,SAASI,YAAT,CAAsBK,aAAtB,EAA6CV,OAA7C,EAAyE;AAAA;;AACvE,QAAMW,QAAQ,GAAG,CAAAX,OAAO,SAAP,IAAAA,OAAO,WAAP,6BAAAA,OAAO,CAAED,IAAT,gEAAea,iBAAf,KAAoC,EAArD;AACA,QAAMC,OAAO,GAAGH,aAAa,IAAIC,QAAjB,IAA6B,CAACA,QAAQ,CAACD,aAAD,CAAtD;AACA,SAAO,CAACG,OAAR;AACD","sourcesContent":["/* eslint-disable camelcase */\nimport {GLTF} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\n// GLTF 1.0 extensions (decode only)\n// import * as KHR_binary_gltf from './KHR_draco_mesh_compression';\n\n// GLTF 2.0 Khronos extensions (decode/encode)\nimport * as EXT_meshopt_compression from '../extensions/EXT_meshopt_compression';\nimport * as EXT_texture_webp from '../extensions/EXT_texture_webp';\nimport * as KHR_texture_basisu from '../extensions/KHR_texture_basisu';\nimport * as KHR_draco_mesh_compression from '../extensions/KHR_draco_mesh_compression';\n\n// Deprecated. These should be handled by rendering library (e.g. luma.gl), not the loader.\nimport * as KHR_lights_punctual from '../extensions/deprecated/KHR_lights_punctual';\nimport * as KHR_materials_unlit from '../extensions/deprecated/KHR_materials_unlit';\nimport * as KHR_techniques_webgl from '../extensions/deprecated/KHR_techniques_webgl';\n\n// Vendor extensions\n\ntype GLTFExtensionPlugin = {\n name: string;\n preprocess?: (gltfData: {json: GLTF}, options: GLTFLoaderOptions, context) => void;\n decode?: (gltfData: {json: GLTF}, options: GLTFLoaderOptions, context) => Promise<void>;\n encode?: (gltfData: {json: GLTF}, options: GLTFLoaderOptions) => void;\n};\n\n/**\n * List of extensions processed by the GLTFLoader\n * Note that may extensions can only be handled on the rendering stage and are left out here\n * These are just extensions that can be handled fully or partially during loading.\n */\nexport const EXTENSIONS: GLTFExtensionPlugin[] = [\n // 1.0\n // KHR_binary_gltf is handled separately - must be processed before other parsing starts\n // KHR_binary_gltf,\n\n // 2.0\n EXT_meshopt_compression,\n EXT_texture_webp,\n // Basisu should come after webp, we want basisu to be preferred if both are provided\n KHR_texture_basisu,\n KHR_draco_mesh_compression,\n KHR_lights_punctual,\n KHR_materials_unlit,\n KHR_techniques_webgl\n];\n\n/** Call before any resource loading starts */\nexport function preprocessExtensions(gltf, options: GLTFLoaderOptions = {}, context?) {\n const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options));\n for (const extension of extensions) {\n extension.preprocess?.(gltf, options, context);\n }\n}\n\n/** Call after resource loading */\nexport async function decodeExtensions(gltf, options: GLTFLoaderOptions = {}, context?) {\n const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options));\n for (const extension of extensions) {\n // Note: We decode async extensions sequentially, this might not be necessary\n // Currently we only have Draco, but when we add Basis we may revisit\n await extension.decode?.(gltf, options, context);\n }\n}\n\nfunction useExtension(extensionName: string, options: GLTFLoaderOptions) {\n const excludes = options?.gltf?.excludeExtensions || {};\n const exclude = extensionName in excludes && !excludes[extensionName];\n return !exclude;\n}\n"],"file":"gltf-extensions.js"}
|
|
@@ -1,515 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
import { getBinaryImageMetadata } from '@loaders.gl/images';
|
|
3
|
-
import { padToNBytes, copyToArray } from '@loaders.gl/loader-utils';
|
|
4
|
-
import { assert } from '../utils/assert';
|
|
5
|
-
import { getAccessorArrayTypeAndLength, getAccessorTypeFromSize, getComponentTypeFromArray } from '../gltf-utils/gltf-utils';
|
|
6
|
-
const DEFAULT_GLTF_JSON = {
|
|
7
|
-
asset: {
|
|
8
|
-
version: '2.0',
|
|
9
|
-
generator: 'loaders.gl'
|
|
10
|
-
},
|
|
11
|
-
buffers: []
|
|
12
|
-
};
|
|
13
|
-
export default class GLTFScenegraph {
|
|
14
|
-
constructor(gltf) {
|
|
15
|
-
_defineProperty(this, "gltf", void 0);
|
|
16
|
-
|
|
17
|
-
_defineProperty(this, "sourceBuffers", void 0);
|
|
18
|
-
|
|
19
|
-
_defineProperty(this, "byteLength", void 0);
|
|
20
|
-
|
|
21
|
-
this.gltf = gltf || {
|
|
22
|
-
json: { ...DEFAULT_GLTF_JSON
|
|
23
|
-
},
|
|
24
|
-
buffers: []
|
|
25
|
-
};
|
|
26
|
-
this.sourceBuffers = [];
|
|
27
|
-
this.byteLength = 0;
|
|
28
|
-
|
|
29
|
-
if (this.gltf.buffers && this.gltf.buffers[0]) {
|
|
30
|
-
this.byteLength = this.gltf.buffers[0].byteLength;
|
|
31
|
-
this.sourceBuffers = [this.gltf.buffers[0]];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get json() {
|
|
36
|
-
return this.gltf.json;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
getApplicationData(key) {
|
|
40
|
-
const data = this.json[key];
|
|
41
|
-
return data;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getExtraData(key) {
|
|
45
|
-
const extras = this.json.extras || {};
|
|
46
|
-
return extras[key];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
getExtension(extensionName) {
|
|
50
|
-
const isExtension = this.getUsedExtensions().find(name => name === extensionName);
|
|
51
|
-
const extensions = this.json.extensions || {};
|
|
52
|
-
return isExtension ? extensions[extensionName] || true : null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
getRequiredExtension(extensionName) {
|
|
56
|
-
const isRequired = this.getRequiredExtensions().find(name => name === extensionName);
|
|
57
|
-
return isRequired ? this.getExtension(extensionName) : null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
getRequiredExtensions() {
|
|
61
|
-
return this.json.extensionsRequired || [];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
getUsedExtensions() {
|
|
65
|
-
return this.json.extensionsUsed || [];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
getObjectExtension(object, extensionName) {
|
|
69
|
-
const extensions = object.extensions || {};
|
|
70
|
-
return extensions[extensionName];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
getScene(index) {
|
|
74
|
-
return this.getObject('scenes', index);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
getNode(index) {
|
|
78
|
-
return this.getObject('nodes', index);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
getSkin(index) {
|
|
82
|
-
return this.getObject('skins', index);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
getMesh(index) {
|
|
86
|
-
return this.getObject('meshes', index);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
getMaterial(index) {
|
|
90
|
-
return this.getObject('materials', index);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
getAccessor(index) {
|
|
94
|
-
return this.getObject('accessors', index);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
getTexture(index) {
|
|
98
|
-
return this.getObject('textures', index);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
getSampler(index) {
|
|
102
|
-
return this.getObject('samplers', index);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
getImage(index) {
|
|
106
|
-
return this.getObject('images', index);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
getBufferView(index) {
|
|
110
|
-
return this.getObject('bufferViews', index);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
getBuffer(index) {
|
|
114
|
-
return this.getObject('buffers', index);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
getObject(array, index) {
|
|
118
|
-
if (typeof index === 'object') {
|
|
119
|
-
return index;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const object = this.json[array] && this.json[array][index];
|
|
123
|
-
|
|
124
|
-
if (!object) {
|
|
125
|
-
throw new Error("glTF file error: Could not find ".concat(array, "[").concat(index, "]"));
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return object;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
getTypedArrayForBufferView(bufferView) {
|
|
132
|
-
bufferView = this.getBufferView(bufferView);
|
|
133
|
-
const bufferIndex = bufferView.buffer;
|
|
134
|
-
const binChunk = this.gltf.buffers[bufferIndex];
|
|
135
|
-
assert(binChunk);
|
|
136
|
-
const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
|
|
137
|
-
return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
getTypedArrayForAccessor(accessor) {
|
|
141
|
-
accessor = this.getAccessor(accessor);
|
|
142
|
-
const bufferView = this.getBufferView(accessor.bufferView);
|
|
143
|
-
const buffer = this.getBuffer(bufferView.buffer);
|
|
144
|
-
const arrayBuffer = buffer.data;
|
|
145
|
-
const {
|
|
146
|
-
ArrayType,
|
|
147
|
-
length
|
|
148
|
-
} = getAccessorArrayTypeAndLength(accessor, bufferView);
|
|
149
|
-
const byteOffset = bufferView.byteOffset + accessor.byteOffset;
|
|
150
|
-
return new ArrayType(arrayBuffer, byteOffset, length);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
getTypedArrayForImageData(image) {
|
|
154
|
-
image = this.getAccessor(image);
|
|
155
|
-
const bufferView = this.getBufferView(image.bufferView);
|
|
156
|
-
const buffer = this.getBuffer(bufferView.buffer);
|
|
157
|
-
const arrayBuffer = buffer.data;
|
|
158
|
-
const byteOffset = bufferView.byteOffset || 0;
|
|
159
|
-
return new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
addApplicationData(key, data) {
|
|
163
|
-
this.json[key] = data;
|
|
164
|
-
return this;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
addExtraData(key, data) {
|
|
168
|
-
this.json.extras = this.json.extras || {};
|
|
169
|
-
this.json.extras[key] = data;
|
|
170
|
-
return this;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
addObjectExtension(object, extensionName, data) {
|
|
174
|
-
object.extensions = object.extensions || {};
|
|
175
|
-
object.extensions[extensionName] = data;
|
|
176
|
-
this.registerUsedExtension(extensionName);
|
|
177
|
-
return this;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
setObjectExtension(object, extensionName, data) {
|
|
181
|
-
const extensions = object.extensions || {};
|
|
182
|
-
extensions[extensionName] = data;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
removeObjectExtension(object, extensionName) {
|
|
186
|
-
const extensions = object.extensions || {};
|
|
187
|
-
const extension = extensions[extensionName];
|
|
188
|
-
delete extensions[extensionName];
|
|
189
|
-
return extension;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
addExtension(extensionName, extensionData = {}) {
|
|
193
|
-
assert(extensionData);
|
|
194
|
-
this.json.extensions = this.json.extensions || {};
|
|
195
|
-
this.json.extensions[extensionName] = extensionData;
|
|
196
|
-
this.registerUsedExtension(extensionName);
|
|
197
|
-
return extensionData;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
addRequiredExtension(extensionName, extensionData = {}) {
|
|
201
|
-
assert(extensionData);
|
|
202
|
-
this.addExtension(extensionName, extensionData);
|
|
203
|
-
this.registerRequiredExtension(extensionName);
|
|
204
|
-
return extensionData;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
registerUsedExtension(extensionName) {
|
|
208
|
-
this.json.extensionsUsed = this.json.extensionsUsed || [];
|
|
209
|
-
|
|
210
|
-
if (!this.json.extensionsUsed.find(ext => ext === extensionName)) {
|
|
211
|
-
this.json.extensionsUsed.push(extensionName);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
registerRequiredExtension(extensionName) {
|
|
216
|
-
this.registerUsedExtension(extensionName);
|
|
217
|
-
this.json.extensionsRequired = this.json.extensionsRequired || [];
|
|
218
|
-
|
|
219
|
-
if (!this.json.extensionsRequired.find(ext => ext === extensionName)) {
|
|
220
|
-
this.json.extensionsRequired.push(extensionName);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
removeExtension(extensionName) {
|
|
225
|
-
if (this.json.extensionsRequired) {
|
|
226
|
-
this._removeStringFromArray(this.json.extensionsRequired, extensionName);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (this.json.extensionsUsed) {
|
|
230
|
-
this._removeStringFromArray(this.json.extensionsUsed, extensionName);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (this.json.extensions) {
|
|
234
|
-
delete this.json.extensions[extensionName];
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
setDefaultScene(sceneIndex) {
|
|
239
|
-
this.json.scene = sceneIndex;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
addScene(scene) {
|
|
243
|
-
const {
|
|
244
|
-
nodeIndices
|
|
245
|
-
} = scene;
|
|
246
|
-
this.json.scenes = this.json.scenes || [];
|
|
247
|
-
this.json.scenes.push({
|
|
248
|
-
nodes: nodeIndices
|
|
249
|
-
});
|
|
250
|
-
return this.json.scenes.length - 1;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
addNode(node) {
|
|
254
|
-
const {
|
|
255
|
-
meshIndex,
|
|
256
|
-
matrix
|
|
257
|
-
} = node;
|
|
258
|
-
this.json.nodes = this.json.nodes || [];
|
|
259
|
-
const nodeData = {
|
|
260
|
-
mesh: meshIndex
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
if (matrix) {
|
|
264
|
-
nodeData.matrix = matrix;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
this.json.nodes.push(nodeData);
|
|
268
|
-
return this.json.nodes.length - 1;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
addMesh(mesh) {
|
|
272
|
-
const {
|
|
273
|
-
attributes,
|
|
274
|
-
indices,
|
|
275
|
-
material,
|
|
276
|
-
mode = 4
|
|
277
|
-
} = mesh;
|
|
278
|
-
|
|
279
|
-
const accessors = this._addAttributes(attributes);
|
|
280
|
-
|
|
281
|
-
const glTFMesh = {
|
|
282
|
-
primitives: [{
|
|
283
|
-
attributes: accessors,
|
|
284
|
-
mode
|
|
285
|
-
}]
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
if (indices) {
|
|
289
|
-
const indicesAccessor = this._addIndices(indices);
|
|
290
|
-
|
|
291
|
-
glTFMesh.primitives[0].indices = indicesAccessor;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (Number.isFinite(material)) {
|
|
295
|
-
glTFMesh.primitives[0].material = material;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
this.json.meshes = this.json.meshes || [];
|
|
299
|
-
this.json.meshes.push(glTFMesh);
|
|
300
|
-
return this.json.meshes.length - 1;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
addPointCloud(attributes) {
|
|
304
|
-
const accessorIndices = this._addAttributes(attributes);
|
|
305
|
-
|
|
306
|
-
const glTFMesh = {
|
|
307
|
-
primitives: [{
|
|
308
|
-
attributes: accessorIndices,
|
|
309
|
-
mode: 0
|
|
310
|
-
}]
|
|
311
|
-
};
|
|
312
|
-
this.json.meshes = this.json.meshes || [];
|
|
313
|
-
this.json.meshes.push(glTFMesh);
|
|
314
|
-
return this.json.meshes.length - 1;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
addImage(imageData, mimeTypeOpt) {
|
|
318
|
-
const metadata = getBinaryImageMetadata(imageData);
|
|
319
|
-
const mimeType = mimeTypeOpt || (metadata === null || metadata === void 0 ? void 0 : metadata.mimeType);
|
|
320
|
-
const bufferViewIndex = this.addBufferView(imageData);
|
|
321
|
-
const glTFImage = {
|
|
322
|
-
bufferView: bufferViewIndex,
|
|
323
|
-
mimeType
|
|
324
|
-
};
|
|
325
|
-
this.json.images = this.json.images || [];
|
|
326
|
-
this.json.images.push(glTFImage);
|
|
327
|
-
return this.json.images.length - 1;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
addBufferView(buffer) {
|
|
331
|
-
const byteLength = buffer.byteLength;
|
|
332
|
-
assert(Number.isFinite(byteLength));
|
|
333
|
-
this.sourceBuffers = this.sourceBuffers || [];
|
|
334
|
-
this.sourceBuffers.push(buffer);
|
|
335
|
-
const glTFBufferView = {
|
|
336
|
-
buffer: 0,
|
|
337
|
-
byteOffset: this.byteLength,
|
|
338
|
-
byteLength
|
|
339
|
-
};
|
|
340
|
-
this.byteLength += padToNBytes(byteLength, 4);
|
|
341
|
-
this.json.bufferViews = this.json.bufferViews || [];
|
|
342
|
-
this.json.bufferViews.push(glTFBufferView);
|
|
343
|
-
return this.json.bufferViews.length - 1;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
addAccessor(bufferViewIndex, accessor) {
|
|
347
|
-
const glTFAccessor = {
|
|
348
|
-
bufferView: bufferViewIndex,
|
|
349
|
-
type: getAccessorTypeFromSize(accessor.size),
|
|
350
|
-
componentType: accessor.componentType,
|
|
351
|
-
count: accessor.count,
|
|
352
|
-
max: accessor.max,
|
|
353
|
-
min: accessor.min
|
|
354
|
-
};
|
|
355
|
-
this.json.accessors = this.json.accessors || [];
|
|
356
|
-
this.json.accessors.push(glTFAccessor);
|
|
357
|
-
return this.json.accessors.length - 1;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
addBinaryBuffer(sourceBuffer, accessor = {
|
|
361
|
-
size: 3
|
|
362
|
-
}) {
|
|
363
|
-
const bufferViewIndex = this.addBufferView(sourceBuffer);
|
|
364
|
-
let minMax = {
|
|
365
|
-
min: accessor.min,
|
|
366
|
-
max: accessor.max
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
if (!minMax.min || !minMax.max) {
|
|
370
|
-
minMax = this._getAccessorMinMax(sourceBuffer, accessor.size);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
const accessorDefaults = {
|
|
374
|
-
size: accessor.size,
|
|
375
|
-
componentType: getComponentTypeFromArray(sourceBuffer),
|
|
376
|
-
count: Math.round(sourceBuffer.length / accessor.size),
|
|
377
|
-
min: minMax.min,
|
|
378
|
-
max: minMax.max
|
|
379
|
-
};
|
|
380
|
-
return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor));
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
addTexture(texture) {
|
|
384
|
-
const {
|
|
385
|
-
imageIndex
|
|
386
|
-
} = texture;
|
|
387
|
-
const glTFTexture = {
|
|
388
|
-
source: imageIndex
|
|
389
|
-
};
|
|
390
|
-
this.json.textures = this.json.textures || [];
|
|
391
|
-
this.json.textures.push(glTFTexture);
|
|
392
|
-
return this.json.textures.length - 1;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
addMaterial(pbrMaterialInfo) {
|
|
396
|
-
this.json.materials = this.json.materials || [];
|
|
397
|
-
this.json.materials.push(pbrMaterialInfo);
|
|
398
|
-
return this.json.materials.length - 1;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
createBinaryChunk() {
|
|
402
|
-
var _this$json, _this$json$buffers;
|
|
403
|
-
|
|
404
|
-
this.gltf.buffers = [];
|
|
405
|
-
const totalByteLength = this.byteLength;
|
|
406
|
-
const arrayBuffer = new ArrayBuffer(totalByteLength);
|
|
407
|
-
const targetArray = new Uint8Array(arrayBuffer);
|
|
408
|
-
let dstByteOffset = 0;
|
|
409
|
-
|
|
410
|
-
for (const sourceBuffer of this.sourceBuffers || []) {
|
|
411
|
-
dstByteOffset = copyToArray(sourceBuffer, targetArray, dstByteOffset);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
if ((_this$json = this.json) !== null && _this$json !== void 0 && (_this$json$buffers = _this$json.buffers) !== null && _this$json$buffers !== void 0 && _this$json$buffers[0]) {
|
|
415
|
-
this.json.buffers[0].byteLength = totalByteLength;
|
|
416
|
-
} else {
|
|
417
|
-
this.json.buffers = [{
|
|
418
|
-
byteLength: totalByteLength
|
|
419
|
-
}];
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
this.gltf.binary = arrayBuffer;
|
|
423
|
-
this.sourceBuffers = [arrayBuffer];
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
_removeStringFromArray(array, string) {
|
|
427
|
-
let found = true;
|
|
428
|
-
|
|
429
|
-
while (found) {
|
|
430
|
-
const index = array.indexOf(string);
|
|
431
|
-
|
|
432
|
-
if (index > -1) {
|
|
433
|
-
array.splice(index, 1);
|
|
434
|
-
} else {
|
|
435
|
-
found = false;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
_addAttributes(attributes = {}) {
|
|
441
|
-
const result = {};
|
|
442
|
-
|
|
443
|
-
for (const attributeKey in attributes) {
|
|
444
|
-
const attributeData = attributes[attributeKey];
|
|
445
|
-
|
|
446
|
-
const attrName = this._getGltfAttributeName(attributeKey);
|
|
447
|
-
|
|
448
|
-
const accessor = this.addBinaryBuffer(attributeData.value, attributeData);
|
|
449
|
-
result[attrName] = accessor;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
return result;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
_addIndices(indices) {
|
|
456
|
-
return this.addBinaryBuffer(indices, {
|
|
457
|
-
size: 1
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
_getGltfAttributeName(attributeName) {
|
|
462
|
-
switch (attributeName.toLowerCase()) {
|
|
463
|
-
case 'position':
|
|
464
|
-
case 'positions':
|
|
465
|
-
case 'vertices':
|
|
466
|
-
return 'POSITION';
|
|
467
|
-
|
|
468
|
-
case 'normal':
|
|
469
|
-
case 'normals':
|
|
470
|
-
return 'NORMAL';
|
|
471
|
-
|
|
472
|
-
case 'color':
|
|
473
|
-
case 'colors':
|
|
474
|
-
return 'COLOR_0';
|
|
475
|
-
|
|
476
|
-
case 'texcoord':
|
|
477
|
-
case 'texcoords':
|
|
478
|
-
return 'TEXCOORD_0';
|
|
479
|
-
|
|
480
|
-
default:
|
|
481
|
-
return attributeName;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
_getAccessorMinMax(buffer, size) {
|
|
486
|
-
const result = {
|
|
487
|
-
min: null,
|
|
488
|
-
max: null
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
if (buffer.length < size) {
|
|
492
|
-
return result;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
result.min = [];
|
|
496
|
-
result.max = [];
|
|
497
|
-
const initValues = buffer.subarray(0, size);
|
|
498
|
-
|
|
499
|
-
for (const value of initValues) {
|
|
500
|
-
result.min.push(value);
|
|
501
|
-
result.max.push(value);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
for (let index = size; index < buffer.length; index += size) {
|
|
505
|
-
for (let componentIndex = 0; componentIndex < size; componentIndex++) {
|
|
506
|
-
result.min[0 + componentIndex] = Math.min(result.min[0 + componentIndex], buffer[index + componentIndex]);
|
|
507
|
-
result.max[0 + componentIndex] = Math.max(result.max[0 + componentIndex], buffer[index + componentIndex]);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
return result;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
}
|
|
515
|
-
//# sourceMappingURL=gltf-scenegraph.js.map
|