three.cad/src/react/fileExporter.js

40 lines
917 B
JavaScript
Raw Normal View History

2021-04-17 21:32:14 +08:00
const link = document.createElement( 'a' );
link.style.display = 'none';
document.body.appendChild( link );
function save(blob, filename) {
link.href = URL.createObjectURL(blob);
link.download = filename;
link.click();
}
function saveArrayBuffer( buffer, filename ) {
2021-04-18 05:08:14 +08:00
// save( new Blob( [ buffer ], { type: 'application/octet-stream' } ), filename );
save( new Blob( [ buffer ], { type: 'model/stl' } ), filename );
2021-04-17 21:32:14 +08:00
}
function saveString( text, filename ) {
2021-04-18 05:08:14 +08:00
// save( new Blob( [ text ], { type: 'text/plain' } ), filename );
save( new Blob( [ text ], { type: 'application/json' } ), filename );
2021-04-17 21:32:14 +08:00
}
export function STLExport() {
if (sc.selected[0] && sc.selected[0].userData.type == 'mesh') {
const result = STLexp.parse( sc.selected[0], { binary: true } );
saveArrayBuffer( result, 'box.stl' );
}
}
export function savePart() {
2021-04-18 05:08:14 +08:00
saveString( sc.saveString(), 'uncomp.json' );
2021-04-17 21:32:14 +08:00
}