forked from blender/blender
BLEN-343: Create PreviewEngine #8
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
#include "sceneDelegate/blenderSceneDelegate.h"
|
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
|
||||||
using namespace pxr;
|
using namespace pxr;
|
||||||
|
@ -16,20 +16,13 @@
|
|||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
#include "RNA_blender_cpp.h"
|
#include "RNA_blender_cpp.h"
|
||||||
|
|
||||||
|
#include "sceneDelegate/blenderSceneDelegate.h"
|
||||||
#include "renderTaskDelegate.h"
|
#include "renderTaskDelegate.h"
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class BlenderSceneDelegate;
|
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
public:
|
public:
|
||||||
enum class EngineType {
|
|
||||||
Viewport = 1,
|
|
||||||
Final,
|
|
||||||
Preview
|
|
||||||
};
|
|
||||||
|
|
||||||
Engine(BL::RenderEngine &b_engine, const std::string &delegateId);
|
Engine(BL::RenderEngine &b_engine, const std::string &delegateId);
|
||||||
virtual ~Engine();
|
virtual ~Engine();
|
||||||
DagerD marked this conversation as resolved
|
|||||||
|
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
#include "sceneDelegate/blenderSceneDelegate.h"
|
|
||||||
#include "finalEngine.h"
|
#include "finalEngine.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "utils.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)
|
void FinalEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, HdRenderSettingsMap &renderSettings)
|
||||||
{
|
{
|
||||||
sceneDelegate = std::make_unique<BlenderSceneDelegate>(renderIndex.get(),
|
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);
|
sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data);
|
||||||
|
|
||||||
for (auto const& setting : renderSettings) {
|
for (auto const& setting : renderSettings) {
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <pxr/usdImaging/usdAppUtils/camera.h>
|
#include <pxr/usdImaging/usdAppUtils/camera.h>
|
||||||
|
|
||||||
#include "sceneDelegate/blenderSceneDelegate.h"
|
|
||||||
#include "previewEngine.h"
|
#include "previewEngine.h"
|
||||||
#include "camera.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)
|
void PreviewEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, HdRenderSettingsMap &renderSettings)
|
||||||
{
|
{
|
||||||
is_synced = false;
|
|
||||||
|
|
||||||
sceneDelegate = std::make_unique<BlenderSceneDelegate>(renderIndex.get(),
|
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);
|
sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data);
|
||||||
|
|
||||||
for (auto const& setting : renderSettings) {
|
for (auto const& setting : renderSettings) {
|
||||||
renderDelegate->SetRenderSetting(setting.first, setting.second);
|
renderDelegate->SetRenderSetting(setting.first, setting.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
is_synced = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewEngine::render(BL::Depsgraph &b_depsgraph)
|
void PreviewEngine::render(BL::Depsgraph &b_depsgraph)
|
||||||
{
|
{
|
||||||
if (!is_synced) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BL::Scene b_scene = b_depsgraph.scene();
|
BL::Scene b_scene = b_depsgraph.scene();
|
||||||
string layerName = b_depsgraph.view_layer().name();
|
string layerName = b_depsgraph.view_layer().name();
|
||||||
GfVec2i buffer_res {b_scene.render().resolution_x(),
|
GfVec2i buffer_res {b_scene.render().resolution_x(),
|
||||||
|
@ -18,9 +18,6 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
HdRenderSettingsMap renderSettings;
|
HdRenderSettingsMap renderSettings;
|
||||||
|
|
||||||
private:
|
|
||||||
bool is_synced;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -12,7 +12,7 @@ using namespace pxr;
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
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)
|
: HdSceneDelegate(parentIndex, delegateID)
|
||||||
, depsgraph(nullptr)
|
, depsgraph(nullptr)
|
||||||
, context(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)
|
HdMeshTopology BlenderSceneDelegate::GetMeshTopology(SdfPath const& id)
|
||||||
{
|
{
|
||||||
MeshData *m_data = mesh_data(id);
|
MeshData *m_data = mesh_data(id);
|
||||||
|
@ -13,17 +13,21 @@
|
|||||||
#include "light.h"
|
#include "light.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include "instance.h"
|
#include "instance.h"
|
||||||
#include "../engine.h"
|
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||||
public:
|
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;
|
~BlenderSceneDelegate() override = default;
|
||||||
|
|
||||||
void populate(Depsgraph *depsgraph, bContext *context);
|
void populate(Depsgraph *depsgraph, bContext *context);
|
||||||
Engine::EngineType get_engine_type();
|
|
||||||
|
|
||||||
// delegate methods
|
// delegate methods
|
||||||
pxr::HdMeshTopology GetMeshTopology(pxr::SdfPath const &id) override;
|
pxr::HdMeshTopology GetMeshTopology(pxr::SdfPath const &id) override;
|
||||||
@ -35,6 +39,8 @@ public:
|
|||||||
pxr::VtValue GetMaterialResource(pxr::SdfPath const &materialId) override;
|
pxr::VtValue GetMaterialResource(pxr::SdfPath const &materialId) override;
|
||||||
bool GetVisible(pxr::SdfPath const &id) override;
|
bool GetVisible(pxr::SdfPath const &id) override;
|
||||||
|
|
||||||
|
EngineType engine_type;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ObjectData *object_data(pxr::SdfPath const &id);
|
ObjectData *object_data(pxr::SdfPath const &id);
|
||||||
MeshData *mesh_data(pxr::SdfPath const &id);
|
MeshData *mesh_data(pxr::SdfPath const &id);
|
||||||
@ -56,8 +62,6 @@ private:
|
|||||||
MaterialDataMap materials;
|
MaterialDataMap materials;
|
||||||
std::unique_ptr<WorldData> world_data;
|
std::unique_ptr<WorldData> world_data;
|
||||||
InstanceDataMap instances;
|
InstanceDataMap instances;
|
||||||
|
|
||||||
Engine::EngineType engine_type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -25,7 +25,7 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
|
|||||||
{
|
{
|
||||||
Light *light = (Light *)((Object *)id)->data;
|
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 / 1000
|
||||||
: light->energy;
|
: light->energy;
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
#include "sceneDelegate/blenderSceneDelegate.h"
|
|
||||||
#include "viewportEngine.h"
|
#include "viewportEngine.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@ -245,7 +244,7 @@ void ViewportEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, Hd
|
|||||||
{
|
{
|
||||||
if (!sceneDelegate) {
|
if (!sceneDelegate) {
|
||||||
sceneDelegate = std::make_unique<BlenderSceneDelegate>(renderIndex.get(),
|
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);
|
sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user
move to BlenderSceneDelegate class