From c617b252ff362e2ef6c91dcefce1af4ee93d7b9a Mon Sep 17 00:00:00 2001 From: Stephen Early Date: Sat, 10 Apr 2021 17:39:46 +0100 Subject: [PATCH] Improve WebGL export javascript template Several improvements to the javascript in the template: * Render on demand rather than continuously * Support high-DPI displays * Fix the frustum depth for both cameras * Deal correctly with the browser window being resized * Only show controls for objects with geometry Also some changes made for code clarity: * Use 'const' and 'let' instead of 'var', as appropriate * Use for...of and .map() instead of iterating over arrays using a loop counter --- src/Mod/Arch/importWebGL.py | 783 ++++++++++++++++++++---------------- 1 file changed, 434 insertions(+), 349 deletions(-) diff --git a/src/Mod/Arch/importWebGL.py b/src/Mod/Arch/importWebGL.py index 3558dca0a8..e2e2302200 100644 --- a/src/Mod/Arch/importWebGL.py +++ b/src/Mod/Arch/importWebGL.py @@ -38,6 +38,7 @@ """FreeCAD WebGL Exporter""" import FreeCAD,Mesh,Draft,Part,OfflineRenderingUtils,json,six +import textwrap if FreeCAD.GuiUp: import FreeCADGui @@ -60,291 +61,324 @@ base = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!#$%&()*+- baseFloat = ',.-0123456789' def getHTMLTemplate(): - return """ + return textwrap.dedent("""\ + $pagetitle - - - + + + + + - """ + """) def export( exportList, filename, colors = None, camera = None ): """Exports objects to an html file""" @@ -772,11 +858,10 @@ def export( exportList, filename, colors = None, camera = None ): html = html.replace('$version',version[0] + '.' + version[1] + '.' + version[2]) # Remove data compression in JS - if disableCompression: html = html.replace('$disableCompression','true') - else: html = html.replace('$disableCompression','false') + data['compressed'] = not disableCompression + data['base'] = base + data['baseFloat'] = baseFloat - html = html.replace('$base', base) - html = html.replace('$float', baseFloat) html = html.replace('$data', json.dumps(data, separators=(',', ':')) ) # Shape Data if six.PY2: