diff --git a/apps/jscad-web/main.js b/apps/jscad-web/main.js index 6a8d602..2ae9bea 100644 --- a/apps/jscad-web/main.js +++ b/apps/jscad-web/main.js @@ -13,6 +13,7 @@ import * as remote from './src/remote.js' import { formatStacktrace } from './src/stacktrace.js' import { ViewState } from './src/viewState.js' import * as welcome from './src/welcome.js' +import { runMain } from '../../packages/worker/worker.js' export const byId = id => document.getElementById(id) const appBase = document.baseURI @@ -20,6 +21,7 @@ let currentBase = appBase const toUrl = path => new URL(path, appBase).toString() const viewState = new ViewState() +viewState.onRequireReRender = ()=>paramChangeCallback(lastParams) const gizmo = (window.gizmo = new Gizmo()) byId('overlay').parentNode.appendChild(gizmo) @@ -173,7 +175,7 @@ sendCmdAndSpin('init', { }, }).then(() => { if (loadDefault) { - runScript({ script: defaultCode }) + runScript({ script: defaultCode, smooth: viewState.smoothRender }) } }) @@ -189,18 +191,18 @@ const paramChangeCallback = async params => { working = true let result try{ - result = await sendCmdAndSpin('runMain', { params }) + result = await sendCmdAndSpin('runMain', { params, smooth: viewState.smoothRender }) } finally{ working = false } - handlers.entities(result) + handlers.entities(result, {smooth: viewState.smoothRender}) if(lastParams && lastParams != params) paramChangeCallback(lastParams) } const runScript = async ({ script, url = './index.js', base = currentBase, root }) => { currentBase = base loadDefault = false // don't load default model if something else was loaded - const result = await sendCmdAndSpin('runScript', { script, url, base, root }) + const result = await sendCmdAndSpin('runScript', { script, url, base, root, smooth: viewState.smoothRender }) genParams({ target: byId('paramsDiv'), params: result.def || {}, callback: paramChangeCallback }) handlers.entities(result) } diff --git a/apps/jscad-web/src/viewState.js b/apps/jscad-web/src/viewState.js index ba54dbe..49b7108 100644 --- a/apps/jscad-web/src/viewState.js +++ b/apps/jscad-web/src/viewState.js @@ -16,6 +16,7 @@ export class ViewState { const darkMode = byId('dark-mode') const showAxis = byId('show-axis') const showGrid = byId('show-grid') + const smoothRender = byId('smooth-render') darkMode.addEventListener('change', () => { this.themeName = darkMode.checked ? 'dark' : 'light' if (darkMode.checked) { @@ -25,6 +26,9 @@ export class ViewState { } this.setTheme(this.themeName) }) + smoothRender.addEventListener('change', () => { + this.setSmoothRender(smoothRender.checked) + }) showAxis.addEventListener('change', () => this.setAxes(showAxis.checked)) showGrid.addEventListener('change', () => this.setGrid(showGrid.checked)) } @@ -41,6 +45,12 @@ export class ViewState { this.saveState() } + setSmoothRender(smoothRender, fireEvent = true) { + this.smoothRender = smoothRender + this.saveState() + if(fireEvent) this.onRequireReRender() + } + setTheme(themeName) { if (!themes[themeName]) throw new Error(`unknown theme ${themeName}`) this.themeName = themeName @@ -86,7 +96,7 @@ export class ViewState { if (grid) items.push({ id: 'grid', items: grid }) if (model) items.push({ id: 'model', items: model }) - this.viewer?.setScene({ items }) + this.viewer?.setScene({ items }, {smooth:this.smoothRender}) } setEngine(viewer) { @@ -108,6 +118,8 @@ export class ViewState { byId('show-axis').checked = this.showAxis this.showGrid = localStorage.getItem('engine.showGrid') !== 'false' byId('show-grid').checked = this.showGrid + this.smoothRender = !!localStorage.getItem('engine.smoothRender') + byId('smooth-render').checked = this.smoothRender const cameraLocation = localStorage.getItem('camera.location') this.camera = cameraLocation ? JSON.parse(cameraLocation) : { position: [180, -180, 220] } } @@ -116,5 +128,8 @@ export class ViewState { localStorage.setItem('engine.theme', this.themeName) localStorage.setItem('engine.showAxis', this.showAxis) localStorage.setItem('engine.showGrid', this.showGrid) + localStorage.setItem('engine.smoothRender', this.smoothRender) } + + onRequireReRender(){} } diff --git a/apps/jscad-web/static/index.html b/apps/jscad-web/static/index.html index 8644dc0..17e8f24 100644 --- a/apps/jscad-web/static/index.html +++ b/apps/jscad-web/static/index.html @@ -82,6 +82,7 @@