forked from blender/blender
BLEN-335: Export environment light #1
@ -3,8 +3,10 @@
|
||||
|
||||
#include <pxr/imaging/hd/light.h>
|
||||
#include <pxr/imaging/hd/material.h>
|
||||
#include <pxr/imaging/hd/renderDelegate.h>
|
||||
#include <pxr/usd/usdLux/tokens.h>
|
||||
#include <pxr/imaging/hdSt/tokens.h>
|
||||
#include <pxr/base/gf/rotation.h>
|
||||
|
||||
#include "glog/logging.h"
|
||||
|
||||
@ -449,7 +451,15 @@ GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const& id)
|
||||
HdRenderIndex &index = GetRenderIndex();
|
||||
|
||||
if (index.GetSprim(HdPrimTypeTokens->domeLight, id)) {
|
||||
return GfMatrix4d().SetIdentity();
|
||||
GfMatrix4d transform = world_data.transform();
|
||||
if (world_data.has_data(UsdLuxTokens->orientToStageUpAxis)) {
|
||||
transform *= GfMatrix4d(GfRotation(GfVec3d(1.0, 0.0, 0.0), -90), GfVec3d());
|
||||
}
|
||||
BogdanNagirniak marked this conversation as resolved
|
||||
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());
|
||||
}
|
||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
move this to WorldData::transform() move this to WorldData::transform()
|
||||
return transform;
|
||||
}
|
||||
|
||||
return objects[id].transform();
|
||||
|
@ -17,12 +17,10 @@
|
||||
#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"
|
||||
|
||||
#include "world.h"
|
||||
#include "../utils.h"
|
||||
|
||||
/* TODO : add custom tftoken "transparency"? */
|
||||
|
||||
@ -32,15 +30,16 @@ using namespace std;
|
||||
namespace blender::render::hydra {
|
||||
|
||||
WorldData::WorldData()
|
||||
: shading(nullptr),
|
||||
world(nullptr)
|
||||
: b_context(nullptr),
|
||||
shading(nullptr),
|
||||
world(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
`(World *world, bContext *context)`
|
||||
WorldData::WorldData(View3DShading *shading, World *world, BL::Context *b_context)
|
||||
: shading(shading),
|
||||
world(world),
|
||||
b_context(b_context)
|
||||
: b_context(b_context),
|
||||
shading(shading),
|
||||
world(world)
|
||||
{
|
||||
set_as_world();
|
||||
}
|
||||
@ -63,7 +62,7 @@ TfToken WorldData::prim_type()
|
||||
|
||||
GfMatrix4d WorldData::transform()
|
||||
{
|
||||
return GfMatrix4d();
|
||||
return GfMatrix4d().SetIdentity();
|
||||
}
|
||||
|
||||
VtValue &WorldData::get_data(TfToken const &key)
|
||||
@ -85,8 +84,9 @@ void WorldData::set_as_world()
|
||||
{
|
||||
data.clear();
|
||||
|
||||
if (world->use_nodes) {
|
||||
data[UsdLuxTokens->orientToStageUpAxis] = true;
|
||||
|
||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
move to constructor move to constructor
|
||||
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];
|
||||
@ -105,44 +105,19 @@ void WorldData::set_as_world()
|
||||
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;
|
||||
Image *image = (Image *)color_input_node->id;
|
||||
|
||||
if (image) {
|
||||
Main *bmain = CTX_data_main((bContext *)b_context->ptr.data);
|
||||
Scene *scene = CTX_data_scene((bContext *)b_context->ptr.data);
|
||||
|
||||
if (ima) {
|
||||
ReportList reports;
|
||||
ImageSaveOptions opts;
|
||||
Main *bmain = CTX_data_main((bContext *)b_context->ptr.data);
|
||||
opts.im_format.imtype = R_IMF_IMTYPE_PNG;
|
||||
|
||||
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;
|
||||
|
||||
if (ima->source == IMA_SRC_GENERATED) {
|
||||
image_name.append(ima->id.name + 2).append(".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;
|
||||
opts.save_copy = true;
|
||||
|
||||
if (BKE_image_save(&reports, bmain, ima, &tex->iuser, &opts)) {
|
||||
data[HdLightTokens->textureFile] = SdfAssetPath(tempfile, tempfile);
|
||||
}
|
||||
BKE_image_save_options_free(&opts);
|
||||
string cached_image_path = cache_image(bmain, scene, image, &tex->iuser, &opts, &reports);
|
||||
if (!cached_image_path.empty()) {
|
||||
data[HdLightTokens->textureFile] = SdfAssetPath(cached_image_path, cached_image_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,17 +33,15 @@ public:
|
||||
bool has_data(pxr::TfToken const &key);
|
||||
void update_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
|
||||
|
||||
BL::Context *b_context;
|
||||
View3DShading *shading;
|
||||
World *world;
|
||||
BL::Context *b_context;
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
std::map<pxr::TfToken, pxr::VtValue> data;
|
||||
|
||||
void set_as_world();
|
||||
void set_as_shading();
|
||||
std::string get_image_filepath(const bNode *tex_node);
|
||||
};
|
||||
|
||||
BogdanNagirniak marked this conversation as resolved
Bogdan Nagirniak
commented
remove unused methods remove unused methods
|
||||
template<class T>
|
||||
|
@ -2,9 +2,18 @@
|
||||
* Copyright 2011-2022 Blender Foundation */
|
||||
|
||||
#include <sstream>
|
||||
#include <filesystem>
|
||||
|
||||
#include <pxr/base/tf/stringUtils.h>
|
||||
|
||||
#include "BKE_appdir.h"
|
||||
#include "BKE_image_save.h"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_path_util.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
using namespace pxr;
|
||||
using namespace std;
|
||||
|
||||
DagerD marked this conversation as resolved
Bogdan Nagirniak
commented
remove this remove this
|
||||
namespace blender::render::hydra {
|
||||
@ -14,23 +23,63 @@ string formatDuration(chrono::milliseconds millisecs)
|
||||
stringstream ss;
|
||||
bool neg = millisecs < 0ms;
|
||||
if (neg)
|
||||
millisecs = -millisecs;
|
||||
millisecs = -millisecs;
|
||||
auto m = chrono::duration_cast<chrono::minutes>(millisecs);
|
||||
millisecs -= m;
|
||||
auto s = chrono::duration_cast<chrono::seconds>(millisecs);
|
||||
millisecs -= s;
|
||||
if (neg)
|
||||
ss << "-";
|
||||
ss << "-";
|
||||
if (m < 10min)
|
||||
ss << "0";
|
||||
ss << "0";
|
||||
ss << to_string(m / 1min) << ":";
|
||||
if (s < 10s)
|
||||
ss << "0";
|
||||
ss << to_string(s/1s) << ":";
|
||||
ss << "0";
|
||||
ss << to_string(s / 1s) << ":";
|
||||
if (millisecs < 10ms)
|
||||
ss << "0";
|
||||
ss << to_string(millisecs/1ms/10);
|
||||
ss << "0";
|
||||
ss << to_string(millisecs / 1ms / 10);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
DagerD marked this conversation as resolved
Bogdan Nagirniak
commented
add {...} add {...}
|
||||
} // namespace blender::render::hydra
|
||||
string cache_image(Main *bmain,
|
||||
Scene *scene,
|
||||
Image *image,
|
||||
ImageUser *iuser,
|
||||
ImageSaveOptions *opts,
|
||||
ReportList *reports)
|
||||
{
|
||||
const string default_format = ".png";
|
||||
|
||||
char tempfile[FILE_MAX];
|
||||
|
||||
if (!BKE_image_save_options_init(opts, bmain, scene, image, iuser, true, false)) {
|
||||
BKE_image_save_options_free(opts);
|
||||
return "";
|
||||
}
|
||||
|
||||
string image_name;
|
||||
|
||||
if (image->source == IMA_SRC_GENERATED) {
|
||||
image_name = TfMakeValidIdentifier(image_name.append(image->id.name + 2));
|
||||
}
|
||||
else {
|
||||
image_name = image->filepath == NULL ? image->filepath : image->id.name + 2;
|
||||
image_name = std::filesystem::path(image_name).filename().replace_extension().string();
|
||||
image_name = TfMakeValidIdentifier(image_name);
|
||||
}
|
||||
|
||||
image_name.append(default_format);
|
||||
|
||||
BLI_path_join(tempfile, sizeof(tempfile), BKE_tempdir_session(), image_name.c_str());
|
||||
STRNCPY(opts->filepath, tempfile);
|
||||
|
||||
if (BKE_image_save(reports, bmain, image, iuser, opts)) {
|
||||
BKE_image_save_options_free(opts);
|
||||
return tempfile;
|
||||
};
|
||||
|
||||
BKE_image_save_options_free(opts);
|
||||
return "";
|
||||
}
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -6,8 +6,17 @@
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_image_save.h"
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
std::string formatDuration(std::chrono::milliseconds secs);
|
||||
std::string cache_image(Main *bmain,
|
||||
Scene *scene,
|
||||
Image *image,
|
||||
ImageUser *iuser,
|
||||
ImageSaveOptions *opts,
|
||||
ReportList *reports);
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
Loading…
Reference in New Issue
Block a user
add TODO comment like: implement this check via render settings