Skip to content

Commit

Permalink
Merge pull request #534 from KhronosGroup/remove-axios
Browse files Browse the repository at this point in the history
Replace `axios` by `fetch`
  • Loading branch information
jim-ec authored Feb 27, 2024
2 parents 9275c22 + 3b1950b commit a9b9c86
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 37 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"sourceType": "module"
},
"globals":{
"axios": false,
"dat": false,
"Stats": false
},
Expand Down
1 change: 0 additions & 1 deletion app_web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"license": "Apache-2.0",
"dependencies": {
"@khronosgroup/gltf-viewer": "..",
"axios": "^0.21.1",
"buefy": "^0.9.4",
"fast-png": "^5.0.3",
"gl-matrix": "^3.2.1",
Expand Down
2 changes: 1 addition & 1 deletion app_web/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default {
resolve({
browser: true,
preferBuiltins: true,
dedupe: ['gl-matrix', 'axios', 'jpeg-js', 'fast-png']
dedupe: ['gl-matrix', 'jpeg-js', 'fast-png']
}),
builtins(),
scss(),
Expand Down
6 changes: 2 additions & 4 deletions app_web/src/model_path_provider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from 'axios';
import path from 'path';

export class GltfModelPathProvider
Expand All @@ -12,9 +11,8 @@ export class GltfModelPathProvider

async initialize()
{
const self = this;
const response = await axios.get(this.modelIndexerPath);
self.populateDictionary(response.data);
const response = await fetch(this.modelIndexerPath);
this.populateDictionary(await response.json());
}

resolve(modelKey, flavour)
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"author": "Khronos Group Inc.",
"license": "Apache-2.0",
"dependencies": {
"axios": "^0.23.0",
"fast-png": "^5.0.3",
"gl-matrix": "^3.2.1",
"jpeg-js": "^0.4.3"
Expand All @@ -47,4 +46,4 @@
"url": "https://github.com/KhronosGroup/glTF-Sample-Viewer/issues"
},
"homepage": "https://github.com/KhronosGroup/glTF-Sample-Viewer/#readme"
}
}
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
resolve({
browser: false,
preferBuiltins: false,
dedupe: ['gl-matrix', 'axios', 'jpeg-js', 'fast-png']
dedupe: ['gl-matrix', 'jpeg-js', 'fast-png']
}),
copy({
targets: [
Expand Down
36 changes: 16 additions & 20 deletions source/ResourceLoader/resource_loader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

import axios from 'axios';
import { glTF } from '../gltf/gltf.js';
import { getIsGlb, getContainingFolder } from '../gltf/utils.js';
import { GlbParser } from './glb_parser.js';
Expand Down Expand Up @@ -54,9 +52,8 @@ class ResourceLoader
if (typeof gltfFile === "string")
{
isGlb = getIsGlb(gltfFile);
let response = await axios.get(gltfFile, { responseType: isGlb ? "arraybuffer" : "json" });
json = response.data;
data = response.data;
const response = await fetch(gltfFile);
json = data = await (isGlb ? response.arrayBuffer() : response.json());
filename = gltfFile;
}
else if (gltfFile instanceof ArrayBuffer)
Expand Down Expand Up @@ -129,9 +126,8 @@ class ResourceLoader
let image = undefined;
if (typeof environmentFile === "string")
{
let response = await axios.get(environmentFile, { responseType: "arraybuffer" });

image = await loadHDR(new Uint8Array(response.data));
let response = await fetch(environmentFile);
image = await loadHDR(new Uint8Array(await response.arrayBuffer()));
}
else if (environmentFile instanceof ArrayBuffer)
{
Expand Down Expand Up @@ -334,12 +330,12 @@ async function _loadEnvironmentFromPanorama(imageHDR, view, luts)
}

environment.images.push(new gltfImage(
undefined,
GL.TEXTURE_2D,
0,
undefined,
undefined,
ImageMimeType.GLTEXTURE,
undefined,
GL.TEXTURE_2D,
0,
undefined,
undefined,
ImageMimeType.GLTEXTURE,
environmentFiltering.ggxLutTextureID));
const lutTexture = new gltfTexture(lutSamplerIdx, [imageIdx++], GL.TEXTURE_2D);
lutTexture.initialized = true; // iblsampler has already initialized the texture
Expand All @@ -351,12 +347,12 @@ async function _loadEnvironmentFromPanorama(imageHDR, view, luts)
// Sheen
// Charlie
environment.images.push(new gltfImage(
undefined,
GL.TEXTURE_2D,
0,
undefined,
undefined,
ImageMimeType.GLTEXTURE,
undefined,
GL.TEXTURE_2D,
0,
undefined,
undefined,
ImageMimeType.GLTEXTURE,
environmentFiltering.charlieLutTextureID));
const charlieLut = new gltfTexture(lutSamplerIdx, [imageIdx++], GL.TEXTURE_2D);
charlieLut.initialized = true; // iblsampler has already initialized the texture
Expand Down
11 changes: 5 additions & 6 deletions source/gltf/buffer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from 'axios';
import { getContainingFolder } from './utils.js';
import { GltfObject } from './gltf_object.js';

Expand Down Expand Up @@ -41,13 +40,13 @@ class gltfBuffer extends GltfObject
return false;
}

const self = this;
axios.get(getContainingFolder(gltf.path) + this.uri, { responseType: 'arraybuffer'})
.then(function(response)
{
self.buffer = response.data;
fetch(getContainingFolder(gltf.path) + this.uri)
.then(response => response.arrayBuffer())
.then(buffer => {
this.buffer = buffer;
callback();
});

return true;
}

Expand Down
1 change: 0 additions & 1 deletion source/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"author": "Khronos Group Inc.",
"license": "Apache-2.0",
"dependencies": {
"axios": "^0.21.1",
"fast-png": "^5.0.3",
"gl-matrix": "^3.2.1",
"jpeg-js": "^0.4.3"
Expand Down

0 comments on commit a9b9c86

Please sign in to comment.