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)
|
static PyObject *cache_image_func(PyObject * /*self*/, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *pycontext, *pyscene, *pyimage;
|
PyObject *pycontext, *pyimage;
|
||||||
if (!PyArg_ParseTuple(args, "OOO", &pycontext, &pyscene, &pyimage)) {
|
if (!PyArg_ParseTuple(args, "OOO", &pycontext, &pyimage)) {
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
DagerD marked this conversation as resolved
Outdated
|
|||||||
|
|
||||||
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext);
|
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext);
|
||||||
Scene *scene = (Scene *)PyLong_AsVoidPtr(pyscene);
|
|
||||||
Image *image = (Image *)PyLong_AsVoidPtr(pyimage);
|
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());
|
return PyUnicode_FromString(image_path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,25 +4,21 @@
|
|||||||
#include <pxr/imaging/hio/imageRegistry.h>
|
#include <pxr/imaging/hio/imageRegistry.h>
|
||||||
|
|
||||||
#include "BKE_appdir.h"
|
#include "BKE_appdir.h"
|
||||||
#include "BKE_image.h"
|
|
||||||
#include "BKE_image_format.h"
|
#include "BKE_image_format.h"
|
||||||
#include "BKE_image_save.h"
|
#include "BKE_image_save.h"
|
||||||
#include "BLI_fileops.h"
|
#include "BLI_fileops.h"
|
||||||
#include "BLI_path_util.h"
|
#include "BLI_path_util.h"
|
||||||
|
|
||||||
#include "DNA_windowmanager_types.h"
|
|
||||||
|
|
||||||
#include "blender_scene_delegate.h"
|
#include "blender_scene_delegate.h"
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
std::string cache_image_file(
|
std::string cache_image_file(Image *image, bContext *context, ImageUser *iuser, bool check_exist)
|
||||||
Image *image, bContext *context, Scene *scene, ImageUser *iuser, bool check_exist)
|
|
||||||
{
|
{
|
||||||
char file_path[FILE_MAX];
|
char file_path[FILE_MAX];
|
||||||
char file_name[32];
|
|
||||||
Main *main = CTX_data_main(context);
|
Main *main = CTX_data_main(context);
|
||||||
|
Scene *scene = CTX_data_scene(context);
|
||||||
ImageSaveOptions opts;
|
ImageSaveOptions opts;
|
||||||
if (BKE_image_save_options_init(&opts, main, scene, image, iuser, false, false)) {
|
if (BKE_image_save_options_init(&opts, main, scene, image, iuser, false, false)) {
|
||||||
char file_name[32];
|
char file_name[32];
|
||||||
@ -52,26 +48,21 @@ std::string cache_image_file(
|
|||||||
return file_path;
|
return file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cache_or_get_image_file(Image *image,
|
std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser *iuser)
|
||||||
BlenderSceneDelegate *scene_delegate,
|
|
||||||
ImageUser *iuser)
|
|
||||||
{
|
{
|
||||||
std::string file_path(FILE_MAX, 0);
|
std::string file_path(FILE_MAX, 0);
|
||||||
if (image->source == IMA_SRC_GENERATED) {
|
if (image->source == IMA_SRC_GENERATED) {
|
||||||
file_path = cache_image_file(
|
file_path = cache_image_file(image, context, iuser, false);
|
||||||
image, scene_delegate->context, scene_delegate->scene, iuser, false);
|
|
||||||
}
|
}
|
||||||
else if (BKE_image_has_packedfile(image)) {
|
else if (BKE_image_has_packedfile(image)) {
|
||||||
file_path = cache_image_file(
|
file_path = cache_image_file(image, context, iuser, true);
|
||||||
image, scene_delegate->context, scene_delegate->scene, iuser, true);
|
|
||||||
}
|
}
|
||||||
else {
|
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);
|
BKE_image_user_file_path_ex(main, iuser, image, file_path.data(), false, true);
|
||||||
|
|
||||||
if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(file_path)) {
|
if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(file_path)) {
|
||||||
file_path = cache_image_file(
|
file_path = cache_image_file(image, context, iuser, true);
|
||||||
image, scene_delegate->context, scene_delegate->scene, iuser, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,18 +3,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "BKE_context.h"
|
||||||
#include "BKE_image.h"
|
#include "BKE_image.h"
|
||||||
#include "BKE_image_save.h"
|
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class BlenderSceneDelegate;
|
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);
|
||||||
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);
|
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -87,7 +87,8 @@ void WorldData::init()
|
|||||||
NodeTexImage *tex = static_cast<NodeTexImage *>(color_input_node->storage);
|
NodeTexImage *tex = static_cast<NodeTexImage *>(color_input_node->storage);
|
||||||
Image *image = (Image *)color_input_node->id;
|
Image *image = (Image *)color_input_node->id;
|
||||||
if (image) {
|
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()) {
|
if (!image_path.empty()) {
|
||||||
data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path);
|
data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user
why did you remove this?
Mistake. Fixed.