2026-03-09 13:17:15 +01:00
|
|
|
|
|
|
|
|
#include "global.h"
|
|
|
|
|
|
2026-04-05 16:09:00 +02:00
|
|
|
char *_import_blend_material_path;
|
|
|
|
|
|
2026-03-10 21:00:00 +01:00
|
|
|
void _import_blend_material_on_next_frame(void *_) {
|
2026-03-07 21:12:59 +01:00
|
|
|
char *save;
|
2026-03-06 12:56:38 +01:00
|
|
|
if (path_is_protected()) {
|
|
|
|
|
save = string_copy(iron_internal_save_path());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
save = string_copy(path_data());
|
|
|
|
|
}
|
2026-03-10 21:00:00 +01:00
|
|
|
save = string("%s%s", save, "blender");
|
2026-03-06 12:56:38 +01:00
|
|
|
iron_create_directory(save);
|
|
|
|
|
|
2026-03-10 21:00:00 +01:00
|
|
|
char *py = string("\
|
2026-03-06 12:56:38 +01:00
|
|
|
import bpy;\n\
|
|
|
|
|
bpy.context.scene.render.engine = 'CYCLES'\n\
|
|
|
|
|
bpy.context.scene.cycles.samples = 4\n\
|
|
|
|
|
bpy.ops.mesh.primitive_plane_add()\n\
|
|
|
|
|
plane = bpy.context.selected_objects[0]\n\
|
|
|
|
|
img = bpy.data.images.new('bake', 2048, 2048)\n\
|
|
|
|
|
img.file_format = 'JPEG'\n\
|
|
|
|
|
for mat in bpy.data.materials:\n\
|
|
|
|
|
if mat.name == 'Dots Stroke':\n\
|
|
|
|
|
continue\n\
|
|
|
|
|
plane.data.materials.append(mat)\n\
|
|
|
|
|
node = mat.node_tree.nodes.new(type='ShaderNodeTexImage')\n\
|
|
|
|
|
node.image = img\n\
|
|
|
|
|
mat.node_tree.nodes.active = node\n\
|
|
|
|
|
bpy.ops.object.bake(type='DIFFUSE')\n\
|
2026-03-10 21:00:00 +01:00
|
|
|
img.filepath_raw = '%s/blender_base.jpg'\n\
|
2026-03-06 12:56:38 +01:00
|
|
|
img.save()\n\
|
|
|
|
|
bpy.ops.object.bake(type='ROUGHNESS')\n\
|
2026-03-10 21:00:00 +01:00
|
|
|
img.filepath_raw = '%s/blender_rough.jpg'\n\
|
2026-03-06 12:56:38 +01:00
|
|
|
img.save()\n\
|
|
|
|
|
bpy.ops.object.bake(type='NORMAL')\n\
|
2026-03-10 21:00:00 +01:00
|
|
|
img.filepath_raw = '%s/blender_nor.jpg'\n\
|
2026-03-06 12:56:38 +01:00
|
|
|
img.save()\n\
|
|
|
|
|
break\n\
|
2026-03-10 21:00:00 +01:00
|
|
|
",
|
|
|
|
|
save, save, save);
|
2026-03-06 12:56:38 +01:00
|
|
|
|
2026-04-05 16:41:00 +02:00
|
|
|
iron_sys_command(string("\"%s\" \"%s\" -b --python-expr \"%s\"", g_config->blender, _import_blend_material_path, py));
|
2026-03-06 12:56:38 +01:00
|
|
|
import_folder_run(save);
|
|
|
|
|
}
|
2026-03-09 23:02:08 +01:00
|
|
|
|
|
|
|
|
void _import_blend_material() {
|
2026-03-15 11:37:45 +01:00
|
|
|
console_toast(tr("Baking material"));
|
2026-03-09 23:02:08 +01:00
|
|
|
sys_notify_on_next_frame(&_import_blend_material_on_next_frame, NULL);
|
|
|
|
|
}
|
2026-04-04 21:38:20 +02:00
|
|
|
|
|
|
|
|
void import_blend_material_run_box() {
|
|
|
|
|
if (ui_tab(ui_handle(__ID__), tr("Import Material"), false, -1, false)) {
|
|
|
|
|
import_blend_mesh_ui();
|
|
|
|
|
|
|
|
|
|
ui_row2();
|
|
|
|
|
if (ui_icon_button(tr("Cancel"), ICON_CLOSE, UI_ALIGN_CENTER)) {
|
|
|
|
|
ui_box_hide();
|
|
|
|
|
}
|
|
|
|
|
if (ui_icon_button(tr("Import"), ICON_CHECK, UI_ALIGN_CENTER) || ui->is_return_down) {
|
|
|
|
|
|
|
|
|
|
ui_box_hide();
|
|
|
|
|
|
2026-04-05 16:41:00 +02:00
|
|
|
if (g_config->blender == NULL || string_equals(g_config->blender, "")) {
|
2026-04-04 21:38:20 +02:00
|
|
|
console_error(tr("Blender executable path not set"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_import_blend_material();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void import_blend_material_run(char *path) {
|
|
|
|
|
gc_unroot(_import_blend_material_path);
|
|
|
|
|
_import_blend_material_path = string_copy(path);
|
|
|
|
|
gc_root(_import_blend_material_path);
|
|
|
|
|
|
|
|
|
|
ui_box_show_custom(&import_blend_material_run_box, 400, 200, NULL, true, "");
|
|
|
|
|
}
|