From c14a823dc148b2ca6cbafcfee1065b977536998a Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Tue, 15 Jul 2025 15:16:54 -0700 Subject: [PATCH] Update visual defaults Somewhat more conventional visual presentation: + Use a neutral gray background a-la most other CAD/modelling software for better contrast with the geometry (which defaults to a bright yellow). This is done with the "skybox-environment" image in model-viewer, so add a new setting value in settings.ts for this (it can be overriden in the URL just like other settings) + But using a skybox will cause that image to be used for lighting too, which is clearly not desired. So fetch a nice professional HDRI image from Polyhaven for lighting. This is much better (more directional, higher contrast) than the default light environment anyway. + The checkerboard texture isn't really a good default. Use a 1x1 white pixel instead, essentially presenting the model materials unchanged. Also collect the default color in gltf.py out of the code and put it next to the texture for clarity. This should probably be wired through to a setting at some point. Signed-off-by: Andy Ross --- frontend/misc/settings.ts | 6 +++++- frontend/viewer/ModelViewerWrapper.vue | 4 ++-- yacv_server/gltf.py | 11 ++++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/frontend/misc/settings.ts b/frontend/misc/settings.ts index 0a37825..e657ab2 100644 --- a/frontend/misc/settings.ts +++ b/frontend/misc/settings.ts @@ -29,7 +29,11 @@ export async function settings() { panSensitivity: 1, exposure: 1, shadowIntensity: 0, - background: '', + // Nice low-res outdoor/high-contrast HDRI image (CC0 licensed) for lighting + background: "https://dl.polyhaven.org/file/ph-assets/HDRIs/hdr/1k/qwantani_afternoon_1k.hdr", + // Uniform (1x1 pixel) medium gray background for visibility + skybox: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNsaFjwHwAFyQKh26fFAAAAAABJRU5ErkJggg==", + }; // Auto-override any settings from the URL diff --git a/frontend/viewer/ModelViewerWrapper.vue b/frontend/viewer/ModelViewerWrapper.vue index e35bd4f..b94ac42 100644 --- a/frontend/viewer/ModelViewerWrapper.vue +++ b/frontend/viewer/ModelViewerWrapper.vue @@ -215,7 +215,7 @@ watch(disableTap, (newDisableTap) => { @@ -302,4 +302,4 @@ watch(disableTap, (newDisableTap) => { float: left; transition: width 0.3s; } - \ No newline at end of file + diff --git a/yacv_server/gltf.py b/yacv_server/gltf.py index 6c4a2df..df61a2d 100644 --- a/yacv_server/gltf.py +++ b/yacv_server/gltf.py @@ -4,9 +4,10 @@ import numpy as np from build123d import Location, Plane, Vector from pygltflib import * -_checkerboard_image_bytes = base64.decodebytes( - b'iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAF0lEQVQI12N49OjR////Gf' - b'/////48WMATwULS8tcyj8AAAAASUVORK5CYII=') +# PNG file containing 1x1 while pixel +_default_tex = (b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+ip1sAAAAASUVORK5CYII=') + +_default_color = (1.0, 0.75, 0.0, 1.0) def get_version() -> str: try: @@ -36,7 +37,7 @@ class GLTFMgr: vertex_positions: List[float] # x, y, z vertex_colors: List[float] # r, g, b, a - def __init__(self, image: Optional[Tuple[bytes, str]] = (_checkerboard_image_bytes, 'image/png')): + def __init__(self, image: Optional[Tuple[bytes, str]] = (_default_tex, 'image/png')): self.gltf = GLTF2( asset=Asset(generator=f"yacv_server@{get_version()}"), scene=0, @@ -79,7 +80,7 @@ class GLTFMgr: def add_face(self, vertices_raw: List[Vector], indices_raw: List[Tuple[int, int, int]], tex_coord_raw: List[Tuple[float, float]], color: Optional[Tuple[float, float, float, float]] = None): """Add a face to the GLTF mesh""" - if color is None: color = (1.0, 0.75, 0.0, 1.0) + if color is None: color = _default_color # assert len(vertices_raw) == len(tex_coord_raw), f"Vertices and texture coordinates have different lengths" # assert min([i for t in indices_raw for i in t]) == 0, f"Face indices start at {min(indices_raw)}" # assert max([e for t in indices_raw for e in t]) < len(vertices_raw), f"Indices have non-existing vertices"