Files
armorpaint/paint/sources/ui/tab_plugins.c
T

152 lines
5.0 KiB
C
Raw Normal View History

2026-03-09 13:17:15 +01:00
2026-06-04 11:00:05 +02:00
#include "../global.h"
2026-03-09 13:17:15 +01:00
2026-03-06 12:56:38 +01:00
void tab_plugins_draw(ui_handle_t *htab) {
2026-03-15 11:37:45 +01:00
if (ui_tab(htab, tr("Plugins"), false, -1, false)) {
2026-03-06 12:56:38 +01:00
ui_begin_sticky();
2026-08-21 22:35:41 +02:00
f32_array_t *row = f32_array_create_from_raw_tmp(
2026-03-06 12:56:38 +01:00
(f32[]){
-100,
},
1);
ui_row(row);
2026-03-15 11:37:45 +01:00
if (ui_icon_button(tr("Preferences"), ICON_COG, UI_ALIGN_CENTER)) {
2026-03-31 12:48:56 +02:00
box_preferences_htab->i = PREFERENCES_TAB_PLUGINS;
2026-03-06 12:56:38 +01:00
box_preferences_show();
}
ui_end_sticky();
// Draw plugins
2026-06-08 15:35:04 +02:00
string_array_t *keys = map_keys(g_plugins);
2026-03-06 12:56:38 +01:00
for (i32 i = 0; i < keys->length; ++i) {
2026-06-08 15:35:04 +02:00
plugin_t *p = any_map_get(g_plugins, keys->buffer[i]);
2026-03-07 21:12:59 +01:00
if (p->on_ui != NULL) {
2026-03-23 23:20:02 +01:00
minic_ctx_call_fn(p->ctx, p->on_ui, NULL, 0);
2026-03-06 12:56:38 +01:00
}
}
2026-08-21 22:35:41 +02:00
array_free(keys);
free(keys);
2026-03-06 12:56:38 +01:00
}
}
2026-03-23 23:20:02 +01:00
#ifdef WITH_PLUGINS
2026-05-05 22:41:16 +02:00
2026-03-23 23:20:02 +01:00
void proc_uv_unwrap(void *mesh);
2026-05-05 22:41:16 +02:00
2026-03-06 12:56:38 +01:00
void plugin_uv_unwrap_button() {
2026-06-05 20:34:10 +02:00
util_mesh_merge(g_project->_->paint_objects);
2026-04-28 16:03:44 +02:00
if (g_context->merged_object == NULL) {
return;
}
mesh_data_t *mmd = g_context->merged_object->data;
i16_array_t *merged_posa = mmd->vertex_arrays->buffer[0]->values;
i16_array_t *merged_nora = mmd->vertex_arrays->buffer[1]->values;
u32_array_t *merged_inda = mmd->index_array;
i16_array_t *posa = malloc(sizeof(i16_array_t));
posa->length = posa->capacity = merged_posa->length;
posa->buffer = malloc(merged_posa->length * sizeof(i16));
memcpy(posa->buffer, merged_posa->buffer, merged_posa->length * sizeof(i16));
i16_array_t *nora = malloc(sizeof(i16_array_t));
nora->length = nora->capacity = merged_nora->length;
nora->buffer = malloc(merged_nora->length * sizeof(i16));
memcpy(nora->buffer, merged_nora->buffer, merged_nora->length * sizeof(i16));
u32_array_t *inda = malloc(sizeof(u32_array_t));
inda->length = inda->capacity = merged_inda->length;
inda->buffer = malloc(merged_inda->length * sizeof(u32));
memcpy(inda->buffer, merged_inda->buffer, merged_inda->length * sizeof(u32));
2026-08-21 22:35:41 +02:00
raw_mesh_t *mesh = ALLOC_INIT(raw_mesh_t, {.posa = posa, .nora = nora, .texa = NULL, .inda = inda});
2026-04-28 16:03:44 +02:00
proc_uv_unwrap(mesh);
i32 ioff = 0;
f32 max_scale = mmd->scale_pos;
2026-06-05 20:34:10 +02:00
for (i32 i = 0; i < g_project->_->paint_objects->length; ++i) {
mesh_data_t *md = g_project->_->paint_objects->buffer[i]->data;
2026-04-28 16:03:44 +02:00
i32 ilen = md->index_array->length;
f32 rescale = max_scale / md->scale_pos;
i16_array_t *new_posa = i16_array_create(ilen * 4);
i16_array_t *new_nora = i16_array_create(ilen * 2);
i16_array_t *new_texa = i16_array_create(ilen * 2);
u32_array_t *new_inda = u32_array_create(ilen);
for (i32 j = 0; j < ilen; ++j) {
i32 src = (ioff + j) * 4;
new_posa->buffer[j * 4] = (i16)math_floor(mesh->posa->buffer[src] * rescale);
new_posa->buffer[j * 4 + 1] = (i16)math_floor(mesh->posa->buffer[src + 1] * rescale);
new_posa->buffer[j * 4 + 2] = (i16)math_floor(mesh->posa->buffer[src + 2] * rescale);
new_posa->buffer[j * 4 + 3] = mesh->posa->buffer[src + 3];
}
for (i32 j = 0; j < ilen * 2; ++j) {
new_nora->buffer[j] = mesh->nora->buffer[ioff * 2 + j];
}
for (i32 j = 0; j < ilen * 2; ++j) {
new_texa->buffer[j] = mesh->texa->buffer[ioff * 2 + j];
}
for (i32 j = 0; j < ilen; ++j) {
new_inda->buffer[j] = (u32)j;
}
md->vertex_arrays->buffer[0]->values = new_posa;
md->vertex_arrays->buffer[1]->values = new_nora;
md->vertex_arrays->buffer[2]->values = new_texa;
md->index_array = new_inda;
2026-03-06 12:56:38 +01:00
mesh_data_build(md);
2026-04-28 16:03:44 +02:00
ioff += ilen;
2026-03-06 12:56:38 +01:00
}
2026-04-28 16:03:44 +02:00
free(mesh->posa->buffer);
free(mesh->posa);
free(mesh->nora->buffer);
free(mesh->nora);
free(mesh->texa->buffer);
free(mesh->texa);
free(mesh->inda->buffer);
free(mesh->inda);
2026-03-07 21:12:59 +01:00
util_mesh_merge(NULL);
2026-05-15 10:10:39 +02:00
util_uv_uvmap_cached = false;
2026-03-06 12:56:38 +01:00
}
2026-04-28 16:03:44 +02:00
2026-05-05 22:41:16 +02:00
void plugin_uv_unwrap_per_object_button(mesh_object_t *mo) {
2026-05-05 22:50:19 +02:00
mesh_data_t *md = mo->data;
i16_array_t *md_posa = md->vertex_arrays->buffer[0]->values;
i16_array_t *md_nora = md->vertex_arrays->buffer[1]->values;
u32_array_t *md_inda = md->index_array;
i16_array_t *posa = malloc(sizeof(i16_array_t));
posa->length = posa->capacity = md_posa->length;
posa->buffer = malloc(md_posa->length * sizeof(i16));
memcpy(posa->buffer, md_posa->buffer, md_posa->length * sizeof(i16));
i16_array_t *nora = malloc(sizeof(i16_array_t));
nora->length = nora->capacity = md_nora->length;
nora->buffer = malloc(md_nora->length * sizeof(i16));
memcpy(nora->buffer, md_nora->buffer, md_nora->length * sizeof(i16));
2026-05-05 22:41:16 +02:00
2026-05-05 22:50:19 +02:00
u32_array_t *inda = malloc(sizeof(u32_array_t));
inda->length = inda->capacity = md_inda->length;
inda->buffer = malloc(md_inda->length * sizeof(u32));
memcpy(inda->buffer, md_inda->buffer, md_inda->length * sizeof(u32));
2026-08-21 22:35:41 +02:00
raw_mesh_t *mesh = ALLOC_INIT(raw_mesh_t, {.posa = posa, .nora = nora, .texa = NULL, .inda = inda});
2026-05-05 22:50:19 +02:00
proc_uv_unwrap(mesh);
md->vertex_arrays->buffer[0]->values = mesh->posa;
md->vertex_arrays->buffer[1]->values = mesh->nora;
md->vertex_arrays->buffer[2]->values = mesh->texa;
md->index_array = mesh->inda;
mesh_data_build(md);
2026-05-15 10:10:39 +02:00
util_uv_uvmap_cached = false;
2026-05-05 22:41:16 +02:00
}
2026-04-28 16:03:44 +02:00
2026-03-23 23:20:02 +01:00
#endif