Work on port of meshgen code

This commit is contained in:
Tuomas Katajisto 2025-07-07 22:27:12 +03:00
parent 9330ebf8d6
commit d8ad5acf77
3 changed files with 46 additions and 42 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -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<float>& vecs, std::vector<float>& normals){
std::vector<Vector3> quads3d;
for(TrileSide side : TrileSideValues){
for(int i=0; i<quads[side].size(); i++){
std::vector<Vector2> 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<Quad>& quadSet){
auto parentIt = quadSet.lower_bound(quad);
while(!isInsideOther(quad,*parentIt)){