Finally working meshgen port

This commit is contained in:
Tuomas Katajisto 2025-07-12 00:07:40 +03:00
parent 5d017f0a2b
commit e52b06da03
4 changed files with 47 additions and 26 deletions

View File

@ -5,8 +5,9 @@ get_level_editor_camera :: () -> Camera {
camera.near = 0.1;
camera.far = 100;
camera.position = .{5,5,5};
camera.target = .{0,0,0};
camera.position = .{xx (sin(get_time()) * 2),xx sin(get_time() * 0.3),xx (cos(get_time()) * 2)};
camera.target = .{0.5,0.5,0.5};
camera.position += .{0.5, 0.5, 0.5};
return camera;
}

View File

@ -43,10 +43,6 @@ current_trile : Trile;
#scope_file
apply_tool_to_trixel :: (x: s64, y: s64, z: s64) {
//temptest:
print("Testing meshgen!\n");
set_trile("test", generate_mesh_matias(*current_trile));
if current_tool == .PAINT {
current_trile.trixels[x][y][z].material.color = current_color;
}
@ -189,6 +185,12 @@ draw_tool_tab :: (theme: *GR.Overall_Theme, area: GR.Rect) {
r.y += r.h;
GR.slider(r, *brush_radius, 0, 12, 1, *theme.slider_theme);
r.y += r.h * 2;
if GR.button(r, "Save and gen", *theme.button_theme) {
//temptest:
print("Testing meshgen!\n");
set_trile("test", generate_mesh_matias(*current_trile));
};
}
draw_material_tab :: (theme: *GR.Overall_Theme, area: GR.Rect) {

View File

@ -1,6 +1,6 @@
Trile_Side :: enum_flags u8 {
TOP :: 0x0; // Larger Y
LEFT :: 0x1; // Larger Z
TOP :: 0x1; // Larger Y
LEFT :: 0x2; // Larger Z
RIGHT :: 0x4; // Smaller Z
FRONT :: 0x8; // Larger X
BACK :: 0x10; // Smaller X
@ -233,9 +233,10 @@ init_quads :: (quads: *Quads) { // NOTE: unsure about if this is correctly porte
for i : 0..15 {
quadset : Quad_Set;
table_add(*quadset, .{.{16,16}, .{0,0}}, true);
array_add(*quads.*[idx], quadset);
array_add(*(quads.*[idx]), quadset);
}
}
print("qcount??: %", quads[0].count);
}
// Looking at the side, what axis should be used as x,y and z,
@ -244,17 +245,17 @@ init_quads :: (quads: *Quads) { // NOTE: unsure about if this is correctly porte
change_perspective :: (x: *$T, y: *T, z: *T, side: Trile_Side) -> (*T,*T,*T) {
if #complete side == {
case Trile_Side.TOP;
return y, x, z;
case Trile_Side.BOTTOM;
return y, z, x;
case Trile_Side.FRONT;
return x, z, y;
case Trile_Side.BACK;
return x, y, z;
case Trile_Side.LEFT;
return z, y, x;
case Trile_Side.RIGHT;
case Trile_Side.BOTTOM;
return z, x, y;
case Trile_Side.FRONT;
return z, y, x;
case Trile_Side.BACK;
return y, z, x;
case Trile_Side.LEFT;
return y, x, z;
case Trile_Side.RIGHT;
return x, y, z;
}
}
@ -312,9 +313,9 @@ quads_to_vecs :: (quads: *Quads, vecs: *[..]float, normals: *[..]float) {
for side : trileSideValues {
idx := side_to_quad_list_index(side);
for 0..quads[idx].count-1 {
for 0..quads.*[idx].count-1 {
quads2d : [..]Vector2;
table := quads.*[idx][it];
table := *(quads.*[idx][it]);
for k, v : table {
array_add(*quads2d, v.bottomLeft);
array_add(*quads2d, .{v.bottomLeft.x, v.topRight.y});
@ -343,11 +344,28 @@ a_is_inside_b :: (a: Quad, b: Quad) -> bool {
remove_quad :: (quad: Quad, quadSet: *Quad_Set) {
parent : Quad;
qlist : [..]Quad;
for k,v : quadSet {
if v < quad then continue;
if a_is_inside_b(quad, v) {
table_remove(quadSet, v);
parent = v;
array_add(*qlist, v);
}
Sort :: #import "Sort";
qcomp :: (a: Quad, b: Quad) -> s64 {
if a < b then return -1;
if b < a then return 1;
return 0;
}
Sort.bubble_sort(qlist, qcomp);
for qlist {
if it < quad then continue;
if a_is_inside_b(quad, it) {
parent = it;
table_remove(quadSet, it);
break;
}
}
@ -406,7 +424,7 @@ generate_mesh_matias :: (trileptr : *Trile) -> Mesh {
quadVecs : [..]float;
quadNorms : [..]float;
generate_basic_quad_mesh(trileptr,*quadVecs,*quadNorms);
generate_optimized_quad_mesh(trileptr,*quadVecs,*quadNorms);
print("Quad vecs size: %\n", quadVecs.count);
quads_to_triangles(*quadVecs, *triangleVecs,*quadNorms, *triangleNorms);

View File

@ -159,7 +159,7 @@ create_trixel_pipeline :: () {
create_trile_pipeline :: () {
pipeline: sg_pipeline_desc;
shader_desc := trixel_shader_desc(sg_query_backend());
shader_desc := trile_shader_desc(sg_query_backend());
pipeline.shader = sg_make_shader(*shader_desc);
pipeline.layout.buffers[0].stride = 4*3;
pipeline.layout.buffers[1].stride = 4*3;