From b989d9c778b5c153cc6e97aaa76779d447dd2207 Mon Sep 17 00:00:00 2001 From: David Carley Date: Tue, 23 Mar 2021 22:19:03 -0700 Subject: [PATCH] Fixed the 3d preview on Safari --- src/js/path-viewer.js | 52 +++++++++++++++++++------------------------ src/py/bbctrl/Web.py | 2 +- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/js/path-viewer.js b/src/js/path-viewer.js index 03d4d0b..f790af0 100644 --- a/src/js/path-viewer.js +++ b/src/js/path-viewer.js @@ -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); + } }, diff --git a/src/py/bbctrl/Web.py b/src/py/bbctrl/Web.py index a19a677..0b05e71 100644 --- a/src/py/bbctrl/Web.py +++ b/src/py/bbctrl/Web.py @@ -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')