forked from blender/blender
Caching generated image leads to infinite loop in preview render #53
@ -224,16 +224,15 @@ static PyObject *engine_set_render_setting_func(PyObject * /*self*/, PyObject *a
|
||||
|
||||
static PyObject *cache_image_func(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
PyObject *pycontext, *pyscene, *pyimage;
|
||||
if (!PyArg_ParseTuple(args, "OOO", &pycontext, &pyscene, &pyimage)) {
|
||||
PyObject *pycontext, *pyimage;
|
||||
if (!PyArg_ParseTuple(args, "OOO", &pycontext, &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);
|
||||
std::string image_path = cache_image_file(image, context, NULL, false);
|
||||
return PyUnicode_FromString(image_path.c_str());
|
||||
}
|
||||
|
||||
|
@ -4,25 +4,21 @@
|
||||
#include <pxr/imaging/hio/imageRegistry.h>
|
||||
|
||||
#include "BKE_appdir.h"
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_image_format.h"
|
||||
#include "BKE_image_save.h"
|
||||
#include "BLI_fileops.h"
|
||||
#include "BLI_path_util.h"
|
||||
|
||||
#include "DNA_windowmanager_types.h"
|
||||
|
||||
#include "blender_scene_delegate.h"
|
||||
#include "image.h"
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
std::string cache_image_file(
|
||||
Image *image, bContext *context, Scene *scene, ImageUser *iuser, bool check_exist)
|
||||
std::string cache_image_file(Image *image, bContext *context, ImageUser *iuser, bool check_exist)
|
||||
{
|
||||
char file_path[FILE_MAX];
|
||||
char file_name[32];
|
||||
Main *main = CTX_data_main(context);
|
||||
Scene *scene = CTX_data_scene(context);
|
||||
ImageSaveOptions opts;
|
||||
if (BKE_image_save_options_init(&opts, main, scene, image, iuser, false, false)) {
|
||||
char file_name[32];
|
||||
@ -52,26 +48,21 @@ std::string cache_image_file(
|
||||
return file_path;
|
||||
}
|
||||
|
||||
std::string cache_or_get_image_file(Image *image,
|
||||
BlenderSceneDelegate *scene_delegate,
|
||||
ImageUser *iuser)
|
||||
std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser *iuser)
|
||||
{
|
||||
std::string file_path(FILE_MAX, 0);
|
||||
if (image->source == IMA_SRC_GENERATED) {
|
||||
file_path = cache_image_file(
|
||||
image, scene_delegate->context, scene_delegate->scene, iuser, false);
|
||||
file_path = cache_image_file(image, context, iuser, false);
|
||||
}
|
||||
else if (BKE_image_has_packedfile(image)) {
|
||||
file_path = cache_image_file(
|
||||
image, scene_delegate->context, scene_delegate->scene, iuser, true);
|
||||
file_path = cache_image_file(image, context, iuser, true);
|
||||
}
|
||||
else {
|
||||
Main *main = CTX_data_main(scene_delegate->context);
|
||||
Main *main = CTX_data_main(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->context, scene_delegate->scene, iuser, true);
|
||||
file_path = cache_image_file(image, context, iuser, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,18 +3,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_image_save.h"
|
||||
|
||||
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);
|
||||
std::string cache_image_file(Image *image, bContext *context, ImageUser *iuser, bool check_exist);
|
||||
std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser *iuser);
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -87,7 +87,8 @@ void WorldData::init()
|
||||
NodeTexImage *tex = static_cast<NodeTexImage *>(color_input_node->storage);
|
||||
Image *image = (Image *)color_input_node->id;
|
||||
if (image) {
|
||||
std::string image_path = cache_or_get_image_file(image, scene_delegate_, &tex->iuser);
|
||||
std::string image_path = cache_or_get_image_file(
|
||||
image, scene_delegate_->context, &tex->iuser);
|
||||
if (!image_path.empty()) {
|
||||
data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user