jsketcher/web/app/cad/stl/io.js
2022-08-15 23:47:20 -07:00

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();
}