Files
armorpaint/base/sources/ts/import_blend_mesh.ts
T

57 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-03-13 23:50:11 +01:00
2025-01-06 09:00:53 +01:00
function import_blend_mesh_ui() {
if (config_raw.blender == null) {
config_raw.blender = "";
}
2025-01-06 17:45:16 +01:00
ui_text(tr("Blender Executable"));
2025-01-06 09:00:53 +01:00
let ar: f32[] = [ 7 / 8, 1 / 8];
ui_row(ar);
let h: ui_handle_t = ui_handle(__ID__);
h.text = config_raw.blender;
2025-01-06 17:45:16 +01:00
config_raw.blender = ui_text_input(h);
2025-01-06 09:00:53 +01:00
if (ui_button("...")) {
ui_files_show("", false, false, function (path: string) {
2025-01-06 17:45:16 +01:00
///if arm_windows
path = string_replace_all(path, "\\", "/");
///end
2025-01-06 09:00:53 +01:00
config_raw.blender = path;
2025-01-06 11:06:59 +01:00
config_save();
2025-01-06 09:00:53 +01:00
});
}
}
2024-03-13 23:50:11 +01:00
function import_blend_mesh_run(path: string, replace_existing: bool = true) {
2024-08-25 21:48:02 +02:00
2025-01-06 09:00:53 +01:00
if (config_raw.blender == null || config_raw.blender == "") {
console_error(tr("Blender executable path not set"));
return;
}
let save: string;
if (path_is_protected()) {
2025-03-09 17:02:12 +01:00
save = iron_internal_save_path();
2025-01-06 09:00:53 +01:00
}
else {
save = path_data();
}
save += "tmp.obj";
2025-01-06 17:45:16 +01:00
///if arm_windows
path = string_replace_all(path, "\\", "\\\\");
save = string_replace_all(save, "\\", "\\\\");
///end
// Have to use ; instead of \n on windows
2025-01-06 09:00:53 +01:00
let py: string = "\
2025-01-06 17:45:16 +01:00
import bpy;\
2025-01-06 09:00:53 +01:00
bpy.ops.wm.obj_export(filepath='" + save + "',export_triangulated_mesh=True,export_materials=False,check_existing=False)";
2025-01-06 17:45:16 +01:00
let bl: string = string_replace_all(config_raw.blender, " ", "\\ ");
iron_sys_command(bl + " \"" + path + "\" -b --python-expr \"" + py + "\"");
2025-01-06 09:00:53 +01:00
import_obj_run(save, replace_existing);
2024-03-13 23:50:11 +01:00
}