Merge pull request #46 from dacarley/safari-3d-preview

Fixed the 3d preview on Safari
This commit is contained in:
OneFinityCNC
2021-03-31 23:28:52 -04:00
committed by GitHub
2 changed files with 24 additions and 30 deletions

View File

@@ -125,7 +125,7 @@ module.exports = {
methods: {
update: function () {
update: async function () {
if (!this.webglAvailable) {
return;
}
@@ -142,38 +142,28 @@ module.exports = {
if (!this.enabled || !this.toolpath.filename) return;
function get(url) {
var d = $.Deferred();
var xhr = new XMLHttpRequest();
async function get(url) {
const response = await fetch(`${url}?${Math.random()}`);
const arrayBuffer = await response.arrayBuffer();
xhr.open('GET', url + '?' + Math.random(), true);
xhr.responseType = 'arraybuffer';
xhr.onload = function (e) {
if (xhr.response) d.resolve(new Float32Array(xhr.response));
else d.reject();
};
xhr.send();
return d.promise();
return new Float32Array(arrayBuffer);
}
var d1 = get('/api/path/' + this.toolpath.filename + '/positions');
var d2 = get('/api/path/' + this.toolpath.filename + '/speeds');
const [positions, speeds] = await Promise.all([
get('/api/path/' + this.toolpath.filename + '/positions'),
get('/api/path/' + this.toolpath.filename + '/speeds')
]);
$.when(d1, d2).done(function (positions, speeds) {
this.positions = positions
this.speeds = speeds;
this.loading = false;
this.positions = positions
this.speeds = speeds;
this.loading = false;
// Update scene
this.scene = new THREE.Scene();
this.draw(this.scene);
this.snap(this.snapView);
// Update scene
this.scene = new THREE.Scene();
this.draw(this.scene);
this.snap(this.snapView);
this.update_view();
}.bind(this))
this.update_view();
},
@@ -264,8 +254,12 @@ module.exports = {
}
var bounds = new THREE.Box3(min, max);
if (bounds.isEmpty()) envelope.geometry = this.create_empty_geom();
else envelope.geometry = this.create_bbox_geom(bounds);
if (bounds.isEmpty()) {
envelope.geometry = this.create_empty_geom();
}
else {
envelope.geometry = this.create_bbox_geom(bounds);
}
},

View File

@@ -312,7 +312,7 @@ class PathHandler(bbctrl.APIHandler):
self.write_json(meta)
return
filename = filename + '-' + dataType[1:] + '.gz'
filename = filename + '-' + dataType[1:]
self.set_header('Content-Disposition', 'filename="%s"' % filename)
self.set_header('Content-Type', 'application/octet-stream')
self.set_header('Content-Encoding', 'gzip')