From d8ad5acf7778e2606e0dfec93425eaa14e6e81c3 Mon Sep 17 00:00:00 2001 From: katajisto Date: Mon, 7 Jul 2025 22:27:12 +0300 Subject: [PATCH] Work on port of meshgen code --- build.sh | 5 ++- src/editor/trile_editor.jai | 22 +++++++++++++ src/meshgen.jai | 61 +++++++++++++------------------------ 3 files changed, 46 insertions(+), 42 deletions(-) diff --git a/build.sh b/build.sh index 6350368..3c2663e 100755 --- a/build.sh +++ b/build.sh @@ -4,6 +4,5 @@ cd src/shaders/ ./compile_shaders.sh cd .. cd .. -/home/katajisto/bin/jai/bin/jai-linux -x64 first.jai -./first & -/home/katajisto/bin/jai/bin/jai-linux first.jai - wasm +jai -x64 first.jai +./first diff --git a/src/editor/trile_editor.jai b/src/editor/trile_editor.jai index 8057fee..ff8e481 100644 --- a/src/editor/trile_editor.jai +++ b/src/editor/trile_editor.jai @@ -3,6 +3,8 @@ rotation : float = 0.0; tilt : float = 0.0; zoom : float = 3.0; +brush_radius : int = 5; + roughness : int = 0; metallic : int = 0; emittance : int = 0; @@ -62,6 +64,22 @@ handle_tool_click :: () { if current_mode == .POINT { apply_tool_to_trixel(hovered_trixel_x, hovered_trixel_y, hovered_trixel_z); } + if current_mode == .BRUSH { + is_in_radius :: (point : Vector3, radius: float) -> bool { + center : Vector3 = .{xx hovered_trixel_x, xx hovered_trixel_y, xx hovered_trixel_z}; + return length(point - center) <= radius; + } + + for x: 0..15 { + for y: 0..15 { + for z: 0..15 { + if is_in_radius(.{xx x, xx y, xx z}, xx brush_radius) { + apply_tool_to_trixel(x,y,z); + } + } + } + } + } if current_mode == .AREA { if area_active { // Apply tool to all trixels in the area. @@ -164,6 +182,9 @@ draw_tool_tab :: (theme: *GR.Overall_Theme, area: GR.Rect) { if GR.button(r, "Brush (c-B)", *t_button_selectable(theme, current_mode == .BRUSH)) { current_mode = .BRUSH; } + + r.y += r.h; + GR.slider(r, *brush_radius, 0, 12, 1, *theme.slider_theme); } draw_material_tab :: (theme: *GR.Overall_Theme, area: GR.Rect) { @@ -241,6 +262,7 @@ draw_trile :: () { hovered_trixel_x = x; hovered_trixel_y = y; hovered_trixel_z = z; + print("%\n", hit.normal); min_distance = hit.distance; } } diff --git a/src/meshgen.jai b/src/meshgen.jai index 8b47615..02f224f 100644 --- a/src/meshgen.jai +++ b/src/meshgen.jai @@ -231,9 +231,9 @@ init_quads :: (quads: *Quads) { // NOTE: unsure about if this is correctly porte for side : trileSideValues { idx := side_to_quad_list_index(side); for i : 0..15 { - qlist := *quads[idx]; - array_add(qlist, .{}); - table_add(qlist[i], .{.{16,16}, .{0,0}}, true); + quadset : Quad_Set; + table_add(*quadset, .{.{16,16}, .{0,0}}, true); + array_add(*quads.*[idx], quadset); } } } @@ -258,12 +258,12 @@ change_perspective :: (x: *$T, y: *T, z: *T, side: Trile_Side) -> (*T,*T,*T) { } } -quad2d_add_to_quads_3d :: (quads2d: *[..]Vector2, quads3d: *[..]Vector3, side: Trile_Side, depth: int, normals: *[..]float) { +quad2d_add_to_quads3d :: (quads2d: *[..]Vector2, quads3d: *[..]Vector3, side: Trile_Side, depth: int, normals: *[..]float) { x, y, z : float; normal : [3]float; offset : float = 0.0; - ux, uy, uz = change_perspective(*x, *y, *z, side); + ux, uy, uz := change_perspective(*x, *y, *z, side); if side == { case Trile_Side.TOP; @@ -314,51 +314,34 @@ quads_to_vecs :: (quads: *Quads, vecs: *[..]float, normals: *[..]float) { idx := side_to_quad_list_index(side); for 0..quads[idx].count-1 { quads2d : [..]Vector2; - Quad_Set :: Table(Quad, bool, quad_hash, quad_comp); - Quads :: [6][..]Quad_Set; - for quad : quads[idx][it] { - array_add(*quads2d, quad.bottomLeft); - array_add(*quads2d, .{quad.bottomLeft.x, quad.topRight.y}); - array_add(*quads2d, quad.topRight); - array_add(*quads2d, .{quad.topRight.x, quad.bottomLeft.y}); + table := quads.*[idx][it]; + for k, v : table { + array_add(*quads2d, v.bottomLeft); + array_add(*quads2d, .{v.bottomLeft.x, v.topRight.y}); + array_add(*quads2d, v.topRight); + array_add(*quads2d, .{v.topRight.x, v.bottomLeft.y}); } - quad2_add_to_quads3d(*quads2d, *quads3d, side, it, normals); + quad2d_add_to_quads3d(*quads2d, *quads3d, side, it, normals); } } + for quad : quads3d { + array_add(vecs, quad.x); + array_add(vecs, quad.y); + array_add(vecs, quad.z); + } } -/* - -void quadsToVecs(Quads& quads, std::vector& vecs, std::vector& normals){ - std::vector quads3d; - for(TrileSide side : TrileSideValues){ - for(int i=0; i quads2d; - for(Quad quad : quads[side][i]){ - quads2d.push_back(quad.bottomLeft); - quads2d.push_back({quad.bottomLeft.x,quad.topRight.y}); - quads2d.push_back(quad.topRight); - quads2d.push_back({quad.topRight.x,quad.bottomLeft.y}); - } - quad2dAddToQuads3d(quads2d,quads3d,side,i,normals); - } - } - for(Vector3 quad : quads3d) { - vecs.push_back(quad.x); - vecs.push_back(quad.y); - vecs.push_back(quad.z); - } -} - -bool isInsideOther(Quad a, Quad other){ - if( (other.topRight.x >= a.topRight.x) && (other.topRight.y >= a.topRight.y)){ - if( (other.bottomLeft.x <= a.bottomLeft.x) && (other.bottomLeft.y <= a.bottomLeft.y) ){ +a_is_inside_b :: (a: Quad, b: Quad) -> bool { + if (b.topRight.x >= a.topRight.x) && (b.topRight.y >= a.topRight.y) { + if (b.bottomLeft.x <= a.bottomLeft.x) && (b.bottomLeft.y <= a.bottomLeft.y) { return true; } } return false; } +/* + void removeQuad(Quad quad, std::set& quadSet){ auto parentIt = quadSet.lower_bound(quad); while(!isInsideOther(quad,*parentIt)){