forked from blender/blender
BLEN-343: Create PreviewEngine #8
@ -50,6 +50,8 @@ set(SRC
|
|||||||
engine.cc
|
engine.cc
|
||||||
finalEngine.h
|
finalEngine.h
|
||||||
finalEngine.cc
|
finalEngine.cc
|
||||||
|
previewEngine.h
|
||||||
|
previewEngine.cc
|
||||||
viewportEngine.h
|
viewportEngine.h
|
||||||
viewportEngine.cc
|
viewportEngine.cc
|
||||||
camera.h
|
camera.h
|
||||||
|
@ -27,6 +27,7 @@ public:
|
|||||||
virtual ~Engine();
|
virtual ~Engine();
|
||||||
DagerD marked this conversation as resolved
|
|||||||
|
|
||||||
virtual void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) = 0;
|
virtual void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) = 0;
|
||||||
|
virtual void render(BL::Depsgraph &b_depsgraph) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float getRendererPercentDone();
|
float getRendererPercentDone();
|
||||||
|
@ -19,10 +19,10 @@ using namespace pxr;
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
void FinalEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::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"));
|
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) {
|
||||||
|
@ -12,8 +12,8 @@ namespace blender::render::hydra {
|
|||||||
class FinalEngine : public Engine {
|
class FinalEngine : public Engine {
|
||||||
public:
|
public:
|
||||||
using Engine::Engine;
|
using Engine::Engine;
|
||||||
void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override;
|
virtual void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override;
|
||||||
virtual void render(BL::Depsgraph &b_depsgraph);
|
virtual void render(BL::Depsgraph &b_depsgraph) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
pxr::GfVec2i get_resolution(BL::RenderSettings b_render);
|
pxr::GfVec2i get_resolution(BL::RenderSettings b_render);
|
||||||
|
73
source/blender/render/hydra/previewEngine.cc
Normal file
73
source/blender/render/hydra/previewEngine.cc
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/* SPDX-License-Identifier: Apache-2.0
|
||||||
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
|
#include <pxr/usdImaging/usdAppUtils/camera.h>
|
||||||
|
|
||||||
|
#include "previewEngine.h"
|
||||||
|
#include "camera.h"
|
||||||
|
|
||||||
|
using namespace pxr;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
|
void PreviewEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, HdRenderSettingsMap &renderSettings)
|
||||||
|
{
|
||||||
|
sceneDelegate = std::make_unique<BlenderSceneDelegate>(renderIndex.get(),
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewEngine::render(BL::Depsgraph &b_depsgraph)
|
||||||
|
{
|
||||||
|
BL::Scene b_scene = b_depsgraph.scene();
|
||||||
|
string layerName = b_depsgraph.view_layer().name();
|
||||||
|
GfVec2i buffer_res {b_scene.render().resolution_x(),
|
||||||
|
b_scene.render().resolution_y()};
|
||||||
|
|
||||||
|
GfCamera gfCamera = CameraData((Object *)b_scene.camera().ptr.data, buffer_res, GfVec4f(0, 0, 1, 1)).gf_camera(GfVec4f(0, 0, 1, 1));
|
||||||
DagerD marked this conversation as resolved
Bogdan Nagirniak
commented
check check `if (!sceneDelegate)` instead is_synced
|
|||||||
|
|
||||||
|
freeCameraDelegate->SetCamera(gfCamera);
|
||||||
|
renderTaskDelegate->SetCameraAndViewport(freeCameraDelegate->GetCameraId(), GfVec4d(0, 0, buffer_res[0], buffer_res[1]));
|
||||||
|
renderTaskDelegate->SetRendererAov(HdAovTokens->color);
|
||||||
|
|
||||||
|
HdTaskSharedPtrVector tasks = renderTaskDelegate->GetTasks();
|
||||||
|
|
||||||
|
vector<float> pixels = vector<float>(buffer_res[0] * buffer_res[1] * 4); // 4 - number of channels
|
||||||
|
|
||||||
|
{
|
||||||
|
// Release the GIL before calling into hydra, in case any hydra plugins call into python.
|
||||||
|
TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||||
|
engine->Execute(renderIndex.get(), &tasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (b_engine.test_break()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (renderTaskDelegate->IsConverged()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderTaskDelegate->GetRendererAovData(HdAovTokens->color, pixels.data());
|
||||||
|
updateRenderResult(layerName, buffer_res[0], buffer_res[1], pixels);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderTaskDelegate->GetRendererAovData(HdAovTokens->color, pixels.data());
|
||||||
|
updateRenderResult(layerName, buffer_res[0], buffer_res[1], pixels);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewEngine::updateRenderResult(const string &layerName, int width, int height, vector<float> &pixels)
|
||||||
|
{
|
||||||
|
BL::RenderResult b_result = b_engine.begin_result(0, 0, width, height, layerName.c_str(), NULL);
|
||||||
|
BL::CollectionRef b_passes = b_result.layers[0].passes;
|
||||||
|
b_passes[0].rect(pixels.data());
|
||||||
|
b_engine.end_result(b_result, false, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace blender::render::hydra
|
23
source/blender/render/hydra/previewEngine.h
Normal file
23
source/blender/render/hydra/previewEngine.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* SPDX-License-Identifier: Apache-2.0
|
||||||
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "finalEngine.h"
|
||||||
|
|
||||||
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
|
class PreviewEngine : public FinalEngine {
|
||||||
DagerD marked this conversation as resolved
Bogdan Nagirniak
commented
Maybe inherit from FinalEngine? Maybe inherit from FinalEngine?
|
|||||||
|
public:
|
||||||
|
using FinalEngine::FinalEngine;
|
||||||
|
void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override;
|
||||||
|
void render(BL::Depsgraph &b_depsgraph) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void updateRenderResult(const std::string &layerName, int width, int height, std::vector<float> &pixels);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
HdRenderSettingsMap renderSettings;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace blender::render::hydra
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "finalEngine.h"
|
#include "finalEngine.h"
|
||||||
#include "viewportEngine.h"
|
#include "viewportEngine.h"
|
||||||
|
#include "previewEngine.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -130,9 +131,13 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
|
|||||||
BL::RenderEngine b_engine(engineptr);
|
BL::RenderEngine b_engine(engineptr);
|
||||||
|
|
||||||
Engine *engine;
|
Engine *engine;
|
||||||
|
|
||||||
if (string(engineType) == "VIEWPORT") {
|
if (string(engineType) == "VIEWPORT") {
|
||||||
engine = new ViewportEngine(b_engine, delegateId);
|
engine = new ViewportEngine(b_engine, delegateId);
|
||||||
}
|
}
|
||||||
|
else if (string(engineType) == "PREVIEW") {
|
||||||
|
engine = new PreviewEngine(b_engine, delegateId);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
if (b_engine.bl_use_gpu_context()) {
|
if (b_engine.bl_use_gpu_context()) {
|
||||||
engine = new FinalEngineGL(b_engine, delegateId);
|
engine = new FinalEngineGL(b_engine, delegateId);
|
||||||
@ -204,11 +209,12 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args)
|
|||||||
static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args)
|
static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *pyengine, *pydepsgraph;
|
PyObject *pyengine, *pydepsgraph;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "OO", &pyengine, &pydepsgraph)) {
|
if (!PyArg_ParseTuple(args, "OO", &pyengine, &pydepsgraph)) {
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
FinalEngine *engine = (FinalEngine *)PyLong_AsVoidPtr(pyengine);
|
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
|
||||||
|
|
||||||
PointerRNA depsgraphptr;
|
PointerRNA depsgraphptr;
|
||||||
RNA_pointer_create(NULL, &RNA_Depsgraph, (ID *)PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
|
RNA_pointer_create(NULL, &RNA_Depsgraph, (ID *)PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
|
||||||
@ -241,7 +247,7 @@ static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args)
|
|||||||
|
|
||||||
/* Allow Blender to execute other Python scripts. */
|
/* Allow Blender to execute other Python scripts. */
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
engine->viewDraw(b_depsgraph, b_context);
|
engine->render(b_depsgraph, b_context);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
@ -12,11 +12,12 @@ using namespace pxr;
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID)
|
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)
|
||||||
, view3d(nullptr)
|
, view3d(nullptr)
|
||||||
|
, engine_type(engine_type)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,13 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||||
public:
|
public:
|
||||||
BlenderSceneDelegate(pxr::HdRenderIndex *renderIndex, pxr::SdfPath const &delegateId);
|
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);
|
||||||
@ -33,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);
|
||||||
|
@ -3,13 +3,14 @@
|
|||||||
|
|
||||||
#include "BKE_lib_id.h"
|
#include "BKE_lib_id.h"
|
||||||
|
|
||||||
|
#include "blenderSceneDelegate.h"
|
||||||
#include "id.h"
|
#include "id.h"
|
||||||
|
|
||||||
using namespace pxr;
|
using namespace pxr;
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
IdData::IdData(pxr::HdSceneDelegate *scene_delegate, ID *id)
|
IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id)
|
||||||
: scene_delegate(scene_delegate)
|
: scene_delegate(scene_delegate)
|
||||||
, id(id)
|
, id(id)
|
||||||
{
|
{
|
||||||
|
@ -11,9 +11,11 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
|
class BlenderSceneDelegate;
|
||||||
|
|
||||||
class IdData {
|
class IdData {
|
||||||
public:
|
public:
|
||||||
IdData(pxr::HdSceneDelegate *scene_delegate, ID *id);
|
IdData(BlenderSceneDelegate *scene_delegate, ID *id);
|
||||||
virtual ~IdData() = default;
|
virtual ~IdData() = default;
|
||||||
|
|
||||||
std::string name();
|
std::string name();
|
||||||
@ -32,7 +34,7 @@ class IdData {
|
|||||||
virtual void mark_prim_dirty(DirtyBits dirty_bits) = 0;
|
virtual void mark_prim_dirty(DirtyBits dirty_bits) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
pxr::HdSceneDelegate *scene_delegate;
|
BlenderSceneDelegate *scene_delegate;
|
||||||
ID *id;
|
ID *id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
/* SPDX-License-Identifier: Apache-2.0
|
/* SPDX-License-Identifier: Apache-2.0
|
||||||
* Copyright 2011-2022 Blender Foundation */
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
|
#include "blenderSceneDelegate.h"
|
||||||
#include "instance.h"
|
#include "instance.h"
|
||||||
|
|
||||||
using namespace pxr;
|
using namespace pxr;
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
InstanceData::InstanceData(pxr::HdSceneDelegate *scene_delegate, DupliObject *dupli)
|
InstanceData::InstanceData(BlenderSceneDelegate *scene_delegate, DupliObject *dupli)
|
||||||
: IdData(scene_delegate, (ID *)dupli->ob_data)
|
: IdData(scene_delegate, (ID *)dupli->ob_data)
|
||||||
, dupli(dupli)
|
, dupli(dupli)
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,7 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
class InstanceData: public IdData {
|
class InstanceData: public IdData {
|
||||||
public:
|
public:
|
||||||
InstanceData(pxr::HdSceneDelegate *scene_delegate, DupliObject *dupli);
|
InstanceData(BlenderSceneDelegate *scene_delegate, DupliObject *dupli);
|
||||||
|
|
||||||
int random_id();
|
int random_id();
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "BKE_light.h"
|
#include "BKE_light.h"
|
||||||
#include "DNA_light_types.h"
|
#include "DNA_light_types.h"
|
||||||
|
|
||||||
|
#include "blenderSceneDelegate.h"
|
||||||
#include "light.h"
|
#include "light.h"
|
||||||
|
|
||||||
using namespace pxr;
|
using namespace pxr;
|
||||||
@ -19,12 +20,15 @@ using namespace boost::algorithm;
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
LightData::LightData(pxr::HdSceneDelegate *scene_delegate, Object *object)
|
LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||||
: ObjectData(scene_delegate, object)
|
: ObjectData(scene_delegate, object)
|
||||||
{
|
{
|
||||||
Light *light = (Light *)((Object *)id)->data;
|
Light *light = (Light *)((Object *)id)->data;
|
||||||
|
|
||||||
data[HdLightTokens->intensity] = light->energy;
|
data[HdLightTokens->intensity] = scene_delegate->engine_type == BlenderSceneDelegate::EngineType::Preview
|
||||||
|
? light->energy / 1000
|
||||||
|
: light->energy;
|
||||||
|
|
||||||
data[HdLightTokens->color] = GfVec3f(light->r, light->g, light->b);
|
data[HdLightTokens->color] = GfVec3f(light->r, light->g, light->b);
|
||||||
|
|
||||||
switch (light->type) {
|
switch (light->type) {
|
||||||
|
@ -13,7 +13,7 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
class LightData: public ObjectData {
|
class LightData: public ObjectData {
|
||||||
public:
|
public:
|
||||||
LightData(pxr::HdSceneDelegate *scene_delegate, Object *object);
|
LightData(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||||
|
|
||||||
pxr::VtValue get_data(pxr::TfToken const &key) override;
|
pxr::VtValue get_data(pxr::TfToken const &key) override;
|
||||||
void insert_prim() override;
|
void insert_prim() override;
|
||||||
|
@ -11,18 +11,19 @@
|
|||||||
#include "BKE_material.h"
|
#include "BKE_material.h"
|
||||||
#include "BKE_lib_id.h"
|
#include "BKE_lib_id.h"
|
||||||
|
|
||||||
|
#include "blenderSceneDelegate.h"
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
|
|
||||||
using namespace pxr;
|
using namespace pxr;
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
std::unique_ptr<MaterialData> MaterialData::init(pxr::HdSceneDelegate *scene_delegate, Material *material)
|
std::unique_ptr<MaterialData> MaterialData::init(BlenderSceneDelegate *scene_delegate, Material *material)
|
||||||
{
|
{
|
||||||
return std::make_unique<MaterialData>(scene_delegate, material);
|
return std::make_unique<MaterialData>(scene_delegate, material);
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::SdfPath MaterialData::prim_id(pxr::HdSceneDelegate *scene_delegate, Material *material)
|
pxr::SdfPath MaterialData::prim_id(BlenderSceneDelegate *scene_delegate, Material *material)
|
||||||
{
|
{
|
||||||
/* Making id of material in form like M_<pointer in 16 hex digits format>.
|
/* Making id of material in form like M_<pointer in 16 hex digits format>.
|
||||||
* Example: M_000002074e812088 */
|
* Example: M_000002074e812088 */
|
||||||
@ -31,7 +32,7 @@ pxr::SdfPath MaterialData::prim_id(pxr::HdSceneDelegate *scene_delegate, Materia
|
|||||||
return scene_delegate->GetDelegateID().AppendElementString(str);
|
return scene_delegate->GetDelegateID().AppendElementString(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialData::MaterialData(pxr::HdSceneDelegate *scene_delegate, Material *material)
|
MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *material)
|
||||||
: IdData(scene_delegate, (ID *)material)
|
: IdData(scene_delegate, (ID *)material)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,10 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
class MaterialData: IdData {
|
class MaterialData: IdData {
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<MaterialData> init(pxr::HdSceneDelegate *scene_delegate, Material *material);
|
static std::unique_ptr<MaterialData> init(BlenderSceneDelegate *scene_delegate, Material *material);
|
||||||
static pxr::SdfPath prim_id(pxr::HdSceneDelegate *scene_delegate, Material *material);
|
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Material *material);
|
||||||
|
|
||||||
MaterialData(pxr::HdSceneDelegate *scene_delegate, Material *material);
|
MaterialData(BlenderSceneDelegate *scene_delegate, Material *material);
|
||||||
|
|
||||||
pxr::VtValue get_data(pxr::TfToken const &key) override;
|
pxr::VtValue get_data(pxr::TfToken const &key) override;
|
||||||
void insert_prim() override;
|
void insert_prim() override;
|
||||||
|
@ -11,14 +11,14 @@
|
|||||||
#include "BKE_object.h"
|
#include "BKE_object.h"
|
||||||
#include "BKE_material.h"
|
#include "BKE_material.h"
|
||||||
|
|
||||||
|
#include "blenderSceneDelegate.h"
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
|
|
||||||
using namespace pxr;
|
using namespace pxr;
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
MeshData::MeshData(pxr::HdSceneDelegate *scene_delegate, Object *object)
|
MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||||
: ObjectData(scene_delegate, object)
|
: ObjectData(scene_delegate, object)
|
||||||
{
|
{
|
||||||
if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT &&
|
if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT &&
|
||||||
|
@ -12,7 +12,7 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
class MeshData: public ObjectData {
|
class MeshData: public ObjectData {
|
||||||
public:
|
public:
|
||||||
MeshData(pxr::HdSceneDelegate *scene_delegate, Object *object);
|
MeshData(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||||
|
|
||||||
pxr::VtValue get_data(pxr::TfToken const &key) override;
|
pxr::VtValue get_data(pxr::TfToken const &key) override;
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "BKE_object.h"
|
#include "BKE_object.h"
|
||||||
|
|
||||||
|
#include "blenderSceneDelegate.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
#include "light.h"
|
#include "light.h"
|
||||||
@ -30,7 +31,7 @@ bool ObjectData::supported(Object *object)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<ObjectData> ObjectData::init(pxr::HdSceneDelegate *scene_delegate, Object *object)
|
std::unique_ptr<ObjectData> ObjectData::init(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||||
{
|
{
|
||||||
switch (object->type) {
|
switch (object->type) {
|
||||||
case OB_MESH:
|
case OB_MESH:
|
||||||
@ -50,7 +51,7 @@ std::unique_ptr<ObjectData> ObjectData::init(pxr::HdSceneDelegate *scene_delegat
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::SdfPath ObjectData::prim_id(pxr::HdSceneDelegate *scene_delegate, Object *object)
|
pxr::SdfPath ObjectData::prim_id(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||||
{
|
{
|
||||||
/* Making id of object in form like O_<pointer in 16 hex digits format>. Example:
|
/* Making id of object in form like O_<pointer in 16 hex digits format>. Example:
|
||||||
* O_000002073e369608 */
|
* O_000002073e369608 */
|
||||||
@ -59,7 +60,7 @@ pxr::SdfPath ObjectData::prim_id(pxr::HdSceneDelegate *scene_delegate, Object *o
|
|||||||
return scene_delegate->GetDelegateID().AppendElementString(str);
|
return scene_delegate->GetDelegateID().AppendElementString(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectData::ObjectData(pxr::HdSceneDelegate *scene_delegate, Object *object)
|
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||||
: IdData(scene_delegate, (ID *)object)
|
: IdData(scene_delegate, (ID *)object)
|
||||||
, visible(true)
|
, visible(true)
|
||||||
{
|
{
|
||||||
|
@ -17,10 +17,10 @@ namespace blender::render::hydra {
|
|||||||
class ObjectData: public IdData {
|
class ObjectData: public IdData {
|
||||||
public:
|
public:
|
||||||
static bool supported(Object *object);
|
static bool supported(Object *object);
|
||||||
static std::unique_ptr<ObjectData> init(pxr::HdSceneDelegate *scene_delegate, Object *object);
|
static std::unique_ptr<ObjectData> init(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||||
static pxr::SdfPath prim_id(pxr::HdSceneDelegate *scene_delegate, Object *object);
|
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||||
|
|
||||||
ObjectData(pxr::HdSceneDelegate *scene_delegate, Object *object);
|
ObjectData(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||||
|
|
||||||
int type();
|
int type();
|
||||||
pxr::GfMatrix4d transform();
|
pxr::GfMatrix4d transform();
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
|
#include "blenderSceneDelegate.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include "../utils.h"
|
#include "../utils.h"
|
||||||
|
|
||||||
@ -31,18 +32,18 @@ using namespace pxr;
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
std::unique_ptr<WorldData> WorldData::init(pxr::HdSceneDelegate *scene_delegate,
|
std::unique_ptr<WorldData> WorldData::init(BlenderSceneDelegate *scene_delegate,
|
||||||
World *world, bContext *context)
|
World *world, bContext *context)
|
||||||
{
|
{
|
||||||
return std::make_unique<WorldData>(scene_delegate, world, context);
|
return std::make_unique<WorldData>(scene_delegate, world, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
SdfPath WorldData::prim_id(HdSceneDelegate *scene_delegate)
|
SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate)
|
||||||
{
|
{
|
||||||
return scene_delegate->GetDelegateID().AppendElementString("World");
|
return scene_delegate->GetDelegateID().AppendElementString("World");
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldData::WorldData(pxr::HdSceneDelegate *scene_delegate, World *world, bContext *context)
|
WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context)
|
||||||
: IdData(scene_delegate, (ID *)world)
|
: IdData(scene_delegate, (ID *)world)
|
||||||
{
|
{
|
||||||
data[UsdLuxTokens->orientToStageUpAxis] = true;
|
data[UsdLuxTokens->orientToStageUpAxis] = true;
|
||||||
|
@ -20,10 +20,10 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
class WorldData: public IdData {
|
class WorldData: public IdData {
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<WorldData> init(pxr::HdSceneDelegate *scene_delegate, World *world, bContext *context);
|
static std::unique_ptr<WorldData> init(BlenderSceneDelegate *scene_delegate, World *world, bContext *context);
|
||||||
static pxr::SdfPath prim_id(pxr::HdSceneDelegate *scene_delegate);
|
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate);
|
||||||
|
|
||||||
WorldData(pxr::HdSceneDelegate *scene_delegate, World *world, bContext *context);
|
WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context);
|
||||||
|
|
||||||
pxr::GfMatrix4d transform();
|
pxr::GfMatrix4d transform();
|
||||||
|
|
||||||
|
@ -244,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"));
|
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);
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ void ViewportEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, Hd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportEngine::viewDraw(BL::Depsgraph &b_depsgraph, BL::Context &b_context)
|
void ViewportEngine::render(BL::Depsgraph &b_depsgraph, BL::Context &b_context)
|
||||||
{
|
{
|
||||||
ViewSettings viewSettings(b_context);
|
ViewSettings viewSettings(b_context);
|
||||||
if (viewSettings.width() * viewSettings.height() == 0) {
|
if (viewSettings.width() * viewSettings.height() == 0) {
|
||||||
@ -307,6 +307,10 @@ void ViewportEngine::viewDraw(BL::Depsgraph &b_depsgraph, BL::Context &b_context
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ViewportEngine::render(BL::Depsgraph &b_depsgraph)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void ViewportEngine::notifyStatus(const string &info, const string &status)
|
void ViewportEngine::notifyStatus(const string &info, const string &status)
|
||||||
{
|
{
|
||||||
b_engine.update_stats(status.c_str(), info.c_str());
|
b_engine.update_stats(status.c_str(), info.c_str());
|
||||||
|
@ -33,7 +33,8 @@ class ViewportEngine : public Engine {
|
|||||||
public:
|
public:
|
||||||
using Engine::Engine;
|
using Engine::Engine;
|
||||||
void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override;
|
void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override;
|
||||||
void viewDraw(BL::Depsgraph &b_depsgraph, BL::Context &b_context);
|
void render(BL::Depsgraph &b_depsgraph) override;
|
||||||
|
void render(BL::Depsgraph &b_depsgraph, BL::Context &b_context);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void notifyStatus(const std::string &title, const std::string &info);
|
void notifyStatus(const std::string &title, const std::string &info);
|
||||||
|
Loading…
Reference in New Issue
Block a user
move to BlenderSceneDelegate class