@loaders.gl/gltf 4.2.0-alpha.4 → 4.2.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +1049 -517
- package/dist/dist.min.js +9 -0
- package/dist/glb-loader.d.ts +2 -2
- package/dist/glb-loader.d.ts.map +1 -1
- package/dist/glb-loader.js +22 -21
- package/dist/glb-writer.d.ts +2 -2
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +27 -24
- package/dist/gltf-loader.d.ts +3 -3
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +31 -36
- package/dist/gltf-writer.js +24 -26
- package/dist/index.cjs +95 -284
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +17 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/api/gltf-extensions.d.ts +2 -2
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +45 -22
- package/dist/lib/api/gltf-scenegraph.d.ts +2 -2
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +561 -438
- package/dist/lib/api/normalize-gltf-v1.js +250 -181
- package/dist/lib/api/post-process-gltf.d.ts +3 -3
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
- package/dist/lib/api/post-process-gltf.js +375 -339
- package/dist/lib/encoders/encode-glb.js +62 -48
- package/dist/lib/encoders/encode-gltf.js +24 -10
- package/dist/lib/extensions/EXT_mesh_features.d.ts +2 -2
- package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_mesh_features.js +55 -33
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +2 -2
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +27 -31
- package/dist/lib/extensions/EXT_structural_metadata.d.ts +2 -2
- package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_structural_metadata.js +434 -230
- package/dist/lib/extensions/EXT_texture_webp.d.ts +2 -2
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +24 -17
- 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 +29 -15
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +2 -2
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +110 -87
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +2 -2
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +19 -12
- package/dist/lib/extensions/KHR_texture_transform.d.ts +2 -2
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_transform.js +194 -154
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +2 -2
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +263 -143
- 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 +44 -32
- 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 +30 -24
- 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 +65 -52
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +2 -2
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
- package/dist/lib/extensions/utils/3d-tiles-utils.js +298 -181
- package/dist/lib/gltf-utils/get-typed-array.d.ts +1 -1
- package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -1
- package/dist/lib/gltf-utils/get-typed-array.js +54 -42
- 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-attribute-utils.js +58 -52
- package/dist/lib/gltf-utils/gltf-constants.js +27 -27
- package/dist/lib/gltf-utils/gltf-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.js +67 -60
- package/dist/lib/gltf-utils/resolve-url.js +12 -10
- 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 +132 -89
- package/dist/lib/parsers/parse-gltf.d.ts +3 -3
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +155 -126
- package/dist/lib/types/glb-types.js +0 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.js +0 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.js +0 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.js +0 -1
- package/dist/lib/types/gltf-json-schema.js +2 -1
- package/dist/lib/types/gltf-postprocessed-schema.js +2 -1
- package/dist/lib/types/gltf-types.d.ts +3 -3
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/dist/lib/types/gltf-types.js +1 -1
- package/dist/lib/utils/assert.js +6 -4
- package/dist/lib/utils/version.js +3 -1
- package/dist/meshopt/meshopt-decoder.js +86 -67
- package/dist/webp/webp.js +28 -19
- package/package.json +12 -8
- 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_mesh_features.js.map +0 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js.map +0 -1
- package/dist/lib/extensions/EXT_structural_metadata.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/KHR_texture_transform.js.map +0 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.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/extensions/utils/3d-tiles-utils.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-ext-feature-metadata-schema.js.map +0 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.js.map +0 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.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/meshopt/meshopt-encoder.ts.disabled +0 -409
- package/dist/webp/webp.js.map +0 -1
|
@@ -1,179 +1,299 @@
|
|
|
1
1
|
import { GLTFScenegraph } from "../../api/gltf-scenegraph.js";
|
|
2
2
|
import { convertRawBufferToMetadataArray, getPrimitiveTextureData, primitivePropertyDataToAttributes, getArrayElementByteSize, getOffsetsForProperty, parseVariableLengthArrayNumeric, parseFixedLengthArrayNumeric, getPropertyDataString } from "../utils/3d-tiles-utils.js";
|
|
3
|
+
/** Extension name */
|
|
3
4
|
const EXT_FEATURE_METADATA_NAME = 'EXT_feature_metadata';
|
|
4
5
|
export const name = EXT_FEATURE_METADATA_NAME;
|
|
5
6
|
export async function decode(gltfData, options) {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
8
|
+
decodeExtFeatureMetadata(scenegraph, options);
|
|
8
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Decodes feature metadata from extension.
|
|
12
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
13
|
+
* @param options - GLTFLoader options.
|
|
14
|
+
*/
|
|
9
15
|
function decodeExtFeatureMetadata(scenegraph, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
// Decoding metadata involves buffers processing.
|
|
17
|
+
// So, if buffers have not been loaded, there is no reason to process metadata.
|
|
18
|
+
if (!options.gltf?.loadBuffers) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const extension = scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);
|
|
22
|
+
if (!extension) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (options.gltf?.loadImages) {
|
|
26
|
+
decodePropertyTextures(scenegraph, extension);
|
|
27
|
+
}
|
|
28
|
+
decodePropertyTables(scenegraph, extension);
|
|
22
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Processes the data stored in the textures
|
|
32
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
33
|
+
* @param extension - Top-level extension.
|
|
34
|
+
*/
|
|
23
35
|
function decodePropertyTextures(scenegraph, extension) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
featureTextures
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
}
|
|
36
|
+
const schema = extension.schema;
|
|
37
|
+
if (!schema) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const schemaClasses = schema.classes;
|
|
41
|
+
const { featureTextures } = extension;
|
|
42
|
+
if (schemaClasses && featureTextures) {
|
|
43
|
+
for (const schemaName in schemaClasses) {
|
|
44
|
+
const schemaClass = schemaClasses[schemaName];
|
|
45
|
+
const featureTexture = findFeatureTextureByClass(featureTextures, schemaName);
|
|
46
|
+
if (featureTexture) {
|
|
47
|
+
handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
41
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Processes the data stored in the property tables.
|
|
54
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
55
|
+
* @param extension - Top-level extension.
|
|
56
|
+
*/
|
|
42
57
|
function decodePropertyTables(scenegraph, extension) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
const schema = extension.schema;
|
|
59
|
+
if (!schema) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const schemaClasses = schema.classes;
|
|
63
|
+
const propertyTables = extension.featureTables;
|
|
64
|
+
if (schemaClasses && propertyTables) {
|
|
65
|
+
for (const schemaName in schemaClasses) {
|
|
66
|
+
const propertyTable = findPropertyTableByClass(propertyTables, schemaName);
|
|
67
|
+
if (propertyTable) {
|
|
68
|
+
processPropertyTable(scenegraph, schema, propertyTable);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
57
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Finds the property table by class name.
|
|
75
|
+
* @param propertyTables - propertyTable definition taken from the top-level extension.
|
|
76
|
+
* @param schemaClassName - class name in the extension schema.
|
|
77
|
+
*/
|
|
58
78
|
function findPropertyTableByClass(propertyTables, schemaClassName) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
79
|
+
for (const propertyTableName in propertyTables) {
|
|
80
|
+
const propertyTable = propertyTables[propertyTableName];
|
|
81
|
+
if (propertyTable.class === schemaClassName) {
|
|
82
|
+
return propertyTable;
|
|
83
|
+
}
|
|
63
84
|
}
|
|
64
|
-
|
|
65
|
-
return null;
|
|
85
|
+
return null;
|
|
66
86
|
}
|
|
67
87
|
function findFeatureTextureByClass(featureTextures, schemaClassName) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
88
|
+
for (const featureTexturesName in featureTextures) {
|
|
89
|
+
const featureTable = featureTextures[featureTexturesName];
|
|
90
|
+
if (featureTable.class === schemaClassName) {
|
|
91
|
+
return featureTable;
|
|
92
|
+
}
|
|
72
93
|
}
|
|
73
|
-
|
|
74
|
-
return null;
|
|
94
|
+
return null;
|
|
75
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Navigates through all properies in the property table, gets properties data,
|
|
98
|
+
* and put the data to `propertyTable.data` as an array.
|
|
99
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
100
|
+
* @param schema - schema object.
|
|
101
|
+
* @param propertyTable - propertyTable definition taken from the top-level extension.
|
|
102
|
+
*/
|
|
76
103
|
function processPropertyTable(scenegraph, schema, propertyTable) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
104
|
+
// Though 'class' is not required by spec, it doesn't make any scence when it's not provided.
|
|
105
|
+
// So, bale out here.
|
|
106
|
+
if (!propertyTable.class) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const schemaClass = schema.classes?.[propertyTable.class];
|
|
110
|
+
if (!schemaClass) {
|
|
111
|
+
throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`);
|
|
112
|
+
}
|
|
113
|
+
const numberOfElements = propertyTable.count; // `propertyTable.count` is a number of elements in each property array.
|
|
114
|
+
for (const propertyName in schemaClass.properties) {
|
|
115
|
+
const classProperty = schemaClass.properties[propertyName];
|
|
116
|
+
const propertyTableProperty = propertyTable.properties?.[propertyName];
|
|
117
|
+
if (propertyTableProperty) {
|
|
118
|
+
// Getting all elements (`numberOfElements`) of the array in the `propertyTableProperty`
|
|
119
|
+
const data = getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty);
|
|
120
|
+
propertyTableProperty.data = data;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
95
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Navigates through all properies in feature texture and gets properties data.
|
|
126
|
+
* Data will be stored in featureTexture.properties[propertyName].data.
|
|
127
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
128
|
+
* @param featureTexture
|
|
129
|
+
* @param schemaClass
|
|
130
|
+
*/
|
|
96
131
|
function handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
}
|
|
132
|
+
const attributeName = featureTexture.class;
|
|
133
|
+
for (const propertyName in schemaClass.properties) {
|
|
134
|
+
const featureTextureProperty = featureTexture?.properties?.[propertyName];
|
|
135
|
+
if (featureTextureProperty) {
|
|
136
|
+
const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);
|
|
137
|
+
featureTextureProperty.data = data;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
106
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Decodes properties from binary sourse based on property type.
|
|
143
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
144
|
+
* @param schemaProperty
|
|
145
|
+
* @param numberOfFeatures
|
|
146
|
+
* @param featureTableProperty
|
|
147
|
+
*/
|
|
107
148
|
function getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfFeatures, featureTableProperty) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
149
|
+
let data = [];
|
|
150
|
+
const bufferView = featureTableProperty.bufferView;
|
|
151
|
+
const dataArray = scenegraph.getTypedArrayForBufferView(bufferView);
|
|
152
|
+
const arrayOffsets = getArrayOffsetsForProperty(scenegraph, classProperty, featureTableProperty, numberOfFeatures);
|
|
153
|
+
const stringOffsets = getStringOffsetsForProperty(scenegraph, classProperty, featureTableProperty, numberOfFeatures);
|
|
154
|
+
if (classProperty.type === 'STRING' || classProperty.componentType === 'STRING') {
|
|
155
|
+
data = getPropertyDataString(numberOfFeatures, dataArray, arrayOffsets, stringOffsets);
|
|
156
|
+
}
|
|
157
|
+
else if (isNumericProperty(classProperty)) {
|
|
158
|
+
data = getPropertyDataNumeric(classProperty, numberOfFeatures, dataArray, arrayOffsets);
|
|
159
|
+
}
|
|
160
|
+
return data;
|
|
119
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Parses propertyTable.property.arrayOffsets that are offsets of sub-arrays in a flatten array of values.
|
|
164
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
165
|
+
* @param classProperty - class property object.
|
|
166
|
+
* @param propertyTableProperty - propertyTable's property metadata.
|
|
167
|
+
* @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
|
|
168
|
+
* @returns Typed array with offset values.
|
|
169
|
+
* @see https://github.com/CesiumGS/glTF/blob/2976f1183343a47a29e4059a70961371cd2fcee8/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json#L21
|
|
170
|
+
*/
|
|
120
171
|
function getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
172
|
+
/*
|
|
173
|
+
If ARRAY is used, then componentType must also be specified.
|
|
174
|
+
ARRAY is a fixed-length array when componentCount is defined, and variable-length otherwise.
|
|
175
|
+
*/
|
|
176
|
+
if (classProperty.type === 'ARRAY' &&
|
|
177
|
+
// `componentCount` is a number of fixed-length array elements.
|
|
178
|
+
// If `componentCount` is NOT defined, it's a VARIABLE-length array
|
|
179
|
+
typeof classProperty.componentCount === 'undefined' &&
|
|
180
|
+
// `arrayOffsetBufferView` is an index of the buffer view containing offsets for variable-length arrays.
|
|
181
|
+
typeof propertyTableProperty.arrayOffsetBufferView !== 'undefined') {
|
|
182
|
+
// Data are in a VARIABLE-length array
|
|
183
|
+
return getOffsetsForProperty(scenegraph, propertyTableProperty.arrayOffsetBufferView, propertyTableProperty.offsetType || 'UINT32', // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView
|
|
184
|
+
numberOfElements);
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
125
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Parses featureTable.property.stringOffsetBufferView.
|
|
190
|
+
* String offsets is an array of offsets of strings in the united array of characters.
|
|
191
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
192
|
+
* @param propertyTableProperty - propertyTable's property metadata.
|
|
193
|
+
* @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
|
|
194
|
+
* @returns Typed array of offset values. The number of offsets in the array is equal to `numberOfElements` plus one.
|
|
195
|
+
* @see https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/featureTable.property.schema.json#L50C10-L50C32
|
|
196
|
+
*/
|
|
126
197
|
function getStringOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
198
|
+
if (typeof propertyTableProperty.stringOffsetBufferView !== 'undefined' // `stringOffsetBufferView` is an index of the buffer view containing offsets for strings.
|
|
199
|
+
) {
|
|
200
|
+
// Data are in a FIXED-length array
|
|
201
|
+
return getOffsetsForProperty(scenegraph, propertyTableProperty.stringOffsetBufferView, propertyTableProperty.offsetType || 'UINT32', // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView
|
|
202
|
+
numberOfElements);
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
131
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Checks if the feature table property is of numeric type.
|
|
208
|
+
* @param schemaPropertyType - feature table property
|
|
209
|
+
* @returns true if property is numeric, else - false
|
|
210
|
+
*/
|
|
132
211
|
function isNumericProperty(schemaProperty) {
|
|
133
|
-
|
|
134
|
-
|
|
212
|
+
const types = [
|
|
213
|
+
'UINT8',
|
|
214
|
+
'INT16',
|
|
215
|
+
'UINT16',
|
|
216
|
+
'INT32',
|
|
217
|
+
'UINT32',
|
|
218
|
+
'INT64',
|
|
219
|
+
'UINT64',
|
|
220
|
+
'FLOAT32',
|
|
221
|
+
'FLOAT64'
|
|
222
|
+
];
|
|
223
|
+
return (types.includes(schemaProperty.type) ||
|
|
224
|
+
(typeof schemaProperty.componentType !== 'undefined' &&
|
|
225
|
+
types.includes(schemaProperty.componentType)));
|
|
135
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Decodes properties of numeric types from binary sourse.
|
|
229
|
+
* @param classProperty - class property object.
|
|
230
|
+
* @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
|
|
231
|
+
* @param valuesDataBytes - Data taken from values property of the property table property.
|
|
232
|
+
* @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
|
|
233
|
+
* @returns Property values in a typed array or in an array of typed arrays.
|
|
234
|
+
*/
|
|
136
235
|
function getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
236
|
+
const isArray = classProperty.type === 'ARRAY';
|
|
237
|
+
const arrayCount = classProperty.componentCount;
|
|
238
|
+
/*
|
|
239
|
+
We are getting Numeric data. So,
|
|
240
|
+
the component type can be one of NumericComponentType,
|
|
241
|
+
the attribute type should be 'SCALAR'
|
|
242
|
+
*/
|
|
243
|
+
const attributeType = 'SCALAR';
|
|
244
|
+
const componentType = classProperty.componentType || classProperty.type;
|
|
245
|
+
const elementSize = getArrayElementByteSize(attributeType, componentType);
|
|
246
|
+
const elementCount = valuesDataBytes.byteLength / elementSize;
|
|
247
|
+
const valuesData = convertRawBufferToMetadataArray(valuesDataBytes, attributeType, componentType, elementCount);
|
|
248
|
+
if (isArray) {
|
|
249
|
+
if (arrayOffsets) {
|
|
250
|
+
// VARIABLE-length array
|
|
251
|
+
return parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize);
|
|
252
|
+
}
|
|
253
|
+
if (arrayCount) {
|
|
254
|
+
// FIXED-length array
|
|
255
|
+
return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);
|
|
256
|
+
}
|
|
257
|
+
return [];
|
|
258
|
+
}
|
|
259
|
+
return valuesData;
|
|
154
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Gets properties from texture associated with all mesh primitives.
|
|
263
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
264
|
+
* @param featureTextureProperty
|
|
265
|
+
* @param attributeName
|
|
266
|
+
* @returns Feature texture data
|
|
267
|
+
*/
|
|
155
268
|
function getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
269
|
+
const json = scenegraph.gltf.json;
|
|
270
|
+
if (!json.meshes) {
|
|
271
|
+
return [];
|
|
272
|
+
}
|
|
273
|
+
const featureTextureTable = [];
|
|
274
|
+
for (const mesh of json.meshes) {
|
|
275
|
+
for (const primitive of mesh.primitives) {
|
|
276
|
+
processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return featureTextureTable;
|
|
167
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Processes data encoded in the texture associated with the primitive. This data will be accessible through the attributes.
|
|
283
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
284
|
+
* @param attributeName
|
|
285
|
+
* @param featureTextureProperty
|
|
286
|
+
* @param featureTextureTable
|
|
287
|
+
* @param primitive
|
|
288
|
+
*/
|
|
168
289
|
function processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
290
|
+
const textureInfoTopLevel = {
|
|
291
|
+
channels: featureTextureProperty.channels,
|
|
292
|
+
...featureTextureProperty.texture
|
|
293
|
+
};
|
|
294
|
+
const propertyData = getPrimitiveTextureData(scenegraph, textureInfoTopLevel, primitive);
|
|
295
|
+
if (!propertyData) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive);
|
|
178
299
|
}
|
|
179
|
-
//# sourceMappingURL=EXT_feature_metadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_lights_punctual.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_lights_punctual.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,
|
|
1
|
+
{"version":3,"file":"KHR_lights_punctual.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_lights_punctual.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,wCAAqC;AAOvD,eAAO,MAAM,IAAI,wBAAsB,CAAC;AAExC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBlE;AAGD,wBAAsB,MAAM,CAAC,QAAQ,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BpD"}
|
|
@@ -1,42 +1,54 @@
|
|
|
1
|
+
// GLTF EXTENSION: KHR_lights_punctual
|
|
2
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
|
|
1
3
|
import { assert } from "../../utils/assert.js";
|
|
2
4
|
import { GLTFScenegraph } from "../../api/gltf-scenegraph.js";
|
|
3
5
|
const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
|
|
4
6
|
export const name = KHR_LIGHTS_PUNCTUAL;
|
|
5
7
|
export async function decode(gltfData) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
9
|
+
const { json } = gltfScenegraph;
|
|
10
|
+
// Move the light array out of the extension and remove the extension
|
|
11
|
+
const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);
|
|
12
|
+
if (extension) {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
gltfScenegraph.json.lights = extension.lights;
|
|
15
|
+
gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);
|
|
16
|
+
}
|
|
17
|
+
// Any nodes that have the extension, add lights field pointing to light object
|
|
18
|
+
// and remove the extension
|
|
19
|
+
for (const node of json.nodes || []) {
|
|
20
|
+
const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
21
|
+
if (nodeExtension) {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
node.light = nodeExtension.light;
|
|
24
|
+
}
|
|
25
|
+
gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
19
26
|
}
|
|
20
|
-
gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
21
|
-
}
|
|
22
27
|
}
|
|
28
|
+
// Move the light ar ray out of the extension and remove the extension
|
|
23
29
|
export async function encode(gltfData) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
31
|
+
const { json } = gltfScenegraph;
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
if (json.lights) {
|
|
34
|
+
const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
assert(!extension.lights);
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
extension.lights = json.lights;
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
delete json.lights;
|
|
41
|
+
}
|
|
42
|
+
// Any nodes that have lights field pointing to light object
|
|
43
|
+
// add the extension
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
if (gltfScenegraph.json.lights) {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
for (const light of gltfScenegraph.json.lights) {
|
|
48
|
+
const node = light.node;
|
|
49
|
+
gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);
|
|
50
|
+
}
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
delete gltfScenegraph.json.lights;
|
|
38
53
|
}
|
|
39
|
-
delete gltfScenegraph.json.lights;
|
|
40
|
-
}
|
|
41
54
|
}
|
|
42
|
-
//# sourceMappingURL=KHR_lights_punctual.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_materials_unlit.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_materials_unlit.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,
|
|
1
|
+
{"version":3,"file":"KHR_materials_unlit.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_materials_unlit.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,wCAAqC;AAMvD,eAAO,MAAM,IAAI,wBAAsB,CAAC;AAExC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBlE;AAED,wBAAgB,MAAM,CAAC,QAAQ,KAAA,QAkB9B"}
|
|
@@ -1,33 +1,39 @@
|
|
|
1
|
+
// GLTF EXTENSION: KHR_materials_unlit
|
|
2
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
|
|
1
3
|
import { GLTFScenegraph } from "../../api/gltf-scenegraph.js";
|
|
2
4
|
const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
|
|
3
5
|
export const name = KHR_MATERIALS_UNLIT;
|
|
4
6
|
export async function decode(gltfData) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
8
|
+
const { json } = gltfScenegraph;
|
|
9
|
+
// Any nodes that have the extension, add lights field pointing to light object
|
|
10
|
+
// and remove the extension
|
|
11
|
+
for (const material of json.materials || []) {
|
|
12
|
+
const extension = material.extensions && material.extensions.KHR_materials_unlit;
|
|
13
|
+
if (extension) {
|
|
14
|
+
// @ts-ignore TODO
|
|
15
|
+
material.unlit = true;
|
|
16
|
+
}
|
|
17
|
+
gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
|
|
13
18
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
|
|
19
|
+
// Remove the top-level extension
|
|
20
|
+
gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
|
|
17
21
|
}
|
|
18
22
|
export function encode(gltfData) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
24
|
+
const { json } = gltfScenegraph;
|
|
25
|
+
// Any nodes that have lights field pointing to light object
|
|
26
|
+
// add the extension
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
if (gltfScenegraph.materials) {
|
|
29
|
+
for (const material of json.materials || []) {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
if (material.unlit) {
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
delete material.unlit;
|
|
34
|
+
gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
|
|
35
|
+
gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
30
38
|
}
|
|
31
|
-
}
|
|
32
39
|
}
|
|
33
|
-
//# sourceMappingURL=KHR_materials_unlit.js.map
|
|
@@ -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,
|
|
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,wCAAqC;AAMvD,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"}
|