BLEN-343: Create PreviewEngine #8

Merged
Bogdan Nagirniak merged 5 commits from BLEN-343 into hydra-render 2023-03-03 14:55:28 +01:00
9 changed files with 15 additions and 38 deletions
Showing only changes of commit f2a3093d8e - Show all commits

View File

@ -9,7 +9,6 @@
#include "glog/logging.h"
#include "sceneDelegate/blenderSceneDelegate.h"
#include "engine.h"
using namespace pxr;

View File

@ -16,20 +16,13 @@
#include "MEM_guardedalloc.h"
#include "RNA_blender_cpp.h"
#include "sceneDelegate/blenderSceneDelegate.h"
#include "renderTaskDelegate.h"
namespace blender::render::hydra {
class BlenderSceneDelegate;
class Engine {
public:
enum class EngineType {
Viewport = 1,
Final,
Preview
};
Engine(BL::RenderEngine &b_engine, const std::string &delegateId);
virtual ~Engine();
DagerD marked this conversation as resolved
Review

move to BlenderSceneDelegate class

move to BlenderSceneDelegate class

View File

@ -10,7 +10,6 @@
#include "glog/logging.h"
#include "sceneDelegate/blenderSceneDelegate.h"
#include "finalEngine.h"
#include "camera.h"
#include "utils.h"
@ -23,7 +22,7 @@ namespace blender::render::hydra {
void FinalEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, HdRenderSettingsMap &renderSettings)
{
sceneDelegate = std::make_unique<BlenderSceneDelegate>(renderIndex.get(),
SdfPath::AbsoluteRootPath().AppendElementString("scene"), EngineType::Final);
SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Final);
sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data);
for (auto const& setting : renderSettings) {

View File

@ -3,7 +3,6 @@
#include <pxr/usdImaging/usdAppUtils/camera.h>
#include "sceneDelegate/blenderSceneDelegate.h"
#include "previewEngine.h"
#include "camera.h"
@ -14,25 +13,17 @@ namespace blender::render::hydra {
void PreviewEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, HdRenderSettingsMap &renderSettings)
{
is_synced = false;
sceneDelegate = std::make_unique<BlenderSceneDelegate>(renderIndex.get(),
SdfPath::AbsoluteRootPath().AppendElementString("scene"), EngineType::Preview);
SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Preview);
sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data);
for (auto const& setting : renderSettings) {
renderDelegate->SetRenderSetting(setting.first, setting.second);
}
is_synced = true;
}
void PreviewEngine::render(BL::Depsgraph &b_depsgraph)
{
if (!is_synced) {
return;
}
BL::Scene b_scene = b_depsgraph.scene();
string layerName = b_depsgraph.view_layer().name();
GfVec2i buffer_res {b_scene.render().resolution_x(),

View File

@ -18,9 +18,6 @@ namespace blender::render::hydra {
protected:
HdRenderSettingsMap renderSettings;
private:
bool is_synced;
};
} // namespace blender::render::hydra

View File

@ -12,7 +12,7 @@ using namespace pxr;
namespace blender::render::hydra {
BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID, Engine::EngineType engine_type)
BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID, BlenderSceneDelegate::EngineType engine_type)
: HdSceneDelegate(parentIndex, delegateID)
, depsgraph(nullptr)
, context(nullptr)
@ -310,11 +310,6 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
}
}
Engine::EngineType BlenderSceneDelegate::get_engine_type()
{
return engine_type;
}
HdMeshTopology BlenderSceneDelegate::GetMeshTopology(SdfPath const& id)
{
MeshData *m_data = mesh_data(id);

View File

@ -13,17 +13,21 @@
#include "light.h"
#include "world.h"
#include "instance.h"
#include "../engine.h"
namespace blender::render::hydra {
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
public:
BlenderSceneDelegate(pxr::HdRenderIndex *renderIndex, pxr::SdfPath const &delegateId, Engine::EngineType engine_type);
enum class EngineType {
Viewport = 1,
Final,
Preview
};
BlenderSceneDelegate(pxr::HdRenderIndex *renderIndex, pxr::SdfPath const &delegateId, BlenderSceneDelegate::EngineType engine_type);
~BlenderSceneDelegate() override = default;
void populate(Depsgraph *depsgraph, bContext *context);
Engine::EngineType get_engine_type();
// delegate methods
pxr::HdMeshTopology GetMeshTopology(pxr::SdfPath const &id) override;
@ -35,6 +39,8 @@ public:
pxr::VtValue GetMaterialResource(pxr::SdfPath const &materialId) override;
bool GetVisible(pxr::SdfPath const &id) override;
EngineType engine_type;
private:
ObjectData *object_data(pxr::SdfPath const &id);
MeshData *mesh_data(pxr::SdfPath const &id);
@ -56,8 +62,6 @@ private:
MaterialDataMap materials;
std::unique_ptr<WorldData> world_data;
InstanceDataMap instances;
Engine::EngineType engine_type;
};
} // namespace blender::render::hydra

View File

@ -25,7 +25,7 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
{
Light *light = (Light *)((Object *)id)->data;
data[HdLightTokens->intensity] = scene_delegate->get_engine_type() == Engine::EngineType::Preview
data[HdLightTokens->intensity] = scene_delegate->engine_type == BlenderSceneDelegate::EngineType::Preview
? light->energy / 1000
: light->energy;

View File

@ -12,7 +12,6 @@
#include "glog/logging.h"
#include "sceneDelegate/blenderSceneDelegate.h"
#include "viewportEngine.h"
#include "camera.h"
#include "utils.h"
@ -245,7 +244,7 @@ void ViewportEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, Hd
{
if (!sceneDelegate) {
sceneDelegate = std::make_unique<BlenderSceneDelegate>(renderIndex.get(),
SdfPath::AbsoluteRootPath().AppendElementString("scene"), EngineType::Viewport);
SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Viewport);
}
sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data);