forked from blender/blender
BLEN-343: Create PreviewEngine #8
@ -9,6 +9,7 @@
|
||||
|
||||
#include "glog/logging.h"
|
||||
|
||||
#include "sceneDelegate/blenderSceneDelegate.h"
|
||||
#include "engine.h"
|
||||
|
||||
using namespace pxr;
|
||||
|
@ -16,13 +16,20 @@
|
||||
#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 {
|
||||
DagerD marked this conversation as resolved
|
||||
Viewport = 1,
|
||||
Final,
|
||||
Preview
|
||||
};
|
||||
|
||||
Engine(BL::RenderEngine &b_engine, const std::string &delegateId);
|
||||
virtual ~Engine();
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "glog/logging.h"
|
||||
|
||||
#include "sceneDelegate/blenderSceneDelegate.h"
|
||||
#include "finalEngine.h"
|
||||
#include "camera.h"
|
||||
#include "utils.h"
|
||||
@ -22,7 +23,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"));
|
||||
SdfPath::AbsoluteRootPath().AppendElementString("scene"), EngineType::Final);
|
||||
sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data);
|
||||
|
||||
for (auto const& setting : renderSettings) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <pxr/usdImaging/usdAppUtils/camera.h>
|
||||
|
||||
#include "sceneDelegate/blenderSceneDelegate.h"
|
||||
#include "previewEngine.h"
|
||||
#include "camera.h"
|
||||
|
||||
@ -16,7 +17,7 @@ void PreviewEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, HdR
|
||||
is_synced = false;
|
||||
|
||||
sceneDelegate = std::make_unique<BlenderSceneDelegate>(renderIndex.get(),
|
||||
SdfPath::AbsoluteRootPath().AppendElementString("scene"));
|
||||
SdfPath::AbsoluteRootPath().AppendElementString("scene"), EngineType::Preview);
|
||||
sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data);
|
||||
|
||||
for (auto const& setting : renderSettings) {
|
||||
|
@ -12,11 +12,12 @@ using namespace pxr;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID)
|
||||
BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID, Engine::EngineType engine_type)
|
||||
: HdSceneDelegate(parentIndex, delegateID)
|
||||
, depsgraph(nullptr)
|
||||
, context(nullptr)
|
||||
, view3d(nullptr)
|
||||
, engine_type(engine_type)
|
||||
{
|
||||
}
|
||||
|
||||
@ -309,6 +310,11 @@ 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);
|
||||
|
@ -13,15 +13,17 @@
|
||||
#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);
|
||||
BlenderSceneDelegate(pxr::HdRenderIndex *renderIndex, pxr::SdfPath const &delegateId, Engine::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;
|
||||
@ -54,6 +56,8 @@ private:
|
||||
MaterialDataMap materials;
|
||||
std::unique_ptr<WorldData> world_data;
|
||||
InstanceDataMap instances;
|
||||
|
||||
Engine::EngineType engine_type;
|
||||
};
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -3,13 +3,14 @@
|
||||
|
||||
#include "BKE_lib_id.h"
|
||||
|
||||
#include "blenderSceneDelegate.h"
|
||||
#include "id.h"
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
IdData::IdData(pxr::HdSceneDelegate *scene_delegate, ID *id)
|
||||
IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id)
|
||||
: scene_delegate(scene_delegate)
|
||||
, id(id)
|
||||
{
|
||||
|
@ -11,9 +11,11 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
class BlenderSceneDelegate;
|
||||
|
||||
class IdData {
|
||||
public:
|
||||
IdData(pxr::HdSceneDelegate *scene_delegate, ID *id);
|
||||
IdData(BlenderSceneDelegate *scene_delegate, ID *id);
|
||||
virtual ~IdData() = default;
|
||||
|
||||
std::string name();
|
||||
@ -32,7 +34,7 @@ class IdData {
|
||||
virtual void mark_prim_dirty(DirtyBits dirty_bits) = 0;
|
||||
|
||||
protected:
|
||||
pxr::HdSceneDelegate *scene_delegate;
|
||||
BlenderSceneDelegate *scene_delegate;
|
||||
ID *id;
|
||||
};
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0
|
||||
* Copyright 2011-2022 Blender Foundation */
|
||||
|
||||
#include "blenderSceneDelegate.h"
|
||||
#include "instance.h"
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
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)
|
||||
, dupli(dupli)
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ namespace blender::render::hydra {
|
||||
|
||||
class InstanceData: public IdData {
|
||||
public:
|
||||
InstanceData(pxr::HdSceneDelegate *scene_delegate, DupliObject *dupli);
|
||||
InstanceData(BlenderSceneDelegate *scene_delegate, DupliObject *dupli);
|
||||
|
||||
int random_id();
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "BKE_light.h"
|
||||
#include "DNA_light_types.h"
|
||||
|
||||
#include "blenderSceneDelegate.h"
|
||||
#include "light.h"
|
||||
|
||||
using namespace pxr;
|
||||
@ -19,12 +20,15 @@ using namespace boost::algorithm;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
LightData::LightData(pxr::HdSceneDelegate *scene_delegate, Object *object)
|
||||
LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||
: ObjectData(scene_delegate, object)
|
||||
{
|
||||
Light *light = (Light *)((Object *)id)->data;
|
||||
|
||||
data[HdLightTokens->intensity] = light->energy;
|
||||
data[HdLightTokens->intensity] = scene_delegate->get_engine_type() == Engine::EngineType::Preview
|
||||
? light->energy / 1000
|
||||
: light->energy;
|
||||
|
||||
data[HdLightTokens->color] = GfVec3f(light->r, light->g, light->b);
|
||||
|
||||
switch (light->type) {
|
||||
|
@ -13,7 +13,7 @@ namespace blender::render::hydra {
|
||||
|
||||
class LightData: public ObjectData {
|
||||
public:
|
||||
LightData(pxr::HdSceneDelegate *scene_delegate, Object *object);
|
||||
LightData(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||
|
||||
pxr::VtValue get_data(pxr::TfToken const &key) override;
|
||||
void insert_prim() override;
|
||||
|
@ -11,18 +11,19 @@
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_lib_id.h"
|
||||
|
||||
#include "blenderSceneDelegate.h"
|
||||
#include "material.h"
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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>.
|
||||
* Example: M_000002074e812088 */
|
||||
@ -31,7 +32,7 @@ pxr::SdfPath MaterialData::prim_id(pxr::HdSceneDelegate *scene_delegate, Materia
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
@ -15,10 +15,10 @@ namespace blender::render::hydra {
|
||||
|
||||
class MaterialData: IdData {
|
||||
public:
|
||||
static std::unique_ptr<MaterialData> init(pxr::HdSceneDelegate *scene_delegate, Material *material);
|
||||
static pxr::SdfPath prim_id(pxr::HdSceneDelegate *scene_delegate, Material *material);
|
||||
static std::unique_ptr<MaterialData> init(BlenderSceneDelegate *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;
|
||||
void insert_prim() override;
|
||||
|
@ -11,14 +11,14 @@
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_material.h"
|
||||
|
||||
|
||||
#include "blenderSceneDelegate.h"
|
||||
#include "mesh.h"
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
MeshData::MeshData(pxr::HdSceneDelegate *scene_delegate, Object *object)
|
||||
MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||
: ObjectData(scene_delegate, object)
|
||||
{
|
||||
if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT &&
|
||||
|
@ -12,7 +12,7 @@ namespace blender::render::hydra {
|
||||
|
||||
class MeshData: public ObjectData {
|
||||
public:
|
||||
MeshData(pxr::HdSceneDelegate *scene_delegate, Object *object);
|
||||
MeshData(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||
|
||||
pxr::VtValue get_data(pxr::TfToken const &key) override;
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "BKE_object.h"
|
||||
|
||||
#include "blenderSceneDelegate.h"
|
||||
#include "object.h"
|
||||
#include "mesh.h"
|
||||
#include "light.h"
|
||||
@ -30,7 +31,7 @@ bool ObjectData::supported(Object *object)
|
||||
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) {
|
||||
case OB_MESH:
|
||||
@ -50,7 +51,7 @@ std::unique_ptr<ObjectData> ObjectData::init(pxr::HdSceneDelegate *scene_delegat
|
||||
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:
|
||||
* O_000002073e369608 */
|
||||
@ -59,7 +60,7 @@ pxr::SdfPath ObjectData::prim_id(pxr::HdSceneDelegate *scene_delegate, Object *o
|
||||
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)
|
||||
, visible(true)
|
||||
{
|
||||
|
@ -17,10 +17,10 @@ namespace blender::render::hydra {
|
||||
class ObjectData: public IdData {
|
||||
public:
|
||||
static bool supported(Object *object);
|
||||
static std::unique_ptr<ObjectData> init(pxr::HdSceneDelegate *scene_delegate, Object *object);
|
||||
static pxr::SdfPath prim_id(pxr::HdSceneDelegate *scene_delegate, Object *object);
|
||||
static std::unique_ptr<ObjectData> init(BlenderSceneDelegate *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();
|
||||
pxr::GfMatrix4d transform();
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "glog/logging.h"
|
||||
|
||||
#include "blenderSceneDelegate.h"
|
||||
#include "world.h"
|
||||
#include "../utils.h"
|
||||
|
||||
@ -31,18 +32,18 @@ using namespace pxr;
|
||||
|
||||
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)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
WorldData::WorldData(pxr::HdSceneDelegate *scene_delegate, World *world, bContext *context)
|
||||
WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context)
|
||||
: IdData(scene_delegate, (ID *)world)
|
||||
{
|
||||
data[UsdLuxTokens->orientToStageUpAxis] = true;
|
||||
|
@ -20,10 +20,10 @@ namespace blender::render::hydra {
|
||||
|
||||
class WorldData: public IdData {
|
||||
public:
|
||||
static std::unique_ptr<WorldData> init(pxr::HdSceneDelegate *scene_delegate, World *world, bContext *context);
|
||||
static pxr::SdfPath prim_id(pxr::HdSceneDelegate *scene_delegate);
|
||||
static std::unique_ptr<WorldData> init(BlenderSceneDelegate *scene_delegate, World *world, bContext *context);
|
||||
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();
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "glog/logging.h"
|
||||
|
||||
#include "sceneDelegate/blenderSceneDelegate.h"
|
||||
#include "viewportEngine.h"
|
||||
#include "camera.h"
|
||||
#include "utils.h"
|
||||
@ -244,7 +245,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"));
|
||||
SdfPath::AbsoluteRootPath().AppendElementString("scene"), EngineType::Viewport);
|
||||
}
|
||||
sceneDelegate->populate((Depsgraph *)b_depsgraph.ptr.data, (bContext *)b_context.ptr.data);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user
move to BlenderSceneDelegate class