Blender V5.0
io/usd/hydra/world.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "world.hh"
6#include "usd_private.hh"
7
8#include <pxr/base/gf/rotation.h>
9#include <pxr/base/gf/vec2f.h>
10#include <pxr/base/gf/vec3f.h>
11#include <pxr/base/vt/array.h>
12#include <pxr/imaging/hd/light.h>
13#include <pxr/imaging/hd/renderDelegate.h>
14#include <pxr/imaging/hd/tokens.h>
15#include <pxr/usd/usdLux/tokens.h>
16
17#include "DNA_scene_types.h"
18#include "DNA_world_types.h"
19
20#include "BLI_math_constants.h"
21
22#include "BKE_studiolight.h"
23
25#include "image.hh"
26
27/* TODO: add custom `tftoken` "transparency"? */
28
29/* NOTE: opacity and blur aren't supported by USD */
30
31namespace blender::io::hydra {
32
33WorldData::WorldData(HydraSceneDelegate *scene_delegate, pxr::SdfPath const &prim_id)
34 : LightData(scene_delegate, nullptr, prim_id)
35{
36 prim_type_ = pxr::HdPrimTypeTokens->domeLight;
37}
38
40{
41 data_.clear();
42
43 pxr::GfVec3f color(1.0f, 1.0f, 1.0f);
44 float intensity = 1.0f;
45 pxr::SdfAssetPath texture_file;
46
47 if (scene_delegate_->shading_settings.use_scene_world) {
48 const World *world = scene_delegate_->scene->world;
49 ID_LOG("%s", world->id.name);
50
53
54 if (res.image) {
55 const std::string file_path = cache_or_get_image_file(
56 scene_delegate_->bmain, scene_delegate_->scene, res.image, res.iuser);
57 if (!file_path.empty()) {
58 texture_file = pxr::SdfAssetPath(file_path, file_path);
59 }
60
61 if (res.mult_found) {
62 color = pxr::GfVec3f(res.color_mult);
63 }
64 }
65 else if (res.color_found) {
66 const std::string File_path = blender::io::usd::cache_image_color(res.color);
67 texture_file = pxr::SdfAssetPath(File_path, File_path);
68 intensity = res.intensity;
69 }
70 else {
71 intensity = 0.0f;
72 color = pxr::GfVec3f(0.0f, 0.0f, 0.0f);
73 }
74
75 transform = res.transform;
76 }
77 else {
78 ID_LOG("studiolight: %s", scene_delegate_->shading_settings.studiolight_name.c_str());
79
81 scene_delegate_->shading_settings.studiolight_name.c_str(),
83 if (sl != nullptr && sl->flag & STUDIOLIGHT_TYPE_WORLD) {
84 texture_file = pxr::SdfAssetPath(sl->filepath, sl->filepath);
85 /* Coefficient to follow Cycles result */
86 intensity = scene_delegate_->shading_settings.studiolight_intensity / 2;
87 }
88
89 transform = pxr::GfMatrix4d().SetRotate(
90 pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, -1.0),
91 RAD2DEGF(scene_delegate_->shading_settings.studiolight_rotation)));
92 }
93
94 data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true;
95 data_[pxr::HdLightTokens->intensity] = intensity;
96 data_[pxr::HdLightTokens->exposure] = 0.0f;
97 data_[pxr::HdLightTokens->color] = color;
98 data_[pxr::HdLightTokens->textureFile] = texture_file;
99}
100
102{
103 ID_LOG("");
104
105 if (!scene_delegate_->shading_settings.use_scene_world ||
106 (scene_delegate_->shading_settings.use_scene_world && scene_delegate_->scene->world))
107 {
108 init();
109 if (data_.empty()) {
110 remove();
111 return;
112 }
113 insert();
114 scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id,
115 pxr::HdLight::AllDirty);
116 }
117 else {
118 remove();
119 }
120}
121
122} // namespace blender::io::hydra
@ STUDIOLIGHT_TYPE_WORLD
struct StudioLight * BKE_studiolight_find(const char *name, int flag)
#define STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE
#define RAD2DEGF(_rad)
pxr::SdfPath prim_id
Definition id.hh:36
HydraSceneDelegate * scene_delegate_
Definition id.hh:39
LightData(HydraSceneDelegate *scene_delegate, const Object *object, pxr::SdfPath const &prim_id)
std::map< pxr::TfToken, pxr::VtValue > data_
Definition light.hh:23
pxr::GfMatrix4d transform
Definition object.hh:24
WorldData(HydraSceneDelegate *scene_delegate, pxr::SdfPath const &prim_id)
#define ID_LOG(msg,...)
Definition id.hh:53
std::string cache_or_get_image_file(Main *bmain, Scene *scene, Image *image, ImageUser *iuser)
void world_material_to_dome_light(const USDExportParams &params, const Scene *scene, pxr::UsdStageRefPtr stage)
std::string cache_image_color(const float color[4])
char name[258]
Definition DNA_ID.h:432
char filepath[FILE_MAX]