diff --git a/yacv_server/logo.py b/yacv_server/logo.py index b7487d3..8f774f5 100644 --- a/yacv_server/logo.py +++ b/yacv_server/logo.py @@ -4,12 +4,21 @@ import os from OCP.TopoDS import TopoDS_Shape from build123d import * +from build123d import Shape def build_logo() -> TopoDS_Shape: """Builds the CAD part of the logo""" - with BuildPart(Plane.XY.offset(30)) as logo_obj: - Box(10, 20, 30) + with BuildPart(Plane.XY.offset(50)) as logo_obj: + Box(22, 40, 30) + fillet(edges().filter_by(Axis.Y).group_by(Axis.Z)[-1], 10) + offset(solid(), 2, openings=faces().group_by(Axis.Z)[0] + faces().filter_by(Plane.XZ)) + text_at_plane = Plane.YZ + text_at_plane.origin = faces().group_by(Axis.X)[-1].face().center() + with BuildSketch(text_at_plane.location): + Text('Yet Another\nCAD Viewer', 7, font_path='/usr/share/fonts/TTF/OpenSans-Regular.ttf') + extrude(amount=1) + return logo_obj.part.wrapped diff --git a/yacv_server/tessellate.py b/yacv_server/tessellate.py index a5e6c2c..6ae0f15 100644 --- a/yacv_server/tessellate.py +++ b/yacv_server/tessellate.py @@ -18,6 +18,7 @@ from OCP.TopoDS import TopoDS_Face, TopoDS_Edge, TopoDS_Shape, TopoDS_Vertex from build123d import Face, Vector, Shape, Vertex from pygltflib import LINE_STRIP, GLTF2, Material, PbrMetallicRoughness, TRIANGLES, POINTS, TextureInfo +import mylogger from gltf import create_gltf, _checkerboard_image @@ -106,12 +107,15 @@ def _tessellate_face( ) -> GLTF2: """Tessellate a face into a list of triangle vertices and a list of triangle indices""" face = Face(ocp_face) - print("Tessellating face", face.center()) + face.mesh(tolerance, angular_tolerance) + loc = TopLoc_Location() + poly = BRep_Tool.Triangulation_s(face.wrapped, loc) + if poly is None: + mylogger.logger.warn("No triangulation found for face") + return GLTF2() tri_mesh = face.tessellate(tolerance, angular_tolerance) # Get UV of each face from the parameters - loc = TopLoc_Location() - poly = BRep_Tool.Triangulation_s(face.wrapped, loc) uv = [ [v.X(), v.Y()] for v in (poly.UVNode(i) for i in range(1, poly.NbNodes() + 1)) @@ -122,7 +126,7 @@ def _tessellate_face( tex_coord = np.array(uv) mode = TRIANGLES material = Material(pbrMetallicRoughness=PbrMetallicRoughness( - baseColorFactor=[0.3, 1.0, 0.2, 1.0], roughnessFactor=0.1, baseColorTexture=TextureInfo(index=0)), + baseColorFactor=[0.3, 1.0, 0.2, 1.0], metallicFactor=0.1, baseColorTexture=TextureInfo(index=0)), alphaCutoff=None) return create_gltf(vertices, indices, tex_coord, mode, material, images=[_checkerboard_image]) @@ -151,7 +155,7 @@ def _tessellate_edge( tex_coord = np.array([], dtype=np.float32) mode = LINE_STRIP material = Material( - pbrMetallicRoughness=PbrMetallicRoughness(baseColorFactor=[0.3, 0.3, 1.0, 1.0]), + pbrMetallicRoughness=PbrMetallicRoughness(baseColorFactor=[0.0, 0.0, 0.3, 1.0]), alphaCutoff=None) return create_gltf(np.array(vertices), indices, tex_coord, mode, material)