forked from blender/blender
Add IBL support #29
@ -5,8 +5,8 @@
|
|||||||
#include "DNA_screen_types.h"
|
#include "DNA_screen_types.h"
|
||||||
#include "DNA_view3d_types.h"
|
#include "DNA_view3d_types.h"
|
||||||
|
|
||||||
#include "scene_delegate/object.h"
|
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
#include "scene_delegate/object.h"
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ pxr::SdfPath BlenderSceneDelegate::prim_id(ID *id, const char *prefix) const
|
|||||||
{
|
{
|
||||||
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
||||||
char str[32];
|
char str[32];
|
||||||
snprintf(str, 32, "%s_%016llx", prefix, (uint64_t)id);
|
snprintf(str, 32, "%s_%016llx", prefix, (uintptr_t)id);
|
||||||
return GetDelegateID().AppendElementString(str);
|
return GetDelegateID().AppendElementString(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "BKE_appdir.h"
|
#include "BKE_appdir.h"
|
||||||
#include "BKE_image.h"
|
#include "BKE_image.h"
|
||||||
#include "BKE_image_save.h"
|
#include "BKE_image_save.h"
|
||||||
|
#include "BLI_fileops.h"
|
||||||
#include "BLI_path_util.h"
|
#include "BLI_path_util.h"
|
||||||
#include "BLI_string.h"
|
#include "BLI_string.h"
|
||||||
|
|
||||||
@ -17,48 +18,63 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
|
static std::string cache_image_file(Image *image,
|
||||||
|
BlenderSceneDelegate *scene_delegate,
|
||||||
|
ImageUser *iuser,
|
||||||
|
bool check_exist)
|
||||||
|
{
|
||||||
|
std::string file_path(FILE_MAX, 0);
|
||||||
|
char file_name[32];
|
||||||
|
snprintf(file_name, 32, "img_%016llx.hdr", (uintptr_t)image);
|
||||||
|
BLI_path_join(file_path.data(),
|
||||||
|
file_path.capacity(),
|
||||||
|
BKE_tempdir_session(),
|
||||||
|
"hydra_image_cache",
|
||||||
|
file_name);
|
||||||
|
|
||||||
|
if (check_exist && BLI_exists(file_path.c_str())) {
|
||||||
|
return file_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
Main *main = CTX_data_main(scene_delegate->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)) {
|
||||||
|
STRNCPY(opts.filepath, file_path.c_str());
|
||||||
|
ReportList reports;
|
||||||
|
if (!BKE_image_save(&reports, main, image, iuser, &opts)) {
|
||||||
|
file_path = "";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
BKE_image_save_options_free(&opts);
|
||||||
|
|
||||||
|
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s -> %s", image->id.name, file_path.c_str());
|
||||||
|
return file_path;
|
||||||
|
}
|
||||||
|
|
||||||
std::string cache_or_get_image_file(Image *image,
|
std::string cache_or_get_image_file(Image *image,
|
||||||
BlenderSceneDelegate *scene_delegate,
|
BlenderSceneDelegate *scene_delegate,
|
||||||
ImageUser *iuser)
|
ImageUser *iuser)
|
||||||
{
|
{
|
||||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", image->id.name);
|
std::string file_path(FILE_MAX, 0);
|
||||||
|
if (image->source == IMA_SRC_GENERATED) {
|
||||||
|
file_path = cache_image_file(image, scene_delegate, iuser, false);
|
||||||
|
}
|
||||||
|
else if (BKE_image_has_packedfile(image)) {
|
||||||
|
file_path = cache_image_file(image, scene_delegate, 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);
|
||||||
|
|
||||||
std::string image_path(FILE_MAX, 0);
|
if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(file_path)) {
|
||||||
Main *main = CTX_data_main(scene_delegate->context);
|
file_path = cache_image_file(image, scene_delegate, iuser, true);
|
||||||
if (pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(image->filepath)) {
|
}
|
||||||
BKE_image_user_file_path_ex(main, iuser, image, image_path.data(), false, true);
|
|
||||||
return image_path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageSaveOptions opts;
|
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s -> %s", image->id.name, file_path.c_str());
|
||||||
opts.im_format.imtype = R_IMF_IMTYPE_RADHDR;
|
return file_path;
|
||||||
|
|
||||||
if (!BKE_image_save_options_init(
|
|
||||||
&opts, main, scene_delegate->scene, image, iuser, true, false)) {
|
|
||||||
BKE_image_save_options_free(&opts);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
char image_name[32];
|
|
||||||
snprintf(image_name, 32, "img_%016llx.hdr", (uint64_t)image);
|
|
||||||
|
|
||||||
BLI_path_join(image_path.data(),
|
|
||||||
image_path.capacity(),
|
|
||||||
BKE_tempdir_session(),
|
|
||||||
"hydra_image_cache",
|
|
||||||
image_name);
|
|
||||||
STRNCPY(opts.filepath, image_path.c_str());
|
|
||||||
|
|
||||||
ReportList reports;
|
|
||||||
if (!BKE_image_save(&reports, main, image, iuser, &opts)) {
|
|
||||||
BKE_image_save_options_free(&opts);
|
|
||||||
return "";
|
|
||||||
};
|
|
||||||
|
|
||||||
BKE_image_save_options_free(&opts);
|
|
||||||
|
|
||||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s: cached=%s", image->id.name, image_path.c_str());
|
|
||||||
return image_path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
Loading…
Reference in New Issue
Block a user