forked from blender/blender
Collection of bugfixes #76
@ -2,6 +2,7 @@
|
||||
* Copyright 2011-2022 Blender Foundation */
|
||||
|
||||
#include "DNA_camera_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_view3d_types.h"
|
||||
|
||||
@ -10,11 +11,9 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
CameraData::CameraData(bContext *context)
|
||||
CameraData::CameraData(View3D *v3d, ARegion *region)
|
||||
{
|
||||
View3D *view3d = CTX_wm_view3d(context);
|
||||
RegionView3D *region_data = (RegionView3D *)CTX_wm_region_data(context);
|
||||
ARegion *region = CTX_wm_region(context);
|
||||
RegionView3D *region_data = (RegionView3D *)region->regiondata;
|
||||
|
||||
/* This constant was found experimentally, didn't find such option in
|
||||
* context.view3d or context.region_data. */
|
||||
@ -27,9 +26,9 @@ CameraData::CameraData(bContext *context)
|
||||
switch (region_data->persp) {
|
||||
case RV3D_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);
|
||||
focal_length_ = view3d->lens;
|
||||
focal_length_ = v3d->lens;
|
||||
|
||||
if (ratio > 1.0) {
|
||||
sensor_size_ = pxr::GfVec2f(VIEWPORT_SENSOR_SIZE, VIEWPORT_SENSOR_SIZE / ratio);
|
||||
@ -44,8 +43,8 @@ CameraData::CameraData(bContext *context)
|
||||
mode_ = CAM_ORTHO;
|
||||
lens_shift_ = pxr::GfVec2f(0.0f, 0.0f);
|
||||
|
||||
float o_size = region_data->dist * VIEWPORT_SENSOR_SIZE / view3d->lens;
|
||||
float o_depth = view3d->clip_end;
|
||||
float o_size = region_data->dist * VIEWPORT_SENSOR_SIZE / v3d->lens;
|
||||
float o_depth = v3d->clip_end;
|
||||
|
||||
clip_range_ = pxr::GfRange1f(-o_depth * 0.5, o_depth * 0.5);
|
||||
|
||||
@ -60,7 +59,7 @@ CameraData::CameraData(bContext *context)
|
||||
|
||||
case RV3D_CAMOB: {
|
||||
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;
|
||||
|
||||
/* This formula was taken from previous plugin with corresponded comment.
|
||||
|
@ -8,15 +8,15 @@
|
||||
#include <pxr/base/gf/camera.h>
|
||||
#include <pxr/base/gf/vec2f.h>
|
||||
|
||||
#include "BKE_context.h"
|
||||
|
||||
#include "DNA_object_types.h"
|
||||
struct ARegion;
|
||||
struct Object;
|
||||
struct View3D;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
class CameraData {
|
||||
public:
|
||||
CameraData(bContext *context);
|
||||
CameraData(View3D *v3d, ARegion *region);
|
||||
CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile);
|
||||
|
||||
pxr::GfCamera gf_camera();
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include "BLI_path_util.h"
|
||||
|
||||
#include "BKE_context.h"
|
||||
|
||||
#include "GPU_context.h"
|
||||
|
||||
#include "DEG_depsgraph_query.h"
|
||||
@ -83,7 +85,7 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context)
|
||||
hydra_scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
||||
render_index_.get(), scene_path, scene_delegate_settings_);
|
||||
}
|
||||
hydra_scene_delegate_->populate(depsgraph, context);
|
||||
hydra_scene_delegate_->populate(depsgraph, CTX_wm_view3d(context));
|
||||
}
|
||||
else {
|
||||
/* Slow USD export for reference. */
|
||||
@ -98,7 +100,7 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context)
|
||||
usd_scene_delegate_ = std::make_unique<USDSceneDelegate>(
|
||||
render_index_.get(), scene_path, scene_delegate_settings_);
|
||||
}
|
||||
usd_scene_delegate_->populate(depsgraph, context);
|
||||
usd_scene_delegate_->populate(depsgraph);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include <pxr/usdImaging/usdImagingGL/engine.h>
|
||||
|
||||
#include "BKE_appdir.h"
|
||||
#include "BKE_context.h"
|
||||
|
||||
#include "BLI_fileops.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);
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -198,14 +198,14 @@ pxr::HdVolumeFieldDescriptorVector BlenderSceneDelegate::GetVolumeFieldDescripto
|
||||
return v_data->field_descriptors();
|
||||
}
|
||||
|
||||
void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
||||
void BlenderSceneDelegate::populate(Depsgraph *deps, View3D *v3d)
|
||||
{
|
||||
bool is_populated = depsgraph != nullptr;
|
||||
|
||||
depsgraph = deps;
|
||||
context = cont;
|
||||
bmain = DEG_get_bmain(deps);
|
||||
scene = DEG_get_input_scene(depsgraph);
|
||||
view3d = CTX_wm_view3d(context);
|
||||
view3d = v3d;
|
||||
|
||||
if (is_populated) {
|
||||
check_updates();
|
||||
@ -231,7 +231,7 @@ void BlenderSceneDelegate::clear()
|
||||
materials_.clear();
|
||||
|
||||
depsgraph = nullptr;
|
||||
context = nullptr;
|
||||
bmain = nullptr;
|
||||
scene = nullptr;
|
||||
view3d = nullptr;
|
||||
}
|
||||
|
@ -6,8 +6,8 @@
|
||||
#include <pxr/base/gf/vec2f.h>
|
||||
#include <pxr/imaging/hd/sceneDelegate.h>
|
||||
|
||||
#include "BKE_context.h"
|
||||
#include "BLI_map.hh"
|
||||
|
||||
#include "DEG_depsgraph.h"
|
||||
|
||||
#include "CLG_log.h"
|
||||
@ -22,6 +22,11 @@
|
||||
#include "volume_modifier.h"
|
||||
#include "world.h"
|
||||
|
||||
struct Depsgraph;
|
||||
struct Main;
|
||||
struct Scene;
|
||||
struct View3D;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE;
|
||||
@ -69,12 +74,12 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
pxr::HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(
|
||||
pxr::SdfPath const &volume_id) override;
|
||||
|
||||
void populate(Depsgraph *depsgraph, bContext *context);
|
||||
void populate(Depsgraph *depsgraph, View3D *v3d);
|
||||
void clear();
|
||||
|
||||
Depsgraph *depsgraph = nullptr;
|
||||
bContext *context = nullptr;
|
||||
View3D *view3d = nullptr;
|
||||
Main *bmain = nullptr;
|
||||
Scene *scene = nullptr;
|
||||
const SceneDelegateSettings &settings;
|
||||
ShadingSettings shading_settings;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#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"
|
||||
@ -29,16 +30,12 @@ static std::string get_cache_file(const std::string &file_name, bool mkdir = tru
|
||||
return file_path;
|
||||
}
|
||||
|
||||
static std::string cache_image_file(Image *image,
|
||||
bContext *context,
|
||||
ImageUser *iuser,
|
||||
bool check_exist)
|
||||
static std::string cache_image_file(
|
||||
Main *bmain, Scene *scene, Image *image, ImageUser *iuser, bool check_exist)
|
||||
{
|
||||
std::string file_path;
|
||||
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)) {
|
||||
if (BKE_image_save_options_init(&opts, bmain, scene, image, iuser, false, false)) {
|
||||
char file_name[32];
|
||||
const char *r_ext = BLI_path_extension_or_end(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;
|
||||
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());
|
||||
}
|
||||
else {
|
||||
@ -67,23 +64,22 @@ static std::string cache_image_file(Image *image,
|
||||
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;
|
||||
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)) {
|
||||
file_path = cache_image_file(image, context, iuser, true);
|
||||
file_path = cache_image_file(bmain, scene, image, iuser, true);
|
||||
}
|
||||
else {
|
||||
Main *main = CTX_data_main(context);
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,12 +3,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_image.h"
|
||||
#include <string>
|
||||
|
||||
struct Main;
|
||||
struct Scene;
|
||||
struct Image;
|
||||
struct ImageUser;
|
||||
|
||||
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]);
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -42,7 +42,7 @@ USDSceneDelegate::~USDSceneDelegate()
|
||||
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. */
|
||||
const bool use_materialx = !settings_.mx_filename_key.IsEmpty();
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "settings.h"
|
||||
|
||||
struct Depsgraph;
|
||||
struct bContext;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
@ -32,7 +31,7 @@ class USDSceneDelegate {
|
||||
const SceneDelegateSettings &settings_);
|
||||
~USDSceneDelegate();
|
||||
|
||||
void populate(Depsgraph *depsgraph, bContext *context);
|
||||
void populate(Depsgraph *depsgraph);
|
||||
};
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -30,8 +30,7 @@ void VolumeData::init()
|
||||
field_descriptors_.clear();
|
||||
|
||||
Volume *volume = (Volume *)((Object *)this->id)->data;
|
||||
Main *main = CTX_data_main(scene_delegate_->context);
|
||||
if (!BKE_volume_load(volume, main)) {
|
||||
if (!BKE_volume_load(volume, scene_delegate_->bmain)) {
|
||||
return;
|
||||
}
|
||||
filepath_ = BKE_volume_grids_frame_filepath(volume);
|
||||
|
@ -11,14 +11,16 @@
|
||||
#include <pxr/imaging/hd/tokens.h>
|
||||
#include <pxr/usd/usdLux/tokens.h>
|
||||
|
||||
#include "BKE_context.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_runtime.hh"
|
||||
#include "BKE_studiolight.h"
|
||||
#include "BLI_math_rotation.h"
|
||||
#include "BLI_path_util.h"
|
||||
|
||||
#include "NOD_shader.h"
|
||||
|
||||
#include "../engine.h"
|
||||
@ -94,7 +96,7 @@ void WorldData::init()
|
||||
Image *image = (Image *)color_input_node->id;
|
||||
if (image) {
|
||||
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()) {
|
||||
texture_file = pxr::SdfAssetPath(image_path, image_path);
|
||||
}
|
||||
|
@ -6,12 +6,16 @@
|
||||
#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_view3d_types.h"
|
||||
|
||||
#include "BKE_camera.h"
|
||||
#include "BKE_context.h"
|
||||
|
||||
#include "BLI_math_matrix.h"
|
||||
#include "BLI_timecode.h"
|
||||
#include "DEG_depsgraph_query.h"
|
||||
#include "DNA_camera_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
|
||||
#include "GPU_context.h"
|
||||
@ -38,7 +42,8 @@ struct ViewSettings {
|
||||
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);
|
||||
RegionView3D *region_data = (RegionView3D *)CTX_wm_region_data(context);
|
||||
|
Loading…
Reference in New Issue
Block a user