forked from blender/blender
BLEN-335: Export environment light #1
@ -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;
|
||||
|
||||
|
@ -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,33 +100,53 @@ 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;
|
||||
if (ima) {
|
||||
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,
|
||||
CTX_data_scene((bContext *)b_context->ptr.data),
|
||||
ima,
|
||||
&tex->iuser,
|
||||
true,
|
||||
false,
|
||||
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);
|
||||
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;
|
||||
data[HdLightTokens->exposure] = world->exposure;
|
||||
|
Loading…
Reference in New Issue
Block a user