Refactor code after PR #57 #67

Merged
Bogdan Nagirniak merged 9 commits from hydra-object_data-refactor into hydra-render 2023-07-20 22:34:34 +02:00
6 changed files with 33 additions and 63 deletions
Showing only changes of commit 84e11ae430 - Show all commits

View File

@ -10,11 +10,9 @@ namespace blender::render::hydra {
void PreviewEngine::render(Depsgraph *depsgraph)
{
prepare_for_render(depsgraph);
render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color);
{
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
engine_->Execute(render_index_.get(), &tasks_);
}
engine_->Execute(render_index_.get(), &tasks_);
std::vector<float> &pixels = render_images_["Combined"];
while (true) {

View File

@ -24,7 +24,7 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate,
void LightData::init()
{
ID_LOG(1, "");
OBJ_LOG(1, "");
Light *light = (Light *)object->data;
data_.clear();
@ -97,13 +97,13 @@ void LightData::init()
void LightData::insert()
{
ID_LOG(1, "");
OBJ_LOG(1, "");
scene_delegate_->GetRenderIndex().InsertSprim(prim_type_, scene_delegate_, prim_id);
}
void LightData::remove()
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s", prim_id.GetText());
ID_LOG(1, "");
scene_delegate_->GetRenderIndex().RemoveSprim(prim_type_, prim_id);
}
@ -127,13 +127,13 @@ void LightData::update()
}
if (bits != pxr::HdChangeTracker::Clean) {
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, bits);
ID_LOG(1, "");
OBJ_LOG(1, "");
}
}
pxr::VtValue LightData::get_data(pxr::TfToken const &key) const
{
ID_LOG(3, "%s", key.GetText());
OBJ_LOG(3, "%s", key.GetText());
auto it = data_.find(key);
if (it != data_.end()) {
return pxr::VtValue(it->second);

View File

@ -28,7 +28,7 @@ class LightData : public ObjectData {
pxr::VtValue get_data(pxr::TfToken const &key) const override;
private:
protected:
pxr::TfToken prim_type(Light *light);
std::map<pxr::TfToken, pxr::VtValue> data_;

View File

@ -46,4 +46,12 @@ using ObjectDataMap = Map<pxr::SdfPath, std::unique_ptr<ObjectData>>;
pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4]);
#define OBJ_LOG(level, msg, ...) \
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, \
level, \
"%s (%s): " msg, \
prim_id.GetText(), \
object ? object->id.name : "", \
##__VA_ARGS__);
} // namespace blender::render::hydra

View File

@ -33,14 +33,13 @@
namespace blender::render::hydra {
WorldData::WorldData(BlenderSceneDelegate *scene_delegate, pxr::SdfPath const &prim_id)
: IdData(scene_delegate, prim_id)
: LightData(scene_delegate, nullptr, prim_id)
{
prim_type_ = pxr::HdPrimTypeTokens->domeLight;
}
void WorldData::init()
{
write_transform();
data_.clear();
data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true;
@ -51,7 +50,7 @@ void WorldData::init()
if (scene_delegate_->shading_settings.use_scene_world) {
World *world = scene_delegate_->scene->world;
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s: %s", prim_id.GetText(), world->id.name);
ID_LOG(1, "%s", world->id.name);
exposure = world->exposure;
if (world->use_nodes) {
@ -115,21 +114,13 @@ void WorldData::init()
}
}
else {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
1,
"%s: studiolight: %s",
prim_id.GetText(),
scene_delegate_->shading_settings.studiolight_name.c_str());
ID_LOG(1, "studiolight: %s", scene_delegate_->shading_settings.studiolight_name.c_str());
StudioLight *sl = BKE_studiolight_find(
scene_delegate_->shading_settings.studiolight_name.c_str(),
STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE);
if (sl != NULL && sl->flag & STUDIOLIGHT_TYPE_WORLD) {
texture_file = pxr::SdfAssetPath(sl->filepath, sl->filepath);
transform *= pxr::GfMatrix4d(
pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, -1.0),
RAD2DEGF(scene_delegate_->shading_settings.studiolight_rotation)),
pxr::GfVec3d());
/* coefficient to follow Cycles result */
intensity = scene_delegate_->shading_settings.studiolight_intensity / 2;
}
@ -139,45 +130,27 @@ void WorldData::init()
data_[pxr::HdLightTokens->exposure] = exposure;
data_[pxr::HdLightTokens->color] = color;
data_[pxr::HdLightTokens->textureFile] = texture_file;
}
void WorldData::insert()
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s", prim_id.GetText());
scene_delegate_->GetRenderIndex().InsertSprim(
pxr::HdPrimTypeTokens->domeLight, scene_delegate_, prim_id);
}
void WorldData::remove()
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s", prim_id.GetText());
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, prim_id);
write_transform();
}
void WorldData::update()
{
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s", prim_id.GetText());
ID_LOG(1, "");
init();
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id,
pxr::HdLight::AllDirty);
}
pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const
{
auto it = data_.find(key);
if (it != data_.end()) {
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s: %s", prim_id.GetText(), key.GetText());
return pxr::VtValue(it->second);
}
return pxr::VtValue();
}
void WorldData::write_transform()
{
transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d());
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180), pxr::GfVec3d());
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0), pxr::GfVec3d());
transform = pxr::GfMatrix4d().SetRotate(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), 90.0)) *
pxr::GfMatrix4d().SetRotate(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0));
if (!scene_delegate_->shading_settings.use_scene_world) {
transform *= pxr::GfMatrix4d().SetRotate(
pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, -1.0),
RAD2DEGF(scene_delegate_->shading_settings.studiolight_rotation)));
}
}
} // namespace blender::render::hydra

View File

@ -14,28 +14,19 @@
#include "DNA_view3d_types.h"
#include "DNA_world_types.h"
#include "id.h"
#include "light.h"
namespace blender::render::hydra {
class WorldData : public IdData {
class WorldData : public LightData {
public:
WorldData(BlenderSceneDelegate *scene_delegate, pxr::SdfPath const &prim_id);
void init() override;
void insert() override;
void remove() override;
void update() override;
void update(World *world);
pxr::VtValue get_data(pxr::TfToken const &key) const override;
pxr::GfMatrix4d transform;
private:
void write_transform();
std::map<pxr::TfToken, pxr::VtValue> data_;
protected:
void write_transform() override;
};
} // namespace blender::render::hydra