static void export_as_txt(const char *path) { FILE *out; mesh_t *mesh = goxel.layers_mesh; int p[3]; uint8_t v[4]; mesh_iterator_t iter; path = path ?: noc_file_dialog_open(NOC_FILE_DIALOG_SAVE, "text\0*.txt\0", NULL, "untitled.txt"); if (!path) return; out = fopen(path, "w"); fprintf(out, "# Goxel " GOXEL_VERSION_STR "\n"); fprintf(out, "# One line per voxel\n"); fprintf(out, "# X Y Z RRGGBB\n"); iter = mesh_get_iterator(mesh, MESH_ITER_VOXELS); while (mesh_iter(&iter, p)) { mesh_get_at(mesh, &iter, p, v); if (v[3] < 127) continue; fprintf(out, "%d %d %d %02x%02x%02x\n", p[0], p[1], p[2], v[0], v[1], v[2]); } fclose(out); }
static int tool_pick_color_iter(goxel_t *goxel, const inputs_t *inputs, int state, const vec2_t *view_size, bool inside) { bool snaped; vec3_t pos, normal; uvec4b_t color; mesh_t *mesh = goxel->layers_mesh; const bool pressed = inputs->mouse_down[0]; goxel_set_help_text(goxel, "Click on a voxel to pick the color"); snaped = inside && goxel_unproject_on_mesh(goxel, view_size, &inputs->mouse_pos, mesh, &pos, &normal); if (!snaped) return 0; color = mesh_get_at(mesh, &pos); color.a = 255; goxel_set_help_text(goxel, "%d %d %d", color.r, color.g, color.b); if (pressed) goxel->painter.color = color; return 0; }