Collection of bugfixes #76

Merged
Brecht Van Lommel merged 6 commits from brecht/blender:hydra-fixes into hydra-render 2023-07-27 13:38:26 +02:00
13 changed files with 64 additions and 50 deletions
Showing only changes of commit 3b325ca349 - Show all commits

View File

@ -2,6 +2,7 @@
* Copyright 2011-2022 Blender Foundation */ * Copyright 2011-2022 Blender Foundation */
#include "DNA_camera_types.h" #include "DNA_camera_types.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h" #include "DNA_screen_types.h"
#include "DNA_view3d_types.h" #include "DNA_view3d_types.h"
@ -10,11 +11,9 @@
namespace blender::render::hydra { namespace blender::render::hydra {
CameraData::CameraData(bContext *context) CameraData::CameraData(View3D *v3d, ARegion *region)
{ {
View3D *view3d = CTX_wm_view3d(context); RegionView3D *region_data = (RegionView3D *)region->regiondata;
RegionView3D *region_data = (RegionView3D *)CTX_wm_region_data(context);
ARegion *region = CTX_wm_region(context);
/* This constant was found experimentally, didn't find such option in /* This constant was found experimentally, didn't find such option in
* context.view3d or context.region_data. */ * context.view3d or context.region_data. */
@ -27,9 +26,9 @@ CameraData::CameraData(bContext *context)
switch (region_data->persp) { switch (region_data->persp) {
case RV3D_PERSP: { case RV3D_PERSP: {
mode_ = CAM_PERSP; mode_ = CAM_PERSP;
clip_range_ = pxr::GfRange1f(view3d->clip_start, view3d->clip_end); clip_range_ = pxr::GfRange1f(v3d->clip_start, v3d->clip_end);
lens_shift_ = pxr::GfVec2f(0.0, 0.0); lens_shift_ = pxr::GfVec2f(0.0, 0.0);
focal_length_ = view3d->lens; focal_length_ = v3d->lens;
if (ratio > 1.0) { if (ratio > 1.0) {
sensor_size_ = pxr::GfVec2f(VIEWPORT_SENSOR_SIZE, VIEWPORT_SENSOR_SIZE / ratio); sensor_size_ = pxr::GfVec2f(VIEWPORT_SENSOR_SIZE, VIEWPORT_SENSOR_SIZE / ratio);
@ -44,8 +43,8 @@ CameraData::CameraData(bContext *context)
mode_ = CAM_ORTHO; mode_ = CAM_ORTHO;
lens_shift_ = pxr::GfVec2f(0.0f, 0.0f); lens_shift_ = pxr::GfVec2f(0.0f, 0.0f);
float o_size = region_data->dist * VIEWPORT_SENSOR_SIZE / view3d->lens; float o_size = region_data->dist * VIEWPORT_SENSOR_SIZE / v3d->lens;
float o_depth = view3d->clip_end; float o_depth = v3d->clip_end;
clip_range_ = pxr::GfRange1f(-o_depth * 0.5, o_depth * 0.5); clip_range_ = pxr::GfRange1f(-o_depth * 0.5, o_depth * 0.5);
@ -60,7 +59,7 @@ CameraData::CameraData(bContext *context)
case RV3D_CAMOB: { case RV3D_CAMOB: {
pxr::GfMatrix4d mat = transform_; pxr::GfMatrix4d mat = transform_;
*this = CameraData(view3d->camera, res, pxr::GfVec4f(0, 0, 1, 1)); *this = CameraData(v3d->camera, res, pxr::GfVec4f(0, 0, 1, 1));
transform_ = mat; transform_ = mat;
/* This formula was taken from previous plugin with corresponded comment. /* This formula was taken from previous plugin with corresponded comment.

View File

@ -8,15 +8,15 @@
#include <pxr/base/gf/camera.h> #include <pxr/base/gf/camera.h>
#include <pxr/base/gf/vec2f.h> #include <pxr/base/gf/vec2f.h>
#include "BKE_context.h" struct ARegion;
struct Object;
#include "DNA_object_types.h" struct View3D;
namespace blender::render::hydra { namespace blender::render::hydra {
class CameraData { class CameraData {
public: public:
CameraData(bContext *context); CameraData(View3D *v3d, ARegion *region);
CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile); CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile);
pxr::GfCamera gf_camera(); pxr::GfCamera gf_camera();

View File

@ -10,6 +10,8 @@
#include "BLI_path_util.h" #include "BLI_path_util.h"
#include "BKE_context.h"
#include "GPU_context.h" #include "GPU_context.h"
#include "DEG_depsgraph_query.h" #include "DEG_depsgraph_query.h"
@ -83,7 +85,7 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context)
hydra_scene_delegate_ = std::make_unique<BlenderSceneDelegate>( hydra_scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
render_index_.get(), scene_path, scene_delegate_settings_); render_index_.get(), scene_path, scene_delegate_settings_);
} }
hydra_scene_delegate_->populate(depsgraph, context); hydra_scene_delegate_->populate(depsgraph, CTX_wm_view3d(context));
} }
else { else {
/* Slow USD export for reference. */ /* Slow USD export for reference. */
@ -98,7 +100,7 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context)
usd_scene_delegate_ = std::make_unique<USDSceneDelegate>( usd_scene_delegate_ = std::make_unique<USDSceneDelegate>(
render_index_.get(), scene_path, scene_delegate_settings_); render_index_.get(), scene_path, scene_delegate_settings_);
} }
usd_scene_delegate_->populate(depsgraph, context); usd_scene_delegate_->populate(depsgraph);
} }
} }

View File

@ -11,6 +11,8 @@
#include <pxr/usdImaging/usdImagingGL/engine.h> #include <pxr/usdImaging/usdImagingGL/engine.h>
#include "BKE_appdir.h" #include "BKE_appdir.h"
#include "BKE_context.h"
#include "BLI_fileops.h" #include "BLI_fileops.h"
#include "BLI_path_util.h" #include "BLI_path_util.h"
@ -220,7 +222,8 @@ static PyObject *cache_or_get_image_file_func(PyObject * /*self*/, PyObject *arg
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext); bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext);
Image *image = (Image *)PyLong_AsVoidPtr(pyimage); Image *image = (Image *)PyLong_AsVoidPtr(pyimage);
std::string image_path = cache_or_get_image_file(image, context, nullptr); std::string image_path = cache_or_get_image_file(
CTX_data_main(context), CTX_data_scene(context), image, nullptr);
return PyUnicode_FromString(image_path.c_str()); return PyUnicode_FromString(image_path.c_str());
} }

View File

@ -198,14 +198,14 @@ pxr::HdVolumeFieldDescriptorVector BlenderSceneDelegate::GetVolumeFieldDescripto
return v_data->field_descriptors(); return v_data->field_descriptors();
} }
void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) void BlenderSceneDelegate::populate(Depsgraph *deps, View3D *v3d)
{ {
bool is_populated = depsgraph != nullptr; bool is_populated = depsgraph != nullptr;
depsgraph = deps; depsgraph = deps;
context = cont; bmain = DEG_get_bmain(deps);
scene = DEG_get_input_scene(depsgraph); scene = DEG_get_input_scene(depsgraph);
view3d = CTX_wm_view3d(context); view3d = v3d;
if (is_populated) { if (is_populated) {
check_updates(); check_updates();
@ -231,7 +231,7 @@ void BlenderSceneDelegate::clear()
materials_.clear(); materials_.clear();
depsgraph = nullptr; depsgraph = nullptr;
context = nullptr; bmain = nullptr;
scene = nullptr; scene = nullptr;
view3d = nullptr; view3d = nullptr;
} }

View File

@ -6,8 +6,8 @@
#include <pxr/base/gf/vec2f.h> #include <pxr/base/gf/vec2f.h>
#include <pxr/imaging/hd/sceneDelegate.h> #include <pxr/imaging/hd/sceneDelegate.h>
#include "BKE_context.h"
#include "BLI_map.hh" #include "BLI_map.hh"
#include "DEG_depsgraph.h" #include "DEG_depsgraph.h"
#include "CLG_log.h" #include "CLG_log.h"
@ -22,6 +22,11 @@
#include "volume_modifier.h" #include "volume_modifier.h"
#include "world.h" #include "world.h"
struct Depsgraph;
struct Main;
struct Scene;
struct View3D;
namespace blender::render::hydra { namespace blender::render::hydra {
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE;
@ -69,12 +74,12 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
pxr::HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors( pxr::HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(
pxr::SdfPath const &volume_id) override; pxr::SdfPath const &volume_id) override;
void populate(Depsgraph *depsgraph, bContext *context); void populate(Depsgraph *depsgraph, View3D *v3d);
void clear(); void clear();
Depsgraph *depsgraph = nullptr; Depsgraph *depsgraph = nullptr;
bContext *context = nullptr;
View3D *view3d = nullptr; View3D *view3d = nullptr;
Main *bmain = nullptr;
Scene *scene = nullptr; Scene *scene = nullptr;
const SceneDelegateSettings &settings; const SceneDelegateSettings &settings;
ShadingSettings shading_settings; ShadingSettings shading_settings;

View File

@ -4,6 +4,7 @@
#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"
@ -29,16 +30,12 @@ static std::string get_cache_file(const std::string &file_name, bool mkdir = tru
return file_path; return file_path;
} }
static std::string cache_image_file(Image *image, static std::string cache_image_file(
bContext *context, Main *bmain, Scene *scene, Image *image, ImageUser *iuser, bool check_exist)
ImageUser *iuser,
bool check_exist)
{ {
std::string file_path; std::string file_path;
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, bmain, scene, image, iuser, false, false)) {
char file_name[32]; char file_name[32];
const char *r_ext = BLI_path_extension_or_end(image->id.name); const char *r_ext = BLI_path_extension_or_end(image->id.name);
if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(image->id.name)) { if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(image->id.name)) {
@ -55,7 +52,7 @@ static std::string cache_image_file(Image *image,
opts.save_copy = true; opts.save_copy = true;
STRNCPY(opts.filepath, file_path.c_str()); STRNCPY(opts.filepath, file_path.c_str());
if (BKE_image_save(nullptr, main, image, iuser, &opts)) { if (BKE_image_save(nullptr, bmain, image, iuser, &opts)) {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path.c_str()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path.c_str());
} }
else { else {
@ -67,23 +64,22 @@ static std::string cache_image_file(Image *image,
return file_path; return file_path;
} }
std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser *iuser) std::string cache_or_get_image_file(Main *bmain, Scene *scene, Image *image, ImageUser *iuser)
{ {
std::string file_path; std::string file_path;
if (image->source == IMA_SRC_GENERATED) { if (image->source == IMA_SRC_GENERATED) {
file_path = cache_image_file(image, context, iuser, false); file_path = cache_image_file(bmain, scene, image, iuser, false);
} }
else if (BKE_image_has_packedfile(image)) { else if (BKE_image_has_packedfile(image)) {
file_path = cache_image_file(image, context, iuser, true); file_path = cache_image_file(bmain, scene, image, iuser, true);
} }
else { else {
Main *main = CTX_data_main(context);
char str[FILE_MAX]; char str[FILE_MAX];
BKE_image_user_file_path_ex(main, iuser, image, str, false, true); BKE_image_user_file_path_ex(bmain, iuser, image, str, false, true);
file_path = str; file_path = str;
if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(file_path)) { if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(file_path)) {
file_path = cache_image_file(image, context, iuser, true); file_path = cache_image_file(bmain, scene, image, iuser, true);
} }
} }

View File

@ -3,12 +3,16 @@
#pragma once #pragma once
#include "BKE_context.h" #include <string>
#include "BKE_image.h"
struct Main;
struct Scene;
struct Image;
struct ImageUser;
namespace blender::render::hydra { namespace blender::render::hydra {
std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser *iuser); std::string cache_or_get_image_file(Main *bmain, Scene *Scene, Image *image, ImageUser *iuser);
std::string cache_image_color(float color[4]); std::string cache_image_color(float color[4]);
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -42,7 +42,7 @@ USDSceneDelegate::~USDSceneDelegate()
BLI_delete(temp_dir_.c_str(), true, true); BLI_delete(temp_dir_.c_str(), true, true);
} }
void USDSceneDelegate::populate(Depsgraph *depsgraph, bContext * /*context*/) void USDSceneDelegate::populate(Depsgraph *depsgraph)
{ {
/* TODO: implement MaterialX support in USD exporter. */ /* TODO: implement MaterialX support in USD exporter. */
const bool use_materialx = !settings_.mx_filename_key.IsEmpty(); const bool use_materialx = !settings_.mx_filename_key.IsEmpty();

View File

@ -11,7 +11,6 @@
#include "settings.h" #include "settings.h"
struct Depsgraph; struct Depsgraph;
struct bContext;
namespace blender::render::hydra { namespace blender::render::hydra {
@ -32,7 +31,7 @@ class USDSceneDelegate {
const SceneDelegateSettings &settings_); const SceneDelegateSettings &settings_);
~USDSceneDelegate(); ~USDSceneDelegate();
void populate(Depsgraph *depsgraph, bContext *context); void populate(Depsgraph *depsgraph);
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -30,8 +30,7 @@ void VolumeData::init()
field_descriptors_.clear(); field_descriptors_.clear();
Volume *volume = (Volume *)((Object *)this->id)->data; Volume *volume = (Volume *)((Object *)this->id)->data;
Main *main = CTX_data_main(scene_delegate_->context); if (!BKE_volume_load(volume, scene_delegate_->bmain)) {
if (!BKE_volume_load(volume, main)) {
return; return;
} }
filepath_ = BKE_volume_grids_frame_filepath(volume); filepath_ = BKE_volume_grids_frame_filepath(volume);

View File

@ -11,14 +11,16 @@
#include <pxr/imaging/hd/tokens.h> #include <pxr/imaging/hd/tokens.h>
#include <pxr/usd/usdLux/tokens.h> #include <pxr/usd/usdLux/tokens.h>
#include "BKE_context.h"
#include "DNA_node_types.h" #include "DNA_node_types.h"
#include "DNA_scene_types.h"
#include "BLI_math_rotation.h"
#include "BLI_path_util.h"
#include "BKE_node.h" #include "BKE_node.h"
#include "BKE_node_runtime.hh" #include "BKE_node_runtime.hh"
#include "BKE_studiolight.h" #include "BKE_studiolight.h"
#include "BLI_math_rotation.h"
#include "BLI_path_util.h"
#include "NOD_shader.h" #include "NOD_shader.h"
#include "../engine.h" #include "../engine.h"
@ -94,7 +96,7 @@ void WorldData::init()
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( std::string image_path = cache_or_get_image_file(
image, scene_delegate_->context, &tex->iuser); scene_delegate_->bmain, scene_delegate_->scene, image, &tex->iuser);
if (!image_path.empty()) { if (!image_path.empty()) {
texture_file = pxr::SdfAssetPath(image_path, image_path); texture_file = pxr::SdfAssetPath(image_path, image_path);
} }

View File

@ -6,12 +6,16 @@
#include <pxr/usd/usdGeom/camera.h> #include <pxr/usd/usdGeom/camera.h>
#include "DNA_vec_types.h" /* this include must be before BKE_camera.h due to "rctf" type */ #include "DNA_vec_types.h" /* this include must be before BKE_camera.h due to "rctf" type */
#include "DNA_view3d_types.h"
#include "BKE_camera.h" #include "BKE_camera.h"
#include "BKE_context.h"
#include "BLI_math_matrix.h" #include "BLI_math_matrix.h"
#include "BLI_timecode.h" #include "BLI_timecode.h"
#include "DEG_depsgraph_query.h" #include "DEG_depsgraph_query.h"
#include "DNA_camera_types.h" #include "DNA_camera_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h" #include "DNA_screen_types.h"
#include "GPU_context.h" #include "GPU_context.h"
@ -38,7 +42,8 @@ struct ViewSettings {
pxr::GfVec4i border; pxr::GfVec4i border;
}; };
ViewSettings::ViewSettings(bContext *context) : camera_data(context) ViewSettings::ViewSettings(bContext *context)
: camera_data(CTX_wm_view3d(context), CTX_wm_region(context))
{ {
View3D *view3d = CTX_wm_view3d(context); View3D *view3d = CTX_wm_view3d(context);
RegionView3D *region_data = (RegionView3D *)CTX_wm_region_data(context); RegionView3D *region_data = (RegionView3D *)CTX_wm_region_data(context);