paint: cleanup

This commit is contained in:
luboslenco
2026-06-08 11:54:42 +02:00
parent 1f27859d9a
commit c3623b12f5
48 changed files with 479 additions and 474 deletions
+37 -36
View File
@@ -180,41 +180,42 @@ void export_arm_run_project() {
layer_data_t_array_t *ld = any_array_create_from_raw((void *[]){}, 0);
for (i32 i = 0; i < g_project->_->layers->length; ++i) {
slot_layer_t *l = g_project->_->layers->buffer[i];
layer_data_t *d = GC_ALLOC_INIT(layer_data_t, {.name = l->name,
.res = l->texpaint != NULL ? l->texpaint->width : g_project->_->layers->buffer[0]->texpaint->width,
.bpp = bpp,
.texpaint = l->texpaint != NULL ? lz4_encode(gpu_get_texture_pixels(l->texpaint)) : NULL,
.uv_scale = l->scale,
.uv_rot = l->angle,
.uv_type = l->uv_type,
.uv_map = l->uv_map,
.decal_mat = l->uv_type == UV_TYPE_PROJECT ? mat4_to_f32_array(l->decal_mat) : NULL,
.opacity_mask = l->mask_opacity,
.fill_material = l->fill_material != NULL ? array_index_of(g_project->_->materials, l->fill_material) : -1,
.object_mask = l->object_mask,
.blending = l->blending,
.parent = l->parent != NULL ? array_index_of(g_project->_->layers, l->parent) : -1,
.visible = l->visible,
.texpaint_nor = l->texpaint_nor != NULL ? lz4_encode(gpu_get_texture_pixels(l->texpaint_nor)) : NULL,
.texpaint_pack = l->texpaint_pack != NULL ? lz4_encode(gpu_get_texture_pixels(l->texpaint_pack)) : NULL,
.paint_base = l->paint_base,
.paint_opac = l->paint_opac,
.paint_occ = l->paint_occ,
.paint_rough = l->paint_rough,
.paint_met = l->paint_met,
.paint_nor = l->paint_nor,
.paint_nor_blend = l->paint_nor_blend,
.paint_height = l->paint_height,
.paint_height_blend = l->paint_height_blend,
.paint_emis = l->paint_emis,
.paint_subs = l->paint_subs,
.path_points = l->path_points,
.path_points_world = l->path_points_world,
.path_points_camera = l->path_points_camera,
.path_points_parent = l->path_points_parent,
.path_tool = l->path_tool,
.path_curved = l->path_curved,
.path_material = l->path_material != NULL ? array_index_of(g_project->_->materials, l->path_material) : -1});
layer_data_t *d =
GC_ALLOC_INIT(layer_data_t, {.name = l->name,
.res = l->texpaint != NULL ? l->texpaint->width : g_project->_->layers->buffer[0]->texpaint->width,
.bpp = bpp,
.texpaint = l->texpaint != NULL ? lz4_encode(gpu_get_texture_pixels(l->texpaint)) : NULL,
.uv_scale = l->scale,
.uv_rot = l->angle,
.uv_type = l->uv_type,
.uv_map = l->uv_map,
.decal_mat = l->uv_type == UV_TYPE_PROJECT ? mat4_to_f32_array(l->decal_mat) : NULL,
.opacity_mask = l->mask_opacity,
.fill_material = l->fill_material != NULL ? array_index_of(g_project->_->materials, l->fill_material) : -1,
.object_mask = l->object_mask,
.blending = l->blending,
.parent = l->parent != NULL ? array_index_of(g_project->_->layers, l->parent) : -1,
.visible = l->visible,
.texpaint_nor = l->texpaint_nor != NULL ? lz4_encode(gpu_get_texture_pixels(l->texpaint_nor)) : NULL,
.texpaint_pack = l->texpaint_pack != NULL ? lz4_encode(gpu_get_texture_pixels(l->texpaint_pack)) : NULL,
.paint_base = l->paint_base,
.paint_opac = l->paint_opac,
.paint_occ = l->paint_occ,
.paint_rough = l->paint_rough,
.paint_met = l->paint_met,
.paint_nor = l->paint_nor,
.paint_nor_blend = l->paint_nor_blend,
.paint_height = l->paint_height,
.paint_height_blend = l->paint_height_blend,
.paint_emis = l->paint_emis,
.paint_subs = l->paint_subs,
.path_points = l->path_points,
.path_points_world = l->path_points_world,
.path_points_camera = l->path_points_camera,
.path_points_parent = l->path_points_parent,
.path_tool = l->path_tool,
.path_curved = l->path_curved,
.path_material = l->path_material != NULL ? array_index_of(g_project->_->materials, l->path_material) : -1});
any_array_push(ld, d);
}
@@ -231,7 +232,7 @@ void export_arm_run_project() {
g_project->assets = texture_files;
g_project->packed_assets = packed_assets;
g_project->swatches = g_project->swatches;
g_project->envmap = g_project->envmap != NULL ? (same_drive ? path_to_relative(g_project->_->filepath, g_project->envmap) : g_project->envmap) : NULL;
g_project->envmap = g_project->envmap != NULL ? (same_drive ? path_to_relative(g_project->_->filepath, g_project->envmap) : g_project->envmap) : NULL;
g_project->envmap_strength = scene_world->strength;
g_project->envmap_angle = g_context->envmap_angle;
g_project->envmap_blur = g_context->show_envmap_blur;
+20 -16
View File
@@ -303,7 +303,7 @@ void export_obj_run_sculpt(char *path, mesh_object_t_array_t *paint_objects) {
export_obj_write_string(o, string("o %s\n", p->base->name));
for (i32 i = 0; i < len; ++i) {
f32 x = buffer_get_f32(pixels, i * 16) * sc;
f32 x = buffer_get_f32(pixels, i * 16) * sc;
f32 y = buffer_get_f32(pixels, i * 16 + 4) * sc;
f32 z = buffer_get_f32(pixels, i * 16 + 8) * sc;
export_obj_write_string(o, "v ");
@@ -317,22 +317,26 @@ void export_obj_run_sculpt(char *path, mesh_object_t_array_t *paint_objects) {
for (i32 t = 0; t < tris; ++t) {
i32 i0 = t * 3, i1 = t * 3 + 1, i2 = t * 3 + 2;
f32 x0 = buffer_get_f32(pixels, i0 * 16) * sc;
f32 y0 = buffer_get_f32(pixels, i0 * 16 + 4) * sc;
f32 z0 = buffer_get_f32(pixels, i0 * 16 + 8) * sc;
f32 x1 = buffer_get_f32(pixels, i1 * 16) * sc;
f32 y1 = buffer_get_f32(pixels, i1 * 16 + 4) * sc;
f32 z1 = buffer_get_f32(pixels, i1 * 16 + 8) * sc;
f32 x2 = buffer_get_f32(pixels, i2 * 16) * sc;
f32 y2 = buffer_get_f32(pixels, i2 * 16 + 4) * sc;
f32 z2 = buffer_get_f32(pixels, i2 * 16 + 8) * sc;
f32 x0 = buffer_get_f32(pixels, i0 * 16) * sc;
f32 y0 = buffer_get_f32(pixels, i0 * 16 + 4) * sc;
f32 z0 = buffer_get_f32(pixels, i0 * 16 + 8) * sc;
f32 x1 = buffer_get_f32(pixels, i1 * 16) * sc;
f32 y1 = buffer_get_f32(pixels, i1 * 16 + 4) * sc;
f32 z1 = buffer_get_f32(pixels, i1 * 16 + 8) * sc;
f32 x2 = buffer_get_f32(pixels, i2 * 16) * sc;
f32 y2 = buffer_get_f32(pixels, i2 * 16 + 4) * sc;
f32 z2 = buffer_get_f32(pixels, i2 * 16 + 8) * sc;
f32 e1x = x1 - x0, e1y = y1 - y0, e1z = z1 - z0;
f32 e2x = x2 - x0, e2y = y2 - y0, e2z = z2 - z0;
f32 nx = e1y * e2z - e1z * e2y;
f32 ny = e1z * e2x - e1x * e2z;
f32 nz = e1x * e2y - e1y * e2x;
f32 nl = math_sqrt(nx * nx + ny * ny + nz * nz);
if (nl > 0.0) { nx /= nl; ny /= nl; nz /= nl; }
f32 nx = e1y * e2z - e1z * e2y;
f32 ny = e1z * e2x - e1x * e2z;
f32 nz = e1x * e2y - e1y * e2x;
f32 nl = math_sqrt(nx * nx + ny * ny + nz * nz);
if (nl > 0.0) {
nx /= nl;
ny /= nl;
nz /= nl;
}
export_obj_write_string(o, "vn ");
export_obj_write_string(o, f32_to_string(nx));
export_obj_write_string(o, " ");
@@ -343,7 +347,7 @@ void export_obj_run_sculpt(char *path, mesh_object_t_array_t *paint_objects) {
}
for (i32 i = 0; i < len; ++i) {
f32 u = texa->buffer[i * 2] * inv;
f32 u = texa->buffer[i * 2] * inv;
f32 v = 1.0 - texa->buffer[i * 2 + 1] * inv;
export_obj_write_string(o, "vt ");
export_obj_write_string(o, f32_to_string(u));
+4 -4
View File
@@ -109,20 +109,20 @@ static char *export_player_index = "\
static void export_player_run_on_download(char *url, buffer_t *ab) {}
void export_player_run(char *path) {
#ifndef NDEBUG
#ifndef NDEBUG
console_error(tr("Not available in debug build")); // Requires --embed
return;
#endif
#endif
char *path_base = path_base_dir(path);
char *_project_filepath = string_copy(g_project->_->filepath);
g_project->_->filepath = string("%s/%s", path_base, "start.arm");
g_project->_->filepath = string("%s/%s", path_base, "start.arm");
bool _pack_assets_on_save = g_context->pack_assets_on_save;
g_context->pack_assets_on_save = true;
export_arm_run_project();
g_context->pack_assets_on_save = _pack_assets_on_save;
g_project->_->filepath = _project_filepath;
g_project->_->filepath = _project_filepath;
if (box_export_h_export_player_target->i == PLAYER_TARGET_WEB) {
char *start_js = string("%s/start.js", path_base);
+1 -1
View File
@@ -41,7 +41,7 @@ static void export_texture_write_texture(char *file, buffer_t *pixels, i32 type,
g_project->assets = any_array_create_from_raw((void *[]){}, 0);
}
any_array_push(g_project->assets, asset->file);
asset->image = image;
asset->image = image;
asset_t_array_t *assets = any_array_create_from_raw(
(void *[]){
asset,
+8 -8
View File
@@ -365,11 +365,11 @@ void import_arm_run_project(char *path) {
g_context->paint_object->base->transform->scale = (vec4_t){1, 1, 1, 1.0};
transform_build_matrix(g_context->paint_object->base->transform);
g_context->paint_object->base->name = md->name;
g_project->_->paint_objects = any_array_create_from_raw(
(void *[]){
g_context->paint_object,
},
1);
g_project->_->paint_objects = any_array_create_from_raw(
(void *[]){
g_context->paint_object,
},
1);
for (i32 i = 1; i < project->mesh_datas->length; ++i) {
mesh_data_t *raw = project->mesh_datas->buffer[i];
@@ -387,8 +387,8 @@ void import_arm_run_project(char *path) {
}
if (project->mesh_assets != NULL && project->mesh_assets->length > 0) {
char *file = project->mesh_assets->buffer[0];
char *abs = data_is_abs(file) ? file : string("%s%s", base, file);
char *file = project->mesh_assets->buffer[0];
char *abs = data_is_abs(file) ? file : string("%s%s", base, file);
g_project->mesh_assets = any_array_create_from_raw(
(void *[]){
abs,
@@ -536,7 +536,7 @@ void import_arm_run_project(char *path) {
context_set_layer(g_project->_->layers->buffer[0]);
// Materials
material_data_t *m0 = data_get_material("Scene", "Material");
material_data_t *m0 = data_get_material("Scene", "Material");
g_project->_->materials = any_array_create_from_raw((void *[]){}, 0);
for (i32 i = 0; i < project->material_nodes->length; ++i) {
ui_node_canvas_t *n = project->material_nodes->buffer[i];
+2 -3
View File
@@ -4,12 +4,11 @@
void import_audio_run(char *path) {
#ifdef IRON_AUDIO
sound_t *s = data_get_sound(path);
iron_a1_play_sound(s->sound_, false, 1, false);
sound_t *s = data_get_sound(path);
iron_a1_play_sound(s->sound_, false, 1, false);
string_array_t *ar = string_split(path, PATH_SEP);
char *name = ar->buffer[ar->length - 1];
console_info(string("%s %s", tr("Audio imported:"), name));
#endif
}
+5 -5
View File
@@ -184,11 +184,11 @@ void import_mesh_make_mesh(raw_mesh_t *mesh) {
mesh_object_set_data(g_context->paint_object, md);
g_context->paint_object->base->name = mesh->name;
g_project->_->paint_objects = any_array_create_from_raw(
(void *[]){
g_context->paint_object,
},
1);
g_project->_->paint_objects = any_array_create_from_raw(
(void *[]){
g_context->paint_object,
},
1);
md->_->handle = string_copy(raw->name);
any_map_set(data_cached_meshes, md->_->handle, md);
+1 -1
View File
@@ -61,7 +61,7 @@ void import_texture_run(char *path, bool hdr_as_envmap) {
if (g_context->texture == NULL) {
g_context->texture = asset;
}
asset->image = image;
asset->image = image;
ui_base_hwnds->buffer[TAB_AREA_STATUS]->redraws = 2;
console_info(string("%s %s", tr("Texture imported:"), name));