forked from blender/blender
BLEN-335: Export environment light #1
@ -23,7 +23,7 @@ void FinalEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::
|
|||||||
{
|
{
|
||||||
sceneDelegate = std::make_unique<BlenderSceneDelegate>(renderIndex.get(),
|
sceneDelegate = std::make_unique<BlenderSceneDelegate>(renderIndex.get(),
|
||||||
SdfPath::AbsoluteRootPath().AppendElementString("scene"));
|
SdfPath::AbsoluteRootPath().AppendElementString("scene"));
|
||||||
sceneDelegate->Populate(b_depsgraph);
|
sceneDelegate->Populate(b_depsgraph, b_context);
|
||||||
|
|
||||||
for (auto const& setting : renderSettings) {
|
for (auto const& setting : renderSettings) {
|
||||||
renderDelegate->SetRenderSetting(setting.first, setting.second);
|
renderDelegate->SetRenderSetting(setting.first, setting.second);
|
||||||
|
@ -57,7 +57,7 @@ void BlenderSceneDelegate::add_world(View3DShading *view3DShading, World *world)
|
|||||||
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_data.shading != view3DShading || world_data.world != world) {
|
||||||
world_data = WorldData(view3DShading, world);
|
world_data = WorldData(view3DShading, world, b_context);
|
||||||
GetRenderIndex().InsertSprim(HdPrimTypeTokens->domeLight, this, world_light_id);
|
GetRenderIndex().InsertSprim(HdPrimTypeTokens->domeLight, this, world_light_id);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -249,12 +249,13 @@ bool BlenderSceneDelegate::supported_object(Object *object)
|
|||||||
object->type == OB_MBALL;
|
object->type == OB_MBALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlenderSceneDelegate::Populate(BL::Depsgraph &b_deps, View3D *v3d)
|
void BlenderSceneDelegate::Populate(BL::Depsgraph &b_deps, BL::Context &b_cont)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "Populate " << is_populated;
|
LOG(INFO) << "Populate " << is_populated;
|
||||||
|
|
||||||
view3d = v3d;
|
view3d = (View3D *)b_cont.space_data().ptr.data;;
|
||||||
b_depsgraph = &b_deps;
|
b_depsgraph = &b_deps;
|
||||||
|
b_context = &b_cont;
|
||||||
|
|
||||||
if (!is_populated) {
|
if (!is_populated) {
|
||||||
/* Export initial objects */
|
/* Export initial objects */
|
||||||
|
@ -26,7 +26,7 @@ public:
|
|||||||
BlenderSceneDelegate(HdRenderIndex* renderIndex, SdfPath const &delegateId);
|
BlenderSceneDelegate(HdRenderIndex* renderIndex, SdfPath const &delegateId);
|
||||||
~BlenderSceneDelegate() override = default;
|
~BlenderSceneDelegate() override = default;
|
||||||
|
|
||||||
void Populate(BL::Depsgraph &b_deps, View3D *v3d = nullptr);
|
void Populate(BL::Depsgraph &b_deps, BL::Context &b_context);
|
||||||
|
|
||||||
// delegate methods
|
// delegate methods
|
||||||
HdMeshTopology GetMeshTopology(SdfPath const& id) override;
|
HdMeshTopology GetMeshTopology(SdfPath const& id) override;
|
||||||
@ -55,6 +55,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BL::Depsgraph *b_depsgraph;
|
BL::Depsgraph *b_depsgraph;
|
||||||
|
BL::Context *b_context;
|
||||||
View3D *view3d;
|
View3D *view3d;
|
||||||
bool is_populated;
|
bool is_populated;
|
||||||
ObjectDataMap objects;
|
ObjectDataMap objects;
|
||||||
|
@ -8,9 +8,12 @@
|
|||||||
#include <pxr/usd/usdLux/tokens.h>
|
#include <pxr/usd/usdLux/tokens.h>
|
||||||
|
|
||||||
#include "DNA_node_types.h"
|
#include "DNA_node_types.h"
|
||||||
|
#include "DNA_windowmanager_types.h"
|
||||||
|
#include "BKE_context.h"
|
||||||
#include "BKE_node.h"
|
#include "BKE_node.h"
|
||||||
#include "BKE_node_runtime.hh"
|
#include "BKE_node_runtime.hh"
|
||||||
#include "BKE_image.h"
|
#include "BKE_image.h"
|
||||||
|
#include "BKE_image_save.h"
|
||||||
#include "NOD_shader.h"
|
#include "NOD_shader.h"
|
||||||
#include "BLI_path_util.h"
|
#include "BLI_path_util.h"
|
||||||
|
|
||||||
@ -29,9 +32,10 @@ WorldData::WorldData()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldData::WorldData(View3DShading *shading, World *world)
|
WorldData::WorldData(View3DShading *shading, World *world, BL::Context *b_context)
|
||||||
: shading(shading),
|
: shading(shading),
|
||||||
world(world)
|
world(world),
|
||||||
|
b_context(b_context)
|
||||||
BogdanNagirniak marked this conversation as resolved
|
|||||||
{
|
{
|
||||||
set_as_world();
|
set_as_world();
|
||||||
}
|
}
|
||||||
@ -95,13 +99,28 @@ void WorldData::set_as_world()
|
|||||||
if (!color_input.directly_linked_links().is_empty()) {
|
if (!color_input.directly_linked_links().is_empty()) {
|
||||||
bNode *color_input_node = color_input.directly_linked_links()[0]->fromnode;
|
bNode *color_input_node = color_input.directly_linked_links()[0]->fromnode;
|
||||||
if (color_input_node->type == SH_NODE_TEX_IMAGE) {
|
if (color_input_node->type == SH_NODE_TEX_IMAGE) {
|
||||||
|
NodeTexImage *tex = static_cast<NodeTexImage *>(color_input_node->storage);
|
||||||
|
Image *ima = (Image *)color_input_node->id;
|
||||||
|
ReportList reports;
|
||||||
|
ImageSaveOptions opts;
|
||||||
|
Main *bmain = CTX_data_main((bContext *)b_context->ptr.data);
|
||||||
|
if (BKE_image_save_options_init(&opts,
|
||||||
|
bmain,
|
||||||
|
(Scene *)b_context->scene().ptr.data,
|
||||||
|
ima,
|
||||||
|
&tex->iuser,
|
||||||
|
true,
|
||||||
|
false)) {
|
||||||
|
STRNCPY(opts.filepath, "C:\\Users\\user\\Downloads\\test\\123_false.png");
|
||||||
|
opts.im_format.imtype = R_IMF_IMTYPE_TIFF;
|
||||||
|
BKE_image_save(&reports, bmain, ima, &tex->iuser, &opts);
|
||||||
|
|
||||||
data[HdLightTokens->textureFile] = SdfAssetPath(
|
data[HdLightTokens->textureFile] = SdfAssetPath(
|
||||||
"C:\\Users\\user\\Desktop\\WUH6nAqWDDk.jpg",
|
"C:\\Users\\user\\Desktop\\WUH6nAqWDDk.jpg",
|
||||||
"C:\\Users\\user\\Desktop\\WUH6nAqWDDk.jpg"); // get_image_filepath(color_input_node);
|
"C:\\Users\\user\\Desktop\\WUH6nAqWDDk.jpg");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//blender::Span<bNode *> world_nodes = world->nodetree->nodes_by_type("ShaderNodeOutputWorld");
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data[HdLightTokens->intensity] = 1.0f;
|
data[HdLightTokens->intensity] = 1.0f;
|
||||||
@ -124,39 +143,4 @@ void WorldData::set_as_shading()
|
|||||||
shading->single_color[2]
|
shading->single_color[2]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
string WorldData::get_image_filepath(const bNode *tex_node)
|
|
||||||
{
|
|
||||||
if (!tex_node) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
Image *tex_image = reinterpret_cast<Image *>(tex_node->id);
|
|
||||||
if (!tex_image || !BKE_image_has_filepath(tex_image)) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BKE_image_has_packedfile(tex_image)) {
|
|
||||||
/* Put image in the same directory as the .MTL file. */
|
|
||||||
const char *filename = BLI_path_slash_rfind(tex_image->filepath) + 1;
|
|
||||||
fprintf(stderr,
|
|
||||||
"Packed image found:'%s'. Unpack and place the image in the same "
|
|
||||||
"directory as the .MTL file.\n",
|
|
||||||
filename);
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
char path[FILE_MAX];
|
|
||||||
BLI_strncpy(path, tex_image->filepath, FILE_MAX);
|
|
||||||
|
|
||||||
if (tex_image->source == IMA_SRC_SEQUENCE) {
|
|
||||||
char head[FILE_MAX], tail[FILE_MAX];
|
|
||||||
ushort numlen;
|
|
||||||
int framenr = static_cast<NodeTexImage *>(tex_node->storage)->iuser.framenr;
|
|
||||||
BLI_path_sequence_decode(path, head, tail, &numlen);
|
|
||||||
BLI_path_sequence_encode(path, head, tail, numlen, framenr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return path;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -13,13 +13,14 @@
|
|||||||
|
|
||||||
#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);
|
WorldData(View3DShading *shading, World *world, BL::Context *b_context);
|
||||||
|
|
||||||
std::string name();
|
std::string name();
|
||||||
int type();
|
int type();
|
||||||
@ -34,6 +35,7 @@ public:
|
|||||||
|
|
||||||
View3DShading *shading;
|
View3DShading *shading;
|
||||||
World *world;
|
World *world;
|
||||||
|
BL::Context *b_context;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -545,7 +545,7 @@ void ViewportEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, px
|
|||||||
SdfPath::AbsoluteRootPath().AppendElementString("scene"));
|
SdfPath::AbsoluteRootPath().AppendElementString("scene"));
|
||||||
}
|
}
|
||||||
View3D *view3d = (View3D *)b_context.space_data().ptr.data;
|
View3D *view3d = (View3D *)b_context.space_data().ptr.data;
|
||||||
sceneDelegate->Populate(b_depsgraph, view3d);
|
sceneDelegate->Populate(b_depsgraph, b_context);
|
||||||
|
|
||||||
for (auto const& setting : renderSettings) {
|
for (auto const& setting : renderSettings) {
|
||||||
renderDelegate->SetRenderSetting(setting.first, setting.second);
|
renderDelegate->SetRenderSetting(setting.first, setting.second);
|
||||||
|
Loading…
Reference in New Issue
Block a user
(World *world, bContext *context)