From 33434aed834d2e61b9c33bac6825e007d9705afb Mon Sep 17 00:00:00 2001 From: Moises Pelaez Date: Wed, 15 May 2024 18:54:13 -0400 Subject: [PATCH 1/3] Fix HTML5 full screen auto resize --- blender/arm/write_data.py | 52 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/blender/arm/write_data.py b/blender/arm/write_data.py index 9b2078422..08bdb6581 100644 --- a/blender/arm/write_data.py +++ b/blender/arm/write_data.py @@ -347,6 +347,9 @@ def write_khafilejs(is_play, export_physics: bool, export_navigation: bool, expo if wrd.arm_winresize or state.target == 'html5': assets.add_khafile_def('arm_resizable') + if get_winmode(wrd.arm_winmode) == 1 and state.target.startswith('html5'): + assets.add_khafile_def('kha_html5_disable_automatic_size_adjust') + # if bpy.data.scenes[0].unit_settings.system_rotation == 'DEGREES': # assets.add_khafile_def('arm_degrees') @@ -467,7 +470,17 @@ def write_mainhx(scene_name, resx, resy, is_play, is_publish): with open('Sources/Main.hx', 'w', encoding="utf-8") as f: f.write( """// Auto-generated -package ; +package; +""") + if winmode == 1 and state.target.startswith('html5'): + f.write(""" +import js.Browser.document; +import js.Browser.window; +import js.html.CanvasElement; +import kha.Macros; +""") + + f.write(""" class Main { public static inline var projectName = '""" + arm.utils.safestr(wrd.arm_project_name) + """'; public static inline var projectVersion = '""" + arm.utils.safestr(wrd.arm_project_version) + """'; @@ -487,7 +500,12 @@ class Main { public static inline var resolutionSize = """ + str(rpdat.arm_rp_resolution_size) + """;""") f.write(""" - public static function main() {""") + public static function main() { + """) + + if winmode == 1 and state.target.startswith('html5'): + f.write("""setFullWindowCanvas();""") + if rpdat.arm_skin != 'Off': f.write(""" iron.object.BoneAnimation.skinMaxBones = """ + str(rpdat.arm_skin_max_bones) + """;""") @@ -526,6 +544,36 @@ class Main { """ + pathpack + """.renderpath.RenderPathCreator.get ); } + """) + + if winmode == 1 and state.target.startswith('html5'): + f.write(""" + static function setFullWindowCanvas(): Void { + document.documentElement.style.padding = "0"; + document.documentElement.style.margin = "0"; + document.body.style.padding = "0"; + document.body.style.margin = "0"; + final canvas: CanvasElement = cast document.getElementById(Macros.canvasId()); + canvas.style.display = "block"; + final resize = function() { + var w = document.documentElement.clientWidth; + var h = document.documentElement.clientHeight; + if (w == 0 || h == 0) { + w = window.innerWidth; + h = window.innerHeight; + } + canvas.width = Std.int(w * window.devicePixelRatio); + canvas.height = Std.int(h * window.devicePixelRatio); + if (canvas.style.width == "") { + canvas.style.width = "100%"; + canvas.style.height = "100%"; + } + } + window.onresize = resize; + resize(); + }""") + + f.write(""" } """) From 9061d15990343efb4d4705d6c426f1292cd53e84 Mon Sep 17 00:00:00 2001 From: Moises Pelaez Date: Wed, 15 May 2024 19:27:53 -0400 Subject: [PATCH 2/3] Improve html5 fullscreen autoresize styling --- blender/arm/write_data.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/blender/arm/write_data.py b/blender/arm/write_data.py index 08bdb6581..57e4f5b69 100644 --- a/blender/arm/write_data.py +++ b/blender/arm/write_data.py @@ -472,6 +472,7 @@ def write_mainhx(scene_name, resx, resy, is_play, is_publish): """// Auto-generated package; """) + if winmode == 1 and state.target.startswith('html5'): f.write(""" import js.Browser.document; @@ -479,14 +480,13 @@ def write_mainhx(scene_name, resx, resy, is_play, is_publish): import js.html.CanvasElement; import kha.Macros; """) - + f.write(""" class Main { public static inline var projectName = '""" + arm.utils.safestr(wrd.arm_project_name) + """'; public static inline var projectVersion = '""" + arm.utils.safestr(wrd.arm_project_version) + """'; public static inline var projectPackage = '""" + arm.utils.safestr(wrd.arm_project_package) + """';""") - if rpdat.rp_voxels == 'Voxel GI' or rpdat.rp_voxels == 'Voxel AO': f.write(""" public static inline var voxelgiClipmapCount = """ + str(rpdat.arm_voxelgi_clipmap_count) + """; @@ -499,16 +499,16 @@ class Main { f.write(""" public static inline var resolutionSize = """ + str(rpdat.arm_rp_resolution_size) + """;""") - f.write(""" - public static function main() { - """) - + f.write("""\n + public static function main() {""") if winmode == 1 and state.target.startswith('html5'): - f.write("""setFullWindowCanvas();""") + f.write(""" + setFullWindowCanvas();""") if rpdat.arm_skin != 'Off': f.write(""" iron.object.BoneAnimation.skinMaxBones = """ + str(rpdat.arm_skin_max_bones) + """;""") + if rpdat.rp_shadows: if rpdat.rp_shadowmap_cascades != '1': f.write(""" @@ -517,6 +517,7 @@ class Main { if rpdat.arm_shadowmap_bounds != 1.0: f.write(""" iron.object.LightObject.cascadeBounds = """ + str(rpdat.arm_shadowmap_bounds) + """;""") + if is_publish and wrd.arm_loadscreen: asset_references = list(set(assets.assets)) loadscreen_class = 'armory.trait.internal.LoadingScreen' @@ -525,11 +526,15 @@ class Main { f.write(""" armory.system.Starter.numAssets = """ + str(len(asset_references)) + """; armory.system.Starter.drawLoading = """ + loadscreen_class + """.render;""") + if wrd.arm_ui == 'Enabled': if wrd.arm_canvas_img_scaling_quality == 'low': - f.write(f"armory.ui.Canvas.imageScaleQuality = kha.graphics2.ImageScaleQuality.Low;") + f.write(""" + armory.ui.Canvas.imageScaleQuality = kha.graphics2.ImageScaleQuality.Low;""") elif wrd.arm_canvas_img_scaling_quality == 'high': - f.write(f"armory.ui.Canvas.imageScaleQuality = kha.graphics2.ImageScaleQuality.High;") + f.write(""" + armory.ui.Canvas.imageScaleQuality = kha.graphics2.ImageScaleQuality.High;""") + f.write(""" armory.system.Starter.main( '""" + arm.utils.safestr(scene_name) + scene_ext + """', @@ -543,11 +548,10 @@ class Main { """ + ('true' if wrd.arm_vsync else 'false') + """, """ + pathpack + """.renderpath.RenderPathCreator.get ); - } - """) + }""") if winmode == 1 and state.target.startswith('html5'): - f.write(""" + f.write("""\n static function setFullWindowCanvas(): Void { document.documentElement.style.padding = "0"; document.documentElement.style.margin = "0"; From 81146f6c31d3d4811fb171d94302f451e800d9e1 Mon Sep 17 00:00:00 2001 From: Moises Pelaez Date: Wed, 15 May 2024 19:34:16 -0400 Subject: [PATCH 3/3] Minor changes in code-style --- blender/arm/write_data.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/blender/arm/write_data.py b/blender/arm/write_data.py index 57e4f5b69..cf55e50c4 100644 --- a/blender/arm/write_data.py +++ b/blender/arm/write_data.py @@ -470,16 +470,14 @@ def write_mainhx(scene_name, resx, resy, is_play, is_publish): with open('Sources/Main.hx', 'w', encoding="utf-8") as f: f.write( """// Auto-generated -package; -""") +package;\n""") if winmode == 1 and state.target.startswith('html5'): f.write(""" import js.Browser.document; import js.Browser.window; import js.html.CanvasElement; -import kha.Macros; -""") +import kha.Macros;\n""") f.write(""" class Main { @@ -578,8 +576,7 @@ class Main { }""") f.write(""" -} -""") +}\n""") def write_indexhtml(w, h, is_publish): wrd = bpy.data.worlds['Arm']