Skip to content
This repository was archived by the owner on Jan 24, 2020. It is now read-only.

Commit e10dbb3

Browse files
author
Avaer Kazmer
committed
Add model file reading
1 parent 8dd199c commit e10dbb3

File tree

1 file changed

+14
-40
lines changed

1 file changed

+14
-40
lines changed

index.html

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -887,48 +887,22 @@
887887

888888
console.log(`file ${i}: ${file.name}`);
889889

890-
const _loadModel = u => {
890+
const reader = new FileReader();
891+
reader.onload = async e => {
892+
let data = new Uint8Array(reader.result, 0, reader.result.byteLength);
893+
const d = '/lol';
894+
const p = `${d}/${file.name}`;
895+
console.log('writing', p, data.byteLength);
896+
await localforage.write(p, data);
897+
data = null;
898+
data = await localforage.read(p);
899+
console.log('got file', data.map(data => data.length));
900+
const u = URL.createObjectURL(new Blob(data, {
901+
type: 'application/octet-stream',
902+
}));
891903
_addNewApp(u, faviconImg, 'model', -1);
892904
};
893-
const _loadLocal = () => {
894-
console.log('loading', file.name);
895-
const reader = new FileReader();
896-
reader.onload = async e => {
897-
let data = new Uint8Array(reader.result, 0, reader.result.byteLength);
898-
const d = '/lol';
899-
const p = `${d}/${file.name}`;
900-
console.log('writing', p, data.byteLength);
901-
await localforage.write(p, data);
902-
data = null;
903-
data = await localforage.read(p);
904-
console.log('got file', data.map(data => data.length));
905-
const u = URL.createObjectURL(new Blob(data, {
906-
type: 'application/octet-stream',
907-
}));
908-
_loadModel(u);
909-
};
910-
reader.readAsArrayBuffer(file);
911-
};
912-
const _loadRemote = () => {
913-
const u = `https://webaverse.s3.amazonaws.com/lol/${file.name}`;
914-
fetch(u, {
915-
method: 'PUT',
916-
body: file,
917-
mode: 'cors',
918-
})
919-
.then(res => res.arrayBuffer())
920-
.then(() => {
921-
_loadModel(u);
922-
})
923-
.catch(err => {
924-
console.warn(err.stack);
925-
});
926-
};
927-
if (!_isInMultiverse()) {
928-
_loadLocal();
929-
} else {
930-
_loadRemote();
931-
}
905+
reader.readAsArrayBuffer(file);
932906
}
933907
}
934908
}

0 commit comments

Comments
 (0)