@loaders.gl/gltf 4.0.0-alpha.6 → 4.0.0-alpha.7
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/dist.min.js +1415 -1339
- package/dist/es5/glb-loader.js +2 -2
- package/dist/es5/glb-loader.js.map +1 -1
- package/dist/es5/glb-writer.js +3 -4
- package/dist/es5/glb-writer.js.map +1 -1
- package/dist/es5/gltf-loader.js +3 -3
- package/dist/es5/gltf-loader.js.map +1 -1
- package/dist/es5/index.js +9 -3
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/api/gltf-scenegraph.js +47 -30
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/es5/lib/api/post-process-gltf.js +164 -116
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
- package/dist/es5/lib/encoders/encode-glb.js +1 -1
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
- package/dist/es5/lib/encoders/encode-gltf.js +2 -3
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +3 -5
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_texture_webp.js +2 -3
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +2 -3
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +6 -5
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +3 -4
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_transform.js +9 -8
- package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +2 -2
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +3 -3
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +3 -3
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +2 -2
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-utils.js +24 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/es5/lib/parsers/parse-glb.js +10 -10
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
- package/dist/es5/lib/parsers/parse-gltf.js +6 -10
- package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-postprocessed-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-types.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/esm/glb-loader.js +1 -1
- package/dist/esm/glb-loader.js.map +1 -1
- package/dist/esm/glb-writer.js +1 -1
- package/dist/esm/glb-writer.js.map +1 -1
- package/dist/esm/gltf-loader.js +3 -3
- package/dist/esm/gltf-loader.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
- package/dist/esm/lib/api/gltf-scenegraph.js +40 -29
- package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/esm/lib/api/post-process-gltf.js +167 -112
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
- package/dist/esm/lib/encoders/encode-glb.js +1 -1
- package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
- package/dist/esm/lib/encoders/encode-gltf.js +1 -1
- package/dist/esm/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js +2 -3
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_texture_webp.js +1 -1
- package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_binary_gltf.js +1 -1
- package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +5 -4
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_basisu.js +2 -2
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_transform.js +7 -6
- package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +1 -1
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-utils.js +20 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/esm/lib/parsers/parse-glb.js +10 -10
- package/dist/esm/lib/parsers/parse-glb.js.map +1 -1
- package/dist/esm/lib/parsers/parse-gltf.js +5 -6
- package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-types.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/glb-loader.d.ts +2 -2
- package/dist/glb-loader.js +2 -5
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +4 -6
- package/dist/gltf-loader.d.ts +5 -5
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +3 -3
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -5
- package/dist/lib/api/gltf-extensions.d.ts +1 -1
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.d.ts +6 -4
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +43 -30
- package/dist/lib/api/post-process-gltf.d.ts +4 -1
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
- package/dist/lib/api/post-process-gltf.js +186 -123
- package/dist/lib/encoders/encode-glb.d.ts +13 -1
- package/dist/lib/encoders/encode-glb.d.ts.map +1 -1
- package/dist/lib/encoders/encode-glb.js +15 -4
- package/dist/lib/encoders/encode-gltf.js +2 -5
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +3 -7
- package/dist/lib/extensions/EXT_texture_webp.d.ts +1 -1
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +2 -5
- package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.js +2 -5
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +5 -8
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +3 -6
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_transform.js +7 -10
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +2 -5
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +3 -6
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +3 -6
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +2 -5
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.d.ts +7 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.js +28 -1
- package/dist/lib/parsers/parse-glb.d.ts +15 -3
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
- package/dist/lib/parsers/parse-glb.js +43 -18
- package/dist/lib/parsers/parse-gltf.d.ts +8 -4
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +13 -34
- package/dist/lib/types/gltf-json-schema.d.ts +151 -138
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-postprocessed-schema.d.ts +174 -209
- package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-postprocessed-schema.js +1 -1
- package/dist/lib/types/gltf-types.d.ts +18 -6
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/glb-loader.ts +3 -3
- package/src/glb-writer.ts +3 -1
- package/src/gltf-loader.ts +12 -8
- package/src/index.ts +32 -13
- package/src/lib/api/gltf-extensions.ts +1 -1
- package/src/lib/api/gltf-scenegraph.ts +55 -37
- package/src/lib/api/post-process-gltf.ts +275 -150
- package/src/lib/encoders/encode-glb.ts +15 -5
- package/src/lib/encoders/encode-gltf.ts +1 -1
- package/src/lib/extensions/EXT_meshopt_compression.ts +4 -6
- package/src/lib/extensions/EXT_texture_webp.ts +2 -2
- package/src/lib/extensions/KHR_binary_gltf.ts +2 -2
- package/src/lib/extensions/KHR_draco_mesh_compression.ts +7 -7
- package/src/lib/extensions/KHR_texture_basisu.ts +3 -3
- package/src/lib/extensions/KHR_texture_transform.ts +22 -19
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +2 -2
- package/src/lib/extensions/deprecated/KHR_lights_punctual.ts +2 -2
- package/src/lib/extensions/deprecated/KHR_materials_unlit.ts +2 -2
- package/src/lib/extensions/deprecated/KHR_techniques_webgl.ts +2 -2
- package/src/lib/gltf-utils/gltf-attribute-utils.ts +1 -1
- package/src/lib/gltf-utils/gltf-utils.ts +31 -0
- package/src/lib/parsers/parse-glb.ts +50 -24
- package/src/lib/parsers/parse-gltf.ts +22 -16
- package/src/lib/types/gltf-json-schema.ts +165 -138
- package/src/lib/types/gltf-postprocessed-schema.ts +289 -212
- package/src/lib/types/gltf-types.ts +35 -59
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode-gltf.js","names":["encodeGLBSync","encodeGLTFSync","gltf","arrayBuffer","byteOffset","options","convertBuffersToBase64","firstBuffer","arguments","length","undefined","buffers","Error"],"sources":["../../../../src/lib/encoders/encode-gltf.ts"],"sourcesContent":["import encodeGLBSync from './encode-glb';\n\nexport type GLTFEncodeOptions = Record<string, any>;\n\n/**\n * Encode the full glTF file as a binary GLB file\n * Returns an ArrayBuffer that represents the complete GLB image that can be saved to file\n *\n * @todo - Does not support encoding to non-GLB versions of glTF format. Other formats\n * - Encode as a textual JSON file with binary data in base64 data URLs.\n * - Encode as a JSON with all images (and buffers?) in separate binary files\n *\n * glb-file-format-specification\n * @see https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#\n *\n * @param gltf\n * @param arrayBuffer\n * @param byteOffset\n * @param options\n * @returns\n */\nexport function encodeGLTFSync(gltf, arrayBuffer, byteOffset, options) {\n convertBuffersToBase64(gltf);\n\n // TODO: Copy buffers to binary\n\n return encodeGLBSync(gltf, arrayBuffer, byteOffset, options);\n}\n\nfunction convertBuffersToBase64(gltf, {firstBuffer = 0} = {}) {\n if (gltf.buffers && gltf.buffers.length > firstBuffer) {\n throw new Error('encodeGLTF: multiple buffers not yet implemented');\n }\n}\n"],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"encode-gltf.js","names":["encodeGLBSync","encodeGLTFSync","gltf","arrayBuffer","byteOffset","options","convertBuffersToBase64","firstBuffer","arguments","length","undefined","buffers","Error"],"sources":["../../../../src/lib/encoders/encode-gltf.ts"],"sourcesContent":["import {encodeGLBSync} from './encode-glb';\n\nexport type GLTFEncodeOptions = Record<string, any>;\n\n/**\n * Encode the full glTF file as a binary GLB file\n * Returns an ArrayBuffer that represents the complete GLB image that can be saved to file\n *\n * @todo - Does not support encoding to non-GLB versions of glTF format. Other formats\n * - Encode as a textual JSON file with binary data in base64 data URLs.\n * - Encode as a JSON with all images (and buffers?) in separate binary files\n *\n * glb-file-format-specification\n * @see https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#\n *\n * @param gltf\n * @param arrayBuffer\n * @param byteOffset\n * @param options\n * @returns\n */\nexport function encodeGLTFSync(gltf, arrayBuffer, byteOffset, options) {\n convertBuffersToBase64(gltf);\n\n // TODO: Copy buffers to binary\n\n return encodeGLBSync(gltf, arrayBuffer, byteOffset, options);\n}\n\nfunction convertBuffersToBase64(gltf, {firstBuffer = 0} = {}) {\n if (gltf.buffers && gltf.buffers.length > firstBuffer) {\n throw new Error('encodeGLTF: multiple buffers not yet implemented');\n }\n}\n"],"mappings":"AAAA,SAAQA,aAAa,QAAO,cAAc;AAqB1C,OAAO,SAASC,cAAcA,CAACC,IAAI,EAAEC,WAAW,EAAEC,UAAU,EAAEC,OAAO,EAAE;EACrEC,sBAAsB,CAACJ,IAAI,CAAC;EAI5B,OAAOF,aAAa,CAACE,IAAI,EAAEC,WAAW,EAAEC,UAAU,EAAEC,OAAO,CAAC;AAC9D;AAEA,SAASC,sBAAsBA,CAACJ,IAAI,EAA0B;EAAA,IAAxB;IAACK,WAAW,GAAG;EAAC,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAC1D,IAAIN,IAAI,CAACS,OAAO,IAAIT,IAAI,CAACS,OAAO,CAACF,MAAM,GAAGF,WAAW,EAAE;IACrD,MAAM,IAAIK,KAAK,CAAC,kDAAkD,CAAC;EACrE;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
1
|
+
import { GLTFScenegraph } from '../api/gltf-scenegraph';
|
|
2
2
|
import { meshoptDecodeGltfBuffer } from '../../meshopt/meshopt-decoder';
|
|
3
3
|
const DEFAULT_MESHOPT_OPTIONS = {
|
|
4
4
|
byteOffset: 0,
|
|
@@ -35,8 +35,7 @@ async function decodeMeshoptBufferView(scenegraph, bufferView) {
|
|
|
35
35
|
const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength);
|
|
36
36
|
const result = new Uint8Array(scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer, bufferView.byteOffset, bufferView.byteLength);
|
|
37
37
|
await meshoptDecodeGltfBuffer(result, count, byteStride, source, mode, filter);
|
|
38
|
-
|
|
38
|
+
scenegraph.removeObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION);
|
|
39
39
|
}
|
|
40
|
-
return null;
|
|
41
40
|
}
|
|
42
41
|
//# sourceMappingURL=EXT_meshopt_compression.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_meshopt_compression.js","names":["GLTFScenegraph","meshoptDecodeGltfBuffer","DEFAULT_MESHOPT_OPTIONS","byteOffset","filter","EXT_MESHOPT_COMPRESSION","name","decode","gltfData","options","_options$gltf","scenegraph","gltf","decompressMeshes","promises","bufferViewIndex","json","bufferViews","push","decodeMeshoptBufferView","Promise","all","removeExtension","bufferView","meshoptExtension","getObjectExtension","byteLength","byteStride","count","mode","buffer","bufferIndex","buffers","source","Uint8Array","arrayBuffer","result"],"sources":["../../../../src/lib/extensions/EXT_meshopt_compression.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport type {GLTF, GLTFBufferView, GLTF_EXT_meshopt_compression} from '../types/gltf-
|
|
1
|
+
{"version":3,"file":"EXT_meshopt_compression.js","names":["GLTFScenegraph","meshoptDecodeGltfBuffer","DEFAULT_MESHOPT_OPTIONS","byteOffset","filter","EXT_MESHOPT_COMPRESSION","name","decode","gltfData","options","_options$gltf","scenegraph","gltf","decompressMeshes","promises","bufferViewIndex","json","bufferViews","push","decodeMeshoptBufferView","Promise","all","removeExtension","bufferView","meshoptExtension","getObjectExtension","byteLength","byteStride","count","mode","buffer","bufferIndex","buffers","source","Uint8Array","arrayBuffer","result","removeObjectExtension"],"sources":["../../../../src/lib/extensions/EXT_meshopt_compression.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport type {GLTF, GLTFBufferView, GLTF_EXT_meshopt_compression} from '../types/gltf-json-schema';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\nimport {meshoptDecodeGltfBuffer} from '../../meshopt/meshopt-decoder';\n\n// @ts-ignore\n// eslint-disable-next-line\nconst DEFAULT_MESHOPT_OPTIONS = {\n byteOffset: 0,\n filter: 'NONE'\n};\n\n/** Extension name */\nconst EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';\n\nexport const name = EXT_MESHOPT_COMPRESSION;\n\nexport async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions) {\n const scenegraph = new GLTFScenegraph(gltfData);\n\n if (!options?.gltf?.decompressMeshes) {\n return;\n }\n\n const promises: Promise<any>[] = [];\n for (const bufferViewIndex of gltfData.json.bufferViews || []) {\n promises.push(decodeMeshoptBufferView(scenegraph, bufferViewIndex));\n }\n\n // Decompress meshes in parallel\n await Promise.all(promises);\n\n // We have now decompressed all primitives, so remove the top-level extension\n scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION);\n}\n\n/** Decode one meshopt buffer view */\nasync function decodeMeshoptBufferView(\n scenegraph: GLTFScenegraph,\n bufferView: GLTFBufferView\n): Promise<void> {\n const meshoptExtension = scenegraph.getObjectExtension<GLTF_EXT_meshopt_compression>(\n bufferView,\n EXT_MESHOPT_COMPRESSION\n );\n if (meshoptExtension) {\n const {\n byteOffset = 0,\n byteLength = 0,\n byteStride,\n count,\n mode,\n filter = 'NONE',\n buffer: bufferIndex\n } = meshoptExtension;\n const buffer = scenegraph.gltf.buffers[bufferIndex];\n\n const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength);\n const result = new Uint8Array(\n scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer,\n bufferView.byteOffset,\n bufferView.byteLength\n );\n await meshoptDecodeGltfBuffer(result, count, byteStride, source, mode, filter);\n scenegraph.removeObjectExt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U,CAACC,IAAI,CAACoB,OAAO,CAACD,WAAW,CAAC;IAEnD,MAAME,MAAM,GAAG,IAAIC,UAAU,CAACJ,MAAM,CAACK,WAAW,EAAEL,MAAM,CAAC3B,UAAU,GAAGA,UAAU,EAAEuB,UAAU,CAAC;IAC7F,MAAMU,MAAM,GAAG,IAAIF,UAAU,CAC3BvB,UAAU,CAACC,IAAI,CAACoB,OAAO,CAACT,UAAU,CAACO,MAAM,CAAC,CAACK,WAAW,EACtDZ,UAAU,CAACpB,UAAU,EACrBoB,UAAU,CAACG,UACb,CAAC;IACD,MAAMzB,uBAAuB,CAACmC,MAAM,EAAER,KAAK,EAAED,UAAU,EAAEM,MAAM,EAAEJ,IAAI,EAAEzB,MAAM,CAAC;IAC9EO,UAAU,CAAC0B,qBAAqB,CAACd,UAAU,EAAElB,uBAAuB,CAAC;EACvE;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isImageFormatSupported } from '@loaders.gl/images';
|
|
2
|
-
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
2
|
+
import { GLTFScenegraph } from '../api/gltf-scenegraph';
|
|
3
3
|
const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
|
|
4
4
|
export const name = EXT_TEXTURE_WEBP;
|
|
5
5
|
export function preprocess(gltfData, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_texture_webp.js","names":["isImageFormatSupported","GLTFScenegraph","EXT_TEXTURE_WEBP","name","preprocess","gltfData","options","scenegraph","getRequiredExtensions","includes","Error","concat","json","texture","textures","extension","getObjectExtension","source","removeObjectExtension","removeExtension"],"sources":["../../../../src/lib/extensions/EXT_texture_webp.ts"],"sourcesContent":["// GLTF EXTENSION: EXT_TEXTURE_WEBP\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_EXT_texture_webp} from '../types/gltf-
|
|
1
|
+
{"version":3,"file":"EXT_texture_webp.js","names":["isImageFormatSupported","GLTFScenegraph","EXT_TEXTURE_WEBP","name","preprocess","gltfData","options","scenegraph","getRequiredExtensions","includes","Error","concat","json","texture","textures","extension","getObjectExtension","source","removeObjectExtension","removeExtension"],"sources":["../../../../src/lib/extensions/EXT_texture_webp.ts"],"sourcesContent":["// GLTF EXTENSION: EXT_TEXTURE_WEBP\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_EXT_texture_webp} from '../types/gltf-json-schema';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport {isImageFormatSupported} from '@loaders.gl/images';\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\n\nconst EXT_TEXTURE_WEBP = 'EXT_texture_webp';\n\n/** Extension name */\nexport const name = EXT_TEXTURE_WEBP;\n\n/**\n * Replaces a texture source reference with the extension texture\n * Done in preprocess() to prevent load of default image\n */\nexport function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {\n const scenegraph = new GLTFScenegraph(gltfData);\n\n if (!isImageFormatSupported('image/webp')) {\n if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {\n throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`);\n }\n return;\n }\n\n const {json} = scenegraph;\n\n for (const texture of json.textures || []) {\n const extension = scenegraph.getObjectExtension<GLTF_EXT_texture_webp>(\n texture,\n EXT_TEXTURE_WEBP\n );\n if (extension) {\n // TODO - if multiple texture extensions are present which one wins?\n texture.source = extension.source;\n }\n scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP);\n }\n\n // Remove the top-level extension\n scenegraph.removeExtension(EXT_TEXTURE_WEBP);\n}\n"],"mappings":"AAOA,SAAQA,sBAAsB,QAAO,oBAAoB;AACzD,SAAQC,cAAc,QAAO,wBAAwB;AAErD,MAAMC,gBAAgB,GAAG,kBAAkB;AAG3C,OAAO,MAAMC,IAAI,GAAGD,gBAAgB;AAMpC,OAAO,SAASE,UAAUA,CAACC,QAAsB,EAAEC,OAA0B,EAAQ;EACnF,MAAMC,UAAU,GAAG,IAAIN,cAAc,CAACI,QAAQ,CAAC;EAE/C,IAAI,CAACL,sBAAsB,CAAC,YAAY,CAAC,EAAE;IACzC,IAAIO,UAAU,CAACC,qBAAqB,CAAC,CAAC,CAACC,QAAQ,CAACP,gBAAgB,CAAC,EAAE;MACjE,MAAM,IAAIQ,KAAK,6BAAAC,MAAA,CAA6BT,gBAAgB,8BAA2B,CAAC;IAC1F;IACA;EACF;EAEA,MAAM;IAACU;EAAI,CAAC,GAAGL,UAAU;EAEzB,KAAK,MAAMM,OAAO,IAAID,IAAI,CAACE,QAAQ,IAAI,EAAE,EAAE;IACzC,MAAMC,SAAS,GAAGR,UAAU,CAACS,kBAAkB,CAC7CH,OAAO,EACPX,gBACF,CAAC;IACD,IAAIa,SAAS,EAAE;MAEbF,OAAO,CAACI,MAAM,GAAGF,SAAS,CAACE,MAAM;IACnC;IACAV,UAAU,CAACW,qBAAqB,CAACL,OAAO,EAAEX,gBAAgB,CAAC;EAC7D;EAGAK,UAAU,CAACY,eAAe,CAACjB,gBAAgB,CAAC;AAC9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_binary_gltf.js","names":["GLTFScenegraph","KHR_BINARY_GLTF","name","preprocess","gltfData","gltfScenegraph","json","image","images","extension","getObjectExtension","Object","assign","removeObjectExtension","buffers","uri","removeExtension"],"sources":["../../../../src/lib/extensions/KHR_binary_gltf.ts"],"sourcesContent":["// GLTF 1.0 EXTENSION: KHR_binary_glTF\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-
|
|
1
|
+
{"version":3,"file":"KHR_binary_gltf.js","names":["GLTFScenegraph","KHR_BINARY_GLTF","name","preprocess","gltfData","gltfScenegraph","json","image","images","extension","getObjectExtension","Object","assign","removeObjectExtension","buffers","uri","removeExtension"],"sources":["../../../../src/lib/extensions/KHR_binary_gltf.ts"],"sourcesContent":["// GLTF 1.0 EXTENSION: KHR_binary_glTF\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-json-schema';\n\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\n\nconst KHR_BINARY_GLTF = 'KHR_binary_glTF';\n\n/** Extension name */\nexport const name = KHR_BINARY_GLTF;\n\nexport function preprocess(gltfData: {json: GLTF}): void {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // Note: json.buffers.binary_glTF also needs to be replaced\n // This is currently done during gltf normalization\n\n // Image and shader nodes can have the extension\n // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/image.KHR_binary_glTF.schema.json\n for (const image of json.images || []) {\n const extension = gltfScenegraph.getObjectExtension<GLTF_KHR_binary_glTF>(\n image,\n KHR_BINARY_GLTF\n );\n // The data in the extension is valid as glTF 2.0 data inside the object, so just copy it in\n if (extension) {\n Object.assign(image, extension);\n }\n gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF);\n }\n\n // TODO shaders - At least traverse and throw error if used?\n // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/shader.KHR_binary_glTF.schema.json\n\n // glTF v1 one files have a partially formed URI field that is not expected in (and causes problems in) 2.0\n if (json.buffers && json.buffers[0]) {\n delete json.buffers[0].uri;\n }\n\n // Remove the top-level extension as it has now been processed\n gltfScenegraph.removeExtension(KHR_BINARY_GLTF);\n}\n\n// KHR_binary_gltf is a 1.0 extension that is supported natively by 2.0\n// export function encode() {\n// throw new Error(KHR_BINARY_GLTF);\n// }\n"],"mappings":"AAMA,SAAQA,cAAc,QAAO,wBAAwB;AAErD,MAAMC,eAAe,GAAG,iBAAiB;AAGzC,OAAO,MAAMC,IAAI,GAAGD,eAAe;AAEnC,OAAO,SAASE,UAAUA,CAACC,QAAsB,EAAQ;EACvD,MAAMC,cAAc,GAAG,IAAIL,cAAc,CAACI,QAAQ,CAAC;EACnD,MAAM;IAACE;EAAI,CAAC,GAAGD,cAAc;EAO7B,KAAK,MAAME,KAAK,IAAID,IAAI,CAACE,MAAM,IAAI,EAAE,EAAE;IACrC,MAAMC,SAAS,GAAGJ,cAAc,CAACK,kBAAkB,CACjDH,KAAK,EACLN,eACF,CAAC;IAED,IAAIQ,SAAS,EAAE;MACbE,MAAM,CAACC,MAAM,CAACL,KAAK,EAAEE,SAAS,CAAC;IACjC;IACAJ,cAAc,CAACQ,qBAAqB,CAACN,KAAK,EAAEN,eAAe,CAAC;EAC9D;EAMA,IAAIK,IAAI,CAACQ,OAAO,IAAIR,IAAI,CAACQ,OAAO,CAAC,CAAC,CAAC,EAAE;IACnC,OAAOR,IAAI,CAACQ,OAAO,CAAC,CAAC,CAAC,CAACC,GAAG;EAC5B;EAGAV,cAAc,CAACW,eAAe,CAACf,eAAe,CAAC;AACjD"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { DracoLoader } from '@loaders.gl/draco';
|
|
2
2
|
import { sliceArrayBuffer } from '@loaders.gl/loader-utils';
|
|
3
|
-
import {
|
|
3
|
+
import { GLTFScenegraph } from '../api/gltf-scenegraph';
|
|
4
4
|
import { getGLTFAccessors, getGLTFAccessor } from '../gltf-utils/gltf-attribute-utils';
|
|
5
5
|
const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';
|
|
6
6
|
export const name = KHR_DRACO_MESH_COMPRESSION;
|
|
7
7
|
export function preprocess(gltfData, options, context) {
|
|
8
|
-
const scenegraph = new
|
|
8
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
9
9
|
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
10
10
|
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {}
|
|
11
11
|
}
|
|
@@ -15,7 +15,7 @@ export async function decode(gltfData, options, context) {
|
|
|
15
15
|
if (!(options !== null && options !== void 0 && (_options$gltf = options.gltf) !== null && _options$gltf !== void 0 && _options$gltf.decompressMeshes)) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
const scenegraph = new
|
|
18
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
19
19
|
const promises = [];
|
|
20
20
|
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
21
21
|
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
@@ -27,7 +27,7 @@ export async function decode(gltfData, options, context) {
|
|
|
27
27
|
}
|
|
28
28
|
export function encode(gltfData) {
|
|
29
29
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
30
|
-
const scenegraph = new
|
|
30
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
31
31
|
for (const mesh of scenegraph.json.meshes || []) {
|
|
32
32
|
compressMesh(mesh, options);
|
|
33
33
|
scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);
|
|
@@ -63,6 +63,7 @@ async function decompressPrimitive(scenegraph, primitive, options, context) {
|
|
|
63
63
|
if (decodedData.indices) {
|
|
64
64
|
primitive.indices = getGLTFAccessor(decodedData.indices);
|
|
65
65
|
}
|
|
66
|
+
scenegraph.removeObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);
|
|
66
67
|
checkPrimitive(primitive);
|
|
67
68
|
}
|
|
68
69
|
function compressMesh(attributes, indices) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_draco_mesh_compression.js","names":["DracoLoader","sliceArrayBuffer","default","Scenegraph","getGLTFAccessors","getGLTFAccessor","KHR_DRACO_MESH_COMPRESSION","name","preprocess","gltfData","options","context","scenegraph","primitive","makeMeshPrimitiveIterator","getObjectExtension","decode","_options$gltf","gltf","decompressMeshes","promises","push","decompressPrimitive","Promise","all","removeExtension","encode","arguments","length","undefined","mesh","json","meshes","compressMesh","addRequiredExtension","dracoExtension","buffer","getTypedArrayForBufferView","bufferView","bufferCopy","byteOffset","parse","dracoOptions","decodedData","decodedAttributes","attributes","attributeName","decodedAttribute","Object","entries","accessorIndex","accessor","getAccessor","min","max","indices","checkPrimitive","_context$parseSync","mode","DracoWriter","Error","compressedData","encodeSync","parseSync","call","fauxAccessors","_addFauxAttributes","bufferViewIndex","addBufferView","glTFMesh","primitives","extensions","keys"],"sources":["../../../../src/lib/extensions/KHR_draco_mesh_compression.ts"],"sourcesContent":["// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression\n// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported\n/* eslint-disable camelcase */\n\n/* eslint-disable camelcase */\nimport type {\n GLTF,\n GLTFAccessor,\n GLTFMeshPrimitive,\n GLTF_KHR_draco_mesh_compression\n} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport type {LoaderContext} from '@loaders.gl/loader-utils';\nimport {DracoLoader} from '@loaders.gl/draco';\nimport {DracoLoaderOptions, DracoMesh} from '@loaders.gl/draco';\nimport {sliceArrayBuffer} from '@loaders.gl/loader-utils';\nimport {default as Scenegraph} from '../api/gltf-scenegraph';\nimport {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';\n\nconst KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';\n\n/** Extension name */\nexport const name = KHR_DRACO_MESH_COMPRESSION;\n\nexport function preprocess(\n gltfData: {json: GLTF},\n options: GLTFLoaderOptions,\n context: LoaderContext\n): void {\n const scenegraph = new Scenegraph(gltfData);\n for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {\n if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {\n // TODO - Remove fallback accessors to make sure we don't load unnecessary buffers\n }\n }\n}\n\nexport async function decode(\n gltfData: {json: GLTF},\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<void> {\n if (!options?.gltf?.decompressMeshes) {\n return;\n }\n\n const scenegraph = new Scenegraph(gltfData);\n const promises: Promise<void>[] = [];\n for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {\n if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {\n promises.push(decompressPrimitive(scenegraph, primitive, options, context));\n }\n }\n\n // Decompress meshes in parallel\n await Promise.all(promises);\n\n // We have now decompressed all primitives, so remove the top-level extension\n scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);\n}\n\nexport function encode(gltfData, options: GLTFLoaderOptions = {}): void {\n const scenegraph = new Scenegraph(gltfData);\n\n for (const mesh of scenegraph.json.meshes || []) {\n // eslint-disable-next-line camelcase\n // @ts-ignore\n compressMesh(mesh, options);\n // NOTE: Only add the extension if something was actually compressed\n scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);\n }\n}\n\n// DECODE\n\n// Unpacks one mesh primitive and removes the extension from the primitive\n// DracoDecoder needs to be imported and registered by app\n// Returns: Promise that resolves when all pending draco decoder jobs for this mesh complete\n\n// TODO - Implement fallback behavior per KHR_DRACO_MESH_COMPRESSION spec\n\nasync function decompressPrimitive(\n scenegraph: Scenegraph,\n primitive: GLTFMeshPrimitive,\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<void> {\n const dracoExtension = scenegraph.getObjectExtension<GLTF_KHR_draco_mesh_compression>(\n primitive,\n KHR_DRACO_MESH_COMPRESSION\n );\n if (!dracoExtension) {\n return;\n }\n\n const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);\n // TODO - parse does not yet deal well with byte offsets embedded in typed arrays. Copy buffer\n // TODO - remove when `parse` is fixed to handle `byteOffset`s\n const bufferCopy = sliceArrayBuffer(buffer.buffer, buffer.byteOffset); // , buffer.byteLength);\n\n const {parse} = context;\n const dracoOptions: DracoLoaderOptions = {...options};\n\n // TODO - remove hack: The entire tileset might be included, too expensive to serialize\n delete dracoOptions['3d-tiles'];\n const decodedData = (await parse(bufferCopy, DracoLoader, dracoOptions, context)) as DracoMesh;\n\n const decodedAttributes: {[key: string]: GLTFAccessor} = getGLTFAccessors(decodedData.attributes);\n\n // Restore min/max values\n for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) {\n if (attributeName in primitive.attributes) {\n const accessorIndex: number = primitive.attributes[attributeName];\n const accessor = scenegraph.getAccessor(accessorIndex);\n if (accessor?.min && accessor?.max) {\n decodedAttribute.min = accessor.min;\n decodedAttribute.max = accessor.max;\n }\n }\n }\n\n // @ts-ignore\n primitive.attributes = decodedAttributes;\n if (decodedData.indices) {\n // @ts-ignore\n primitive.indices = getGLTFAccessor(decodedData.indices);\n }\n\n // Extension has been processed, delete it\n // delete primitive.extensions[KHR_DRACO_MESH_COMPRESSION];\n\n checkPrimitive(primitive);\n}\n\n// ENCODE\n\n// eslint-disable-next-line max-len\n// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported\nfunction compressMesh(attributes, indices, mode: number = 4, options, context: LoaderContext) {\n if (!options.DracoWriter) {\n throw new Error('options.gltf.DracoWriter not provided');\n }\n\n // TODO - use DracoWriter using encode w/ registered DracoWriter...\n const compressedData = options.DracoWriter.encodeSync({attributes});\n\n // Draco compression may change the order and number of vertices in a mesh.\n // To satisfy the requirement that accessors properties be correct for both\n // compressed and uncompressed data, generators should create uncompressed\n // attributes and indices using data that has been decompressed from the Draco buffer,\n // rather than the original source data.\n // @ts-ignore TODO this needs to be fixed\n const decodedData = context?.parseSync?.({attributes});\n const fauxAccessors = options._addFauxAttributes(decodedData.attributes);\n\n const bufferViewIndex = options.addBufferView(compressedData);\n\n const glTFMesh = {\n primitives: [\n {\n attributes: fauxAccessors, // TODO - verify with spec\n mode, // GL.POINTS\n extensions: {\n [KHR_DRACO_MESH_COMPRESSION]: {\n bufferView: bufferViewIndex,\n attributes: fauxAccessors // TODO - verify with spec\n }\n }\n }\n ]\n };\n\n return glTFMesh;\n}\n\n// UTILS\n\nfunction checkPrimitive(primitive: GLTFMeshPrimitive) {\n if (!primitive.attributes && Object.keys(primitive.attributes).length > 0) {\n throw new Error('glTF: Empty primitive detected: Draco decompression failure?');\n }\n}\n\nfunction* makeMeshPrimitiveIterator(scenegraph) {\n for (const mesh of scenegraph.json.meshes || []) {\n for (const primitive of mesh.primitives) {\n yield primitive;\n }\n }\n}\n"],"mappings":"AAcA,SAAQA,WAAW,QAAO,mBAAmB;AAE7C,SAAQC,gBAAgB,QAAO,0BAA0B;AACzD,SAAQC,OAAO,IAAIC,UAAU,QAAO,wBAAwB;AAC5D,SAAQC,gBAAgB,EAAEC,eAAe,QAAO,oCAAoC;AAEpF,MAAMC,0BAA0B,GAAG,4BAA4B;AAG/D,OAAO,MAAMC,IAAI,GAAGD,0BAA0B;AAE9C,OAAO,SAASE,UAAUA,CACxBC,QAAsB,EACtBC,OAA0B,EAC1BC,OAAsB,EAChB;EACN,MAAMC,UAAU,GAAG,IAAIT,UAAU,CAACM,QAAQ,CAAC;EAC3C,KAAK,MAAMI,SAAS,IAAIC,yBAAyB,CAACF,UAAU,CAAC,EAAE;IAC7D,IAAIA,UAAU,CAACG,kBAAkB,CAACF,SAAS,EAAEP,0BAA0B,CAAC,EAAE,CAE1E;EACF;AACF;AAEA,OAAO,eAAeU,MAAMA,CAC1BP,QAAsB,EACtBC,OAA0B,EAC1BC,OAAsB,EACP;EAAA,IAAAM,aAAA;EACf,IAAI,EAACP,OAAO,aAAPA,OAAO,gBAAAO,aAAA,GAAPP,OAAO,CAAEQ,IAAI,cAAAD,aAAA,eAAbA,aAAA,CAAeE,gBAAgB,GAAE;IACpC;EACF;EAEA,MAAMP,UAAU,GAAG,IAAIT,UAAU,CAACM,QAAQ,CAAC;EAC3C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AMnB,SAAS,IAAIiB,IAAI,CAACwC,UAAU,EAAE;MACvC,MAAMzD,SAAS;IACjB;EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"KHR_draco_mesh_compression.js","names":["DracoLoader","sliceArrayBuffer","GLTFScenegraph","getGLTFAccessors","getGLTFAccessor","KHR_DRACO_MESH_COMPRESSION","name","preprocess","gltfData","options","context","scenegraph","primitive","makeMeshPrimitiveIterator","getObjectExtension","decode","_options$gltf","gltf","decompressMeshes","promises","push","decompressPrimitive","Promise","all","removeExtension","encode","arguments","length","undefined","mesh","json","meshes","compressMesh","addRequiredExtension","dracoExtension","buffer","getTypedArrayForBufferView","bufferView","bufferCopy","byteOffset","parse","dracoOptions","decodedData","decodedAttributes","attributes","attributeName","decodedAttribute","Object","entries","accessorIndex","accessor","getAccessor","min","max","indices","removeObjectExtension","checkPrimitive","_context$parseSync","mode","DracoWriter","Error","compressedData","encodeSync","parseSync","call","fauxAccessors","_addFauxAttributes","bufferViewIndex","addBufferView","glTFMesh","primitives","extensions","keys"],"sources":["../../../../src/lib/extensions/KHR_draco_mesh_compression.ts"],"sourcesContent":["// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression\n// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported\n/* eslint-disable camelcase */\n\n/* eslint-disable camelcase */\nimport type {\n GLTF,\n GLTFAccessor,\n GLTFMeshPrimitive,\n GLTF_KHR_draco_mesh_compression\n} from '../types/gltf-json-schema';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport type {LoaderContext} from '@loaders.gl/loader-utils';\nimport {DracoLoader} from '@loaders.gl/draco';\nimport {DracoLoaderOptions, DracoMesh} from '@loaders.gl/draco';\nimport {sliceArrayBuffer} from '@loaders.gl/loader-utils';\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\nimport {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';\n\nconst KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';\n\n/** Extension name */\nexport const name = KHR_DRACO_MESH_COMPRESSION;\n\nexport function preprocess(\n gltfData: {json: GLTF},\n options: GLTFLoaderOptions,\n context: LoaderContext\n): void {\n const scenegraph = new GLTFScenegraph(gltfData);\n for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {\n if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {\n // TODO - Remove fallback accessors to make sure we don't load unnecessary buffers\n }\n }\n}\n\nexport async function decode(\n gltfData: {json: GLTF},\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<void> {\n if (!options?.gltf?.decompressMeshes) {\n return;\n }\n\n const scenegraph = new GLTFScenegraph(gltfData);\n const promises: Promise<void>[] = [];\n for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {\n if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {\n promises.push(decompressPrimitive(scenegraph, primitive, options, context));\n }\n }\n\n // Decompress meshes in parallel\n await Promise.all(promises);\n\n // We have now decompressed all primitives, so remove the top-level extension\n scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);\n}\n\nexport function encode(gltfData, options: GLTFLoaderOptions = {}): void {\n const scenegraph = new GLTFScenegraph(gltfData);\n\n for (const mesh of scenegraph.json.meshes || []) {\n // eslint-disable-next-line camelcase\n // @ts-ignore\n compressMesh(mesh, options);\n // NOTE: Only add the extension if something was actually compressed\n scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);\n }\n}\n\n// DECODE\n\n// Unpacks one mesh primitive and removes the extension from the primitive\n// DracoDecoder needs to be imported and registered by app\n// Returns: Promise that resolves when all pending draco decoder jobs for this mesh complete\n\n// TODO - Implement fallback behavior per KHR_DRACO_MESH_COMPRESSION spec\n\nasync function decompressPrimitive(\n scenegraph: GLTFScenegraph,\n primitive: GLTFMeshPrimitive,\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<void> {\n const dracoExtension = scenegraph.getObjectExtension<GLTF_KHR_draco_mesh_compression>(\n primitive,\n KHR_DRACO_MESH_COMPRESSION\n );\n if (!dracoExtension) {\n return;\n }\n\n const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);\n // TODO - parse does not yet deal well with byte offsets embedded in typed arrays. Copy buffer\n // TODO - remove when `parse` is fixed to handle `byteOffset`s\n const bufferCopy = sliceArrayBuffer(buffer.buffer, buffer.byteOffset); // , buffer.byteLength);\n\n const {parse} = context;\n const dracoOptions: DracoLoaderOptions = {...options};\n\n // TODO - remove hack: The entire tileset might be included, too expensive to serialize\n delete dracoOptions['3d-tiles'];\n const decodedData = (await parse(bufferCopy, DracoLoader, dracoOptions, context)) as DracoMesh;\n\n const decodedAttributes: {[key: string]: GLTFAccessor} = getGLTFAccessors(decodedData.attributes);\n\n // Restore min/max values\n for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) {\n if (attributeName in primitive.attributes) {\n const accessorIndex: number = primitive.attributes[attributeName];\n const accessor = scenegraph.getAccessor(accessorIndex);\n if (accessor?.min && accessor?.max) {\n decodedAttribute.min = accessor.min;\n decodedAttribute.max = accessor.max;\n }\n }\n }\n\n // @ts-ignore\n primitive.attributes = decodedAttributes;\n if (decodedData.indices) {\n // @ts-ignore\n primitive.indices = getGLTFAccessor(decodedData.indices);\n }\n\n // Extension has been processed, delete it\n scenegraph.removeObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);\n\n checkPrimitive(primitive);\n}\n\n// ENCODE\n\n// eslint-disable-next-line max-len\n// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported\nfunction compressMesh(attributes, indices, mode: number = 4, options, context: LoaderContext) {\n if (!options.DracoWriter) {\n throw new Error('options.gltf.DracoWriter not provided');\n }\n\n // TODO - use DracoWriter using encode w/ registered DracoWriter...\n const compressedData = options.DracoWriter.encodeSync({attributes});\n\n // Draco compression may change the order and number of vertices in a mesh.\n // To satisfy the requirement that accessors properties be correct for both\n // compressed and uncompressed data, generators should create uncompressed\n // attributes and indices using data that has been decompressed from the Draco buffer,\n // rather than the original source data.\n // @ts-ignore TODO this needs to be fixed\n const decodedData = context?.parseSync?.({attributes});\n const fauxAccessors = options._addFauxAttributes(decodedData.attributes);\n\n const bufferViewIndex = options.addBufferView(compressedData);\n\n const glTFMesh = {\n primitives: [\n {\n attributes: fauxAccessors, // TODO - verify with spec\n mode, // GL.POINTS\n extensions: {\n [KHR_DRACO_MESH_COMPRESSION]: {\n bufferView: bufferViewIndex,\n attributes: fauxAccessors // TODO - verify with spec\n }\n }\n }\n ]\n };\n\n return glTFMesh;\n}\n\n// UTILS\n\nfunction checkPrimitive(primitive: GLTFMeshPrimitive) {\n if (!primitive.attributes && Object.keys(primitive.attributes).length > 0) {\n throw new Error('glTF: Empty primitive detected: Draco decompression failure?');\n }\n}\n\nfunction* makeMeshPrimitiveIterator(scenegraph) {\n for (const mesh of scenegraph.json.meshes || []) {\n for (const primitive of mesh.primitives) {\n yield primitive;\n }\n }\n}\n"],"mappings":"AAcA,SAAQA,WAAW,QAAO,mBAAmB;AAE7C,SAAQC,gBAAgB,QAAO,0BAA0B;AACzD,SAAQC,cAAc,QAAO,wBAAwB;AACrD,SAAQC,gBAAgB,EAAEC,eAAe,QAAO,oCAAoC;AAEpF,MAAMC,0BAA0B,GAAG,4BAA4B;AAG/D,OAAO,MAAMC,IAAI,GAAGD,0BAA0B;AAE9C,OAAO,SAASE,UAAUA,CACxBC,QAAsB,EACtBC,OAA0B,EAC1BC,OAAsB,EAChB;EACN,MAAMC,UAAU,GAAG,IAAIT,cAAc,CAACM,QAAQ,CAAC;EAC/C,KAAK,MAAMI,SAAS,IAAIC,yBAAyB,CAACF,UAAU,CAAC,EAAE;IAC7D,IAAIA,UAAU,CAACG,kBAAkB,CAACF,SAAS,EAAEP,0BAA0B,CAAC,EAAE,CAE1E;EACF;AACF;AAEA,OAAO,eAAeU,MAAMA,CAC1BP,QAAsB,EACtBC,OAA0B,EA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AAS,CAACgC,UAAU,IAAIG,MAAM,CAACyB,IAAI,CAAC5D,SAAS,CAACgC,UAAU,CAAC,CAACjB,MAAM,GAAG,CAAC,EAAE;IACzE,MAAM,IAAIiC,KAAK,CAAC,8DAA8D,CAAC;EACjF;AACF;AAEA,UAAU/C,yBAAyBA,CAACF,UAAU,EAAE;EAC9C,KAAK,MAAMkB,IAAI,IAAIlB,UAAU,CAACmB,IAAI,CAACC,MAAM,IAAI,EAAE,EAAE;IAC/C,KAAK,MAAMnB,SAAS,IAAIiB,IAAI,CAACyC,UAAU,EAAE;MACvC,MAAM1D,SAAS;IACjB;EACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
1
|
+
import { GLTFScenegraph } from '../api/gltf-scenegraph';
|
|
2
2
|
const KHR_TEXTURE_BASISU = 'KHR_texture_basisu';
|
|
3
3
|
export const name = KHR_TEXTURE_BASISU;
|
|
4
4
|
export function preprocess(gltfData, options) {
|
|
@@ -10,8 +10,8 @@ export function preprocess(gltfData, options) {
|
|
|
10
10
|
const extension = scene.getObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
11
11
|
if (extension) {
|
|
12
12
|
texture.source = extension.source;
|
|
13
|
+
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
13
14
|
}
|
|
14
|
-
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
15
15
|
}
|
|
16
16
|
scene.removeExtension(KHR_TEXTURE_BASISU);
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_texture_basisu.js","names":["GLTFScenegraph","KHR_TEXTURE_BASISU","name","preprocess","gltfData","options","scene","json","texture","textures","extension","getObjectExtension","source","removeObjectExtension","removeExtension"],"sources":["../../../../src/lib/extensions/KHR_texture_basisu.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_texture_basisu\n// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-
|
|
1
|
+
{"version":3,"file":"KHR_texture_basisu.js","names":["GLTFScenegraph","KHR_TEXTURE_BASISU","name","preprocess","gltfData","options","scene","json","texture","textures","extension","getObjectExtension","source","removeObjectExtension","removeExtension"],"sources":["../../../../src/lib/extensions/KHR_texture_basisu.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_texture_basisu\n// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-json-schema';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\n\nconst KHR_TEXTURE_BASISU = 'KHR_texture_basisu';\n\n/** Extension name */\nexport const name = KHR_TEXTURE_BASISU;\n\n/**\n * Replaces a texture source reference with the extension texture\n * Done in preprocess() to prevent load of default image\n */\nexport function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {\n const scene = new GLTFScenegraph(gltfData);\n const {json} = scene;\n\n for (const texture of json.textures || []) {\n const extension = scene.getObjectExtension<GLTF_KHR_texture_basisu>(\n texture,\n KHR_TEXTURE_BASISU\n );\n if (extension) {\n // TODO - if multiple texture extensions are present which one wins?\n texture.source = extension.source;\n scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);\n }\n }\n\n // Remove the top-level extension\n scene.removeExtension(KHR_TEXTURE_BASISU);\n}\n"],"mappings":"AAOA,SAAQA,cAAc,QAAO,wBAAwB;AAErD,MAAMC,kBAAkB,GAAG,oBAAoB;AAG/C,OAAO,MAAMC,IAAI,GAAGD,kBAAkB;AAMtC,OAAO,SAASE,UAAUA,CAACC,QAAsB,EAAEC,OAA0B,EAAQ;EACnF,MAAMC,KAAK,GAAG,IAAIN,cAAc,CAACI,QAAQ,CAAC;EAC1C,MAAM;IAACG;EAAI,CAAC,GAAGD,KAAK;EAEpB,KAAK,MAAME,OAAO,IAAID,IAAI,CAACE,QAAQ,IAAI,EAAE,EAAE;IACzC,MAAMC,SAAS,GAAGJ,KAAK,CAACK,kBAAkB,CACxCH,OAAO,EACPP,kBACF,CAAC;IACD,IAAIS,SAAS,EAAE;MAEbF,OAAO,CAACI,MAAM,GAAGF,SAAS,CAACE,MAAM;MACjCN,KAAK,CAACO,qBAAqB,CAACL,OAAO,EAAEP,kBAAkB,CAAC;IAC1D;EACF;EAGAK,KAAK,CAACQ,eAAe,CAACb,kBAAkB,CAAC;AAC3C"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Vector3, Matrix3 } from '@math.gl/core';
|
|
2
2
|
import { getAccessorArrayTypeAndLength } from '../gltf-utils/gltf-utils';
|
|
3
3
|
import { BYTES, COMPONENTS } from '../gltf-utils/gltf-constants';
|
|
4
|
-
import
|
|
4
|
+
import '../types/gltf-json-schema';
|
|
5
|
+
import { GLTFScenegraph } from '../api/gltf-scenegraph';
|
|
5
6
|
const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
|
|
6
7
|
export const name = EXT_MESHOPT_TRANSFORM;
|
|
7
8
|
const scratchVector = new Vector3();
|
|
@@ -9,8 +10,8 @@ const scratchRotationMatrix = new Matrix3();
|
|
|
9
10
|
const scratchScaleMatrix = new Matrix3();
|
|
10
11
|
export async function decode(gltfData, options) {
|
|
11
12
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
12
|
-
const
|
|
13
|
-
if (!
|
|
13
|
+
const hasExtension = gltfScenegraph.hasExtension(EXT_MESHOPT_TRANSFORM);
|
|
14
|
+
if (!hasExtension) {
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
17
|
const materials = gltfData.json.materials || [];
|
|
@@ -173,9 +174,9 @@ function makeTransformationMatrix(extensionData) {
|
|
|
173
174
|
rotation = 0,
|
|
174
175
|
scale = [1, 1]
|
|
175
176
|
} = extensionData;
|
|
176
|
-
const
|
|
177
|
-
const
|
|
177
|
+
const translationMatrix = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
|
|
178
|
+
const rotationMatrix = scratchRotationMatrix.set(Math.cos(rotation), Math.sin(rotation), 0, -Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
|
|
178
179
|
const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
|
|
179
|
-
return
|
|
180
|
+
return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix);
|
|
180
181
|
}
|
|
181
182
|
//# sourceMappingURL=KHR_texture_transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_texture_transform.js","names":["Vector3","Matrix3","getAccessorArrayTypeAndLength","BYTES","COMPONENTS","GLTFScenegraph","EXT_MESHOPT_TRANSFORM","name","scratchVector","scratchRotationMatrix","scratchScaleMatrix","decode","gltfData","options","gltfScenegraph","extension","getExtension","materials","json","i","length","transformTexCoords","materialIndex","_gltfData$json$materi","_material$pbrMetallic","_material$pbrMetallic2","processedTexCoords","material","baseColorTexture","pbrMetallicRoughness","transformPrimitives","emisiveTexture","emissiveTexture","normalTexture","occlusionTexture","metallicRoughnessTexture","texture","transformParameters","getTransformParameters","meshes","mesh","primitive","primitives","Number","isFinite","transformPrimitive","_texture$extensions","textureInfo","extensions","texCoord","originalTexCoord","isProcessed","findIndex","_ref","original","newTexCoord","matrix","makeTransformationMatrix","push","texCoordAccessor","attributes","concat","_gltfData$json$access","accessor","accessors","bufferView","_gltfData$json$buffer","bufferViews","arrayBuffer","byteOffset","bufferByteOffset","buffers","buffer","ArrayType","bytes","componentType","components","type","elementAddressScale","byteStride","result","Float32Array","count","uv","set","transformByMatrix3","updateGltf","createAttribute","newTexCoordArray","byteLength","originalAccessor","extensionData","offset","rotation","scale","translationMatirx","rotationMatirx","Math","cos","sin","scaleMatrix","multiplyRight"],"sources":["../../../../src/lib/extensions/KHR_texture_transform.ts"],"sourcesContent":["/**\n * https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md\n */\n\nimport {Vector3, Matrix3} from '@math.gl/core';\nimport type {GLTFMeshPrimitive, GLTFWithBuffers} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\nimport {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';\nimport {BYTES, COMPONENTS} from '../gltf-utils/gltf-constants';\nimport {\n Accessor,\n BufferView,\n MaterialNormalTextureInfo,\n MaterialOcclusionTextureInfo,\n TextureInfo as GLTFTextureInfo\n} from '../types/gltf-json-schema';\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\n/** Extension name */\nconst EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';\n\nexport const name = EXT_MESHOPT_TRANSFORM;\n\nconst scratchVector = new Vector3();\nconst scratchRotationMatrix = new Matrix3();\nconst scratchScaleMatrix = new Matrix3();\n\n/** Extension textureInfo https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */\ntype TextureInfo = {\n /** The offset of the UV coordinate origin as a factor of the texture dimensions. */\n offset?: [number, number];\n /** Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise. */\n rotation?: number;\n /** The scale factor applied to the components of the UV coordinates. */\n scale?: [number, number];\n /** Overrides the textureInfo texCoord value if supplied, and if this extension is supported. */\n texCoord?: number;\n};\n/** Intersection of all GLTF textures */\ntype CompoundGLTFTextureInfo = GLTFTextureInfo &\n MaterialNormalTextureInfo &\n MaterialOcclusionTextureInfo;\n/** Parameters for TEXCOORD transformation */\ntype TransformParameters = {\n /** Original texCoord value https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#_textureinfo_texcoord */\n originalTexCoord: number;\n /** New texCoord value from extension https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */\n texCoord: number;\n /** Transformation matrix */\n matrix: Matrix3;\n};\n\n/**\n * The extension entry to process the transformation\n * @param gltfData gltf buffers and json\n * @param options GLTFLoader options\n */\nexport async function decode(gltfData: GLTFWithBuffers, options: GLTFLoaderOptions) {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const extension = gltfScenegraph.getExtension(EXT_MESHOPT_TRANSFORM);\n if (!extension) {\n return;\n }\n const materials = gltfData.json.materials || [];\n for (let i = 0; i < materials.length; i++) {\n transformTexCoords(i, gltfData);\n }\n}\n\n/**\n * Transform TEXCOORD by material\n * @param materialIndex processing material index\n * @param gltfData gltf buffers and json\n */\nfunction transformTexCoords(materialIndex: number, gltfData: GLTFWithBuffers): void {\n // Save processed texCoords in order no to process the same twice\n const processedTexCoords: [number, number][] = [];\n const material = gltfData.json.materials?.[materialIndex];\n const baseColorTexture = material?.pbrMetallicRoughness?.baseColorTexture;\n if (baseColorTexture) {\n transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);\n }\n const emisiveTexture = material?.emissiveTexture;\n if (emisiveTexture) {\n transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);\n }\n const normalTexture = material?.normalTexture;\n if (normalTexture) {\n transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);\n }\n const occlusionTexture = material?.occlusionTexture;\n if (occlusionTexture) {\n transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);\n }\n const metallicRoughnessTexture = material?.pbrMetallicRoughness?.metallicRoughnessTexture;\n if (metallicRoughnessTexture) {\n transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);\n }\n}\n\n/**\n * Transform primitives of the particular material\n * @param gltfData gltf data\n * @param materialIndex primitives with this material will be transformed\n * @param texture texture object\n * @param processedTexCoords storage to save already processed texCoords\n */\nfunction transformPrimitives(\n gltfData: GLTFWithBuffers,\n materialIndex: number,\n texture: CompoundGLTFTextureInfo,\n processedTexCoords: [number, number][]\n) {\n const transformParameters = getTransformParameters(texture, processedTexCoords);\n if (!transformParameters) {\n return;\n }\n const meshes = gltfData.json.meshes || [];\n for (const mesh of meshes) {\n for (const primitive of mesh.primitives) {\n const material = primitive.material;\n if (Number.isFinite(material) && materialIndex === material) {\n transformPrimitive(gltfData, primitive, transformParameters);\n }\n }\n }\n}\n\n/**\n * Get parameters for TEXCOORD transformation\n * @param texture texture object\n * @param processedTexCoords storage to save already processed texCoords\n * @returns texCoord couple and transformation matrix\n */\nfunction getTransformParameters(\n texture: CompoundGLTFTextureInfo,\n processedTexCoords: [number, number][]\n): TransformParameters | null {\n const textureInfo = texture.extensions?.[EXT_MESHOPT_TRANSFORM];\n const {texCoord: originalTexCoord = 0} = texture;\n // If texCoord is not set in the extension, original attribute data will be replaced\n const {texCoord = originalTexCoord} = textureInfo;\n // Make sure that couple [originalTexCoord, extensionTexCoord] is not processed twice\n const isProcessed =\n processedTexCoords.findIndex(\n ([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord\n ) !== -1;\n if (!isProcessed) {\n const matrix = makeTransformationMatrix(textureInfo);\n if (originalTexCoord !== texCoord) {\n texture.texCoord = texCoord;\n }\n processedTexCoords.push([originalTexCoord, texCoord]);\n return {originalTexCoord, texCoord, matrix};\n }\n return null;\n}\n\n/**\n * Transform `TEXCOORD_0` attribute in the primitive\n * @param gltfData gltf data\n * @param primitive primitive object\n * @param transformParameters texCoord couple and transformation matrix\n */\nfunction transformPrimitive(\n gltfData: GLTFWithBuffers,\n primitive: GLTFMeshPrimitive,\n transformParameters: TransformParameters\n) {\n const {originalTexCoord, texCoord, matrix} = transformParameters;\n const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];\n if (Number.isFinite(texCoordAccessor)) {\n // Get accessor of the `TEXCOORD_0` attribute\n const accessor = gltfData.json.accessors?.[texCoordAccessor];\n if (accessor && accessor.bufferView) {\n // Get `bufferView` of the `accessor`\n const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];\n if (bufferView) {\n // Get `arrayBuffer` the `bufferView` look at\n const {arrayBuffer, byteOffset: bufferByteOffset} = gltfData.buffers[bufferView.buffer];\n // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets\n const byteOffset =\n (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);\n // Deduce TypedArray type and its length from `accessor` and `bufferView` data\n const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);\n // Number of bytes each component occupies\n const bytes = BYTES[accessor.componentType];\n // Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2\n const components = COMPONENTS[accessor.type];\n // Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer\n const elementAddressScale = bufferView.byteStride || bytes * components;\n // Data transform to Float32Array\n const result = new Float32Array(length);\n for (let i = 0; i < accessor.count; i++) {\n // Take [u, v] couple from the arrayBuffer\n const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);\n // Set and transform Vector3 per https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#overview\n scratchVector.set(uv[0], uv[1], 1);\n scratchVector.transformByMatrix3(matrix);\n // Save result in Float32Array\n result.set([scratchVector[0], scratchVector[1]], i * components);\n }\n // If texCoord the same, replace gltf structural data\n if (originalTexCoord === texCoord) {\n updateGltf(accessor, bufferView, gltfData.buffers, result);\n } else {\n // If texCoord change, create new attribute\n createAttribute(texCoord, accessor, primitive, gltfData, result);\n }\n }\n }\n }\n}\n\n/**\n * Update GLTF structural objects with new data as we create new `Float32Array` for `TEXCOORD_0`.\n * @param accessor accessor to change\n * @param bufferView bufferView to change\n * @param buffers binary buffers\n * @param newTexcoordArray typed array with data after transformation\n */\nfunction updateGltf(\n accessor: Accessor,\n bufferView: BufferView,\n buffers: {arrayBuffer: ArrayBuffer; byteOffset: number; byteLength: number}[],\n newTexCoordArray: Float32Array\n): void {\n accessor.componentType = 5126;\n buffers.push({\n arrayBuffer: newTexCoordArray.buffer,\n byteOffset: 0,\n byteLength: newTexCoordArray.buffer.byteLength\n });\n bufferView.buffer = buffers.length - 1;\n bufferView.byteLength = newTexCoordArray.buffer.byteLength;\n bufferView.byteOffset = 0;\n delete bufferView.byteStride;\n}\n\n/**\n *\n * @param newTexCoord new `texCoord` value\n * @param originalAccessor original accessor object, that store data before transformation\n * @param primitive primitive object\n * @param gltfData gltf data\n * @param newTexCoordArray typed array with data after transformation\n * @returns\n */\nfunction createAttribute(\n newTexCoord: number,\n originalAccessor: Accessor,\n primitive: GLTFMeshPrimitive,\n gltfData: GLTFWithBuffers,\n newTexCoordArray: Float32Array\n) {\n gltfData.buffers.push({\n arrayBuffer: newTexCoordArray.buffer,\n byteOffset: 0,\n byteLength: newTexCoordArray.buffer.byteLength\n });\n const bufferViews = gltfData.json.bufferViews;\n if (!bufferViews) {\n return;\n }\n bufferViews.push({\n buffer: gltfData.buffers.length - 1,\n byteLength: newTexCoordArray.buffer.byteLength,\n byteOffset: 0\n });\n const accessors = gltfData.json.accessors;\n if (!accessors) {\n return;\n }\n accessors.push({\n bufferView: bufferViews?.length - 1,\n byteOffset: 0,\n componentType: 5126,\n count: originalAccessor.count,\n type: 'VEC2'\n });\n primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;\n}\n\n/**\n * Construct transformation matrix from the extension data (transition, rotation, scale)\n * @param extensionData extension data\n * @returns transformation matrix\n */\nfunction makeTransformationMatrix(extensionData: TextureInfo): Matrix3 {\n const {offset = [0, 0], rotation = 0, scale = [1, 1]} = extensionData;\n const translationMatirx = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);\n const rotationMatirx = scratchRotationMatrix.set(\n Math.cos(rotation),\n Math.sin(rotation),\n 0,\n -Math.sin(rotation),\n Math.cos(rotation),\n 0,\n 0,\n 0,\n 1\n );\n const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);\n return translationMatirx.multiplyRight(rotationMatirx).multiplyRight(scaleMat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,MAAM;IAACC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAAEC,QAAQ,GAAG,CAAC;IAAEC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;EAAC,CAAC,GAAGH,aAAa;EACrE,MAAMI,iBAAiB,GAAG,IAAI9F,OAAO,CAAC,CAAC,CAACmF,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAEQ,MAAM,CAAC,CAAC,CAAC,EAAEA,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;EACtF,MAAMI,cAAc,GAAGvF,qBAAqB,CAAC2E,GAAG,CAC9Ca,IAAI,CAACC,GAAG,CAACL,QAAQ,CAAC,EAClBI,IAAI,CAACE,GAAG,CAACN,QAAQ,CAAC,EAClB,CAAC,EACD,CAACI,IAAI,CAACE,GAAG,CAACN,QAAQ,CAAC,EACnBI,IAAI,CAACC,GAAG,CAACL,QAAQ,CAAC,EAClB,CAAC,EACD,CAAC,EACD,CAAC,EACD,CACF,CAAC;EACD,MAAMO,WAAW,GAAG1F,kBAAkB,CAAC0E,GAAG,CAACU,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAEA,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;EACnF,OAAOC,iBAAiB,CAACM,aAAa,CAACL,cAAc,CAAC,CAACK,aAAa,CAACD,WAAW,CAAC;AACnF"}
|
|
1
|
+
{"version":3,"file":"KHR_texture_transform.js","names":["Vector3","Matrix3","getAccessorArrayTypeAndLength","BYTES","COMPONENTS","GLTFScenegraph","EXT_MESHOPT_TRANSFORM","name","scratchVector","scratchRotationMatrix","scratchScaleMatrix","decode","gltfData","options","gltfScenegraph","hasExtension","materials","json","i","length","transformTexCoords","materialIndex","_gltfData$json$materi","_material$pbrMetallic","_material$pbrMetallic2","processedTexCoords","material","baseColorTexture","pbrMetallicRoughness","transformPrimitives","emisiveTexture","emissiveTexture","normalTexture","occlusionTexture","metallicRoughnessTexture","texture","transformParameters","getTransformParameters","meshes","mesh","primitive","primitives","Number","isFinite","transformPrimitive","_texture$extensions","textureInfo","extensions","texCoord","originalTexCoord","isProcessed","findIndex","_ref","original","newTexCoord","matrix","makeTransformationMatrix","push","texCoordAccessor","attributes","concat","_gltfData$json$access","accessor","accessors","bufferView","_gltfData$json$buffer","bufferViews","arrayBuffer","byteOffset","bufferByteOffset","buffers","buffer","ArrayType","bytes","componentType","components","type","elementAddressScale","byteStride","result","Float32Array","count","uv","set","transformByMatrix3","updateGltf","createAttribute","newTexCoordArray","byteLength","originalAccessor","extensionData","offset","rotation","scale","translationMatrix","rotationMatrix","Math","cos","sin","scaleMatrix","multiplyRight"],"sources":["../../../../src/lib/extensions/KHR_texture_transform.ts"],"sourcesContent":["/**\n * https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md\n */\n\nimport {Vector3, Matrix3} from '@math.gl/core';\nimport type {GLTFWithBuffers} from '../types/gltf-types';\nimport type {\n GLTFMeshPrimitive,\n GLTFAccessor,\n GLTFBufferView,\n GLTFMaterialNormalTextureInfo,\n GLTFMaterialOcclusionTextureInfo,\n GLTFTextureInfo\n} from '../types/gltf-json-schema';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';\nimport {BYTES, COMPONENTS} from '../gltf-utils/gltf-constants';\nimport {} from '../types/gltf-json-schema';\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\n\n/** Extension name */\nconst EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';\n\nexport const name = EXT_MESHOPT_TRANSFORM;\n\nconst scratchVector = new Vector3();\nconst scratchRotationMatrix = new Matrix3();\nconst scratchScaleMatrix = new Matrix3();\n\n/** Extension textureInfo https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */\ntype TextureInfo = {\n /** The offset of the UV coordinate origin as a factor of the texture dimensions. */\n offset?: [number, number];\n /** Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise. */\n rotation?: number;\n /** The scale factor applied to the components of the UV coordinates. */\n scale?: [number, number];\n /** Overrides the textureInfo texCoord value if supplied, and if this extension is supported. */\n texCoord?: number;\n};\n/** Intersection of all GLTF textures */\ntype CompoundGLTFTextureInfo = GLTFTextureInfo &\n GLTFMaterialNormalTextureInfo &\n GLTFMaterialOcclusionTextureInfo;\n/** Parameters for TEXCOORD transformation */\ntype TransformParameters = {\n /** Original texCoord value https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#_textureinfo_texcoord */\n originalTexCoord: number;\n /** New texCoord value from extension https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */\n texCoord: number;\n /** Transformation matrix */\n matrix: Matrix3;\n};\n\n/**\n * The extension entry to process the transformation\n * @param gltfData gltf buffers and json\n * @param options GLTFLoader options\n */\nexport async function decode(gltfData: GLTFWithBuffers, options: GLTFLoaderOptions) {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const hasExtension = gltfScenegraph.hasExtension(EXT_MESHOPT_TRANSFORM);\n if (!hasExtension) {\n return;\n }\n const materials = gltfData.json.materials || [];\n for (let i = 0; i < materials.length; i++) {\n transformTexCoords(i, gltfData);\n }\n}\n\n/**\n * Transform TEXCOORD by material\n * @param materialIndex processing material index\n * @param gltfData gltf buffers and json\n */\nfunction transformTexCoords(materialIndex: number, gltfData: GLTFWithBuffers): void {\n // Save processed texCoords in order no to process the same twice\n const processedTexCoords: [number, number][] = [];\n const material = gltfData.json.materials?.[materialIndex];\n const baseColorTexture = material?.pbrMetallicRoughness?.baseColorTexture;\n if (baseColorTexture) {\n transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);\n }\n const emisiveTexture = material?.emissiveTexture;\n if (emisiveTexture) {\n transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);\n }\n const normalTexture = material?.normalTexture;\n if (normalTexture) {\n transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);\n }\n const occlusionTexture = material?.occlusionTexture;\n if (occlusionTexture) {\n transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);\n }\n const metallicRoughnessTexture = material?.pbrMetallicRoughness?.metallicRoughnessTexture;\n if (metallicRoughnessTexture) {\n transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);\n }\n}\n\n/**\n * Transform primitives of the particular material\n * @param gltfData gltf data\n * @param materialIndex primitives with this material will be transformed\n * @param texture texture object\n * @param processedTexCoords storage to save already processed texCoords\n */\nfunction transformPrimitives(\n gltfData: GLTFWithBuffers,\n materialIndex: number,\n texture: CompoundGLTFTextureInfo,\n processedTexCoords: [number, number][]\n) {\n const transformParameters = getTransformParameters(texture, processedTexCoords);\n if (!transformParameters) {\n return;\n }\n const meshes = gltfData.json.meshes || [];\n for (const mesh of meshes) {\n for (const primitive of mesh.primitives) {\n const material = primitive.material;\n if (Number.isFinite(material) && materialIndex === material) {\n transformPrimitive(gltfData, primitive, transformParameters);\n }\n }\n }\n}\n\n/**\n * Get parameters for TEXCOORD transformation\n * @param texture texture object\n * @param processedTexCoords storage to save already processed texCoords\n * @returns texCoord couple and transformation matrix\n */\nfunction getTransformParameters(\n texture: CompoundGLTFTextureInfo,\n processedTexCoords: [number, number][]\n): TransformParameters | null {\n const textureInfo = texture.extensions?.[EXT_MESHOPT_TRANSFORM];\n const {texCoord: originalTexCoord = 0} = texture;\n // If texCoord is not set in the extension, original attribute data will be replaced\n const {texCoord = originalTexCoord} = textureInfo;\n // Make sure that couple [originalTexCoord, extensionTexCoord] is not processed twice\n const isProcessed =\n processedTexCoords.findIndex(\n ([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord\n ) !== -1;\n if (!isProcessed) {\n const matrix = makeTransformationMatrix(textureInfo);\n if (originalTexCoord !== texCoord) {\n texture.texCoord = texCoord;\n }\n processedTexCoords.push([originalTexCoord, texCoord]);\n return {originalTexCoord, texCoord, matrix};\n }\n return null;\n}\n\n/**\n * Transform `TEXCOORD_0` attribute in the primitive\n * @param gltfData gltf data\n * @param primitive primitive object\n * @param transformParameters texCoord couple and transformation matrix\n */\nfunction transformPrimitive(\n gltfData: GLTFWithBuffers,\n primitive: GLTFMeshPrimitive,\n transformParameters: TransformParameters\n) {\n const {originalTexCoord, texCoord, matrix} = transformParameters;\n const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];\n if (Number.isFinite(texCoordAccessor)) {\n // Get accessor of the `TEXCOORD_0` attribute\n const accessor = gltfData.json.accessors?.[texCoordAccessor];\n if (accessor && accessor.bufferView) {\n // Get `bufferView` of the `accessor`\n const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];\n if (bufferView) {\n // Get `arrayBuffer` the `bufferView` look at\n const {arrayBuffer, byteOffset: bufferByteOffset} = gltfData.buffers[bufferView.buffer];\n // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets\n const byteOffset =\n (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);\n // Deduce TypedArray type and its length from `accessor` and `bufferView` data\n const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);\n // Number of bytes each component occupies\n const bytes = BYTES[accessor.componentType];\n // Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2\n const components = COMPONENTS[accessor.type];\n // Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer\n const elementAddressScale = bufferView.byteStride || bytes * components;\n // Data transform to Float32Array\n const result = new Float32Array(length);\n for (let i = 0; i < accessor.count; i++) {\n // Take [u, v] couple from the arrayBuffer\n const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);\n // Set and transform Vector3 per https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#overview\n scratchVector.set(uv[0], uv[1], 1);\n scratchVector.transformByMatrix3(matrix);\n // Save result in Float32Array\n result.set([scratchVector[0], scratchVector[1]], i * components);\n }\n // If texCoord the same, replace gltf structural data\n if (originalTexCoord === texCoord) {\n updateGltf(accessor, bufferView, gltfData.buffers, result);\n } else {\n // If texCoord change, create new attribute\n createAttribute(texCoord, accessor, primitive, gltfData, result);\n }\n }\n }\n }\n}\n\n/**\n * Update GLTF structural objects with new data as we create new `Float32Array` for `TEXCOORD_0`.\n * @param accessor accessor to change\n * @param bufferView bufferView to change\n * @param buffers binary buffers\n * @param newTexcoordArray typed array with data after transformation\n */\nfunction updateGltf(\n accessor: GLTFAccessor,\n bufferView: GLTFBufferView,\n buffers: {arrayBuffer: ArrayBuffer; byteOffset: number; byteLength: number}[],\n newTexCoordArray: Float32Array\n): void {\n accessor.componentType = 5126;\n buffers.push({\n arrayBuffer: newTexCoordArray.buffer,\n byteOffset: 0,\n byteLength: newTexCoordArray.buffer.byteLength\n });\n bufferView.buffer = buffers.length - 1;\n bufferView.byteLength = newTexCoordArray.buffer.byteLength;\n bufferView.byteOffset = 0;\n delete bufferView.byteStride;\n}\n\n/**\n *\n * @param newTexCoord new `texCoord` value\n * @param originalAccessor original accessor object, that store data before transformation\n * @param primitive primitive object\n * @param gltfData gltf data\n * @param newTexCoordArray typed array with data after transformation\n * @returns\n */\nfunction createAttribute(\n newTexCoord: number,\n originalAccessor: GLTFAccessor,\n primitive: GLTFMeshPrimitive,\n gltfData: GLTFWithBuffers,\n newTexCoordArray: Float32Array\n) {\n gltfData.buffers.push({\n arrayBuffer: newTexCoordArray.buffer,\n byteOffset: 0,\n byteLength: newTexCoordArray.buffer.byteLength\n });\n const bufferViews = gltfData.json.bufferViews;\n if (!bufferViews) {\n return;\n }\n bufferViews.push({\n buffer: gltfData.buffers.length - 1,\n byteLength: newTexCoordArray.buffer.byteLength,\n byteOffset: 0\n });\n const accessors = gltfData.json.accessors;\n if (!accessors) {\n return;\n }\n accessors.push({\n bufferView: bufferViews?.length - 1,\n byteOffset: 0,\n componentType: 5126,\n count: originalAccessor.count,\n type: 'VEC2'\n });\n primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;\n}\n\n/**\n * Construct transformation matrix from the extension data (transition, rotation, scale)\n * @param extensionData extension data\n * @returns transformation matrix\n */\nfunction makeTransformationMatrix(extensionData: TextureInfo): Matrix3 {\n const {offset = [0, 0], rotation = 0, scale = [1, 1]} = extensionData;\n const translationMatrix = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);\n const rotationMatrix = scratchRotationMatrix.set(\n Math.cos(rotation),\n Math.sin(rotation),\n 0,\n -Math.sin(rotation),\n Math.cos(rotation),\n 0,\n 0,\n 0,\n 1\n );\n const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);\n return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix);\n}\n"],"mappings":"AAIA,SAAQA,OAAO,EAAEC,OAAO,QAAO,eAAe;AAY9C,SAAQC,6BAA6B,QAAO,0BAA0B;AACtE,SAAQC,KAAK,EAAEC,UAAU,QAAO,8BAA8B;AAC9D,OAAe,2BAA2B;AAC1C,SAAQC,cAAc,QAAO,wBAAwB;AAGrD,MAAMC,qBAAqB,GAAG,uBAAuB;AAErD,OAAO,MAAMC,IAAI,GAAGD,qBAAqB;AAEzC,MAAME,aAAa,GAAG,IAAIR,OAAO,CAAC,CAAC;AACnC,MAAMS,qBAAqB,GAAG,IAAIR,OAAO,CAAC,CAAC;AAC3C,MAAMS,kBAAkB,GAAG,IAAIT,OAAO,CAAC,CAAC;AAgCxC,OAAO,eAAeU,MAAMA,CAACC,QAAyB,EAAEC,OAA0B,EAAE;EAClF,MAAMC,cAAc,GAAG,IAAIT,cAAc,CAACO,QAAQ,CAAC;EACnD,MAAMG,YAAY,GAAGD,cAAc,CAACC,YAAY,CAACT,qBAAqB,CAAC;EACvE,IAAI,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,EAClB,CAAC,EACD,CAAC,EACD,CAAC,EACD,CACF,CAAC;EACD,MAAMO,WAAW,GAAGzF,kBAAkB,CAACyE,GAAG,CAACU,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAEA,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;EACnF,OAAOC,iBAAiB,CAACM,aAAa,CAACL,cAAc,CAAC,CAACK,aAAa,CAACD,WAAW,CAAC;AACnF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_feature_metadata.js","names":["GLTFScenegraph","EXT_FEATURE_METADATA","name","decode","gltfData","scenegraph","decodeExtFeatureMetadata","_extension$schema","extension","getExtension","schemaClasses","schema","classes","featureTables","featureTextures","console","warn","schemaName","schemaClass","featureTable","findFeatureTableByName","handleFeatureTableProperties","propertyName","properties","_featureTable$propert","schemaProperty","featureTableProperty","numberOfFeatures","count","data","getPropertyDataFromBinarySource","bufferView","getTypedArrayForBufferView","type","stringOffsetBufferView","offsetsData","getStringAttributes","schemaClassName","featureTableName","class","stringsCount","stringsArray","textDecoder","TextDecoder","stringOffset","bytesPerStringSize","index","stringByteSize","stringData","subarray","stringAttribute","push"],"sources":["../../../../../src/lib/extensions/deprecated/EXT_feature_metadata.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport type {GLTF} from '../../types/gltf-
|
|
1
|
+
{"version":3,"file":"EXT_feature_metadata.js","names":["GLTFScenegraph","EXT_FEATURE_METADATA","name","decode","gltfData","scenegraph","decodeExtFeatureMetadata","_extension$schema","extension","getExtension","schemaClasses","schema","classes","featureTables","featureTextures","console","warn","schemaName","schemaClass","featureTable","findFeatureTableByName","handleFeatureTableProperties","propertyName","properties","_featureTable$propert","schemaProperty","featureTableProperty","numberOfFeatures","count","data","getPropertyDataFromBinarySource","bufferView","getTypedArrayForBufferView","type","stringOffsetBufferView","offsetsData","getStringAttributes","schemaClassName","featureTableName","class","stringsCount","stringsArray","textDecoder","TextDecoder","stringOffset","bytesPerStringSize","index","stringByteSize","stringData","subarray","stringAttribute","push"],"sources":["../../../../../src/lib/extensions/deprecated/EXT_feature_metadata.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport type {GLTF} from '../../types/gltf-json-schema';\n\nimport {GLTFScenegraph} from '../../api/gltf-scenegraph';\nimport {\n ClassProperty,\n EXT_feature_metadata_class_object,\n EXT_feature_metadata_feature_table,\n FeatureTableProperty,\n GLTF_EXT_feature_metadata\n} from '../../types/gltf-json-schema';\n\n/** Extension name */\nconst EXT_FEATURE_METADATA = 'EXT_feature_metadata';\n\nexport const name = EXT_FEATURE_METADATA;\n\nexport async function decode(gltfData: {json: GLTF}): Promise<void> {\n const scenegraph = new GLTFScenegraph(gltfData);\n decodeExtFeatureMetadata(scenegraph);\n}\n\n/**\n * Decodes feature metadata from extension\n * @param scenegraph\n */\nfunction decodeExtFeatureMetadata(scenegraph: GLTFScenegraph): void {\n const extension: GLTF_EXT_feature_metadata | null = scenegraph.getExtension(EXT_FEATURE_METADATA);\n const schemaClasses = extension?.schema?.classes;\n const featureTables = extension?.featureTables;\n const featureTextures = extension?.featureTextures;\n\n if (featureTextures) {\n /*\n * TODO add support for featureTextures\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-textures\n */\n // eslint-disable-next-line no-console\n console.warn('featureTextures is not yet supported in the \"EXT_feature_metadata\" extension.');\n }\n\n if (schemaClasses && featureTables) {\n for (const schemaName in schemaClasses) {\n const schemaClass = schemaClasses[schemaName];\n const featureTable = findFeatureTableByName(featureTables, schemaName);\n\n if (featureTable) {\n handleFeatureTableProperties(scenegraph, featureTable, schemaClass);\n }\n }\n }\n}\n\n/**\n * Navigate throw all properies in feature table and gets properties data.\n * @param scenegraph\n * @param featureTable\n * @param schemaClass\n */\nfunction handleFeatureTableProperties(\n scenegraph: GLTFScenegraph,\n featureTable: EXT_feature_metadata_feature_table,\n schemaClass: EXT_feature_metadata_class_object\n): void {\n for (const propertyName in schemaClass.properties) {\n const schemaProperty = schemaClass.properties[propertyName];\n const featureTableProperty = featureTable?.properties?.[propertyName];\n const numberOfFeatures = featureTable.count;\n\n if (featureTableProperty) {\n const data = getPropertyDataFromBinarySource(\n scenegraph,\n schemaProperty,\n numberOfFeatures,\n featureTableProperty\n );\n featureTableProperty.data = data;\n }\n }\n}\n\n/**\n * Decode properties from binary sourse based on property type.\n * @param scenegraph\n * @param schemaProperty\n * @param numberOfFeatures\n * @param featureTableProperty\n */\nfunction getPropertyDataFromBinarySource(\n scenegraph: GLTFScenegraph,\n schemaProperty: ClassProperty,\n numberOfFeatures: number,\n featureTableProperty: FeatureTableProperty\n): Uint8Array | string[] {\n const bufferView = featureTableProperty.bufferView;\n // TODO think maybe we shouldn't get data only in Uint8Array format.\n let data: Uint8Array | string[] = scenegraph.getTypedArrayForBufferView(bufferView);\n\n switch (schemaProperty.type) {\n case 'STRING': {\n // stringOffsetBufferView should be available for string type.\n const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView!;\n const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);\n data = getStringAttributes(data, offsetsData, numberOfFeatures);\n break;\n }\n default:\n }\n\n return data;\n}\n\n/**\n * Find the feature table by class name.\n * @param featureTables\n * @param schemaClassName\n */\nfunction findFeatureTableByName(\n featureTables: {[key: string]: EXT_feature_metadata_feature_table},\n schemaClassName: string\n): EXT_feature_metadata_feature_table | null {\n for (const featureTableName in featureTables) {\n const featureTable = featureTables[featureTableName];\n\n if (featureTable.class === schemaClassName) {\n return featureTable;\n }\n }\n\n return null;\n}\n\n/**\n * Getting string attributes from binary data.\n * Spec - https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#strings\n * @param data\n * @param offsetsData\n * @param stringsCount\n */\nfunction getStringAttributes(\n data: Uint8Array,\n offsetsData: Uint8Array,\n stringsCount: number\n): string[] {\n const stringsArray: string[] = [];\n const textDecoder = new TextDecoder('utf8');\n\n let stringOffset = 0;\n const bytesPerStringSize = 4;\n\n for (let index = 0; index < stringsCount; index++) {\n // TODO check if it is multiplication on bytesPerStringSize is valid operation?\n const stringByteSize =\n offsetsData[(index + 1) * bytesPerStringSize] - offsetsData[index * bytesPerStringSize];\n const stringData = data.subarray(stringOffset, stringByteSize + stringOffset);\n const stringAttribute = textDecoder.decode(stringData);\n\n stringsArray.push(stringAttribute);\n stringOffset += stringByteSize;\n }\n\n return stringsArray;\n}\n"],"mappings":"AAGA,SAAQA,cAAc,QAAO,2BAA2B;AAUxD,MAAMC,oBAAoB,GAAG,sBAAsB;AAEnD,OAAO,MAAMC,IAAI,GAAGD,oBAAoB;AAExC,OAAO,eAAeE,MAAMA,CAACC,QAAsB,EAAiB;EAClE,MAAMC,UAAU,GAAG,IAAIL,cAAc,CAACI,QAAQ,CAAC;EAC/CE,wBAAwB,CAACD,UAAU,CAAC;AACtC;AAMA,SAASC,wBAAwBA,CAACD,UAA0B,EAAQ;EAAA,IAAAE,iBAAA;EAClE,MAAMC,SAA2C,GAAGH,UAAU,CAACI,YAAY,CAACR,oBAAoB,CAAC;EACjG,MAAMS,aAAa,GAAGF,SAAS,aAATA,SAAS,wBAAAD,iBAAA,GAATC,SAAS,CAAEG,MAAM,cAAAJ,iBAAA,uBAAjBA,iBAAA,CAAmBK,OAAO;EAChD,MAAMC,aAAa,GAAGL,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEK,aAAa;EAC9C,MAAMC,eAAe,GAAGN,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEM,eAAe;EAElD,IAAIA,eAAe,EAAE;IAMnBC,OAAO,CAACC,IAAI,CAAC,+EAA+E,CAAC;EAC/F;EAEA,IAAIN,aAAa,IAAIG,aAAa,EAAE;IAClC,KAAK,MAAMI,UAAU,IAAIP,aAAa,EAAE;MACtC,MAAMQ,WAAW,GAAGR,aAAa,CAACO,UAAU,CAAC;MAC7C,MAAME,YAAY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A,OAAOE,IAAI;AACb;AAOA,SAAST,sBAAsBA,CAC7BP,aAAkE,EAClEwB,eAAuB,EACoB;EAC3C,KAAK,MAAMC,gBAAgB,IAAIzB,aAAa,EAAE;IAC5C,MAAMM,YAAY,GAAGN,aAAa,CAACyB,gBAAgB,CAAC;IAEpD,IAAInB,YAAY,CAACoB,KAAK,KAAKF,eAAe,EAAE;MAC1C,OAAOlB,YAAY;IACrB;EACF;EAEA,OAAO,IAAI;AACb;AASA,SAASiB,mBAAmBA,CAC1BP,IAAgB,EAChBM,WAAuB,EACvBK,YAAoB,EACV;EACV,MAAMC,YAAsB,GAAG,EAAE;EACjC,MAAMC,WAAW,GAAG,IAAIC,WAAW,CAAC,MAAM,CAAC;EAE3C,IAAIC,YAAY,GAAG,CAAC;EACpB,MAAMC,kBAAkB,GAAG,CAAC;EAE5B,KAAK,IAAIC,KAAK,GAAG,CAAC,EAAEA,KAAK,GAAGN,YAAY,EAAEM,KAAK,EAAE,EAAE;IAEjD,MAAMC,cAAc,GAClBZ,WAAW,CAAC,CAACW,KAAK,GAAG,CAAC,IAAID,kBAAkB,CAAC,GAAGV,WAAW,CAACW,KAAK,GAAGD,kBAAkB,CAAC;IACzF,MAAMG,UAAU,GAAGnB,IAAI,CAACoB,QAAQ,CAACL,YAAY,EAAEG,cAAc,GAAGH,YAAY,CAAC;IAC7E,MAAMM,eAAe,GAAGR,WAAW,CAACvC,MAAM,CAAC6C,UAAU,CAAC;IAEtDP,YAAY,CAACU,IAAI,CAACD,eAAe,CAAC;IAClCN,YAAY,IAAIG,cAAc;EAChC;EAEA,OAAON,YAAY;AACrB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert } from '../../utils/assert';
|
|
2
|
-
import GLTFScenegraph from '../../api/gltf-scenegraph';
|
|
2
|
+
import { GLTFScenegraph } from '../../api/gltf-scenegraph';
|
|
3
3
|
const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
|
|
4
4
|
export const name = KHR_LIGHTS_PUNCTUAL;
|
|
5
5
|
export async function decode(gltfData) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_lights_punctual.js","names":["assert","GLTFScenegraph","KHR_LIGHTS_PUNCTUAL","name","decode","gltfData","gltfScenegraph","json","extension","getExtension","lights","removeExtension","node","nodes","nodeExtension","getObjectExtension","light","removeObjectExtension","encode","addExtension","addObjectExtension"],"sources":["../../../../../src/lib/extensions/deprecated/KHR_lights_punctual.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_lights_punctual\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual\n\nimport type {GLTF} from '../../types/gltf-
|
|
1
|
+
{"version":3,"file":"KHR_lights_punctual.js","names":["assert","GLTFScenegraph","KHR_LIGHTS_PUNCTUAL","name","decode","gltfData","gltfScenegraph","json","extension","getExtension","lights","removeExtension","node","nodes","nodeExtension","getObjectExtension","light","removeObjectExtension","encode","addExtension","addObjectExtension"],"sources":["../../../../../src/lib/extensions/deprecated/KHR_lights_punctual.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_lights_punctual\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual\n\nimport type {GLTF} from '../../types/gltf-json-schema';\n\nimport {assert} from '../../utils/assert';\nimport {GLTFScenegraph} from '../../api/gltf-scenegraph';\n\nconst KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';\n\nexport const name = KHR_LIGHTS_PUNCTUAL;\n\nexport async function decode(gltfData: {json: GLTF}): Promise<void> {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // Move the light array out of the extension and remove the extension\n const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);\n if (extension) {\n // @ts-ignore\n gltfScenegraph.json.lights = extension.lights;\n gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);\n }\n\n // Any nodes that have the extension, add lights field pointing to light object\n // and remove the extension\n for (const node of json.nodes || []) {\n const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);\n if (nodeExtension) {\n // @ts-ignore\n node.light = nodeExtension.light;\n }\n gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);\n }\n}\n\n// Move the light ar ray out of the extension and remove the extension\nexport async function encode(gltfData): Promise<void> {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // @ts-ignore\n if (json.lights) {\n const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);\n // @ts-ignore\n assert(!extension.lights);\n // @ts-ignore\n extension.lights = json.lights;\n // @ts-ignore\n delete json.lights;\n }\n\n // Any nodes that have lights field pointing to light object\n // add the extension\n // @ts-ignore\n if (gltfScenegraph.json.lights) {\n // @ts-ignore\n for (const light of gltfScenegraph.json.lights) {\n const node = light.node;\n gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);\n }\n // @ts-ignore\n delete gltfScenegraph.json.lights;\n }\n}\n"],"mappings":"AAKA,SAAQA,MAAM,QAAO,oBAAoB;AACzC,SAAQC,cAAc,QAAO,2BAA2B;AAExD,MAAMC,mBAAmB,GAAG,qBAAqB;AAEjD,OAAO,MAAMC,IAAI,GAAGD,mBAAmB;AAEvC,OAAO,eAAeE,MAAMA,CAACC,QAAsB,EAAiB;EAClE,MAAMC,cAAc,GAAG,IAAIL,cAAc,CAACI,QAAQ,CAAC;EACnD,MAAM;IAACE;EAAI,CAAC,GAAGD,cAAc;EAG7B,MAAME,SAAS,GAAGF,cAAc,CAACG,YAAY,CAACP,mBAAmB,CAAC;EAClE,IAAIM,SAAS,EAAE;IAEbF,cAAc,CAACC,IAAI,CAACG,MAAM,GAAGF,SAAS,CAACE,MAAM;IAC7CJ,cAAc,CAACK,eAAe,CAACT,mBAAmB,CAAC;EACrD;EAIA,KAAK,MAAMU,IAAI,IAAIL,IAAI,CAACM,KAAK,IAAI,EAAE,EAAE;IACnC,MAAMC,aAAa,GAAGR,cAAc,CAACS,kBAAkB,CAACH,IAAI,EAAEV,mBAAmB,CAAC;IAClF,IAAIY,aAAa,EAAE;MAEjBF,IAAI,CAACI,KAAK,GAAGF,aAAa,CAACE,KAAK;IAClC;IACAV,cAAc,CAACW,qBAAqB,CAACL,IAAI,EAAEV,mBAAmB,CAAC;EACjE;AACF;AAGA,OAAO,eAAegB,MAAMA,CAACb,QAAQ,EAAiB;EACpD,MAAMC,cAAc,GAAG,IAAIL,cAAc,CAACI,QAAQ,CAAC;EACnD,MAAM;IAACE;EAAI,CAAC,GAAGD,cAAc;EAG7B,IAAIC,IAAI,CAACG,MAAM,EAAE;IACf,MAAMF,SAAS,GAAGF,cAAc,CAACa,YAAY,CAACjB,mBAAmB,CAAC;IAElEF,MAAM,CAAC,CAACQ,SAAS,CAACE,MAAM,CAAC;IAEzBF,SAAS,CAACE,MAAM,GAAGH,IAAI,CAACG,MAAM;IAE9B,OAAOH,IAAI,CAACG,MAAM;EACpB;EAKA,IAAIJ,cAAc,CAACC,IAAI,CAACG,MAAM,EAAE;IAE9B,KAAK,MAAMM,KAAK,IAAIV,cAAc,CAACC,IAAI,CAACG,MAAM,EAAE;MAC9C,MAAME,IAAI,GAAGI,KAAK,CAACJ,IAAI;MACvBN,cAAc,CAACc,kBAAkB,CAACR,IAAI,EAAEV,mBAAmB,EAAEc,KAAK,CAAC;IACrE;IAEA,OAAOV,cAAc,CAACC,IAAI,CAACG,MAAM;EACnC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_materials_unlit.js","names":["GLTFScenegraph","KHR_MATERIALS_UNLIT","name","decode","gltfData","gltfScenegraph","json","material","materials","extension","extensions","KHR_materials_unlit","unlit","removeObjectExtension","removeExtension","encode","addObjectExtension","addExtension"],"sources":["../../../../../src/lib/extensions/deprecated/KHR_materials_unlit.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_materials_unlit\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit\n\nimport type {GLTF} from '../../types/gltf-
|
|
1
|
+
{"version":3,"file":"KHR_materials_unlit.js","names":["GLTFScenegraph","KHR_MATERIALS_UNLIT","name","decode","gltfData","gltfScenegraph","json","material","materials","extension","extensions","KHR_materials_unlit","unlit","removeObjectExtension","removeExtension","encode","addObjectExtension","addExtension"],"sources":["../../../../../src/lib/extensions/deprecated/KHR_materials_unlit.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_materials_unlit\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit\n\nimport type {GLTF} from '../../types/gltf-json-schema';\n\nimport {GLTFScenegraph} from '../../api/gltf-scenegraph';\n\nconst KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';\n\nexport const name = KHR_MATERIALS_UNLIT;\n\nexport async function decode(gltfData: {json: GLTF}): Promise<void> {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // Any nodes that have the extension, add lights field pointing to light object\n // and remove the extension\n for (const material of json.materials || []) {\n const extension = material.extensions && material.extensions.KHR_materials_unlit;\n if (extension) {\n // @ts-ignore TODO\n material.unlit = true;\n }\n gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);\n }\n\n // Remove the top-level extension\n gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);\n}\n\nexport function encode(gltfData) {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // Any nodes that have lights field pointing to light object\n // add the extension\n // @ts-ignore\n if (gltfScenegraph.materials) {\n for (const material of json.materials || []) {\n // @ts-ignore\n if (material.unlit) {\n // @ts-ignore\n delete material.unlit;\n gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});\n gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);\n }\n }\n }\n}\n"],"mappings":"AAKA,SAAQA,cAAc,QAAO,2BAA2B;AAExD,MAAMC,mBAAmB,GAAG,qBAAqB;AAEjD,OAAO,MAAMC,IAAI,GAAGD,mBAAmB;AAEvC,OAAO,eAAeE,MAAMA,CAACC,QAAsB,EAAiB;EAClE,MAAMC,cAAc,GAAG,IAAIL,cAAc,CAACI,QAAQ,CAAC;EACnD,MAAM;IAACE;EAAI,CAAC,GAAGD,cAAc;EAI7B,KAAK,MAAME,QAAQ,IAAID,IAAI,CAACE,SAAS,IAAI,EAAE,EAAE;IAC3C,MAAMC,SAAS,GAAGF,QAAQ,CAACG,UAAU,IAAIH,QAAQ,CAACG,UAAU,CAACC,mBAAmB;IAChF,IAAIF,SAAS,EAAE;MAEbF,QAAQ,CAACK,KAAK,GAAG,IAAI;IACvB;IACAP,cAAc,CAACQ,qBAAqB,CAACN,QAAQ,EAAEN,mBAAmB,CAAC;EACrE;EAGAI,cAAc,CAACS,eAAe,CAACb,mBAAmB,CAAC;AACrD;AAEA,OAAO,SAASc,MAAMA,CAACX,QAAQ,EAAE;EAC/B,MAAMC,cAAc,GAAG,IAAIL,cAAc,CAACI,QAAQ,CAAC;EACnD,MAAM;IAACE;EAAI,CAAC,GAAGD,cAAc;EAK7B,IAAIA,cAAc,CAACG,SAAS,EAAE;IAC5B,KAAK,MAAMD,QAAQ,IAAID,IAAI,CAACE,SAAS,IAAI,EAAE,EAAE;MAE3C,IAAID,QAAQ,CAACK,KAAK,EAAE;QAElB,OAAOL,QAAQ,CAACK,KAAK;QACrBP,cAAc,CAACW,kBAAkB,CAACT,QAAQ,EAAEN,mBAAmB,EAAE,CAAC,CAAC,CAAC;QACpEI,cAAc,CAACY,YAAY,CAAChB,mBAAmB,CAAC;MAClD;IACF;EACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_techniques_webgl.js","names":["GLTFScenegraph","KHR_TECHNIQUES_WEBGL","name","decode","gltfData","gltfScenegraph","json","extension","getExtension","techniques","resolveTechniques","material","materials","materialExtension","getObjectExtension","technique","Object","assign","values","resolveValues","removeObjectExtension","removeExtension","encode","options","techniquesExtension","programs","shaders","textDecoder","TextDecoder","forEach","shader","Number","isFinite","bufferView","code","getTypedArrayForBufferView","Error","program","fragmentShader","vertexShader","keys","uniforms","uniform","value","index","undefined","texture","getTexture"],"sources":["../../../../../src/lib/extensions/deprecated/KHR_techniques_webgl.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_techniques_webgl\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_techniques_webgl\n\nimport type {GLTF} from '../../types/gltf-
|
|
1
|
+
{"version":3,"file":"KHR_techniques_webgl.js","names":["GLTFScenegraph","KHR_TECHNIQUES_WEBGL","name","decode","gltfData","gltfScenegraph","json","extension","getExtension","techniques","resolveTechniques","material","materials","materialExtension","getObjectExtension","technique","Object","assign","values","resolveValues","removeObjectExtension","removeExtension","encode","options","techniquesExtension","programs","shaders","textDecoder","TextDecoder","forEach","shader","Number","isFinite","bufferView","code","getTypedArrayForBufferView","Error","program","fragmentShader","vertexShader","keys","uniforms","uniform","value","index","undefined","texture","getTexture"],"sources":["../../../../../src/lib/extensions/deprecated/KHR_techniques_webgl.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_techniques_webgl\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_techniques_webgl\n\nimport type {GLTF} from '../../types/gltf-json-schema';\n\nimport {GLTFScenegraph} from '../../api/gltf-scenegraph';\n\nconst KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';\n\nexport const name = KHR_TECHNIQUES_WEBGL;\n\nexport async function decode(gltfData: {json: GLTF}): Promise<void> {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL);\n if (extension) {\n const techniques = resolveTechniques(extension, gltfScenegraph);\n\n for (const material of json.materials || []) {\n const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL);\n if (materialExtension) {\n // @ts-ignore TODO\n material.technique = Object.assign(\n {},\n materialExtension,\n // @ts-ignore\n techniques[materialExtension.technique]\n );\n // @ts-ignore TODO\n material.technique.values = resolveValues(material.technique, gltfScenegraph);\n }\n gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL);\n }\n\n // Remove the top-level extension\n gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);\n }\n}\n// eslint-disable-next-line\nexport async function encode(gltfData, options): Promise<void> {\n // TODO\n}\n\nfunction resolveTechniques(\n techniquesExtension: {[key: string]: any},\n // programs: {[key: string]: any}[],\n // shaders: {[key: string]: any}[],\n // techniques: {[key: string]: any}[]\n gltfScenegraph\n) {\n const {programs = [], shaders = [], techniques = []} = techniquesExtension;\n const textDecoder = new TextDecoder();\n\n shaders.forEach((shader) => {\n if (Number.isFinite(shader.bufferView)) {\n shader.code = textDecoder.decode(\n gltfScenegraph.getTypedArrayForBufferView(shader.bufferView)\n );\n } else {\n // TODO: handle URI shader\n throw new Error('KHR_techniques_webgl: no shader code');\n }\n });\n\n programs.forEach((program) => {\n program.fragmentShader = shaders[program.fragmentShader];\n program.vertexShader = shaders[program.vertexShader];\n });\n\n techniques.forEach((technique) => {\n technique.program = programs[technique.program];\n });\n\n return techniques;\n}\n\nfunction resolveValues(technique, gltfScenegraph) {\n const values = Object.assign({}, technique.values);\n\n // merge values from uniforms\n Object.keys(technique.uniforms || {}).forEach((uniform) => {\n if (technique.uniforms[uniform].value && !(uniform in values)) {\n values[uniform] = technique.uniforms[uniform].value;\n }\n });\n\n // resolve textures\n Object.keys(values).forEach((uniform) => {\n if (typeof values[uniform] === 'object' && values[uniform].index !== undefined) {\n // Assume this is a texture\n // TODO: find if there are any other types that can be referenced\n values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index);\n }\n });\n\n return values;\n}\n"],"mappings":"AAKA,SAAQA,cAAc,QAAO,2BAA2B;AAExD,MAAMC,oBAAoB,GAAG,sBAAsB;A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MAAM,CAACwB,OAAO,CAAC,KAAK,QAAQ,IAAIxB,MAAM,CAACwB,OAAO,CAAC,CAACE,KAAK,KAAKC,SAAS,EAAE;MAG9E3B,MAAM,CAACwB,OAAO,CAAC,CAACI,OAAO,GAAGzC,cAAc,CAAC0C,UAAU,CAAC7B,MAAM,CAACwB,OAAO,CAAC,CAACE,KAAK,CAAC;IAC5E;EACF,CAAC,CAAC;EAEF,OAAO1B,MAAM;AACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gltf-attribute-utils.js","names":["getAccessorTypeFromSize","getComponentTypeFromArray","getGLTFAccessors","attributes","accessors","name","attribute","glTFAccessor","getGLTFAccessor","buffer","size","count","getAccessorData","value","byteOffset","type","componentType","ArrayBuffer","isView","toTypedArray","Float32Array","length","array","ArrayType","convertTypedArrays","arguments","undefined","Array","isArray"],"sources":["../../../../src/lib/gltf-utils/gltf-attribute-utils.ts"],"sourcesContent":["// import type {TypedArray} from '../types/loader-utils';\nimport type {GLTFAccessor} from '../types/gltf-
|
|
1
|
+
{"version":3,"file":"gltf-attribute-utils.js","names":["getAccessorTypeFromSize","getComponentTypeFromArray","getGLTFAccessors","attributes","accessors","name","attribute","glTFAccessor","getGLTFAccessor","buffer","size","count","getAccessorData","value","byteOffset","type","componentType","ArrayBuffer","isView","toTypedArray","Float32Array","length","array","ArrayType","convertTypedArrays","arguments","undefined","Array","isArray"],"sources":["../../../../src/lib/gltf-utils/gltf-attribute-utils.ts"],"sourcesContent":["// import type {TypedArray} from '../types/loader-utils';\nimport type {GLTFAccessor} from '../types/gltf-json-schema';\n// TODO - remove\nimport {getAccessorTypeFromSize, getComponentTypeFromArray} from './gltf-utils';\n\n// Returns a fresh attributes object with glTF-standardized attributes names\n// Attributes that cannot be identified will not be included\n// Removes `indices` if present, as it should be stored separately from the attributes\nexport function getGLTFAccessors(attributes): {[key: string]: GLTFAccessor} {\n const accessors = {};\n for (const name in attributes) {\n const attribute = attributes[name];\n if (name !== 'indices') {\n const glTFAccessor = getGLTFAccessor(attribute);\n accessors[name] = glTFAccessor;\n }\n }\n return accessors;\n}\n\n// Fix up a single accessor.\n// Input: typed array or a partial accessor object\n// Return: accessor object\nexport function getGLTFAccessor(attribute) {\n const {buffer, size, count} = getAccessorData(attribute);\n\n const glTFAccessor: GLTFAccessor = {\n // glTF Accessor values\n // TODO: Instead of a bufferView index we could have an actual buffer (typed array)\n // bufferView: null,\n // TODO: Deprecate `value` in favor of bufferView?\n // @ts-ignore\n value: buffer,\n size, // Decoded `type` (e.g. SCALAR)\n\n byteOffset: 0,\n count,\n type: getAccessorTypeFromSize(size),\n componentType: getComponentTypeFromArray(buffer)\n };\n\n return glTFAccessor;\n}\n\n// export function getGLTFAttribute(data, gltfAttributeName): GLTFAccessor {\n// return data.attributes[data.glTFAttributeMap[gltfAttributeName]];\n// }\n\nfunction getAccessorData(attribute) {\n let buffer = attribute;\n let size = 1;\n let count = 0;\n\n if (attribute && attribute.value) {\n buffer = attribute.value;\n size = attribute.size || 1;\n }\n\n if (buffer) {\n if (!ArrayBuffer.isView(buffer)) {\n buffer = toTypedArray(buffer, Float32Array);\n }\n count = buffer.length / size;\n }\n\n return {buffer, size, count};\n}\n\n// Convert non-typed arrays to arrays of specified format\nfunction toTypedArray(array, ArrayType, convertTypedArrays = false) {\n if (!array) {\n return null;\n }\n if (Array.isArray(array)) {\n return new ArrayType(array);\n }\n if (convertTypedArrays && !(array instanceof ArrayType)) {\n return new ArrayType(array);\n }\n return array;\n}\n"],"mappings":"AAGA,SAAQA,uBAAuB,EAAEC,yBAAyB,QAAO,cAAc;AAK/E,OAAO,SAASC,gBAAgBA,CAACC,UAAU,EAAiC;EAC1E,MAAMC,SAAS,GAAG,CAAC,CAAC;EACpB,KAAK,MAAMC,IAAI,IAAIF,UAAU,EAAE;IAC7B,MAAMG,SAAS,GAAGH,UAAU,CAACE,IAAI,CAAC;IAClC,IAAIA,IAAI,KAAK,SAAS,EAAE;MACtB,MAAME,YAAY,GAAG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