forked from blender/blender
Caching generated image leads to infinite loop in preview render #53
@ -17,6 +17,7 @@
|
||||
#include "final_engine.h"
|
||||
#include "preview_engine.h"
|
||||
#include "viewport_engine.h"
|
||||
#include "scene_delegate/image.h"
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
@ -266,6 +267,23 @@ static PyObject *engine_set_render_setting_func(PyObject * /*self*/, PyObject *a
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *cache_image_func(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
PyObject *pycontext, *pyscene ,*pyimage;
|
||||
if (!PyArg_ParseTuple(args, "OOO", &pycontext, &pyscene, &pyimage)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext);
|
||||
Scene *scene = (Scene *)PyLong_AsVoidPtr(pyscene);
|
||||
Image *image = (Image *)PyLong_AsVoidPtr(pyimage);
|
||||
|
||||
std::string image_path = cache_image_file(image, context, scene, NULL, false);
|
||||
|
||||
CLOG_INFO(LOG_RENDER_HYDRA, 1, "Cache image");
|
||||
return PyUnicode_FromString(image_path.c_str());
|
||||
}
|
||||
|
||||
static PyMethodDef methods[] = {
|
||||
{"init", init_func, METH_VARARGS, ""},
|
||||
{"register_plugins", register_plugins_func, METH_VARARGS, ""},
|
||||
@ -274,12 +292,13 @@ static PyMethodDef methods[] = {
|
||||
{"engine_create", engine_create_func, METH_VARARGS, ""},
|
||||
{"engine_free", engine_free_func, METH_VARARGS, ""},
|
||||
{"engine_sync", engine_sync_func, METH_VARARGS, ""},
|
||||
{"engine_sync_usd", engine_sync_usd_func, METH_VARARGS, ""},
|
||||
{"engine_render", engine_render_func, METH_VARARGS, ""},
|
||||
{"engine_view_draw", engine_view_draw_func, METH_VARARGS, ""},
|
||||
{"engine_set_sync_setting", engine_set_sync_setting_func, METH_VARARGS, ""},
|
||||
{"engine_set_render_setting", engine_set_render_setting_func, METH_VARARGS, ""},
|
||||
|
||||
{"cache_image", cache_image_func, METH_VARARGS, ""},
|
||||
|
||||
{NULL, NULL, 0, NULL},
|
||||
};
|
||||
|
||||
|
@ -16,8 +16,8 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
static std::string cache_image_file(Image *image,
|
||||
BlenderSceneDelegate *scene_delegate,
|
||||
std::string cache_image_file(Image *image,
|
||||
bContext *context, Scene *scene,
|
||||
ImageUser *iuser,
|
||||
bool check_exist)
|
||||
{
|
||||
@ -34,11 +34,13 @@ static std::string cache_image_file(Image *image,
|
||||
return file_path;
|
||||
}
|
||||
|
||||
Main *main = CTX_data_main(scene_delegate->context);
|
||||
Main *main = CTX_data_main(context);
|
||||
ImageSaveOptions opts;
|
||||
opts.im_format.imtype = R_IMF_IMTYPE_RADHDR;
|
||||
|
||||
if (BKE_image_save_options_init(&opts, main, scene_delegate->scene, image, iuser, true, false)) {
|
||||
auto prev_source = image->source;
|
||||
|
||||
if (BKE_image_save_options_init(&opts, main, scene, image, iuser, false, false)) {
|
||||
STRNCPY(opts.filepath, file_path.c_str());
|
||||
ReportList reports;
|
||||
if (BKE_image_save(&reports, main, image, iuser, &opts)) {
|
||||
@ -49,6 +51,7 @@ static std::string cache_image_file(Image *image,
|
||||
}
|
||||
}
|
||||
BKE_image_save_options_free(&opts);
|
||||
image->source = prev_source;
|
||||
|
||||
return file_path;
|
||||
}
|
||||
@ -59,17 +62,20 @@ std::string cache_or_get_image_file(Image *image,
|
||||
{
|
||||
std::string file_path(FILE_MAX, 0);
|
||||
if (image->source == IMA_SRC_GENERATED) {
|
||||
file_path = cache_image_file(image, scene_delegate, iuser, false);
|
||||
file_path = cache_image_file(
|
||||
image, scene_delegate->context, scene_delegate->scene, iuser, false);
|
||||
}
|
||||
else if (BKE_image_has_packedfile(image)) {
|
||||
file_path = cache_image_file(image, scene_delegate, iuser, true);
|
||||
file_path = cache_image_file(
|
||||
image, scene_delegate->context, scene_delegate->scene, iuser, true);
|
||||
}
|
||||
else {
|
||||
Main *main = CTX_data_main(scene_delegate->context);
|
||||
BKE_image_user_file_path_ex(main, iuser, image, file_path.data(), false, true);
|
||||
|
||||
if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(file_path)) {
|
||||
file_path = cache_image_file(image, scene_delegate, iuser, true);
|
||||
file_path = cache_image_file(
|
||||
image, scene_delegate->context, scene_delegate->scene, iuser, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,11 @@ namespace blender::render::hydra {
|
||||
|
||||
class BlenderSceneDelegate;
|
||||
|
||||
std::string cache_image_file(Image *image,
|
||||
bContext *context, Scene *scene,
|
||||
ImageUser *iuser,
|
||||
bool check_exist);
|
||||
|
||||
std::string cache_or_get_image_file(Image *image,
|
||||
BlenderSceneDelegate *scene_delegate,
|
||||
ImageUser *iuser);
|
||||
|
Loading…
Reference in New Issue
Block a user