From 7166f9fe3d063efe9b2bdf841f4cf59fadb82fbb Mon Sep 17 00:00:00 2001 From: Yeicor <4929005+Yeicor@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:20:56 +0100 Subject: [PATCH] Improved image location after build123d update --- frontend/misc/network.ts | 3 +++ yacv_server/cad.py | 17 +++++++---------- yacv_server/logo.py | 5 ++--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/frontend/misc/network.ts b/frontend/misc/network.ts index 44c9b89..f2e410b 100644 --- a/frontend/misc/network.ts +++ b/frontend/misc/network.ts @@ -80,6 +80,9 @@ export class NetworkManager extends EventTarget { controller.abort(); // Notify the server that we are done }); } + } else { + // Server is down, wait a little longer before retrying + await new Promise(resolve => setTimeout(resolve, 10 * settings.monitorEveryMs)); } controller.abort(); } catch (e) { // Ignore errors (retry very soon) diff --git a/yacv_server/cad.py b/yacv_server/cad.py index 702078d..3cf78d9 100644 --- a/yacv_server/cad.py +++ b/yacv_server/cad.py @@ -91,13 +91,6 @@ def image_to_gltf(source: str | bytes, center: any, width: Optional[float] = Non if not isinstance(center_loc, TopLoc_Location): raise ValueError('Center location not valid') plane = Plane(Location(center_loc)) - # Convert coordinates system - plane.origin = Vector(plane.origin.X, plane.origin.Z, -plane.origin.Y) - plane.z_dir = -plane.y_dir - plane.y_dir = plane.z_dir - - def vert(v: Vector) -> Tuple[float, float, float]: - return v.X, v.Y, v.Z # Load the image to a byte buffer img = Image.open(source) @@ -121,13 +114,17 @@ def image_to_gltf(source: str | bytes, center: any, width: Optional[float] = Non img.save(img_buf, format=format) img_buf = img_buf.getvalue() + # Convert coordinates system as a last step (gltf is Y-up instead of Z-up) + def vert(v: Vector) -> Vector: + return Vector(v.X, v.Z, -v.Y) + # Build the gltf mgr = GLTFMgr(image=(img_buf, save_mime)) mgr.add_face([ - vert(plane.origin - plane.x_dir * width / 2 - plane.y_dir * height / 2), - vert(plane.origin + plane.x_dir * width / 2 - plane.y_dir * height / 2), - vert(plane.origin + plane.x_dir * width / 2 + plane.y_dir * height / 2), vert(plane.origin - plane.x_dir * width / 2 + plane.y_dir * height / 2), + vert(plane.origin + plane.x_dir * width / 2 + plane.y_dir * height / 2), + vert(plane.origin + plane.x_dir * width / 2 - plane.y_dir * height / 2), + vert(plane.origin - plane.x_dir * width / 2 - plane.y_dir * height / 2), ], [ (0, 2, 1), (0, 3, 2), diff --git a/yacv_server/logo.py b/yacv_server/logo.py index fbdcab2..602fde8 100644 --- a/yacv_server/logo.py +++ b/yacv_server/logo.py @@ -19,9 +19,8 @@ def build_logo(text: bool = True) -> Dict[str, Union[Part, Location, str]]: Text('Yet Another\nCAD Viewer', 7, font_path='/usr/share/fonts/TTF/OpenSans-Regular.ttf') extrude(amount=1) - logo_img_location = logo_obj.faces().group_by(Axis.X)[0].face().center_location # Avoid overlapping: - logo_img_location.position = Vector(logo_img_location.position.X - 4e-2, logo_img_location.position.Y, - logo_img_location.position.Z) + logo_img_location = logo_obj.faces().group_by(Axis.X)[0].face().center_location + logo_img_location *= Location((0, 0, 4e-2), (0, 0, 90)) # Avoid overlapping and adjust placement logo_img_path = os.path.join(ASSETS_DIR, 'img.jpg') img_glb_bytes, img_name = image_to_gltf(logo_img_path, logo_img_location, height=18)