forked from blender/blender
BLEN-335: Export environment light #1
@ -6,18 +6,20 @@
|
|||||||
#include <pxr/imaging/hd/renderDelegate.h>
|
#include <pxr/imaging/hd/renderDelegate.h>
|
||||||
#include <pxr/usd/usdLux/tokens.h>
|
#include <pxr/usd/usdLux/tokens.h>
|
||||||
#include <pxr/imaging/hdSt/tokens.h>
|
#include <pxr/imaging/hdSt/tokens.h>
|
||||||
#include <pxr/base/gf/rotation.h>
|
|
||||||
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
#include "blenderSceneDelegate.h"
|
#include "blenderSceneDelegate.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID)
|
BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID)
|
||||||
: HdSceneDelegate(parentIndex, delegateID),
|
: HdSceneDelegate(parentIndex, delegateID),
|
||||||
b_depsgraph(nullptr),
|
b_depsgraph(nullptr),
|
||||||
|
b_context(nullptr),
|
||||||
view3d(nullptr),
|
view3d(nullptr),
|
||||||
is_populated(false)
|
is_populated(false)
|
||||||
{
|
{
|
||||||
@ -52,21 +54,22 @@ void BlenderSceneDelegate::update_material(Material *material)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlenderSceneDelegate::add_world(View3DShading *view3DShading, World *world)
|
void BlenderSceneDelegate::add_update_world(World *world)
|
||||||
{
|
{
|
||||||
SdfPath world_light_id = world_id(b_context);
|
SdfPath world_light_id = world_id();
|
||||||
|
|
||||||
LOG(INFO) << "Add world: " << world_light_id;
|
LOG(INFO) << "Add world: " << world_light_id;
|
||||||
|
|
||||||
if (world_data.shading != view3DShading || world_data.world != world ||
|
if (!world) {
|
||||||
world_data.b_context != b_context) {
|
world_data.reset();
|
||||||
DagerD marked this conversation as resolved
|
|||||||
world_data = WorldData(view3DShading, world, b_context);
|
GetRenderIndex().RemoveSprim(HdPrimTypeTokens->domeLight, world_light_id);
|
||||||
DagerD marked this conversation as resolved
Bogdan Nagirniak
commented
if (world_data) ... if (world_data) ...
|
|||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
world_data = make_unique<WorldData>(world, (bContext *)b_context->ptr.data);
|
||||||
DagerD marked this conversation as resolved
Bogdan Nagirniak
commented
```
if (!world_data) {
world_data = make_unique....
insertSprim
}
else {
world_data = make_unique....
changetracker
}
```
|
|||||||
GetRenderIndex().InsertSprim(HdPrimTypeTokens->domeLight, this, world_light_id);
|
GetRenderIndex().InsertSprim(HdPrimTypeTokens->domeLight, this, world_light_id);
|
||||||
}
|
|
||||||
else {
|
|
||||||
world_data.update_world();
|
|
||||||
GetRenderIndex().GetChangeTracker().MarkSprimDirty(world_light_id, HdLight::AllDirty);
|
GetRenderIndex().GetChangeTracker().MarkSprimDirty(world_light_id, HdLight::AllDirty);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BlenderSceneDelegate::GetVisible(SdfPath const &id)
|
bool BlenderSceneDelegate::GetVisible(SdfPath const &id)
|
||||||
@ -76,8 +79,8 @@ bool BlenderSceneDelegate::GetVisible(SdfPath const &id)
|
|||||||
|
|
||||||
HdRenderIndex &index = GetRenderIndex();
|
HdRenderIndex &index = GetRenderIndex();
|
||||||
|
|
||||||
if (index.GetSprim(HdPrimTypeTokens->domeLight, id)) {
|
if (id == world_id()) {
|
||||||
return world_data.is_visible();
|
return world_data->is_visible();
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj_data->is_visible();
|
return obj_data->is_visible();
|
||||||
@ -232,13 +235,9 @@ SdfPath BlenderSceneDelegate::material_id(Material *material)
|
|||||||
return GetDelegateID().AppendElementString(str);
|
return GetDelegateID().AppendElementString(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
SdfPath BlenderSceneDelegate::world_id(BL::Context *b_context)
|
SdfPath BlenderSceneDelegate::world_id()
|
||||||
{
|
{
|
||||||
/* Making id of material in form like M_<pointer in 16 hex digits format>. Example:
|
return GetDelegateID().AppendElementString("World");
|
||||||
* W_000002074e812088 */
|
|
||||||
char str[32];
|
|
||||||
snprintf(str, 32, "W_%016llx", (uint64_t)b_context);
|
|
||||||
return GetDelegateID().AppendElementString(str);
|
|
||||||
}
|
}
|
||||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
return GetDelegateID().AppendElementString("World"); return GetDelegateID().AppendElementString("World");
|
|||||||
|
|
||||||
bool BlenderSceneDelegate::supported_object(Object *object)
|
bool BlenderSceneDelegate::supported_object(Object *object)
|
||||||
@ -265,7 +264,7 @@ void BlenderSceneDelegate::Populate(BL::Depsgraph &b_deps, BL::Context &b_cont)
|
|||||||
update_collection();
|
update_collection();
|
||||||
|
|
||||||
World *world = (World *)b_depsgraph->scene().world().ptr.data;
|
World *world = (World *)b_depsgraph->scene().world().ptr.data;
|
||||||
add_world(&view3d->shading, world);
|
add_update_world(world);
|
||||||
|
|
||||||
is_populated = true;
|
is_populated = true;
|
||||||
return;
|
return;
|
||||||
@ -310,6 +309,8 @@ void BlenderSceneDelegate::Populate(BL::Depsgraph &b_deps, BL::Context &b_cont)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (id.is_a(&RNA_Scene)) {
|
if (id.is_a(&RNA_Scene)) {
|
||||||
|
World *world = (World *)b_depsgraph->scene().world().ptr.data;
|
||||||
|
add_update_world(world);
|
||||||
if (!update.is_updated_geometry() && !update.is_updated_transform() && !update.is_updated_shading()) {
|
if (!update.is_updated_geometry() && !update.is_updated_transform() && !update.is_updated_shading()) {
|
||||||
do_update_visibility = true;
|
do_update_visibility = true;
|
||||||
}
|
}
|
||||||
@ -318,13 +319,13 @@ void BlenderSceneDelegate::Populate(BL::Depsgraph &b_deps, BL::Context &b_cont)
|
|||||||
|
|
||||||
if (id.is_a(&RNA_World)) {
|
if (id.is_a(&RNA_World)) {
|
||||||
World *world = (World *)b_depsgraph->scene().world().ptr.data;
|
World *world = (World *)b_depsgraph->scene().world().ptr.data;
|
||||||
add_world(&view3d->shading, world);
|
add_update_world(world);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id.is_a(&RNA_ShaderNodeTree)) {
|
if (id.is_a(&RNA_ShaderNodeTree)) {
|
||||||
World *world = (World *)b_depsgraph->scene().world().ptr.data;
|
World *world = (World *)b_depsgraph->scene().world().ptr.data;
|
||||||
add_world(&view3d->shading, world);
|
add_update_world(world);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -449,16 +450,8 @@ GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const& id)
|
|||||||
|
|
||||||
HdRenderIndex &index = GetRenderIndex();
|
HdRenderIndex &index = GetRenderIndex();
|
||||||
|
|
||||||
if (index.GetSprim(HdPrimTypeTokens->domeLight, id)) {
|
if (id == world_id()) {
|
||||||
GfMatrix4d transform = world_data.transform();
|
return world_data->transform(index.GetRenderDelegate()->GetRendererDisplayName());
|
||||||
if (world_data.has_data(UsdLuxTokens->orientToStageUpAxis)) {
|
|
||||||
transform *= GfMatrix4d(GfRotation(GfVec3d(1.0, 0.0, 0.0), -90), GfVec3d());
|
|
||||||
}
|
|
||||||
if (index.GetRenderDelegate()->GetRendererDisplayName() == "RPR") {
|
|
||||||
transform *= GfMatrix4d(GfRotation(GfVec3d(1.0, 0.0, 0.0), -180), GfVec3d());
|
|
||||||
transform *= GfMatrix4d(GfRotation(GfVec3d(0.0, 0.0, 1.0), 90.0), GfVec3d());
|
|
||||||
}
|
|
||||||
return transform;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return objects[id].transform();
|
return objects[id].transform();
|
||||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
add TODO comment like: implement this check via render settings add TODO comment like: implement this check via render settings
|
|||||||
@ -471,13 +464,7 @@ VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const& id, TfToken cons
|
|||||||
|
|
||||||
HdRenderIndex &index = GetRenderIndex();
|
HdRenderIndex &index = GetRenderIndex();
|
||||||
|
|
||||||
if (index.GetSprim(HdPrimTypeTokens->domeLight, id)) {
|
if (index.HasRprim(id)) {
|
||||||
if (world_data.has_data(key)) {
|
|
||||||
ret = world_data.get_data(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
ObjectData *obj_data = object_data(id);
|
ObjectData *obj_data = object_data(id);
|
||||||
if (obj_data) {
|
if (obj_data) {
|
||||||
if (obj_data->has_data(key)) {
|
if (obj_data->has_data(key)) {
|
||||||
@ -489,6 +476,12 @@ VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const& id, TfToken cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (id == world_id()) {
|
||||||
|
if (world_data->has_data(key)) {
|
||||||
|
ret = world_data->get_data(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,13 +43,13 @@ private:
|
|||||||
MaterialData *material_data(SdfPath const &id);
|
MaterialData *material_data(SdfPath const &id);
|
||||||
SdfPath object_id(Object *object);
|
SdfPath object_id(Object *object);
|
||||||
SdfPath material_id(Material *material);
|
SdfPath material_id(Material *material);
|
||||||
SdfPath world_id(BL::Context *b_context);
|
SdfPath world_id();
|
||||||
bool supported_object(Object *object);
|
bool supported_object(Object *object);
|
||||||
|
|
||||||
void add_update_object(Object *object, bool geometry, bool transform, bool shading);
|
void add_update_object(Object *object, bool geometry, bool transform, bool shading);
|
||||||
void set_material(ObjectData &obj_data);
|
void set_material(ObjectData &obj_data);
|
||||||
void update_material(Material *material);
|
void update_material(Material *material);
|
||||||
void add_world(View3DShading *view3DShading, World *world);
|
void add_update_world(World *world);
|
||||||
void update_collection();
|
void update_collection();
|
||||||
void update_visibility();
|
void update_visibility();
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ private:
|
|||||||
bool is_populated;
|
bool is_populated;
|
||||||
ObjectDataMap objects;
|
ObjectDataMap objects;
|
||||||
MaterialDataMap materials;
|
MaterialDataMap materials;
|
||||||
WorldData world_data;
|
std::unique_ptr<WorldData> world_data;
|
||||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
make is as unique_ptr, implement add/remove world make is as unique_ptr, implement add/remove world
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <pxr/base/vt/array.h>
|
#include <pxr/base/vt/array.h>
|
||||||
#include <pxr/base/gf/vec2f.h>
|
#include <pxr/base/gf/vec2f.h>
|
||||||
|
#include <pxr/base/gf/rotation.h>
|
||||||
#include <pxr/imaging/hd/light.h>
|
#include <pxr/imaging/hd/light.h>
|
||||||
#include <pxr/imaging/hd/tokens.h>
|
#include <pxr/imaging/hd/tokens.h>
|
||||||
#include <pxr/usd/usdLux/tokens.h>
|
#include <pxr/usd/usdLux/tokens.h>
|
||||||
@ -30,61 +31,13 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
WorldData::WorldData()
|
WorldData::WorldData()
|
||||||
: b_context(nullptr),
|
: b_context(nullptr),
|
||||||
shading(nullptr),
|
|
||||||
world(nullptr)
|
world(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldData::WorldData(View3DShading *shading, World *world, BL::Context *b_context)
|
WorldData::WorldData(World *world, bContext *b_context)
|
||||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
`(World *world, bContext *context)`
|
|||||||
: b_context(b_context),
|
: b_context(b_context),
|
||||||
shading(shading),
|
|
||||||
world(world)
|
world(world)
|
||||||
{
|
|
||||||
set_as_world();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string WorldData::name()
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
int WorldData::type()
|
|
||||||
{
|
|
||||||
//return object->type;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
TfToken WorldData::prim_type()
|
|
||||||
{
|
|
||||||
return HdPrimTypeTokens->domeLight;
|
|
||||||
}
|
|
||||||
|
|
||||||
GfMatrix4d WorldData::transform()
|
|
||||||
{
|
|
||||||
return GfMatrix4d().SetIdentity();
|
|
||||||
}
|
|
||||||
|
|
||||||
VtValue &WorldData::get_data(TfToken const &key)
|
|
||||||
{
|
|
||||||
return data[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WorldData::has_data(TfToken const &key)
|
|
||||||
{
|
|
||||||
return data.find(key) != data.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorldData::update_world()
|
|
||||||
{
|
|
||||||
set_as_world();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WorldData::is_visible()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorldData::set_as_world()
|
|
||||||
{
|
{
|
||||||
data.clear();
|
data.clear();
|
||||||
|
|
||||||
@ -116,8 +69,8 @@ void WorldData::set_as_world()
|
|||||||
Image *image = (Image *)color_input_node->id;
|
Image *image = (Image *)color_input_node->id;
|
||||||
|
|
||||||
if (image) {
|
if (image) {
|
||||||
Main *bmain = CTX_data_main((bContext *)b_context->ptr.data);
|
Main *bmain = CTX_data_main(b_context);
|
||||||
Scene *scene = CTX_data_scene((bContext *)b_context->ptr.data);
|
Scene *scene = CTX_data_scene(b_context);
|
||||||
|
|
||||||
ReportList reports;
|
ReportList reports;
|
||||||
ImageSaveOptions opts;
|
ImageSaveOptions opts;
|
||||||
@ -134,23 +87,39 @@ void WorldData::set_as_world()
|
|||||||
else {
|
else {
|
||||||
data[HdLightTokens->intensity] = 1.0f;
|
data[HdLightTokens->intensity] = 1.0f;
|
||||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
move to constructor move to constructor
|
|||||||
data[HdLightTokens->exposure] = world->exposure;
|
data[HdLightTokens->exposure] = world->exposure;
|
||||||
data[HdLightTokens->color] = GfVec3f(
|
data[HdLightTokens->color] = GfVec3f(world->horr, world->horg, world->horb);
|
||||||
world->horr,
|
|
||||||
world->horg,
|
|
||||||
world->horb
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldData::set_as_shading()
|
GfMatrix4d WorldData::transform(string renderer_name)
|
||||||
DagerD marked this conversation as resolved
Bogdan Nagirniak
commented
`string const &`
|
|||||||
{
|
{
|
||||||
data[HdLightTokens->intensity] = 1.0f;
|
GfMatrix4d transform = GfMatrix4d().SetIdentity();
|
||||||
data[HdLightTokens->exposure] = 1.0f;
|
|
||||||
data[HdLightTokens->color] = GfVec3f(
|
if (has_data(UsdLuxTokens->orientToStageUpAxis)) {
|
||||||
shading->single_color[0],
|
transform *= GfMatrix4d(GfRotation(GfVec3d(1.0, 0.0, 0.0), -90), GfVec3d());
|
||||||
shading->single_color[1],
|
}
|
||||||
shading->single_color[2]
|
/* TODO : do this check via RenderSettings*/
|
||||||
);
|
if (renderer_name == "RPR") {
|
||||||
|
transform *= GfMatrix4d(GfRotation(GfVec3d(1.0, 0.0, 0.0), -180), GfVec3d());
|
||||||
|
transform *= GfMatrix4d(GfRotation(GfVec3d(0.0, 0.0, 1.0), 90.0), GfVec3d());
|
||||||
|
}
|
||||||
|
|
||||||
|
return transform;
|
||||||
|
}
|
||||||
|
|
||||||
|
VtValue &WorldData::get_data(TfToken const &key)
|
||||||
|
{
|
||||||
|
return data[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WorldData::has_data(TfToken const &key)
|
||||||
|
{
|
||||||
|
return data.find(key) != data.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WorldData::is_visible()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -13,36 +13,28 @@
|
|||||||
|
|
||||||
#include "DNA_view3d_types.h"
|
#include "DNA_view3d_types.h"
|
||||||
#include "DNA_world_types.h"
|
#include "DNA_world_types.h"
|
||||||
#include "RNA_blender_cpp.h"
|
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class WorldData {
|
class WorldData {
|
||||||
public:
|
public:
|
||||||
WorldData();
|
WorldData();
|
||||||
WorldData(View3DShading *shading, World *world, BL::Context *b_context);
|
WorldData(World *world, bContext *b_context);
|
||||||
|
|
||||||
std::string name();
|
|
||||||
int type();
|
|
||||||
pxr::TfToken prim_type();
|
pxr::TfToken prim_type();
|
||||||
pxr::GfMatrix4d transform();
|
pxr::GfMatrix4d transform(std::string renderer_name);
|
||||||
|
|
||||||
pxr::VtValue &get_data(pxr::TfToken const &key);
|
pxr::VtValue &get_data(pxr::TfToken const &key);
|
||||||
template<class T>
|
template<class T>
|
||||||
const T &get_data(pxr::TfToken const &key);
|
const T &get_data(pxr::TfToken const &key);
|
||||||
bool has_data(pxr::TfToken const &key);
|
bool has_data(pxr::TfToken const &key);
|
||||||
void update_world();
|
|
||||||
bool is_visible();
|
bool is_visible();
|
||||||
|
|
||||||
BL::Context *b_context;
|
bContext *b_context;
|
||||||
View3DShading *shading;
|
|
||||||
World *world;
|
World *world;
|
||||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
no need update_world() just recreate it in scene delegate no need update_world() just recreate it in scene delegate
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<pxr::TfToken, pxr::VtValue> data;
|
std::map<pxr::TfToken, pxr::VtValue> data;
|
||||||
|
|
||||||
void set_as_world();
|
|
||||||
void set_as_shading();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
Loading…
Reference in New Issue
Block a user
world_data = nullptr;