forked from blender/blender
BLEN-335: Export environment light #1
@ -20,6 +20,7 @@ set(INC
|
|||||||
../../../../intern/guardedalloc
|
../../../../intern/guardedalloc
|
||||||
../../makesdna
|
../../makesdna
|
||||||
../../makesrna
|
../../makesrna
|
||||||
|
../../nodes
|
||||||
../../blenlib
|
../../blenlib
|
||||||
../../depsgraph
|
../../depsgraph
|
||||||
../../blenkernel
|
../../blenkernel
|
||||||
@ -66,6 +67,8 @@ set(SRC
|
|||||||
sceneDelegate/scene.cc
|
sceneDelegate/scene.cc
|
||||||
sceneDelegate/material.h
|
sceneDelegate/material.h
|
||||||
sceneDelegate/material.cc
|
sceneDelegate/material.cc
|
||||||
|
sceneDelegate/world.h
|
||||||
|
sceneDelegate/world.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LIB
|
set(LIB
|
||||||
|
@ -50,10 +50,32 @@ void BlenderSceneDelegate::update_material(Material *material)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BlenderSceneDelegate::add_world(View3DShading &view3DShading, World &world)
|
||||||
|
{
|
||||||
|
SdfPath world_light_id = world_id(&view3DShading);
|
||||||
|
|
||||||
|
LOG(INFO) << "Add world: " << world_light_id;
|
||||||
|
|
||||||
|
if (world_data.shading != &view3DShading || world_data.world != &world) {
|
||||||
|
world_data = WorldData(&view3DShading, &world);
|
||||||
|
GetRenderIndex().InsertSprim(HdPrimTypeTokens->domeLight, this, world_light_id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
world_data.update_world();
|
||||||
DagerD marked this conversation as resolved
|
|||||||
|
GetRenderIndex().GetChangeTracker().MarkSprimDirty(world_light_id, HdLight::AllDirty);
|
||||||
DagerD marked this conversation as resolved
Bogdan Nagirniak
commented
if (world_data) ... if (world_data) ...
|
|||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool BlenderSceneDelegate::GetVisible(SdfPath const &id)
|
bool BlenderSceneDelegate::GetVisible(SdfPath const &id)
|
||||||
{
|
{
|
||||||
DagerD marked this conversation as resolved
Bogdan Nagirniak
commented
```
if (!world_data) {
world_data = make_unique....
insertSprim
}
else {
world_data = make_unique....
changetracker
}
```
|
|||||||
ObjectData *obj_data = object_data(id);
|
ObjectData *obj_data = object_data(id);
|
||||||
LOG(INFO) << "GetVisible: " << id.GetAsString() << " " << obj_data->is_visible();
|
LOG(INFO) << "GetVisible: " << id.GetAsString();
|
||||||
|
|
||||||
|
HdRenderIndex &index = GetRenderIndex();
|
||||||
|
|
||||||
|
if (index.GetSprim(HdPrimTypeTokens->domeLight, id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return obj_data->is_visible();
|
return obj_data->is_visible();
|
||||||
}
|
}
|
||||||
@ -207,6 +229,15 @@ SdfPath BlenderSceneDelegate::material_id(Material *material)
|
|||||||
return GetDelegateID().AppendElementString(str);
|
return GetDelegateID().AppendElementString(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SdfPath BlenderSceneDelegate::world_id(View3DShading *view3DShading)
|
||||||
|
{
|
||||||
|
/* Making id of material in form like M_<pointer in 16 hex digits format>. Example:
|
||||||
|
* W_000002074e812088 */
|
||||||
|
char str[32];
|
||||||
|
snprintf(str, 32, "W_%016llx", (uint64_t)view3DShading);
|
||||||
|
return GetDelegateID().AppendElementString(str);
|
||||||
|
}
|
||||||
|
|
||||||
bool BlenderSceneDelegate::supported_object(Object *object)
|
bool BlenderSceneDelegate::supported_object(Object *object)
|
||||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
return GetDelegateID().AppendElementString("World"); return GetDelegateID().AppendElementString("World");
|
|||||||
{
|
{
|
||||||
return object->type == OB_MESH ||
|
return object->type == OB_MESH ||
|
||||||
@ -229,6 +260,10 @@ void BlenderSceneDelegate::Populate(BL::Depsgraph &b_deps, View3D *v3d)
|
|||||||
/* Export initial objects */
|
/* Export initial objects */
|
||||||
update_collection();
|
update_collection();
|
||||||
|
|
||||||
|
World *world = (World *)b_depsgraph->scene().world().ptr.data;
|
||||||
|
|
||||||
|
add_world(view3d->shading, *world);
|
||||||
|
|
||||||
is_populated = true;
|
is_populated = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -277,6 +312,12 @@ void BlenderSceneDelegate::Populate(BL::Depsgraph &b_deps, View3D *v3d)
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (id.is_a(&RNA_World)) {
|
||||||
|
World *world = (World *)b_depsgraph->scene().world().ptr.data;
|
||||||
|
add_world(view3d->shading, *world);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_update_collection) {
|
if (do_update_collection) {
|
||||||
@ -397,6 +438,12 @@ GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const& id)
|
|||||||
{
|
{
|
||||||
LOG(INFO) << "GetTransform: " << id.GetAsString();
|
LOG(INFO) << "GetTransform: " << id.GetAsString();
|
||||||
|
|
||||||
|
HdRenderIndex &index = GetRenderIndex();
|
||||||
|
|
||||||
|
if (index.GetSprim(HdPrimTypeTokens->domeLight, id)) {
|
||||||
|
return GfMatrix4d().SetIdentity();
|
||||||
|
}
|
||||||
|
|
||||||
return objects[id].transform();
|
return objects[id].transform();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,14 +451,25 @@ VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const& id, TfToken cons
|
|||||||
{
|
{
|
||||||
LOG(INFO) << "GetLightParamValue: " << id.GetAsString() << " [" << key.GetString() << "]";
|
LOG(INFO) << "GetLightParamValue: " << id.GetAsString() << " [" << key.GetString() << "]";
|
||||||
VtValue ret;
|
VtValue ret;
|
||||||
ObjectData *obj_data = object_data(id);
|
|
||||||
DagerD marked this conversation as resolved
Bogdan Nagirniak
commented
revert this block revert this block
|
|||||||
if (obj_data) {
|
HdRenderIndex &index = GetRenderIndex();
|
||||||
if (obj_data->has_data(key)) {
|
|
||||||
ret = obj_data->get_data(key);
|
if (index.GetSprim(HdPrimTypeTokens->domeLight, id)) {
|
||||||
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
|
|||||||
|
if (world_data.has_data(key)) {
|
||||||
|
ret = world_data.get_data(key);
|
||||||
}
|
}
|
||||||
else if (key == HdLightTokens->exposure) {
|
}
|
||||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
move this to WorldData::transform() move this to WorldData::transform()
|
|||||||
// TODO: temporary value, it should be delivered through Python UI
|
else {
|
||||||
ret = 1.0f;
|
|
||||||
|
ObjectData *obj_data = object_data(id);
|
||||||
|
if (obj_data) {
|
||||||
|
if (obj_data->has_data(key)) {
|
||||||
|
ret = obj_data->get_data(key);
|
||||||
|
}
|
||||||
|
else if (key == HdLightTokens->exposure) {
|
||||||
|
// TODO: temporary value, it should be delivered through Python UI
|
||||||
|
ret = 1.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
else if (id == world_id()) {....} else if (id == world_id()) {....}
|
|||||||
return ret;
|
return ret;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "RNA_blender_cpp.h"
|
#include "RNA_blender_cpp.h"
|
||||||
|
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
#include "world.h"
|
||||||
|
|
||||||
using namespace pxr;
|
using namespace pxr;
|
||||||
|
|
||||||
@ -49,6 +50,8 @@ private:
|
|||||||
void update_material(Material *material);
|
void update_material(Material *material);
|
||||||
void update_collection();
|
void update_collection();
|
||||||
void update_visibility();
|
void update_visibility();
|
||||||
|
void add_world(View3DShading &view3DShading, World &world);
|
||||||
|
SdfPath world_id(View3DShading *view3DShading);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BL::Depsgraph *b_depsgraph;
|
BL::Depsgraph *b_depsgraph;
|
||||||
@ -56,6 +59,7 @@ private:
|
|||||||
bool is_populated;
|
bool is_populated;
|
||||||
ObjectDataMap objects;
|
ObjectDataMap objects;
|
||||||
MaterialDataMap materials;
|
MaterialDataMap materials;
|
||||||
|
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
|
||||||
|
116
source/blender/render/hydra/sceneDelegate/world.cc
Normal file
116
source/blender/render/hydra/sceneDelegate/world.cc
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
/* SPDX-License-Identifier: Apache-2.0
|
||||||
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
|
#include <pxr/base/vt/array.h>
|
||||||
|
#include <pxr/base/gf/vec2f.h>
|
||||||
|
#include <pxr/imaging/hd/light.h>
|
||||||
|
#include <pxr/imaging/hd/tokens.h>
|
||||||
|
#include <pxr/usd/usdLux/tokens.h>
|
||||||
|
|
||||||
|
#include "DNA_node_types.h"
|
||||||
|
|
||||||
|
#include "BKE_node.h"
|
||||||
|
#include "BKE_node_runtime.hh"
|
||||||
|
#include "NOD_shader.h"
|
||||||
|
|
||||||
|
#include "world.h"
|
||||||
|
|
||||||
|
/* TODO : add tftoken "transparency" and RPR specific? */
|
||||||
|
|
||||||
|
using namespace pxr;
|
||||||
|
|
||||||
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
|
WorldData::WorldData()
|
||||||
|
: shading(nullptr),
|
||||||
|
world(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
WorldData::WorldData(View3DShading *shading, World *world)
|
||||||
|
: shading(shading),
|
||||||
|
world(world)
|
||||||
|
{
|
||||||
|
set_as_world();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string WorldData::name()
|
||||||
|
{
|
||||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
`(World *world, bContext *context)`
|
|||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
int WorldData::type()
|
||||||
|
{
|
||||||
|
//return object->type;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TfToken WorldData::prim_type()
|
||||||
|
{
|
||||||
|
return HdPrimTypeTokens->domeLight;
|
||||||
|
}
|
||||||
|
|
||||||
|
GfMatrix4d WorldData::transform()
|
||||||
|
{
|
||||||
|
return GfMatrix4d();
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldData::set_as_world()
|
||||||
|
{
|
||||||
|
if (world->use_nodes) {
|
||||||
|
|
||||||
|
bNode *output_node = ntreeShaderOutputNode(world->nodetree, SHD_OUTPUT_ALL);
|
||||||
|
bNodeSocket input_socket = output_node->input_by_identifier("Surface");
|
||||||
|
bNodeLink const *link = input_socket.directly_linked_links()[0];
|
||||||
|
bNode *input_node = link->fromnode;
|
||||||
|
|
||||||
|
bNodeSocket color_input = input_node->input_by_identifier("Color");
|
||||||
|
bNodeSocket strength_input = input_node->input_by_identifier("Strength");
|
||||||
|
|
||||||
|
float const *color = color_input.default_value_typed<float>();
|
||||||
|
float const *strength = strength_input.default_value_typed<float>();
|
||||||
|
|
||||||
|
data[HdLightTokens->intensity] = strength[1];
|
||||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
move to constructor move to constructor
|
|||||||
|
data[HdLightTokens->exposure] = 1.0f;
|
||||||
|
data[HdLightTokens->color] = GfVec3f(color[0], color[1], color[2]);
|
||||||
|
|
||||||
|
//blender::Span<bNode *> world_nodes = world->nodetree->nodes_by_type("ShaderNodeOutputWorld");
|
||||||
|
}
|
||||||
|
else {
|
||||||
DagerD marked this conversation as resolved
Bogdan Nagirniak
commented
`string const &`
|
|||||||
|
data[HdLightTokens->intensity] = 1.0f;
|
||||||
|
data[HdLightTokens->exposure] = world->exposure;
|
||||||
|
data[HdLightTokens->color] = GfVec3f(
|
||||||
|
world->horr,
|
||||||
|
world->horg,
|
||||||
|
world->horb
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldData::set_as_shading()
|
||||||
|
{
|
||||||
|
data[HdLightTokens->intensity] = 1.0f;
|
||||||
|
data[HdLightTokens->exposure] = 1.0f;
|
||||||
|
data[HdLightTokens->color] = GfVec3f(
|
||||||
|
shading->single_color[0],
|
||||||
|
shading->single_color[1],
|
||||||
|
shading->single_color[2]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace blender::render::hydra
|
51
source/blender/render/hydra/sceneDelegate/world.h
Normal file
51
source/blender/render/hydra/sceneDelegate/world.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* SPDX-License-Identifier: Apache-2.0
|
||||||
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include <pxr/base/gf/matrix4d.h>
|
||||||
|
#include <pxr/usd/sdf/path.h>
|
||||||
|
#include <pxr/base/vt/value.h>
|
||||||
|
#include "pxr/base/tf/staticTokens.h"
|
||||||
|
|
||||||
|
#include "DNA_view3d_types.h"
|
||||||
|
#include "DNA_world_types.h"
|
||||||
|
|
||||||
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
|
class WorldData {
|
||||||
|
public:
|
||||||
|
WorldData();
|
||||||
|
WorldData(View3DShading *shading, World *world);
|
||||||
|
|
||||||
|
std::string name();
|
||||||
|
int type();
|
||||||
|
pxr::TfToken prim_type();
|
||||||
|
pxr::GfMatrix4d transform();
|
||||||
|
|
||||||
|
pxr::VtValue &get_data(pxr::TfToken const &key);
|
||||||
|
template<class T>
|
||||||
|
const T &get_data(pxr::TfToken const &key);
|
||||||
|
bool has_data(pxr::TfToken const &key);
|
||||||
|
void update_world();
|
||||||
|
|
||||||
|
View3DShading *shading;
|
||||||
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
|
|||||||
|
World *world;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::map<pxr::TfToken, pxr::VtValue> data;
|
||||||
|
|
||||||
|
void set_as_world();
|
||||||
|
void set_as_shading();
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
const T &WorldData::get_data(pxr::TfToken const &key)
|
||||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
remove unused methods remove unused methods
|
|||||||
|
{
|
||||||
|
return get_data(key).Get<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace blender::render::hydra
|
Loading…
Reference in New Issue
Block a user
world_data = nullptr;