@loaders.gl/gltf 4.0.0-alpha.5 → 4.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +2 -2
- package/dist/dist.min.js +2037 -1013
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/glb-loader.js +56 -0
- package/dist/es5/glb-loader.js.map +1 -0
- package/dist/es5/glb-writer.js +35 -0
- package/dist/es5/glb-writer.js.map +1 -0
- package/dist/es5/gltf-loader.js +81 -0
- package/dist/es5/gltf-loader.js.map +1 -0
- package/dist/es5/gltf-writer.js +35 -0
- package/dist/es5/gltf-writer.js.map +1 -0
- package/dist/es5/index.js +49 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/api/gltf-extensions.js +109 -0
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -0
- package/dist/es5/lib/api/gltf-scenegraph.js +578 -0
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -0
- package/dist/es5/lib/api/normalize-gltf-v1.js +331 -0
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -0
- package/dist/es5/lib/api/post-process-gltf.js +422 -0
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -0
- package/dist/es5/lib/encoders/encode-glb.js +61 -0
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -0
- package/dist/es5/lib/encoders/encode-gltf.js +21 -0
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -0
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +96 -0
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -0
- package/dist/es5/lib/extensions/EXT_texture_webp.js +44 -0
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +40 -0
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +246 -0
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +37 -0
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_texture_transform.js +229 -0
- package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +103 -0
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +99 -0
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +76 -0
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +113 -0
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
- package/dist/es5/lib/gltf-utils/get-typed-array.js +23 -0
- package/dist/es5/lib/gltf-utils/get-typed-array.js.map +1 -0
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +68 -0
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -0
- package/dist/es5/lib/gltf-utils/gltf-constants.js +48 -0
- package/dist/es5/lib/gltf-utils/gltf-constants.js.map +1 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js +62 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -0
- package/dist/es5/lib/gltf-utils/resolve-url.js +18 -0
- package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -0
- package/dist/es5/lib/parsers/parse-glb.js +120 -0
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -0
- package/dist/es5/lib/parsers/parse-gltf.js +287 -0
- package/dist/es5/lib/parsers/parse-gltf.js.map +1 -0
- package/dist/es5/lib/types/glb-types.js +2 -0
- package/dist/es5/lib/types/glb-types.js.map +1 -0
- package/dist/es5/lib/types/gltf-json-schema.js +2 -0
- package/dist/es5/lib/types/gltf-json-schema.js.map +1 -0
- package/dist/es5/lib/types/gltf-postprocessed-schema.js +2 -0
- package/dist/es5/lib/types/gltf-postprocessed-schema.js.map +1 -0
- package/dist/es5/lib/types/gltf-types.js +2 -0
- package/dist/es5/lib/types/gltf-types.js.map +1 -0
- package/dist/es5/lib/utils/assert.js +12 -0
- package/dist/es5/lib/utils/assert.js.map +1 -0
- package/dist/es5/lib/utils/version.js +9 -0
- package/dist/es5/lib/utils/version.js.map +1 -0
- package/dist/es5/meshopt/meshopt-decoder.js +215 -0
- package/dist/es5/meshopt/meshopt-decoder.js.map +1 -0
- package/dist/es5/webp/webp.js +83 -0
- package/dist/es5/webp/webp.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/glb-loader.js +31 -0
- package/dist/esm/glb-loader.js.map +1 -0
- package/dist/esm/glb-writer.js +27 -0
- package/dist/esm/glb-writer.js.map +1 -0
- package/dist/esm/gltf-loader.js +51 -0
- package/dist/esm/gltf-loader.js.map +1 -0
- package/dist/esm/gltf-writer.js +28 -0
- package/dist/esm/gltf-writer.js.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/api/gltf-extensions.js +35 -0
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -0
- package/dist/esm/lib/api/gltf-scenegraph.js +441 -0
- package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -0
- package/dist/esm/lib/api/normalize-gltf-v1.js +204 -0
- package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -0
- package/dist/esm/lib/api/post-process-gltf.js +341 -0
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -0
- package/dist/esm/lib/encoders/encode-glb.js +54 -0
- package/dist/esm/lib/encoders/encode-glb.js.map +1 -0
- package/dist/esm/lib/encoders/encode-gltf.js +14 -0
- package/dist/esm/lib/encoders/encode-gltf.js.map +1 -0
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js +42 -0
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -0
- package/dist/esm/lib/extensions/EXT_texture_webp.js +25 -0
- package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_binary_gltf.js +21 -0
- package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +110 -0
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_texture_basisu.js +18 -0
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_texture_transform.js +181 -0
- package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +77 -0
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +42 -0
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +33 -0
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +61 -0
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
- package/dist/esm/lib/gltf-utils/get-typed-array.js +16 -0
- package/dist/esm/lib/gltf-utils/get-typed-array.js.map +1 -0
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js +62 -0
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +1 -0
- package/dist/esm/lib/gltf-utils/gltf-constants.js +37 -0
- package/dist/esm/lib/gltf-utils/gltf-constants.js.map +1 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js +54 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -0
- package/dist/esm/lib/gltf-utils/resolve-url.js +12 -0
- package/dist/esm/lib/gltf-utils/resolve-url.js.map +1 -0
- package/dist/esm/lib/parsers/parse-glb.js +114 -0
- package/dist/esm/lib/parsers/parse-glb.js.map +1 -0
- package/dist/esm/lib/parsers/parse-gltf.js +156 -0
- package/dist/esm/lib/parsers/parse-gltf.js.map +1 -0
- package/dist/esm/lib/types/glb-types.js +2 -0
- package/dist/esm/lib/types/glb-types.js.map +1 -0
- package/dist/esm/lib/types/gltf-json-schema.js +2 -0
- package/dist/esm/lib/types/gltf-json-schema.js.map +1 -0
- package/dist/esm/lib/types/gltf-postprocessed-schema.js +2 -0
- package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +1 -0
- package/dist/esm/lib/types/gltf-types.js +2 -0
- package/dist/esm/lib/types/gltf-types.js.map +1 -0
- package/dist/esm/lib/utils/assert.js +6 -0
- package/dist/esm/lib/utils/assert.js.map +1 -0
- package/dist/esm/lib/utils/version.js +2 -0
- package/dist/esm/lib/utils/version.js.map +1 -0
- package/dist/esm/meshopt/meshopt-decoder.js +91 -0
- package/dist/esm/meshopt/meshopt-decoder.js.map +1 -0
- package/dist/esm/meshopt/meshopt-encoder.ts.disabled +409 -0
- package/dist/esm/webp/webp.js +25 -0
- package/dist/esm/webp/webp.js.map +1 -0
- package/dist/glb-loader.d.ts +3 -2
- package/dist/glb-loader.d.ts.map +1 -1
- package/dist/glb-loader.js +33 -28
- package/dist/glb-writer.d.ts +7 -16
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +34 -26
- package/dist/gltf-loader.d.ts +3 -2
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +46 -43
- package/dist/gltf-writer.d.ts +2 -2
- package/dist/gltf-writer.d.ts.map +1 -1
- package/dist/gltf-writer.js +29 -26
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -7
- package/dist/lib/api/gltf-extensions.d.ts +6 -1
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +79 -31
- package/dist/lib/api/gltf-scenegraph.d.ts +5 -11
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +563 -512
- package/dist/lib/api/normalize-gltf-v1.d.ts.map +1 -1
- package/dist/lib/api/normalize-gltf-v1.js +278 -229
- package/dist/lib/api/post-process-gltf.js +324 -376
- package/dist/lib/encoders/encode-glb.d.ts +2 -1
- package/dist/lib/encoders/encode-glb.d.ts.map +1 -1
- package/dist/lib/encoders/encode-glb.js +56 -58
- package/dist/lib/encoders/encode-gltf.d.ts +18 -0
- package/dist/lib/encoders/encode-gltf.d.ts.map +1 -1
- package/dist/lib/encoders/encode-gltf.js +33 -12
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +0 -3
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +39 -50
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +35 -28
- package/dist/lib/extensions/KHR_binary_gltf.js +39 -23
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +126 -111
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +29 -19
- package/dist/lib/extensions/KHR_texture_transform.d.ts +13 -0
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_texture_transform.js +230 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +6 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +118 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +57 -44
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +42 -32
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +76 -62
- package/dist/lib/gltf-utils/get-typed-array.js +39 -14
- package/dist/lib/gltf-utils/gltf-attribute-utils.js +65 -65
- package/dist/lib/gltf-utils/gltf-constants.d.ts +17 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-constants.js +38 -32
- package/dist/lib/gltf-utils/gltf-utils.js +52 -45
- package/dist/lib/gltf-utils/resolve-url.js +17 -15
- package/dist/lib/parsers/parse-glb.d.ts +1 -1
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
- package/dist/lib/parsers/parse-glb.js +120 -107
- package/dist/lib/parsers/parse-gltf.d.ts +2 -2
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +187 -154
- package/dist/lib/types/glb-types.d.ts +3 -3
- package/dist/lib/types/glb-types.d.ts.map +1 -1
- package/dist/lib/types/glb-types.js +2 -2
- package/dist/lib/types/gltf-json-schema.d.ts +396 -11
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-json-schema.js +4 -2
- package/dist/lib/types/gltf-postprocessed-schema.d.ts +10 -10
- package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-postprocessed-schema.js +4 -2
- package/dist/lib/types/gltf-types.d.ts +8 -5
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/dist/lib/types/gltf-types.js +3 -2
- package/dist/lib/utils/assert.js +11 -5
- package/dist/lib/utils/version.js +7 -2
- package/dist/meshopt/meshopt-decoder.js +97 -82
- package/dist/webp/webp.d.ts +1 -1
- package/dist/webp/webp.d.ts.map +1 -1
- package/dist/webp/webp.js +32 -23
- package/package.json +9 -8
- package/src/glb-loader.ts +1 -1
- package/src/glb-writer.ts +9 -3
- package/src/gltf-writer.ts +2 -2
- package/src/index.ts +10 -1
- package/src/lib/api/gltf-extensions.ts +13 -2
- package/src/lib/api/gltf-scenegraph.ts +21 -12
- package/src/lib/api/normalize-gltf-v1.ts +2 -1
- package/src/lib/encoders/encode-glb.ts +8 -1
- package/src/lib/encoders/encode-gltf.ts +18 -9
- package/src/lib/extensions/EXT_meshopt_compression.ts +12 -19
- package/src/lib/extensions/EXT_texture_webp.ts +3 -2
- package/src/lib/extensions/KHR_binary_gltf.ts +1 -1
- package/src/lib/extensions/KHR_draco_mesh_compression.ts +1 -1
- package/src/lib/extensions/KHR_texture_basisu.ts +1 -0
- package/src/lib/extensions/KHR_texture_transform.ts +305 -0
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +163 -0
- package/src/lib/extensions/deprecated/KHR_materials_unlit.ts +3 -3
- package/src/lib/extensions/deprecated/KHR_techniques_webgl.ts +1 -0
- package/src/lib/gltf-utils/gltf-constants.ts +2 -2
- package/src/lib/parsers/parse-gltf.ts +10 -1
- package/src/lib/types/glb-types.ts +1 -1
- package/src/lib/types/gltf-json-schema.ts +434 -5
- package/src/lib/types/gltf-postprocessed-schema.ts +9 -9
- package/src/lib/types/gltf-types.ts +24 -3
- package/dist/bundle.js.map +0 -1
- package/dist/glb-loader.js.map +0 -1
- package/dist/glb-writer.js.map +0 -1
- package/dist/gltf-loader.js.map +0 -1
- package/dist/gltf-writer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/api/gltf-extensions.js.map +0 -1
- package/dist/lib/api/gltf-scenegraph.js.map +0 -1
- package/dist/lib/api/normalize-gltf-v1.js.map +0 -1
- package/dist/lib/api/post-process-gltf.js.map +0 -1
- package/dist/lib/encoders/encode-glb.js.map +0 -1
- package/dist/lib/encoders/encode-gltf.js.map +0 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js.map +0 -1
- package/dist/lib/extensions/EXT_texture_webp.js.map +0 -1
- package/dist/lib/extensions/KHR_binary_gltf.js.map +0 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
- package/dist/lib/extensions/KHR_texture_basisu.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
- package/dist/lib/gltf-utils/get-typed-array.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-constants.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-utils.js.map +0 -1
- package/dist/lib/gltf-utils/resolve-url.js.map +0 -1
- package/dist/lib/parsers/parse-glb.js.map +0 -1
- package/dist/lib/parsers/parse-gltf.js.map +0 -1
- package/dist/lib/types/glb-types.js.map +0 -1
- package/dist/lib/types/gltf-json-schema.js.map +0 -1
- package/dist/lib/types/gltf-postprocessed-schema.js.map +0 -1
- package/dist/lib/types/gltf-types.js.map +0 -1
- package/dist/lib/utils/assert.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/meshopt/meshopt-decoder.js.map +0 -1
- package/dist/webp/webp.js.map +0 -1
- /package/dist/{meshopt → es5/meshopt}/meshopt-encoder.ts.disabled +0 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.decode = exports.name = void 0;
|
|
7
|
+
const gltf_scenegraph_1 = __importDefault(require("../../api/gltf-scenegraph"));
|
|
8
|
+
/** Extension name */
|
|
9
|
+
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
10
|
+
exports.name = EXT_FEATURE_METADATA;
|
|
11
|
+
async function decode(gltfData) {
|
|
12
|
+
const scenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
13
|
+
decodeExtFeatureMetadata(scenegraph);
|
|
14
|
+
}
|
|
15
|
+
exports.decode = decode;
|
|
16
|
+
/**
|
|
17
|
+
* Decodes feature metadata from extension
|
|
18
|
+
* @param scenegraph
|
|
19
|
+
*/
|
|
20
|
+
function decodeExtFeatureMetadata(scenegraph) {
|
|
21
|
+
const extension = scenegraph.getExtension(EXT_FEATURE_METADATA);
|
|
22
|
+
const schemaClasses = extension?.schema?.classes;
|
|
23
|
+
const featureTables = extension?.featureTables;
|
|
24
|
+
const featureTextures = extension?.featureTextures;
|
|
25
|
+
if (featureTextures) {
|
|
26
|
+
/*
|
|
27
|
+
* TODO add support for featureTextures
|
|
28
|
+
* Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-textures
|
|
29
|
+
*/
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
31
|
+
console.warn('featureTextures is not yet supported in the "EXT_feature_metadata" extension.');
|
|
32
|
+
}
|
|
33
|
+
if (schemaClasses && featureTables) {
|
|
34
|
+
for (const schemaName in schemaClasses) {
|
|
35
|
+
const schemaClass = schemaClasses[schemaName];
|
|
36
|
+
const featureTable = findFeatureTableByName(featureTables, schemaName);
|
|
37
|
+
if (featureTable) {
|
|
38
|
+
handleFeatureTableProperties(scenegraph, featureTable, schemaClass);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Navigate throw all properies in feature table and gets properties data.
|
|
45
|
+
* @param scenegraph
|
|
46
|
+
* @param featureTable
|
|
47
|
+
* @param schemaClass
|
|
48
|
+
*/
|
|
49
|
+
function handleFeatureTableProperties(scenegraph, featureTable, schemaClass) {
|
|
50
|
+
for (const propertyName in schemaClass.properties) {
|
|
51
|
+
const schemaProperty = schemaClass.properties[propertyName];
|
|
52
|
+
const featureTableProperty = featureTable?.properties?.[propertyName];
|
|
53
|
+
const numberOfFeatures = featureTable.count;
|
|
54
|
+
if (featureTableProperty) {
|
|
55
|
+
const data = getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty);
|
|
56
|
+
featureTableProperty.data = data;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Decode properties from binary sourse based on property type.
|
|
62
|
+
* @param scenegraph
|
|
63
|
+
* @param schemaProperty
|
|
64
|
+
* @param numberOfFeatures
|
|
65
|
+
* @param featureTableProperty
|
|
66
|
+
*/
|
|
67
|
+
function getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty) {
|
|
68
|
+
const bufferView = featureTableProperty.bufferView;
|
|
69
|
+
// TODO think maybe we shouldn't get data only in Uint8Array format.
|
|
70
|
+
let data = scenegraph.getTypedArrayForBufferView(bufferView);
|
|
71
|
+
switch (schemaProperty.type) {
|
|
72
|
+
case 'STRING': {
|
|
73
|
+
// stringOffsetBufferView should be available for string type.
|
|
74
|
+
const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView;
|
|
75
|
+
const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);
|
|
76
|
+
data = getStringAttributes(data, offsetsData, numberOfFeatures);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
default:
|
|
80
|
+
}
|
|
81
|
+
return data;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Find the feature table by class name.
|
|
85
|
+
* @param featureTables
|
|
86
|
+
* @param schemaClassName
|
|
87
|
+
*/
|
|
88
|
+
function findFeatureTableByName(featureTables, schemaClassName) {
|
|
89
|
+
for (const featureTableName in featureTables) {
|
|
90
|
+
const featureTable = featureTables[featureTableName];
|
|
91
|
+
if (featureTable.class === schemaClassName) {
|
|
92
|
+
return featureTable;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Getting string attributes from binary data.
|
|
99
|
+
* Spec - https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#strings
|
|
100
|
+
* @param data
|
|
101
|
+
* @param offsetsData
|
|
102
|
+
* @param stringsCount
|
|
103
|
+
*/
|
|
104
|
+
function getStringAttributes(data, offsetsData, stringsCount) {
|
|
105
|
+
const stringsArray = [];
|
|
106
|
+
const textDecoder = new TextDecoder('utf8');
|
|
107
|
+
let stringOffset = 0;
|
|
108
|
+
const bytesPerStringSize = 4;
|
|
109
|
+
for (let index = 0; index < stringsCount; index++) {
|
|
110
|
+
// TODO check if it is multiplication on bytesPerStringSize is valid operation?
|
|
111
|
+
const stringByteSize = offsetsData[(index + 1) * bytesPerStringSize] - offsetsData[index * bytesPerStringSize];
|
|
112
|
+
const stringData = data.subarray(stringOffset, stringByteSize + stringOffset);
|
|
113
|
+
const stringAttribute = textDecoder.decode(stringData);
|
|
114
|
+
stringsArray.push(stringAttribute);
|
|
115
|
+
stringOffset += stringByteSize;
|
|
116
|
+
}
|
|
117
|
+
return stringsArray;
|
|
118
|
+
}
|
|
@@ -1,49 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// GLTF EXTENSION: KHR_lights_punctual
|
|
3
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.encode = exports.decode = exports.name = void 0;
|
|
9
|
+
const assert_1 = require("../../utils/assert");
|
|
10
|
+
const gltf_scenegraph_1 = __importDefault(require("../../api/gltf-scenegraph"));
|
|
3
11
|
const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
exports.name = KHR_LIGHTS_PUNCTUAL;
|
|
13
|
+
async function decode(gltfData) {
|
|
14
|
+
const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
15
|
+
const { json } = gltfScenegraph;
|
|
16
|
+
// Move the light array out of the extension and remove the extension
|
|
17
|
+
const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);
|
|
18
|
+
if (extension) {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
gltfScenegraph.json.lights = extension.lights;
|
|
21
|
+
gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);
|
|
22
|
+
}
|
|
23
|
+
// Any nodes that have the extension, add lights field pointing to light object
|
|
24
|
+
// and remove the extension
|
|
25
|
+
for (const node of json.nodes || []) {
|
|
26
|
+
const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
27
|
+
if (nodeExtension) {
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
node.light = nodeExtension.light;
|
|
30
|
+
}
|
|
31
|
+
gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
22
32
|
}
|
|
23
|
-
|
|
24
|
-
gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
25
|
-
}
|
|
26
33
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
exports.decode = decode;
|
|
35
|
+
// Move the light ar ray out of the extension and remove the extension
|
|
36
|
+
async function encode(gltfData) {
|
|
37
|
+
const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
38
|
+
const { json } = gltfScenegraph;
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
if (json.lights) {
|
|
41
|
+
const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
(0, assert_1.assert)(!extension.lights);
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
extension.lights = json.lights;
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
delete json.lights;
|
|
48
|
+
}
|
|
49
|
+
// Any nodes that have lights field pointing to light object
|
|
50
|
+
// add the extension
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
if (gltfScenegraph.json.lights) {
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
for (const light of gltfScenegraph.json.lights) {
|
|
55
|
+
const node = light.node;
|
|
56
|
+
gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);
|
|
57
|
+
}
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
delete gltfScenegraph.json.lights;
|
|
44
60
|
}
|
|
45
|
-
|
|
46
|
-
delete gltfScenegraph.json.lights;
|
|
47
|
-
}
|
|
48
61
|
}
|
|
49
|
-
|
|
62
|
+
exports.encode = encode;
|
|
@@ -1,37 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// GLTF EXTENSION: KHR_materials_unlit
|
|
3
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.encode = exports.decode = exports.name = void 0;
|
|
9
|
+
const gltf_scenegraph_1 = __importDefault(require("../../api/gltf-scenegraph"));
|
|
2
10
|
const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
exports.name = KHR_MATERIALS_UNLIT;
|
|
12
|
+
async function decode(gltfData) {
|
|
13
|
+
const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
14
|
+
const { json } = gltfScenegraph;
|
|
15
|
+
// Any nodes that have the extension, add lights field pointing to light object
|
|
16
|
+
// and remove the extension
|
|
17
|
+
for (const material of json.materials || []) {
|
|
18
|
+
const extension = material.extensions && material.extensions.KHR_materials_unlit;
|
|
19
|
+
if (extension) {
|
|
20
|
+
// @ts-ignore TODO
|
|
21
|
+
material.unlit = true;
|
|
22
|
+
}
|
|
23
|
+
gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
|
|
16
24
|
}
|
|
17
|
-
|
|
18
|
-
gltfScenegraph.
|
|
19
|
-
}
|
|
25
|
+
// Remove the top-level extension
|
|
26
|
+
gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
|
|
20
27
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
json
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
exports.decode = decode;
|
|
29
|
+
function encode(gltfData) {
|
|
30
|
+
const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
31
|
+
const { json } = gltfScenegraph;
|
|
32
|
+
// Any nodes that have lights field pointing to light object
|
|
33
|
+
// add the extension
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
if (gltfScenegraph.materials) {
|
|
36
|
+
for (const material of json.materials || []) {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
if (material.unlit) {
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
delete material.unlit;
|
|
41
|
+
gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
|
|
42
|
+
gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
34
45
|
}
|
|
35
|
-
}
|
|
36
46
|
}
|
|
37
|
-
|
|
47
|
+
exports.encode = encode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_techniques_webgl.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_techniques_webgl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;AAMjD,eAAO,MAAM,IAAI,yBAAuB,CAAC;AAEzC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"KHR_techniques_webgl.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_techniques_webgl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;AAMjD,eAAO,MAAM,IAAI,yBAAuB,CAAC;AAEzC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BlE;AAED,wBAAsB,MAAM,CAAC,QAAQ,KAAA,EAAE,OAAO,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D"}
|
|
@@ -1,68 +1,82 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// GLTF EXTENSION: KHR_techniques_webgl
|
|
3
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_techniques_webgl
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.encode = exports.decode = exports.name = void 0;
|
|
9
|
+
const gltf_scenegraph_1 = __importDefault(require("../../api/gltf-scenegraph"));
|
|
2
10
|
const KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
exports.name = KHR_TECHNIQUES_WEBGL;
|
|
12
|
+
async function decode(gltfData) {
|
|
13
|
+
const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
14
|
+
const { json } = gltfScenegraph;
|
|
15
|
+
const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL);
|
|
16
|
+
if (extension) {
|
|
17
|
+
const techniques = resolveTechniques(extension, gltfScenegraph);
|
|
18
|
+
for (const material of json.materials || []) {
|
|
19
|
+
const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL);
|
|
20
|
+
if (materialExtension) {
|
|
21
|
+
// @ts-ignore TODO
|
|
22
|
+
material.technique = Object.assign({}, materialExtension,
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
techniques[materialExtension.technique]);
|
|
25
|
+
// @ts-ignore TODO
|
|
26
|
+
material.technique.values = resolveValues(material.technique, gltfScenegraph);
|
|
27
|
+
}
|
|
28
|
+
gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL);
|
|
29
|
+
}
|
|
30
|
+
// Remove the top-level extension
|
|
31
|
+
gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
|
|
23
32
|
}
|
|
24
|
-
|
|
25
|
-
gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
|
|
26
|
-
}
|
|
27
33
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
exports.decode = decode;
|
|
35
|
+
// eslint-disable-next-line
|
|
36
|
+
async function encode(gltfData, options) {
|
|
37
|
+
// TODO
|
|
38
|
+
}
|
|
39
|
+
exports.encode = encode;
|
|
40
|
+
function resolveTechniques(techniquesExtension,
|
|
41
|
+
// programs: {[key: string]: any}[],
|
|
42
|
+
// shaders: {[key: string]: any}[],
|
|
43
|
+
// techniques: {[key: string]: any}[]
|
|
44
|
+
gltfScenegraph) {
|
|
45
|
+
const { programs = [], shaders = [], techniques = [] } = techniquesExtension;
|
|
46
|
+
const textDecoder = new TextDecoder();
|
|
47
|
+
shaders.forEach((shader) => {
|
|
48
|
+
if (Number.isFinite(shader.bufferView)) {
|
|
49
|
+
shader.code = textDecoder.decode(gltfScenegraph.getTypedArrayForBufferView(shader.bufferView));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// TODO: handle URI shader
|
|
53
|
+
throw new Error('KHR_techniques_webgl: no shader code');
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
programs.forEach((program) => {
|
|
57
|
+
program.fragmentShader = shaders[program.fragmentShader];
|
|
58
|
+
program.vertexShader = shaders[program.vertexShader];
|
|
59
|
+
});
|
|
60
|
+
techniques.forEach((technique) => {
|
|
61
|
+
technique.program = programs[technique.program];
|
|
62
|
+
});
|
|
63
|
+
return techniques;
|
|
52
64
|
}
|
|
53
|
-
|
|
54
65
|
function resolveValues(technique, gltfScenegraph) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
const values = Object.assign({}, technique.values);
|
|
67
|
+
// merge values from uniforms
|
|
68
|
+
Object.keys(technique.uniforms || {}).forEach((uniform) => {
|
|
69
|
+
if (technique.uniforms[uniform].value && !(uniform in values)) {
|
|
70
|
+
values[uniform] = technique.uniforms[uniform].value;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
// resolve textures
|
|
74
|
+
Object.keys(values).forEach((uniform) => {
|
|
75
|
+
if (typeof values[uniform] === 'object' && values[uniform].index !== undefined) {
|
|
76
|
+
// Assume this is a texture
|
|
77
|
+
// TODO: find if there are any other types that can be referenced
|
|
78
|
+
values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return values;
|
|
67
82
|
}
|
|
68
|
-
//# sourceMappingURL=KHR_techniques_webgl.js.map
|
|
@@ -1,16 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTypedArrayForImageData = exports.getTypedArrayForBufferView = void 0;
|
|
4
|
+
// TODO - GLTFScenegraph should use these
|
|
5
|
+
const assert_1 = require("../utils/assert");
|
|
6
|
+
// accepts buffer view index or buffer view object
|
|
7
|
+
// returns a `Uint8Array`
|
|
8
|
+
function getTypedArrayForBufferView(json, buffers, bufferViewIndex) {
|
|
9
|
+
const bufferView = json.bufferViews[bufferViewIndex];
|
|
10
|
+
(0, assert_1.assert)(bufferView);
|
|
11
|
+
// Get hold of the arrayBuffer
|
|
12
|
+
const bufferIndex = bufferView.buffer;
|
|
13
|
+
const binChunk = buffers[bufferIndex];
|
|
14
|
+
(0, assert_1.assert)(binChunk);
|
|
15
|
+
const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
|
|
16
|
+
return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
|
|
10
17
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
exports.getTypedArrayForBufferView = getTypedArrayForBufferView;
|
|
19
|
+
// accepts accessor index or accessor object
|
|
20
|
+
// returns a `Uint8Array`
|
|
21
|
+
function getTypedArrayForImageData(json, buffers, imageIndex) {
|
|
22
|
+
const image = json.images[imageIndex];
|
|
23
|
+
const bufferViewIndex = json.bufferViews[image.bufferView];
|
|
24
|
+
return getTypedArrayForBufferView(json, buffers, bufferViewIndex);
|
|
15
25
|
}
|
|
16
|
-
|
|
26
|
+
exports.getTypedArrayForImageData = getTypedArrayForImageData;
|
|
27
|
+
/*
|
|
28
|
+
// accepts accessor index or accessor object
|
|
29
|
+
// returns a typed array with type that matches the types
|
|
30
|
+
export function getTypedArrayForAccessor(accessor) {
|
|
31
|
+
accessor = this.getAccessor(accessor);
|
|
32
|
+
const bufferView = this.getBufferView(accessor.bufferView);
|
|
33
|
+
const buffer = this.getBuffer(bufferView.buffer);
|
|
34
|
+
const arrayBuffer = buffer.data;
|
|
35
|
+
|
|
36
|
+
// Create a new typed array as a view into the combined buffer
|
|
37
|
+
const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);
|
|
38
|
+
const byteOffset = bufferView.byteOffset + accessor.byteOffset;
|
|
39
|
+
return new ArrayType(arrayBuffer, byteOffset, length);
|
|
40
|
+
}
|
|
41
|
+
*/
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGLTFAccessor = exports.getGLTFAccessors = void 0;
|
|
4
|
+
// TODO - remove
|
|
5
|
+
const gltf_utils_1 = require("./gltf-utils");
|
|
6
|
+
// Returns a fresh attributes object with glTF-standardized attributes names
|
|
7
|
+
// Attributes that cannot be identified will not be included
|
|
8
|
+
// Removes `indices` if present, as it should be stored separately from the attributes
|
|
9
|
+
function getGLTFAccessors(attributes) {
|
|
10
|
+
const accessors = {};
|
|
11
|
+
for (const name in attributes) {
|
|
12
|
+
const attribute = attributes[name];
|
|
13
|
+
if (name !== 'indices') {
|
|
14
|
+
const glTFAccessor = getGLTFAccessor(attribute);
|
|
15
|
+
accessors[name] = glTFAccessor;
|
|
16
|
+
}
|
|
11
17
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return accessors;
|
|
18
|
+
return accessors;
|
|
15
19
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
exports.getGLTFAccessors = getGLTFAccessors;
|
|
21
|
+
// Fix up a single accessor.
|
|
22
|
+
// Input: typed array or a partial accessor object
|
|
23
|
+
// Return: accessor object
|
|
24
|
+
function getGLTFAccessor(attribute) {
|
|
25
|
+
const { buffer, size, count } = getAccessorData(attribute);
|
|
26
|
+
const glTFAccessor = {
|
|
27
|
+
// glTF Accessor values
|
|
28
|
+
// TODO: Instead of a bufferView index we could have an actual buffer (typed array)
|
|
29
|
+
// bufferView: null,
|
|
30
|
+
// TODO: Deprecate `value` in favor of bufferView?
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
value: buffer,
|
|
33
|
+
size,
|
|
34
|
+
byteOffset: 0,
|
|
35
|
+
count,
|
|
36
|
+
type: (0, gltf_utils_1.getAccessorTypeFromSize)(size),
|
|
37
|
+
componentType: (0, gltf_utils_1.getComponentTypeFromArray)(buffer)
|
|
38
|
+
};
|
|
39
|
+
return glTFAccessor;
|
|
31
40
|
}
|
|
32
|
-
|
|
41
|
+
exports.getGLTFAccessor = getGLTFAccessor;
|
|
42
|
+
// export function getGLTFAttribute(data, gltfAttributeName): GLTFAccessor {
|
|
43
|
+
// return data.attributes[data.glTFAttributeMap[gltfAttributeName]];
|
|
44
|
+
// }
|
|
33
45
|
function getAccessorData(attribute) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
size = attribute.size || 1;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (buffer) {
|
|
44
|
-
if (!ArrayBuffer.isView(buffer)) {
|
|
45
|
-
buffer = toTypedArray(buffer, Float32Array);
|
|
46
|
+
let buffer = attribute;
|
|
47
|
+
let size = 1;
|
|
48
|
+
let count = 0;
|
|
49
|
+
if (attribute && attribute.value) {
|
|
50
|
+
buffer = attribute.value;
|
|
51
|
+
size = attribute.size || 1;
|
|
46
52
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
size,
|
|
54
|
-
count
|
|
55
|
-
};
|
|
53
|
+
if (buffer) {
|
|
54
|
+
if (!ArrayBuffer.isView(buffer)) {
|
|
55
|
+
buffer = toTypedArray(buffer, Float32Array);
|
|
56
|
+
}
|
|
57
|
+
count = buffer.length / size;
|
|
58
|
+
}
|
|
59
|
+
return { buffer, size, count };
|
|
56
60
|
}
|
|
57
|
-
|
|
61
|
+
// Convert non-typed arrays to arrays of specified format
|
|
58
62
|
function toTypedArray(array, ArrayType, convertTypedArrays = false) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return array;
|
|
63
|
+
if (!array) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(array)) {
|
|
67
|
+
return new ArrayType(array);
|
|
68
|
+
}
|
|
69
|
+
if (convertTypedArrays && !(array instanceof ArrayType)) {
|
|
70
|
+
return new ArrayType(array);
|
|
71
|
+
}
|
|
72
|
+
return array;
|
|
72
73
|
}
|
|
73
|
-
//# sourceMappingURL=gltf-attribute-utils.js.map
|