@loaders.gl/gltf 4.0.0-alpha.6 → 4.0.0-alpha.8
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 +1661 -1459
- 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 +52 -32
- 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 +195 -17
- 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 +18 -25
- 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 +45 -31
- 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 +161 -15
- 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 +7 -12
- 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-extensions.js +1 -1
- package/dist/lib/api/gltf-scenegraph.d.ts +8 -5
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +47 -33
- 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 +3 -2
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +195 -23
- 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 +17 -41
- package/dist/lib/types/gltf-json-schema.d.ts +153 -139
- 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 +60 -41
- 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 +264 -23
- 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 +26 -25
- package/src/lib/types/gltf-json-schema.ts +168 -138
- package/src/lib/types/gltf-postprocessed-schema.ts +289 -212
- package/src/lib/types/gltf-types.ts +35 -59
|
@@ -33,12 +33,18 @@ const SAMPLER_PARAMETER_GLTF_TO_GL = {
|
|
|
33
33
|
wrapS: GL_SAMPLER.TEXTURE_WRAP_S,
|
|
34
34
|
wrapT: GL_SAMPLER.TEXTURE_WRAP_T
|
|
35
35
|
};
|
|
36
|
-
const
|
|
36
|
+
const DEFAULT_SAMPLER_PARAMETERS = {
|
|
37
37
|
[GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
|
|
38
38
|
[GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
|
|
39
39
|
[GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
|
|
40
40
|
[GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT
|
|
41
41
|
};
|
|
42
|
+
function makeDefaultSampler() {
|
|
43
|
+
return {
|
|
44
|
+
id: 'default-sampler',
|
|
45
|
+
parameters: DEFAULT_SAMPLER_PARAMETERS
|
|
46
|
+
};
|
|
47
|
+
}
|
|
42
48
|
function getBytesFromComponentType(componentType) {
|
|
43
49
|
return BYTES[componentType];
|
|
44
50
|
}
|
|
@@ -48,7 +54,8 @@ function getSizeFromAccessorType(type) {
|
|
|
48
54
|
class GLTFPostProcessor {
|
|
49
55
|
constructor() {
|
|
50
56
|
_defineProperty(this, "baseUri", '');
|
|
51
|
-
_defineProperty(this, "
|
|
57
|
+
_defineProperty(this, "jsonUnprocessed", void 0);
|
|
58
|
+
_defineProperty(this, "json", void 0);
|
|
52
59
|
_defineProperty(this, "buffers", []);
|
|
53
60
|
_defineProperty(this, "images", []);
|
|
54
61
|
}
|
|
@@ -57,113 +64,130 @@ class GLTFPostProcessor {
|
|
|
57
64
|
const {
|
|
58
65
|
json,
|
|
59
66
|
buffers = [],
|
|
60
|
-
images = []
|
|
67
|
+
images = []
|
|
68
|
+
} = gltf;
|
|
69
|
+
const {
|
|
61
70
|
baseUri = ''
|
|
62
71
|
} = gltf;
|
|
63
72
|
assert(json);
|
|
64
73
|
this.baseUri = baseUri;
|
|
65
|
-
this.json = json;
|
|
66
74
|
this.buffers = buffers;
|
|
67
75
|
this.images = images;
|
|
68
|
-
this.
|
|
76
|
+
this.jsonUnprocessed = json;
|
|
77
|
+
this.json = this._resolveTree(gltf.json, options);
|
|
69
78
|
return this.json;
|
|
70
79
|
}
|
|
71
|
-
_resolveTree(
|
|
80
|
+
_resolveTree(gltf) {
|
|
72
81
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
const json = {
|
|
83
|
+
...gltf
|
|
84
|
+
};
|
|
85
|
+
this.json = json;
|
|
86
|
+
if (gltf.bufferViews) {
|
|
87
|
+
json.bufferViews = gltf.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i));
|
|
75
88
|
}
|
|
76
|
-
if (
|
|
77
|
-
json.images =
|
|
89
|
+
if (gltf.images) {
|
|
90
|
+
json.images = gltf.images.map((image, i) => this._resolveImage(image, i));
|
|
78
91
|
}
|
|
79
|
-
if (
|
|
80
|
-
json.samplers =
|
|
92
|
+
if (gltf.samplers) {
|
|
93
|
+
json.samplers = gltf.samplers.map((sampler, i) => this._resolveSampler(sampler, i));
|
|
81
94
|
}
|
|
82
|
-
if (
|
|
83
|
-
json.textures =
|
|
95
|
+
if (gltf.textures) {
|
|
96
|
+
json.textures = gltf.textures.map((texture, i) => this._resolveTexture(texture, i));
|
|
84
97
|
}
|
|
85
|
-
if (
|
|
86
|
-
json.accessors =
|
|
98
|
+
if (gltf.accessors) {
|
|
99
|
+
json.accessors = gltf.accessors.map((accessor, i) => this._resolveAccessor(accessor, i));
|
|
87
100
|
}
|
|
88
|
-
if (
|
|
89
|
-
json.materials =
|
|
101
|
+
if (gltf.materials) {
|
|
102
|
+
json.materials = gltf.materials.map((material, i) => this._resolveMaterial(material, i));
|
|
90
103
|
}
|
|
91
|
-
if (
|
|
92
|
-
json.meshes =
|
|
104
|
+
if (gltf.meshes) {
|
|
105
|
+
json.meshes = gltf.meshes.map((mesh, i) => this._resolveMesh(mesh, i));
|
|
93
106
|
}
|
|
94
|
-
if (
|
|
95
|
-
json.nodes =
|
|
107
|
+
if (gltf.nodes) {
|
|
108
|
+
json.nodes = gltf.nodes.map((node, i) => this._resolveNode(node, i));
|
|
109
|
+
json.nodes = json.nodes.map((node, i) => this._resolveNodeChildren(node));
|
|
96
110
|
}
|
|
97
|
-
if (
|
|
98
|
-
json.skins =
|
|
111
|
+
if (gltf.skins) {
|
|
112
|
+
json.skins = gltf.skins.map((skin, i) => this._resolveSkin(skin, i));
|
|
99
113
|
}
|
|
100
|
-
if (
|
|
101
|
-
json.scenes =
|
|
114
|
+
if (gltf.scenes) {
|
|
115
|
+
json.scenes = gltf.scenes.map((scene, i) => this._resolveScene(scene, i));
|
|
102
116
|
}
|
|
103
|
-
if (json.scene
|
|
117
|
+
if (typeof this.json.scene === 'number' && json.scenes) {
|
|
104
118
|
json.scene = json.scenes[this.json.scene];
|
|
105
119
|
}
|
|
120
|
+
return json;
|
|
106
121
|
}
|
|
107
122
|
getScene(index) {
|
|
108
|
-
return this._get(
|
|
123
|
+
return this._get(this.json.scenes, index);
|
|
109
124
|
}
|
|
110
125
|
getNode(index) {
|
|
111
|
-
return this._get(
|
|
126
|
+
return this._get(this.json.nodes, index);
|
|
112
127
|
}
|
|
113
128
|
getSkin(index) {
|
|
114
|
-
return this._get(
|
|
129
|
+
return this._get(this.json.skins, index);
|
|
115
130
|
}
|
|
116
131
|
getMesh(index) {
|
|
117
|
-
return this._get(
|
|
132
|
+
return this._get(this.json.meshes, index);
|
|
118
133
|
}
|
|
119
134
|
getMaterial(index) {
|
|
120
|
-
return this._get(
|
|
135
|
+
return this._get(this.json.materials, index);
|
|
121
136
|
}
|
|
122
137
|
getAccessor(index) {
|
|
123
|
-
return this._get(
|
|
138
|
+
return this._get(this.json.accessors, index);
|
|
124
139
|
}
|
|
125
140
|
getCamera(index) {
|
|
126
|
-
return
|
|
141
|
+
return this._get(this.json.cameras, index);
|
|
127
142
|
}
|
|
128
143
|
getTexture(index) {
|
|
129
|
-
return this._get(
|
|
144
|
+
return this._get(this.json.textures, index);
|
|
130
145
|
}
|
|
131
146
|
getSampler(index) {
|
|
132
|
-
return this._get(
|
|
147
|
+
return this._get(this.json.samplers, index);
|
|
133
148
|
}
|
|
134
149
|
getImage(index) {
|
|
135
|
-
return this._get(
|
|
150
|
+
return this._get(this.json.images, index);
|
|
136
151
|
}
|
|
137
152
|
getBufferView(index) {
|
|
138
|
-
return this._get(
|
|
153
|
+
return this._get(this.json.bufferViews, index);
|
|
139
154
|
}
|
|
140
155
|
getBuffer(index) {
|
|
141
|
-
return this._get(
|
|
156
|
+
return this._get(this.json.buffers, index);
|
|
142
157
|
}
|
|
143
158
|
_get(array, index) {
|
|
144
159
|
if (typeof index === 'object') {
|
|
145
160
|
return index;
|
|
146
161
|
}
|
|
147
|
-
const object =
|
|
162
|
+
const object = array && array[index];
|
|
148
163
|
if (!object) {
|
|
149
164
|
console.warn("glTF file error: Could not find ".concat(array, "[").concat(index, "]"));
|
|
150
165
|
}
|
|
151
166
|
return object;
|
|
152
167
|
}
|
|
153
168
|
_resolveScene(scene, index) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
169
|
+
return {
|
|
170
|
+
...scene,
|
|
171
|
+
id: scene.id || "scene-".concat(index),
|
|
172
|
+
nodes: (scene.nodes || []).map(node => this.getNode(node))
|
|
173
|
+
};
|
|
157
174
|
}
|
|
158
|
-
_resolveNode(
|
|
159
|
-
node
|
|
160
|
-
|
|
161
|
-
|
|
175
|
+
_resolveNode(gltfNode, index) {
|
|
176
|
+
const node = {
|
|
177
|
+
...gltfNode,
|
|
178
|
+
id: (gltfNode === null || gltfNode === void 0 ? void 0 : gltfNode.id) || "node-".concat(index)
|
|
179
|
+
};
|
|
180
|
+
if (gltfNode.mesh !== undefined) {
|
|
181
|
+
node.mesh = this.getMesh(gltfNode.mesh);
|
|
182
|
+
}
|
|
183
|
+
if (gltfNode.camera !== undefined) {
|
|
184
|
+
node.camera = this.getCamera(gltfNode.camera);
|
|
185
|
+
}
|
|
186
|
+
if (gltfNode.skin !== undefined) {
|
|
187
|
+
node.skin = this.getSkin(gltfNode.skin);
|
|
162
188
|
}
|
|
163
|
-
if (
|
|
164
|
-
node.mesh =
|
|
165
|
-
} else if (node.meshes !== undefined && node.meshes.length) {
|
|
166
|
-
node.mesh = node.meshes.reduce((accum, meshIndex) => {
|
|
189
|
+
if (gltfNode.meshes !== undefined && gltfNode.meshes.length) {
|
|
190
|
+
node.mesh = gltfNode.meshes.reduce((accum, meshIndex) => {
|
|
167
191
|
const mesh = this.getMesh(meshIndex);
|
|
168
192
|
accum.id = mesh.id;
|
|
169
193
|
accum.primitives = accum.primitives.concat(mesh.primitives);
|
|
@@ -172,44 +196,56 @@ class GLTFPostProcessor {
|
|
|
172
196
|
primitives: []
|
|
173
197
|
});
|
|
174
198
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (node.
|
|
179
|
-
node.
|
|
199
|
+
return node;
|
|
200
|
+
}
|
|
201
|
+
_resolveNodeChildren(node) {
|
|
202
|
+
if (node.children) {
|
|
203
|
+
node.children = node.children.map(child => this.getNode(child));
|
|
180
204
|
}
|
|
181
205
|
return node;
|
|
182
206
|
}
|
|
183
|
-
_resolveSkin(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
207
|
+
_resolveSkin(gltfSkin, index) {
|
|
208
|
+
const inverseBindMatrices = typeof gltfSkin.inverseBindMatrices === 'number' ? this.getAccessor(gltfSkin.inverseBindMatrices) : undefined;
|
|
209
|
+
return {
|
|
210
|
+
...gltfSkin,
|
|
211
|
+
id: gltfSkin.id || "skin-".concat(index),
|
|
212
|
+
inverseBindMatrices
|
|
213
|
+
};
|
|
187
214
|
}
|
|
188
|
-
_resolveMesh(
|
|
189
|
-
mesh
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
215
|
+
_resolveMesh(gltfMesh, index) {
|
|
216
|
+
const mesh = {
|
|
217
|
+
...gltfMesh,
|
|
218
|
+
id: gltfMesh.id || "mesh-".concat(index),
|
|
219
|
+
primitives: []
|
|
220
|
+
};
|
|
221
|
+
if (gltfMesh.primitives) {
|
|
222
|
+
mesh.primitives = gltfMesh.primitives.map(gltfPrimitive => {
|
|
223
|
+
const primitive = {
|
|
224
|
+
...gltfPrimitive,
|
|
225
|
+
attributes: {},
|
|
226
|
+
indices: undefined,
|
|
227
|
+
material: undefined
|
|
194
228
|
};
|
|
195
|
-
const attributes =
|
|
196
|
-
primitive.attributes = {};
|
|
229
|
+
const attributes = gltfPrimitive.attributes;
|
|
197
230
|
for (const attribute in attributes) {
|
|
198
231
|
primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);
|
|
199
232
|
}
|
|
200
|
-
if (
|
|
201
|
-
primitive.indices = this.getAccessor(
|
|
233
|
+
if (gltfPrimitive.indices !== undefined) {
|
|
234
|
+
primitive.indices = this.getAccessor(gltfPrimitive.indices);
|
|
202
235
|
}
|
|
203
|
-
if (
|
|
204
|
-
primitive.material = this.getMaterial(
|
|
236
|
+
if (gltfPrimitive.material !== undefined) {
|
|
237
|
+
primitive.material = this.getMaterial(gltfPrimitive.material);
|
|
205
238
|
}
|
|
206
239
|
return primitive;
|
|
207
240
|
});
|
|
208
241
|
}
|
|
209
242
|
return mesh;
|
|
210
243
|
}
|
|
211
|
-
_resolveMaterial(
|
|
212
|
-
material
|
|
244
|
+
_resolveMaterial(gltfMaterial, index) {
|
|
245
|
+
const material = {
|
|
246
|
+
...gltfMaterial,
|
|
247
|
+
id: gltfMaterial.id || "material-".concat(index)
|
|
248
|
+
};
|
|
213
249
|
if (material.normalTexture) {
|
|
214
250
|
material.normalTexture = {
|
|
215
251
|
...material.normalTexture
|
|
@@ -217,19 +253,19 @@ class GLTFPostProcessor {
|
|
|
217
253
|
material.normalTexture.texture = this.getTexture(material.normalTexture.index);
|
|
218
254
|
}
|
|
219
255
|
if (material.occlusionTexture) {
|
|
220
|
-
material.
|
|
221
|
-
...material.
|
|
256
|
+
material.occlusionTexture = {
|
|
257
|
+
...material.occlusionTexture
|
|
222
258
|
};
|
|
223
259
|
material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
|
|
224
260
|
}
|
|
225
261
|
if (material.emissiveTexture) {
|
|
226
|
-
material.
|
|
227
|
-
...material.
|
|
262
|
+
material.emissiveTexture = {
|
|
263
|
+
...material.emissiveTexture
|
|
228
264
|
};
|
|
229
265
|
material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
|
|
230
266
|
}
|
|
231
267
|
if (!material.emissiveFactor) {
|
|
232
|
-
material.emissiveFactor = material.
|
|
268
|
+
material.emissiveFactor = material.emissiveTexture ? [1, 1, 1] : [0, 0, 0];
|
|
233
269
|
}
|
|
234
270
|
if (material.pbrMetallicRoughness) {
|
|
235
271
|
material.pbrMetallicRoughness = {
|
|
@@ -251,14 +287,23 @@ class GLTFPostProcessor {
|
|
|
251
287
|
}
|
|
252
288
|
return material;
|
|
253
289
|
}
|
|
254
|
-
_resolveAccessor(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
290
|
+
_resolveAccessor(gltfAccessor, index) {
|
|
291
|
+
const bytesPerComponent = getBytesFromComponentType(gltfAccessor.componentType);
|
|
292
|
+
const components = getSizeFromAccessorType(gltfAccessor.type);
|
|
293
|
+
const bytesPerElement = bytesPerComponent * components;
|
|
294
|
+
const accessor = {
|
|
295
|
+
...gltfAccessor,
|
|
296
|
+
id: gltfAccessor.id || "accessor-".concat(index),
|
|
297
|
+
bytesPerComponent,
|
|
298
|
+
components,
|
|
299
|
+
bytesPerElement,
|
|
300
|
+
value: undefined,
|
|
301
|
+
bufferView: undefined,
|
|
302
|
+
sparse: undefined
|
|
303
|
+
};
|
|
304
|
+
if (gltfAccessor.bufferView !== undefined) {
|
|
305
|
+
accessor.bufferView = this.getBufferView(gltfAccessor.bufferView);
|
|
258
306
|
}
|
|
259
|
-
accessor.bytesPerComponent = getBytesFromComponentType(accessor.componentType);
|
|
260
|
-
accessor.components = getSizeFromAccessorType(accessor.type);
|
|
261
|
-
accessor.bytesPerElement = accessor.bytesPerComponent * accessor.components;
|
|
262
307
|
if (accessor.bufferView) {
|
|
263
308
|
const buffer = accessor.bufferView.buffer;
|
|
264
309
|
const {
|
|
@@ -282,15 +327,20 @@ class GLTFPostProcessor {
|
|
|
282
327
|
}
|
|
283
328
|
return result.buffer;
|
|
284
329
|
}
|
|
285
|
-
_resolveTexture(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
330
|
+
_resolveTexture(gltfTexture, index) {
|
|
331
|
+
return {
|
|
332
|
+
...gltfTexture,
|
|
333
|
+
id: gltfTexture.id || "texture-".concat(index),
|
|
334
|
+
sampler: typeof gltfTexture.sampler === 'number' ? this.getSampler(gltfTexture.sampler) : makeDefaultSampler(),
|
|
335
|
+
source: typeof gltfTexture.source === 'number' ? this.getImage(gltfTexture.source) : undefined
|
|
336
|
+
};
|
|
290
337
|
}
|
|
291
|
-
_resolveSampler(
|
|
292
|
-
sampler
|
|
293
|
-
|
|
338
|
+
_resolveSampler(gltfSampler, index) {
|
|
339
|
+
const sampler = {
|
|
340
|
+
id: gltfSampler.id || "sampler-".concat(index),
|
|
341
|
+
...gltfSampler,
|
|
342
|
+
parameters: {}
|
|
343
|
+
};
|
|
294
344
|
for (const key in sampler) {
|
|
295
345
|
const glEnum = this._enumSamplerParameter(key);
|
|
296
346
|
if (glEnum !== undefined) {
|
|
@@ -302,34 +352,39 @@ class GLTFPostProcessor {
|
|
|
302
352
|
_enumSamplerParameter(key) {
|
|
303
353
|
return SAMPLER_PARAMETER_GLTF_TO_GL[key];
|
|
304
354
|
}
|
|
305
|
-
_resolveImage(
|
|
306
|
-
image
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
355
|
+
_resolveImage(gltfImage, index) {
|
|
356
|
+
const image = {
|
|
357
|
+
...gltfImage,
|
|
358
|
+
id: gltfImage.id || "image-".concat(index),
|
|
359
|
+
image: null,
|
|
360
|
+
bufferView: gltfImage.bufferView !== undefined ? this.getBufferView(gltfImage.bufferView) : undefined
|
|
361
|
+
};
|
|
310
362
|
const preloadedImage = this.images[index];
|
|
311
363
|
if (preloadedImage) {
|
|
312
364
|
image.image = preloadedImage;
|
|
313
365
|
}
|
|
314
366
|
return image;
|
|
315
367
|
}
|
|
316
|
-
_resolveBufferView(
|
|
317
|
-
const bufferIndex =
|
|
318
|
-
const result = {
|
|
319
|
-
id: "bufferView-".concat(index),
|
|
320
|
-
...bufferView,
|
|
321
|
-
buffer: this.buffers[bufferIndex]
|
|
322
|
-
};
|
|
368
|
+
_resolveBufferView(gltfBufferView, index) {
|
|
369
|
+
const bufferIndex = gltfBufferView.buffer;
|
|
323
370
|
const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
|
|
324
371
|
let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
|
|
325
|
-
if (
|
|
326
|
-
byteOffset +=
|
|
372
|
+
if (gltfBufferView.byteOffset) {
|
|
373
|
+
byteOffset += gltfBufferView.byteOffset;
|
|
327
374
|
}
|
|
328
|
-
|
|
329
|
-
|
|
375
|
+
const bufferView = {
|
|
376
|
+
id: "bufferView-".concat(index),
|
|
377
|
+
...gltfBufferView,
|
|
378
|
+
buffer: this.buffers[bufferIndex],
|
|
379
|
+
data: new Uint8Array(arrayBuffer, byteOffset, gltfBufferView.byteLength)
|
|
380
|
+
};
|
|
381
|
+
return bufferView;
|
|
330
382
|
}
|
|
331
|
-
_resolveCamera(
|
|
332
|
-
camera
|
|
383
|
+
_resolveCamera(gltfCamera, index) {
|
|
384
|
+
const camera = {
|
|
385
|
+
...gltfCamera,
|
|
386
|
+
id: gltfCamera.id || "camera-".concat(index)
|
|
387
|
+
};
|
|
333
388
|
if (camera.perspective) {}
|
|
334
389
|
if (camera.orthographic) {}
|
|
335
390
|
return camera;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-process-gltf.js","names":["assert","getAccessorArrayTypeAndLength","COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","BYTES","GL_SAMPLER","TEXTURE_MAG_FILTER","TEXTURE_MIN_FILTER","TEXTURE_WRAP_S","TEXTURE_WRAP_T","REPEAT","LINEAR","NEAREST_MIPMAP_LINEAR","SAMPLER_PARAMETER_GLTF_TO_GL","magFilter","minFilter","wrapS","wrapT","DEFAULT_SAMPLER","getBytesFromComponentType","componentType","getSizeFromAccessorType","type","GLTFPostProcessor","constructor","_defineProperty","postProcess","gltf","options","arguments","length","undefined","json","buffers","images","baseUri","_resolveTree","bufferViews","map","bufView","i","_resolveBufferView","image","_resolveImage","samplers","sampler","_resolveSampler","textures","texture","_resolveTexture","accessors","accessor","_resolveAccessor","materials","material","_resolveMaterial","meshes","mesh","_resolveMesh","nodes","node","_resolveNode","skins","skin","_resolveSkin","scenes","scene","_resolveScene","getScene","index","_get","getNode","getSkin","getMesh","getMaterial","getAccessor","getCamera","getTexture","getSampler","getImage","getBufferView","getBuffer","array","object","console","warn","concat","id","children","child","reduce","accum","meshIndex","primitives","camera","inverseBindMatrices","primitive","attributes","attribute","indices","normalTexture","occlusionTexture","occlustionTexture","emissiveTexture","emmisiveTexture","emissiveFactor","pbrMetallicRoughness","mr","baseColorTexture","metallicRoughnessTexture","bufferView","bytesPerComponent","components","bytesPerElement","buffer","ArrayType","byteLength","byteOffset","cutBuffer","arrayBuffer","slice","byteStride","_getValueFromInterleavedBuffer","count","value","result","Uint8Array","elementOffset","set","source","parameters","key","glEnum","_enumSamplerParameter","preloadedImage","bufferIndex","data","_resolveCamera","perspective","orthographic","postProcessGLTF"],"sources":["../../../../src/lib/api/post-process-gltf.ts"],"sourcesContent":["import {assert} from '../utils/assert';\nimport {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';\nimport {BufferView} from '../types/gltf-json-schema';\nimport {BufferView as BufferViewPostprocessed} from '../types/gltf-postprocessed-schema';\n\n// This is a post processor for loaded glTF files\n// The goal is to make the loaded data easier to use in WebGL applications\n//\n// Functions:\n// * Resolve indexed arrays structure of glTF into a linked tree.\n// * Translate stringified enum keys and values into WebGL constants.\n// * Load images (optional)\n\n// ENUM LOOKUP\n\nconst COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16\n};\n\nconst BYTES = {\n 5120: 1, // BYTE\n 5121: 1, // UNSIGNED_BYTE\n 5122: 2, // SHORT\n 5123: 2, // UNSIGNED_SHORT\n 5125: 4, // UNSIGNED_INT\n 5126: 4 // FLOAT\n};\n\nconst GL_SAMPLER = {\n // Sampler parameters\n TEXTURE_MAG_FILTER: 0x2800,\n TEXTURE_MIN_FILTER: 0x2801,\n TEXTURE_WRAP_S: 0x2802,\n TEXTURE_WRAP_T: 0x2803,\n\n // Sampler default values\n REPEAT: 0x2901,\n LINEAR: 0x2601,\n NEAREST_MIPMAP_LINEAR: 0x2702\n};\n\nconst SAMPLER_PARAMETER_GLTF_TO_GL = {\n magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,\n minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,\n wrapS: GL_SAMPLER.TEXTURE_WRAP_S,\n wrapT: GL_SAMPLER.TEXTURE_WRAP_T\n};\n\n// When undefined, a sampler with repeat wrapping and auto filtering should be used.\n// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture\nconst DEFAULT_SAMPLER = {\n [GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,\n [GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,\n [GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,\n [GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT\n};\n\nfunction getBytesFromComponentType(componentType) {\n return BYTES[componentType];\n}\n\nfunction getSizeFromAccessorType(type) {\n return COMPONENTS[type];\n}\n\nclass GLTFPostProcessor {\n baseUri: string = '';\n json: Record<string, any> = {};\n buffers: [] = [];\n images: [] = [];\n\n postProcess(gltf, options = {}) {\n const {json, buffers = [], images = [], baseUri = ''} = gltf;\n assert(json);\n\n this.baseUri = baseUri;\n this.json = json;\n this.buffers = buffers;\n this.images = images;\n\n this._resolveTree(this.json, options);\n\n return this.json;\n }\n\n // Convert indexed glTF structure into tree structure\n // cross-link index resolution, enum lookup, convenience calculations\n // eslint-disable-next-line complexity\n _resolveTree(json, options = {}) {\n if (json.bufferViews) {\n json.bufferViews = json.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i));\n }\n if (json.images) {\n json.images = json.images.map((image, i) => this._resolveImage(image, i));\n }\n if (json.samplers) {\n json.samplers = json.samplers.map((sampler, i) => this._resolveSampler(sampler, i));\n }\n if (json.textures) {\n json.textures = json.textures.map((texture, i) => this._resolveTexture(texture, i));\n }\n if (json.accessors) {\n json.accessors = json.accessors.map((accessor, i) => this._resolveAccessor(accessor, i));\n }\n if (json.materials) {\n json.materials = json.materials.map((material, i) => this._resolveMaterial(material, i));\n }\n if (json.meshes) {\n json.meshes = json.meshes.map((mesh, i) => this._resolveMesh(mesh, i));\n }\n if (json.nodes) {\n json.nodes = json.nodes.map((node, i) => this._resolveNode(node, i));\n }\n if (json.skins) {\n json.skins = json.skins.map((skin, i) => this._resolveSkin(skin, i));\n }\n if (json.scenes) {\n json.scenes = json.scenes.map((scene, i) => this._resolveScene(scene, i));\n }\n if (json.scene !== undefined) {\n json.scene = json.scenes[this.json.scene];\n }\n }\n\n getScene(index) {\n return this._get('scenes', index);\n }\n\n getNode(index) {\n return this._get('nodes', index);\n }\n\n getSkin(index) {\n return this._get('skins', index);\n }\n\n getMesh(index) {\n return this._get('meshes', index);\n }\n\n getMaterial(index) {\n return this._get('materials', index);\n }\n\n getAccessor(index) {\n return this._get('accessors', index);\n }\n\n getCamera(index) {\n return null; // TODO: fix this\n }\n\n getTexture(index) {\n return this._get('textures', index);\n }\n\n getSampler(index) {\n return this._get('samplers', index);\n }\n\n getImage(index) {\n return this._get('images', index);\n }\n\n getBufferView(index) {\n return this._get('bufferViews', index);\n }\n\n getBuffer(index) {\n return this._get('buffers', index);\n }\n\n _get(array, index) {\n // check if already resolved\n if (typeof index === 'object') {\n return index;\n }\n const object = this.json[array] && this.json[array][index];\n if (!object) {\n console.warn(`glTF file error: Could not find ${array}[${index}]`); // eslint-disable-line\n }\n return object;\n }\n\n // PARSING HELPERS\n\n _resolveScene(scene, index) {\n // scene = {...scene};\n scene.id = scene.id || `scene-${index}`;\n scene.nodes = (scene.nodes || []).map((node) => this.getNode(node));\n return scene;\n }\n\n _resolveNode(node, index) {\n // node = {...node};\n node.id = node.id || `node-${index}`;\n if (node.children) {\n node.children = node.children.map((child) => this.getNode(child));\n }\n if (node.mesh !== undefined) {\n node.mesh = this.getMesh(node.mesh);\n } else if (node.meshes !== undefined && node.meshes.length) {\n node.mesh = node.meshes.reduce(\n (accum, meshIndex) => {\n const mesh = this.getMesh(meshIndex);\n accum.id = mesh.id;\n accum.primitives = accum.primitives.concat(mesh.primitives);\n return accum;\n },\n {primitives: []}\n );\n }\n if (node.camera !== undefined) {\n node.camera = this.getCamera(node.camera);\n }\n if (node.skin !== undefined) {\n node.skin = this.getSkin(node.skin);\n }\n return node;\n }\n\n _resolveSkin(skin, index) {\n // skin = {...skin};\n skin.id = skin.id || `skin-${index}`;\n skin.inverseBindMatrices = this.getAccessor(skin.inverseBindMatrices);\n return skin;\n }\n\n _resolveMesh(mesh, index) {\n // mesh = {...mesh};\n mesh.id = mesh.id || `mesh-${index}`;\n if (mesh.primitives) {\n mesh.primitives = mesh.primitives.map((primitive) => {\n primitive = {...primitive};\n const attributes = primitive.attributes;\n primitive.attributes = {};\n for (const attribute in attributes) {\n primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);\n }\n if (primitive.indices !== undefined) {\n primitive.indices = this.getAccessor(primitive.indices);\n }\n if (primitive.material !== undefined) {\n primitive.material = this.getMaterial(primitive.material);\n }\n return primitive;\n });\n }\n return mesh;\n }\n\n _resolveMaterial(material, index) {\n // material = {...material};\n material.id = material.id || `material-${index}`;\n if (material.normalTexture) {\n material.normalTexture = {...material.normalTexture};\n material.normalTexture.texture = this.getTexture(material.normalTexture.index);\n }\n if (material.occlusionTexture) {\n material.occlustionTexture = {...material.occlustionTexture};\n material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);\n }\n if (material.emissiveTexture) {\n material.emmisiveTexture = {...material.emmisiveTexture};\n material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);\n }\n if (!material.emissiveFactor) {\n material.emissiveFactor = material.emmisiveTexture ? [1, 1, 1] : [0, 0, 0];\n }\n\n if (material.pbrMetallicRoughness) {\n material.pbrMetallicRoughness = {...material.pbrMetallicRoughness};\n const mr = material.pbrMetallicRoughness;\n if (mr.baseColorTexture) {\n mr.baseColorTexture = {...mr.baseColorTexture};\n mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);\n }\n if (mr.metallicRoughnessTexture) {\n mr.metallicRoughnessTexture = {...mr.metallicRoughnessTexture};\n mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);\n }\n }\n return material;\n }\n\n _resolveAccessor(accessor, index) {\n // accessor = {...accessor};\n accessor.id = accessor.id || `accessor-${index}`;\n if (accessor.bufferView !== undefined) {\n // Draco encoded meshes don't have bufferView\n accessor.bufferView = this.getBufferView(accessor.bufferView);\n }\n\n // Look up enums\n accessor.bytesPerComponent = getBytesFromComponentType(accessor.componentType);\n accessor.components = getSizeFromAccessorType(accessor.type);\n accessor.bytesPerElement = accessor.bytesPerComponent * accessor.components;\n\n // Create TypedArray for the accessor\n // Note: The canonical way to instantiate is to ignore this array and create\n // WebGLBuffer's using the bufferViews.\n if (accessor.bufferView) {\n const buffer = accessor.bufferView.buffer;\n const {ArrayType, byteLength} = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);\n const byteOffset =\n (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;\n let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);\n if (accessor.bufferView.byteStride) {\n cutBuffer = this._getValueFromInterleavedBuffer(\n buffer,\n byteOffset,\n accessor.bufferView.byteStride,\n accessor.bytesPerElement,\n accessor.count\n );\n }\n accessor.value = new ArrayType(cutBuffer);\n }\n\n return accessor;\n }\n\n /**\n * Take values of particular accessor from interleaved buffer\n * various parts of the buffer\n * @param buffer\n * @param byteOffset\n * @param byteStride\n * @param bytesPerElement\n * @param count\n * @returns\n */\n _getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {\n const result = new Uint8Array(count * bytesPerElement);\n for (let i = 0; i < count; i++) {\n const elementOffset = byteOffset + i * byteStride;\n result.set(\n new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)),\n i * bytesPerElement\n );\n }\n return result.buffer;\n }\n\n _resolveTexture(texture, index) {\n // texture = {...texture};\n texture.id = texture.id || `texture-${index}`;\n texture.sampler = 'sampler' in texture ? this.getSampler(texture.sampler) : DEFAULT_SAMPLER;\n texture.source = this.getImage(texture.source);\n return texture;\n }\n\n _resolveSampler(sampler, index) {\n // sampler = {...sampler};\n sampler.id = sampler.id || `sampler-${index}`;\n // Map textual parameters to GL parameter values\n sampler.parameters = {};\n for (const key in sampler) {\n const glEnum = this._enumSamplerParameter(key);\n if (glEnum !== undefined) {\n sampler.parameters[glEnum] = sampler[key];\n }\n }\n return sampler;\n }\n\n _enumSamplerParameter(key) {\n return SAMPLER_PARAMETER_GLTF_TO_GL[key];\n }\n\n _resolveImage(image, index) {\n // image = {...image};\n image.id = image.id || `image-${index}`;\n if (image.bufferView !== undefined) {\n image.bufferView = this.getBufferView(image.bufferView);\n }\n\n // Check if image has been preloaded by the GLTFLoader\n // If so, link it into the JSON and drop the URI\n const preloadedImage = this.images[index];\n if (preloadedImage) {\n image.image = preloadedImage;\n }\n\n return image;\n }\n\n _resolveBufferView(bufferView: BufferView, index: number): BufferViewPostprocessed {\n // bufferView = {...bufferView};\n const bufferIndex = bufferView.buffer;\n const result: BufferViewPostprocessed = {\n id: `bufferView-${index}`,\n ...bufferView,\n buffer: this.buffers[bufferIndex]\n };\n\n // @ts-expect-error\n const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;\n // @ts-expect-error\n let byteOffset = this.buffers[bufferIndex].byteOffset || 0;\n\n if ('byteOffset' in bufferView) {\n byteOffset += bufferView.byteOffset;\n }\n\n result.data = new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);\n return result;\n }\n\n _resolveCamera(camera, index) {\n camera.id = camera.id || `camera-${index}`;\n // TODO - create 4x4 matrices\n if (camera.perspective) {\n // camera.matrix = createPerspectiveMatrix(camera.perspective);\n }\n if (camera.orthographic) {\n // camera.matrix = createOrthographicMatrix(camera.orthographic);\n }\n return camera;\n }\n}\n\nexport function postProcessGLTF(gltf, options?) {\n return new GLTFPostProcessor().postProcess(gltf, options);\n}\n"],"mappings":";AAAA,SAAQA,MAAM,QAAO,iBAAiB;AACtC,SAAQC,6BAA6B,QAAO,0BAA0B;AActE,MAAMC,UAAU,GAAG;EACjBC,MAAM,EAAE,CAAC;EACTC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE;AACR,CAAC;AAED,MAAMC,KAAK,GAAG;EACZ,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE;AACR,CAAC;AAED,MAAMC,UAAU,GAAG;EAEjBC,kBAAk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WAAW,CAAC,CAAClB,UAAU,IAAI,CAAC;IAE1D,IAAI,YAAY,IAAIP,UAAU,EAAE;MAC9BO,UAAU,IAAIP,UAAU,CAACO,UAAU;IACrC;IAEAQ,MAAM,CAACW,IAAI,GAAG,IAAIV,UAAU,CAACP,WAAW,EAAEF,UAAU,EAAEP,UAAU,CAACM,UAAU,CAAC;IAC5E,OAAOS,MAAM;EACf;EAEAY,cAAcA,CAAC3C,MAAM,EAAEzB,KAAK,EAAE;IAC5ByB,MAAM,CAACP,EAAE,GAAGO,MAAM,CAACP,EAAE,cAAAD,MAAA,CAAcjB,KAAK,CAAE;IAE1C,IAAIyB,MAAM,CAAC4C,WAAW,EAAE,CAExB;IACA,IAAI5C,MAAM,CAAC6C,YAAY,EAAE,CAEzB;IACA,OAAO7C,MAAM;EACf;AACF;AAEA,OAAO,SAAS8C,eAAeA,CAACjH,IAAI,EAAEC,OAAQ,EAAE;EAC9C,OAAO,IAAIL,iBAAiB,CAAC,CAAC,CAACG,WAAW,CAACC,IAAI,EAAEC,OAAO,CAAC;AAC3D"}
|
|
1
|
+
{"version":3,"file":"post-process-gltf.js","names":["assert","getAccessorArrayTypeAndLength","COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","BYTES","GL_SAMPLER","TEXTURE_MAG_FILTER","TEXTURE_MIN_FILTER","TEXTURE_WRAP_S","TEXTURE_WRAP_T","REPEAT","LINEAR","NEAREST_MIPMAP_LINEAR","SAMPLER_PARAMETER_GLTF_TO_GL","magFilter","minFilter","wrapS","wrapT","DEFAULT_SAMPLER_PARAMETERS","makeDefaultSampler","id","parameters","getBytesFromComponentType","componentType","getSizeFromAccessorType","type","GLTFPostProcessor","constructor","_defineProperty","postProcess","gltf","options","arguments","length","undefined","json","buffers","images","baseUri","jsonUnprocessed","_resolveTree","bufferViews","map","bufView","i","_resolveBufferView","image","_resolveImage","samplers","sampler","_resolveSampler","textures","texture","_resolveTexture","accessors","accessor","_resolveAccessor","materials","material","_resolveMaterial","meshes","mesh","_resolveMesh","nodes","node","_resolveNode","_resolveNodeChildren","skins","skin","_resolveSkin","scenes","scene","_resolveScene","getScene","index","_get","getNode","getSkin","getMesh","getMaterial","getAccessor","getCamera","cameras","getTexture","getSampler","getImage","getBufferView","getBuffer","array","object","console","warn","concat","gltfNode","camera","reduce","accum","meshIndex","primitives","children","child","gltfSkin","inverseBindMatrices","gltfMesh","gltfPrimitive","primitive","attributes","indices","attribute","gltfMaterial","normalTexture","occlusionTexture","emissiveTexture","emissiveFactor","pbrMetallicRoughness","mr","baseColorTexture","metallicRoughnessTexture","gltfAccessor","bytesPerComponent","components","bytesPerElement","value","bufferView","sparse","buffer","ArrayType","byteLength","byteOffset","cutBuffer","arrayBuffer","slice","byteStride","_getValueFromInterleavedBuffer","count","result","Uint8Array","elementOffset","set","gltfTexture","source","gltfSampler","key","glEnum","_enumSamplerParameter","gltfImage","preloadedImage","gltfBufferView","bufferIndex","data","_resolveCamera","gltfCamera","perspective","orthographic","postProcessGLTF"],"sources":["../../../../src/lib/api/post-process-gltf.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {GLTFWithBuffers} from '../types/gltf-types';\nimport type {ParseGLTFOptions} from '../parsers/parse-gltf';\n\nimport type {\n GLTF,\n GLTFAccessor,\n GLTFBufferView,\n GLTFCamera,\n GLTFImage,\n GLTFMaterial,\n GLTFMesh,\n GLTFNode,\n GLTFSampler,\n GLTFScene,\n GLTFSkin,\n GLTFTexture\n} from '../types/gltf-json-schema';\n\nimport type {\n GLTFPostprocessed,\n GLTFAccessorPostprocessed,\n GLTFBufferPostprocessed,\n GLTFBufferViewPostprocessed,\n GLTFCameraPostprocessed,\n GLTFImagePostprocessed,\n GLTFMaterialPostprocessed,\n GLTFMeshPostprocessed,\n GLTFNodePostprocessed,\n GLTFSamplerPostprocessed,\n GLTFScenePostprocessed,\n GLTFSkinPostprocessed,\n GLTFTexturePostprocessed,\n GLTFMeshPrimitivePostprocessed\n} from '../types/gltf-postprocessed-schema';\n\nimport {assert} from '../utils/assert';\nimport {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';\n\n// This is a post processor for loaded glTF files\n// The goal is to make the loaded data easier to use in WebGL applications\n//\n// Functions:\n// * Resolve indexed arrays structure of glTF into a linked tree.\n// * Translate stringified enum keys and values into WebGL constants.\n// * Load images (optional)\n\n// ENUM LOOKUP\n\nconst COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16\n};\n\nconst BYTES = {\n 5120: 1, // BYTE\n 5121: 1, // UNSIGNED_BYTE\n 5122: 2, // SHORT\n 5123: 2, // UNSIGNED_SHORT\n 5125: 4, // UNSIGNED_INT\n 5126: 4 // FLOAT\n};\n\nconst GL_SAMPLER = {\n // Sampler parameters\n TEXTURE_MAG_FILTER: 0x2800,\n TEXTURE_MIN_FILTER: 0x2801,\n TEXTURE_WRAP_S: 0x2802,\n TEXTURE_WRAP_T: 0x2803,\n\n // Sampler default values\n REPEAT: 0x2901,\n LINEAR: 0x2601,\n NEAREST_MIPMAP_LINEAR: 0x2702\n};\n\nconst SAMPLER_PARAMETER_GLTF_TO_GL = {\n magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,\n minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,\n wrapS: GL_SAMPLER.TEXTURE_WRAP_S,\n wrapT: GL_SAMPLER.TEXTURE_WRAP_T\n};\n\n// When undefined, a sampler with repeat wrapping and auto filtering should be used.\n// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture\nconst DEFAULT_SAMPLER_PARAMETERS = {\n [GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,\n [GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,\n [GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,\n [GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT\n};\n\nfunction makeDefaultSampler(): GLTFSamplerPostprocessed {\n return {\n id: 'default-sampler',\n parameters: DEFAULT_SAMPLER_PARAMETERS\n };\n}\n\nfunction getBytesFromComponentType(componentType) {\n return BYTES[componentType];\n}\n\nfunction getSizeFromAccessorType(type) {\n return COMPONENTS[type];\n}\n\nclass GLTFPostProcessor {\n baseUri: string = '';\n // @ts-expect-error\n jsonUnprocessed: GLTF;\n // @ts-expect-error\n json: GLTFPostprocessed;\n buffers: {\n arrayBuffer: ArrayBuffer;\n byteOffset: number;\n byteLength: number;\n }[] = [];\n images: any[] = [];\n\n postProcess(gltf: GLTFWithBuffers, options = {}) {\n const {json, buffers = [], images = []} = gltf;\n // @ts-expect-error\n const {baseUri = ''} = gltf;\n assert(json);\n\n this.baseUri = baseUri;\n this.buffers = buffers;\n this.images = images;\n this.jsonUnprocessed = json;\n\n this.json = this._resolveTree(gltf.json, options);\n\n return this.json;\n }\n\n // Convert indexed glTF structure into tree structure\n // cross-link index resolution, enum lookup, convenience calculations\n // eslint-disable-next-line complexity, max-statements\n _resolveTree(gltf: GLTF, options = {}): GLTFPostprocessed {\n // @ts-expect-error\n const json: GLTFPostprocessed = {...gltf};\n this.json = json;\n\n if (gltf.bufferViews) {\n json.bufferViews = gltf.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i));\n }\n if (gltf.images) {\n json.images = gltf.images.map((image, i) => this._resolveImage(image, i));\n }\n if (gltf.samplers) {\n json.samplers = gltf.samplers.map((sampler, i) => this._resolveSampler(sampler, i));\n }\n if (gltf.textures) {\n json.textures = gltf.textures.map((texture, i) => this._resolveTexture(texture, i));\n }\n if (gltf.accessors) {\n json.accessors = gltf.accessors.map((accessor, i) => this._resolveAccessor(accessor, i));\n }\n if (gltf.materials) {\n json.materials = gltf.materials.map((material, i) => this._resolveMaterial(material, i));\n }\n if (gltf.meshes) {\n json.meshes = gltf.meshes.map((mesh, i) => this._resolveMesh(mesh, i));\n }\n if (gltf.nodes) {\n json.nodes = gltf.nodes.map((node, i) => this._resolveNode(node, i));\n json.nodes = json.nodes.map((node, i) => this._resolveNodeChildren(node));\n }\n if (gltf.skins) {\n json.skins = gltf.skins.map((skin, i) => this._resolveSkin(skin, i));\n }\n if (gltf.scenes) {\n json.scenes = gltf.scenes.map((scene, i) => this._resolveScene(scene, i));\n }\n if (typeof this.json.scene === 'number' && json.scenes) {\n json.scene = json.scenes[this.json.scene];\n }\n\n return json;\n }\n\n getScene(index: number): GLTFScenePostprocessed {\n return this._get(this.json.scenes, index);\n }\n\n getNode(index: number): GLTFNodePostprocessed {\n return this._get(this.json.nodes, index);\n }\n\n getSkin(index: number): GLTFSkinPostprocessed {\n return this._get(this.json.skins, index);\n }\n\n getMesh(index: number): GLTFMeshPostprocessed {\n return this._get(this.json.meshes, index);\n }\n\n getMaterial(index: number): GLTFMaterialPostprocessed {\n return this._get(this.json.materials, index);\n }\n\n getAccessor(index: number): GLTFAccessorPostprocessed {\n return this._get(this.json.accessors, index);\n }\n\n getCamera(index: number): GLTFCameraPostprocessed {\n return this._get(this.json.cameras, index);\n }\n\n getTexture(index: number): GLTFTexturePostprocessed {\n return this._get(this.json.textures, index);\n }\n\n getSampler(index: number): GLTFSamplerPostprocessed {\n return this._get(this.json.samplers, index);\n }\n\n getImage(index: number): GLTFImagePostprocessed {\n return this._get(this.json.images, index);\n }\n\n getBufferView(index: number): GLTFBufferViewPostprocessed {\n return this._get(this.json.bufferViews, index);\n }\n\n getBuffer(index: number): GLTFBufferPostprocessed {\n return this._get(this.json.buffers, index);\n }\n\n _get<T>(array: T[] | undefined, index: number): T {\n // check if already resolved\n if (typeof index === 'object') {\n return index;\n }\n const object = array && array[index];\n if (!object) {\n console.warn(`glTF file error: Could not find ${array}[${index}]`); // eslint-disable-line\n }\n return object as T;\n }\n\n // PARSING HELPERS\n\n _resolveScene(scene: GLTFScene, index: number): GLTFScenePostprocessed {\n return {\n ...scene,\n // @ts-ignore\n id: scene.id || `scene-${index}`,\n nodes: (scene.nodes || []).map((node) => this.getNode(node))\n };\n }\n\n _resolveNode(gltfNode: GLTFNode, index: number): GLTFNodePostprocessed {\n // @ts-expect-error\n const node: GLTFNodePostprocessed = {\n ...gltfNode,\n // @ts-expect-error id could already be present, glTF standard does not prevent it\n id: gltfNode?.id || `node-${index}`\n };\n if (gltfNode.mesh !== undefined) {\n node.mesh = this.getMesh(gltfNode.mesh);\n }\n if (gltfNode.camera !== undefined) {\n node.camera = this.getCamera(gltfNode.camera);\n }\n if (gltfNode.skin !== undefined) {\n node.skin = this.getSkin(gltfNode.skin);\n }\n\n // TODO deprecated - Delete in v4.0?\n // @ts-expect-error node.meshes does not seem to be part of the GLTF standard\n if (gltfNode.meshes !== undefined && gltfNode.meshes.length) {\n // @ts-expect-error\n node.mesh = gltfNode.meshes.reduce(\n (accum, meshIndex) => {\n const mesh = this.getMesh(meshIndex);\n accum.id = mesh.id;\n accum.primitives = accum.primitives.concat(mesh.primitives);\n return accum;\n },\n {primitives: []}\n );\n }\n\n return node;\n }\n\n _resolveNodeChildren(node: GLTFNodePostprocessed): GLTFNodePostprocessed {\n if (node.children) {\n // @ts-expect-error node.children are numbers at this stage\n node.children = node.children.map((child) => this.getNode(child));\n }\n return node;\n }\n\n _resolveSkin(gltfSkin: GLTFSkin, index: number): GLTFSkinPostprocessed {\n const inverseBindMatrices =\n typeof gltfSkin.inverseBindMatrices === 'number'\n ? this.getAccessor(gltfSkin.inverseBindMatrices)\n : undefined;\n\n return {\n ...gltfSkin,\n id: gltfSkin.id || `skin-${index}`,\n inverseBindMatrices\n };\n }\n\n _resolveMesh(gltfMesh: GLTFMesh, index: number): GLTFMeshPostprocessed {\n const mesh: GLTFMeshPostprocessed = {\n ...gltfMesh,\n id: gltfMesh.id || `mesh-${index}`,\n primitives: []\n };\n if (gltfMesh.primitives) {\n mesh.primitives = gltfMesh.primitives.map((gltfPrimitive) => {\n const primitive: GLTFMeshPrimitivePostprocessed = {\n ...gltfPrimitive,\n attributes: {},\n indices: undefined,\n material: undefined\n };\n const attributes = gltfPrimitive.attributes;\n for (const attribute in attributes) {\n primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);\n }\n if (gltfPrimitive.indices !== undefined) {\n primitive.indices = this.getAccessor(gltfPrimitive.indices);\n }\n if (gltfPrimitive.material !== undefined) {\n primitive.material = this.getMaterial(gltfPrimitive.material);\n }\n return primitive;\n });\n }\n return mesh;\n }\n\n _resolveMaterial(gltfMaterial: GLTFMaterial, index: number): GLTFMaterialPostprocessed {\n // @ts-expect-error\n const material: GLTFMaterialPostprocessed = {\n ...gltfMaterial,\n // @ts-expect-error\n id: gltfMaterial.id || `material-${index}`\n };\n if (material.normalTexture) {\n material.normalTexture = {...material.normalTexture};\n material.normalTexture.texture = this.getTexture(material.normalTexture.index);\n }\n if (material.occlusionTexture) {\n material.occlusionTexture = {...material.occlusionTexture};\n material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);\n }\n if (material.emissiveTexture) {\n material.emissiveTexture = {...material.emissiveTexture};\n material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);\n }\n if (!material.emissiveFactor) {\n material.emissiveFactor = material.emissiveTexture ? [1, 1, 1] : [0, 0, 0];\n }\n\n if (material.pbrMetallicRoughness) {\n material.pbrMetallicRoughness = {...material.pbrMetallicRoughness};\n const mr = material.pbrMetallicRoughness;\n if (mr.baseColorTexture) {\n mr.baseColorTexture = {...mr.baseColorTexture};\n mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);\n }\n if (mr.metallicRoughnessTexture) {\n mr.metallicRoughnessTexture = {...mr.metallicRoughnessTexture};\n mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);\n }\n }\n return material;\n }\n\n _resolveAccessor(gltfAccessor: GLTFAccessor, index: number): GLTFAccessorPostprocessed {\n // Look up enums\n const bytesPerComponent = getBytesFromComponentType(gltfAccessor.componentType);\n const components = getSizeFromAccessorType(gltfAccessor.type);\n const bytesPerElement = bytesPerComponent * components;\n\n const accessor: GLTFAccessorPostprocessed = {\n ...gltfAccessor,\n // @ts-expect-error\n id: gltfAccessor.id || `accessor-${index}`,\n bytesPerComponent,\n components,\n bytesPerElement,\n value: undefined!,\n bufferView: undefined!,\n sparse: undefined!\n };\n if (gltfAccessor.bufferView !== undefined) {\n // Draco encoded meshes don't have bufferView\n accessor.bufferView = this.getBufferView(gltfAccessor.bufferView);\n }\n\n // Create TypedArray for the accessor\n // Note: The canonical way to instantiate is to ignore this array and create\n // WebGLBuffer's using the bufferViews.\n if (accessor.bufferView) {\n const buffer = accessor.bufferView.buffer;\n const {ArrayType, byteLength} = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);\n const byteOffset =\n (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;\n let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);\n if (accessor.bufferView.byteStride) {\n cutBuffer = this._getValueFromInterleavedBuffer(\n buffer,\n byteOffset,\n accessor.bufferView.byteStride,\n accessor.bytesPerElement,\n accessor.count\n );\n }\n accessor.value = new ArrayType(cutBuffer);\n }\n\n return accessor;\n }\n\n /**\n * Take values of particular accessor from interleaved buffer\n * various parts of the buffer\n * @param buffer\n * @param byteOffset\n * @param byteStride\n * @param bytesPerElement\n * @param count\n * @returns\n */\n _getValueFromInterleavedBuffer(\n buffer,\n byteOffset: number,\n byteStride: number,\n bytesPerElement: number,\n count: number\n ): ArrayBufferLike {\n const result = new Uint8Array(count * bytesPerElement);\n for (let i = 0; i < count; i++) {\n const elementOffset = byteOffset + i * byteStride;\n result.set(\n new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)),\n i * bytesPerElement\n );\n }\n return result.buffer;\n }\n\n _resolveTexture(gltfTexture: GLTFTexture, index: number): GLTFTexturePostprocessed {\n return {\n ...gltfTexture,\n // @ts-expect-error id could already be present, glTF standard does not prevent it\n id: gltfTexture.id || `texture-${index}`,\n sampler:\n typeof gltfTexture.sampler === 'number'\n ? this.getSampler(gltfTexture.sampler)\n : makeDefaultSampler(),\n source: typeof gltfTexture.source === 'number' ? this.getImage(gltfTexture.source) : undefined\n };\n }\n\n _resolveSampler(gltfSampler: GLTFSampler, index: number): GLTFSamplerPostprocessed {\n const sampler: GLTFSamplerPostprocessed = {\n // @ts-expect-error id could already be present, glTF standard does not prevent it\n id: gltfSampler.id || `sampler-${index}`,\n ...gltfSampler,\n parameters: {}\n };\n // Map textual parameters to GL parameter values\n for (const key in sampler) {\n const glEnum = this._enumSamplerParameter(key);\n if (glEnum !== undefined) {\n sampler.parameters[glEnum] = sampler[key];\n }\n }\n return sampler;\n }\n\n _enumSamplerParameter(key: string): number {\n return SAMPLER_PARAMETER_GLTF_TO_GL[key];\n }\n\n _resolveImage(gltfImage: GLTFImage, index: number): GLTFImagePostprocessed {\n const image: GLTFImagePostprocessed = {\n ...gltfImage,\n // @ts-expect-error id could already be present, glTF standard does not prevent it\n id: gltfImage.id || `image-${index}`,\n image: null!,\n bufferView:\n gltfImage.bufferView !== undefined ? this.getBufferView(gltfImage.bufferView) : undefined\n };\n\n // Check if image has been preloaded by the GLTFLoader\n // If so, link it into the JSON and drop the URI\n const preloadedImage = this.images[index];\n if (preloadedImage) {\n image.image = preloadedImage;\n }\n\n return image;\n }\n\n _resolveBufferView(gltfBufferView: GLTFBufferView, index: number): GLTFBufferViewPostprocessed {\n const bufferIndex = gltfBufferView.buffer;\n const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;\n // Add offset of buffer, then offset of buffer view\n let byteOffset = this.buffers[bufferIndex].byteOffset || 0;\n if (gltfBufferView.byteOffset) {\n byteOffset += gltfBufferView.byteOffset;\n }\n\n const bufferView: GLTFBufferViewPostprocessed = {\n // // @ts-expect-error id could already be present, glTF standard does not prevent it\n id: `bufferView-${index}`,\n ...gltfBufferView,\n // ...this.buffers[bufferIndex],\n buffer: this.buffers[bufferIndex],\n data: new Uint8Array(arrayBuffer, byteOffset, gltfBufferView.byteLength)\n };\n\n return bufferView;\n }\n\n _resolveCamera(gltfCamera: GLTFCamera, index): GLTFCameraPostprocessed {\n const camera: GLTFCameraPostprocessed = {\n ...gltfCamera,\n // @ts-expect-error id could already be present, glTF standard does not prevent it\n id: gltfCamera.id || `camera-${index}`\n };\n\n // TODO - create 4x4 matrices\n if (camera.perspective) {\n // camera.matrix = createPerspectiveMatrix(camera.perspective);\n }\n if (camera.orthographic) {\n // camera.matrix = createOrthographicMatrix(camera.orthographic);\n }\n return camera;\n }\n}\n\nexport function postProcessGLTF(\n gltf: GLTFWithBuffers,\n options?: ParseGLTFOptions\n): GLTFPostprocessed {\n return new GLTFPostProcessor().postProcess(gltf, options);\n}\n"],"mappings":";AAqCA,SAAQA,MAAM,QAAO,iBAAiB;AACtC,SAAQC,6BAA6B,QAAO,0BAA0B;AAYtE,MAAMC,UAAU,GAAG;EACjBC,MAAM,EAAE,CAAC;EACTC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE;AACR,CAAC;AAED,MAAMC,KAAK,GAAG;EACZ,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE;AACR,CAAC;AAED,MAAMC,UAAU,GAAG;EAEjBC,kBAAkB,EAAE,MAAM;EAC1BC,kBAAkB,EAAE,MAAM;EAC1BC,cAAc,EAAE,MAAM;EACtBC,cAAc,EAAE,MAAM;EAGtBC,MAAM,EAAE,MAAM;EACdC,MAAM,EAAE,MAAM;EACdC,qBAAqB,EAAE;AACzB,CAAC;AAED,MAAMC,4BAA4B,GAAG;EACnCC,SAAS,EAAET,UAAU,CAACC,kBAAkB;EACxCS,SAAS,EAAEV,UAAU,CAACE,kBAAkB;EACxCS,KAAK,EAAEX,UAAU,C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,MAAM,EAAE,IAAI,CAACzF,OAAO,CAACgH,WAAW,CAAC;MACjCC,IAAI,EAAE,IAAIb,UAAU,CAACN,WAAW,EAAEF,UAAU,EAAEmB,cAAc,CAACpB,UAAU;IACzE,CAAC;IAED,OAAOJ,UAAU;EACnB;EAEA2B,cAAcA,CAACC,UAAsB,EAAE7E,KAAK,EAA2B;IACrE,MAAMoB,MAA+B,GAAG;MACtC,GAAGyD,UAAU;MAEbnI,EAAE,EAAEmI,UAAU,CAACnI,EAAE,cAAAwE,MAAA,CAAclB,KAAK;IACtC,CAAC;IAGD,IAAIoB,MAAM,CAAC0D,WAAW,EAAE,CAExB;IACA,IAAI1D,MAAM,CAAC2D,YAAY,EAAE,CAEzB;IACA,OAAO3D,MAAM;EACf;AACF;AAEA,OAAO,SAAS4D,eAAeA,CAC7B5H,IAAqB,EACrBC,OAA0B,EACP;EACnB,OAAO,IAAIL,iBAAiB,CAAC,CAAC,CAACG,WAAW,CAACC,IAAI,EAAEC,OAAO,CAAC;AAC3D"}
|
|
@@ -3,7 +3,7 @@ const MAGIC_glTF = 0x46546c67;
|
|
|
3
3
|
const MAGIC_JSON = 0x4e4f534a;
|
|
4
4
|
const MAGIC_BIN = 0x004e4942;
|
|
5
5
|
const LE = true;
|
|
6
|
-
export
|
|
6
|
+
export function encodeGLBSync(glb, dataView) {
|
|
7
7
|
let byteOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
8
8
|
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
9
9
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode-glb.js","names":["copyPaddedStringToDataView","copyPaddedArrayBufferToDataView","MAGIC_glTF","MAGIC_JSON","MAGIC_BIN","LE","encodeGLBSync","glb","dataView","byteOffset","arguments","length","undefined","options","magic","version","json","binary","byteOffsetStart","setUint32","byteOffsetFileLength","byteOffsetJsonHeader","jsonString","JSON","stringify","jsonByteLength","byteOffsetBinHeader","binByteLength","fileByteLength"],"sources":["../../../../src/lib/encoders/encode-glb.ts"],"sourcesContent":["/* eslint-disable camelcase, max-statements */\nimport {\n copyPaddedStringToDataView,\n copyPaddedArrayBufferToDataView\n} from '@loaders.gl/loader-utils';\n\nconst MAGIC_glTF = 0x46546c67; // glTF in ASCII\nconst MAGIC_JSON = 0x4e4f534a; // JSON in ASCII\nconst MAGIC_BIN = 0x004e4942; // BIN\\0 in ASCII\n\nconst LE = true; // Binary GLTF is little endian.\n\nexport type GLBEncodeOptions = {};\n\n
|
|
1
|
+
{"version":3,"file":"encode-glb.js","names":["copyPaddedStringToDataView","copyPaddedArrayBufferToDataView","MAGIC_glTF","MAGIC_JSON","MAGIC_BIN","LE","encodeGLBSync","glb","dataView","byteOffset","arguments","length","undefined","options","magic","version","json","binary","byteOffsetStart","setUint32","byteOffsetFileLength","byteOffsetJsonHeader","jsonString","JSON","stringify","jsonByteLength","byteOffsetBinHeader","binByteLength","fileByteLength"],"sources":["../../../../src/lib/encoders/encode-glb.ts"],"sourcesContent":["/* eslint-disable camelcase, max-statements */\nimport {\n copyPaddedStringToDataView,\n copyPaddedArrayBufferToDataView\n} from '@loaders.gl/loader-utils';\n// import type {GLB} from '../types/glb-types';\n\nconst MAGIC_glTF = 0x46546c67; // glTF in ASCII\nconst MAGIC_JSON = 0x4e4f534a; // JSON in ASCII\nconst MAGIC_BIN = 0x004e4942; // BIN\\0 in ASCII\n\nconst LE = true; // Binary GLTF is little endian.\n\nexport type GLBEncodeOptions = {};\n\n/**\n * Encode the full GLB buffer with header etc\n *\n * @param glb\n * @param dataView - if `null`, does not encode but just calculates length\n * @param byteOffset\n * @param options\n * @returns\n *\n * @see https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#glb-file-format-specification\n * @todo type GLB argument\n */\nexport function encodeGLBSync(\n glb,\n dataView: DataView | null,\n byteOffset = 0,\n options: GLBEncodeOptions = {}\n) {\n const {magic = MAGIC_glTF, version = 2, json = {}, binary} = glb;\n\n const byteOffsetStart = byteOffset;\n\n // Write GLB Header\n if (dataView) {\n dataView.setUint32(byteOffset + 0, magic, LE); // Magic number (the ASCII string 'glTF').\n dataView.setUint32(byteOffset + 4, version, LE); // Version 2 of binary glTF container format uint32\n dataView.setUint32(byteOffset + 8, 0, LE); // Total byte length of generated file (uint32), will be set last\n }\n const byteOffsetFileLength = byteOffset + 8;\n byteOffset += 12; // GLB_FILE_HEADER_SIZE\n\n // Write the JSON chunk header\n const byteOffsetJsonHeader = byteOffset;\n if (dataView) {\n dataView.setUint32(byteOffset + 0, 0, LE); // Byte length of json chunk (will be written later)\n dataView.setUint32(byteOffset + 4, MAGIC_JSON, LE); // Chunk type\n }\n byteOffset += 8; // GLB_CHUNK_HEADER_SIZE\n\n // Write the JSON chunk\n const jsonString = JSON.stringify(json);\n byteOffset = copyPaddedStringToDataView(dataView, byteOffset, jsonString, 4);\n\n // Now we know the JSON chunk length so we can write it.\n if (dataView) {\n const jsonByteLength = byteOffset - byteOffsetJsonHeader - 8; // GLB_CHUNK_HEADER_SIZE\n dataView.setUint32(byteOffsetJsonHeader + 0, jsonByteLength, LE); // Byte length of json chunk (uint32)\n }\n\n // Write the BIN chunk if present. The BIN chunk is optional.\n if (binary) {\n const byteOffsetBinHeader = byteOffset;\n\n // Write the BIN chunk header\n if (dataView) {\n dataView.setUint32(byteOffset + 0, 0, LE); // Byte length BIN (uint32)\n dataView.setUint32(byteOffset + 4, MAGIC_BIN, LE); // Chunk type\n }\n byteOffset += 8; // GLB_CHUNK_HEADER_SIZE\n\n byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, binary, 4);\n\n // Now we know the BIN chunk length so we can write it.\n if (dataView) {\n const binByteLength = byteOffset - byteOffsetBinHeader - 8; // GLB_CHUNK_HEADER_SIZE\n dataView.setUint32(byteOffsetBinHeader + 0, binByteLength, LE); // Byte length BIN (uint32)\n }\n }\n\n // Now we know the glb file length so we can write it.\n if (dataView) {\n const fileByteLength = byteOffset - byteOffsetStart;\n data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