BLEN-335: Export environment light #1

Merged
Bogdan Nagirniak merged 13 commits from BLEN-335 into hydra-render 2023-02-17 14:46:46 +01:00
2 changed files with 46 additions and 20 deletions
Showing only changes of commit ab425edc35 - Show all commits

View File

@ -56,7 +56,8 @@ void BlenderSceneDelegate::add_world(View3DShading *view3DShading, World *world)
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.b_context != b_context) {
world_data = WorldData(view3DShading, world, b_context);
GetRenderIndex().InsertSprim(HdPrimTypeTokens->domeLight, this, world_light_id);
}
@ -253,7 +254,7 @@ void BlenderSceneDelegate::Populate(BL::Depsgraph &b_deps, BL::Context &b_cont)
{
LOG(INFO) << "Populate " << is_populated;
view3d = (View3D *)b_cont.space_data().ptr.data;;
view3d = (View3D *)b_cont.space_data().ptr.data;
b_depsgraph = &b_deps;
b_context = &b_cont;

View File

@ -1,19 +1,24 @@
/* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */
#include <filesystem>
#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 "BKE_context.h"
#include "DNA_node_types.h"
#include "DNA_windowmanager_types.h"
#include "BKE_context.h"
#include "BKE_node.h"
#include "BKE_node_runtime.hh"
#include "BKE_image.h"
#include "BKE_image_save.h"
#include "BKE_appdir.h"
#include "NOD_shader.h"
#include "BLI_path_util.h"
@ -95,32 +100,52 @@ void WorldData::set_as_world()
data[HdLightTokens->intensity] = strength[1];
data[HdLightTokens->exposure] = 1.0f;
data[HdLightTokens->color] = GfVec3f(color[0], color[1], color[2]);
PyGILState_STATE gilstate;
gilstate = PyGILState_Ensure();
if (!color_input.directly_linked_links().is_empty()) {
bNode *color_input_node = color_input.directly_linked_links()[0]->fromnode;
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);
if (ima) {
ReportList reports;
ImageSaveOptions opts;
Main *bmain = CTX_data_main((bContext *)b_context->ptr.data);
if (BKE_image_save_options_init(&opts,
bmain,
CTX_data_scene((bContext *)b_context->ptr.data),
ima,
&tex->iuser,
false,
false)) {
char tempfile[FILE_MAX];
string image_name;
data[HdLightTokens->textureFile] = SdfAssetPath(
"C:\\Users\\user\\Desktop\\WUH6nAqWDDk.jpg",
"C:\\Users\\user\\Desktop\\WUH6nAqWDDk.jpg");
if (ima->source == IMA_SRC_GENERATED) {
image_name = strcat((ima->id.name + 2), ".png");
}
else {
image_name = ima->filepath == NULL ?
std::filesystem::path(ima->filepath).filename().string() :
ima->id.name + 2;
}
BLI_path_join(tempfile,
sizeof(tempfile),
BKE_tempdir_session(),
image_name.c_str());
STRNCPY(opts.filepath, tempfile);
opts.im_format.imtype = R_IMF_IMTYPE_PNG;
if (BKE_image_save(&reports, bmain, ima, &tex->iuser, &opts)) {
data[HdLightTokens->textureFile] = SdfAssetPath(tempfile, tempfile);
}
BKE_image_save_options_free(&opts);
}
}
}
}
PyGILState_Release(gilstate);
}
else {
data[HdLightTokens->intensity] = 1.0f;