Files
armorpaint/paint/sources/io/import_blend_mesh.c
T

59 lines
1.7 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-09 23:02:08 +01:00
void import_blend_mesh_ui_blender_folder_picked(char *path) {
2026-03-10 21:00:00 +01:00
#ifdef IRON_WINDOWS
path = string_copy(string_replace_all(path, "\\", "/"));
#endif
2026-04-05 16:41:00 +02:00
g_config->blender = string_copy(path);
2026-03-09 23:02:08 +01:00
config_save();
}
2026-03-06 12:56:38 +01:00
void import_blend_mesh_ui() {
2026-04-05 16:41:00 +02:00
if (g_config->blender == NULL) {
g_config->blender = "";
2026-03-06 12:56:38 +01:00
}
2026-03-15 11:37:45 +01:00
ui_text(tr("Blender Executable"), UI_ALIGN_LEFT, 0x00000000);
2026-03-06 12:56:38 +01:00
f32_array_t *ar = f32_array_create_from_raw(
(f32[]){
2026-03-15 21:14:44 +01:00
7 / 8.0,
1 / 8.0,
2026-03-06 12:56:38 +01:00
},
2);
ui_row(ar);
2026-04-21 10:52:27 +02:00
ui_handle_t *h = ui_handle(__ID__);
h->text = string_copy(g_config->blender);
2026-04-05 16:41:00 +02:00
g_config->blender = string_copy(ui_text_input(h, "", UI_ALIGN_LEFT, true, false));
2026-03-06 12:56:38 +01:00
if (ui_icon_button("", ICON_FOLDER_OPEN, UI_ALIGN_CENTER)) {
2026-03-09 23:02:08 +01:00
ui_files_show("", false, false, &import_blend_mesh_ui_blender_folder_picked);
2026-03-06 12:56:38 +01:00
}
}
2026-03-07 21:12:59 +01:00
void import_blend_mesh_run(char *path, bool replace_existing) {
2026-04-05 16:41:00 +02:00
if (g_config->blender == NULL || string_equals(g_config->blender, "")) {
2026-03-15 11:37:45 +01:00
console_error(tr("Blender executable path not set"));
2026-03-06 12:56:38 +01:00
return;
}
2026-03-07 21:12:59 +01:00
char *save = "tmp.obj";
char *bpy_folder = "data/";
2026-03-06 12:56:38 +01:00
if (path_is_protected()) {
2026-03-10 21:00:00 +01:00
save = string("%s%s", iron_internal_save_path(), save);
2026-03-06 12:56:38 +01:00
bpy_folder = "";
}
// Have to use ; instead of \n on windows
2026-03-10 21:00:00 +01:00
char *py = string("import bpy;bpy.ops.wm.obj_export(filepath='%s%s',export_triangulated_mesh=True,export_materials=False,check_existing=False)", bpy_folder,
string_replace_all(save, "\\", "/"));
#ifdef IRON_WINDOWS
2026-04-05 16:41:00 +02:00
char *bl = string("\"%s\"", string_replace_all(g_config->blender, "/", "\\"));
2026-03-10 21:00:00 +01:00
#else
2026-04-05 16:41:00 +02:00
char *bl = string_replace_all(g_config->blender, " ", "\\ ");
2026-03-10 21:00:00 +01:00
#endif
iron_sys_command(string("%s \"%s\" -b --python-expr \"%s\"", bl, path, py));
2026-03-06 12:56:38 +01:00
import_obj_run(save, replace_existing);
}