mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-08 09:24:18 +01:00
23 lines
No EOL
675 B
JavaScript
23 lines
No EOL
675 B
JavaScript
import {ParseStl} from './stl/stl-reader'
|
|
|
|
export function LoadSTLFromURL(url, solidsConsumer) {
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.onreadystatechange = function(){
|
|
if (this.readyState == 4){
|
|
//console.log(this.response, typeof this.response);
|
|
if (this.status == 200) {
|
|
const reader = new FileReader();
|
|
reader.addEventListener("loadend", () => {
|
|
const solids = ParseStl(reader.result);
|
|
solidsConsumer(solids)
|
|
});
|
|
reader.readAsArrayBuffer(this.response);
|
|
} else {
|
|
solidsConsumer(null, this.status);
|
|
}
|
|
}
|
|
};
|
|
xhr.open('GET', url);
|
|
xhr.responseType = 'blob';
|
|
xhr.send();
|
|
} |