Blender V4.5
usd_reader_domelight.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
7
8#include <pxr/usd/usdLux/domeLight.h>
9#include <pxr/usd/usdLux/domeLight_1.h>
10#include <pxr/usd/usdLux/tokens.h>
11
12namespace usdtokens {
13// Attribute names.
14static const pxr::TfToken color("color", pxr::TfToken::Immortal);
15static const pxr::TfToken intensity("intensity", pxr::TfToken::Immortal);
16static const pxr::TfToken texture_file("texture:file", pxr::TfToken::Immortal);
17static const pxr::TfToken pole_axis("poleAxis", pxr::TfToken::Immortal);
18} // namespace usdtokens
19
20namespace blender::io::usd {
21
32template<typename T>
33static bool get_authored_value(const pxr::UsdAttribute &attr,
34 const double motionSampleTime,
35 const pxr::UsdPrim &prim,
36 const pxr::TfToken fallback_attr_name,
37 T *r_value)
38{
39 if (attr && attr.HasAuthoredValue()) {
40 return attr.Get<T>(r_value, motionSampleTime);
41 }
42
43 if (!prim || fallback_attr_name.IsEmpty()) {
44 return false;
45 }
46
47 pxr::UsdAttribute fallback_attr = prim.GetAttribute(fallback_attr_name);
48 if (fallback_attr && fallback_attr.HasAuthoredValue()) {
49 return fallback_attr.Get<T>(r_value, motionSampleTime);
50 }
51
52 return false;
53}
54
55template<typename T> static float get_intensity(const T &dome_light, float motionSampleTime)
56{
57 float intensity = 1.0f;
58 get_authored_value(dome_light.GetIntensityAttr(),
59 motionSampleTime,
60 dome_light.GetPrim(),
62 &intensity);
63 return intensity;
64}
65
66template<typename T>
67static bool get_tex_path(const T &dome_light, float motionSampleTime, pxr::SdfAssetPath *tex_path)
68{
69 bool has_tex = get_authored_value(dome_light.GetTextureFileAttr(),
70 motionSampleTime,
71 dome_light.GetPrim(),
73 tex_path);
74 return has_tex;
75}
76
77template<typename T>
78static bool get_color(const T &dome_light, float motionSampleTime, pxr::GfVec3f *color)
79{
80 bool has_color = get_authored_value(
81 dome_light.GetColorAttr(), motionSampleTime, dome_light.GetPrim(), usdtokens::color, color);
82 return has_color;
83}
84
85static pxr::TfToken get_pole_axis(const pxr::UsdLuxDomeLight_1 &dome_light, float motionSampleTime)
86{
87 pxr::TfToken pole_axis = pxr::UsdLuxTokens->scene;
89 dome_light.GetPoleAxisAttr(), motionSampleTime, dome_light.GetPrim(), {}, &pole_axis);
90 return pole_axis;
91}
92
94{
95 USDImportDomeLightData dome_light_data;
96
97 /* Time varying dome lights are not currently supported. */
98 const double motionSampleTime = 0.0;
99
100 if (prim_.IsA<pxr::UsdLuxDomeLight>()) {
101 pxr::UsdLuxDomeLight dome_light = pxr::UsdLuxDomeLight(prim_);
102 dome_light_data.intensity = get_intensity(dome_light, motionSampleTime);
103 dome_light_data.has_tex = get_tex_path(
104 dome_light, motionSampleTime, &dome_light_data.tex_path);
105 dome_light_data.has_color = get_color(dome_light, motionSampleTime, &dome_light_data.color);
106 dome_light_data.pole_axis = pxr::UsdLuxTokens->Y;
107 }
108 else if (prim_.IsA<pxr::UsdLuxDomeLight_1>()) {
109 pxr::UsdLuxDomeLight_1 dome_light = pxr::UsdLuxDomeLight_1(prim_);
110 dome_light_data.intensity = get_intensity(dome_light, motionSampleTime);
111 dome_light_data.has_tex = get_tex_path(
112 dome_light, motionSampleTime, &dome_light_data.tex_path);
113 dome_light_data.has_color = get_color(dome_light, motionSampleTime, &dome_light_data.color);
114 dome_light_data.pole_axis = get_pole_axis(dome_light, motionSampleTime);
115 }
116
117 dome_light_to_world_material(import_params_, scene, bmain, dome_light_data, prim_);
118}
119
120} // namespace blender::io::usd
const USDImportParams & import_params_
#define T
static pxr::TfToken get_pole_axis(const pxr::UsdLuxDomeLight_1 &dome_light, float motionSampleTime)
static bool get_tex_path(const T &dome_light, float motionSampleTime, pxr::SdfAssetPath *tex_path)
static bool get_color(const T &dome_light, float motionSampleTime, pxr::GfVec3f *color)
void dome_light_to_world_material(const USDImportParams &params, Scene *scene, Main *bmain, const USDImportDomeLightData &dome_light_data, const pxr::UsdPrim &prim, const double motionSampleTime)
static bool get_authored_value(const pxr::UsdAttribute &attr, const double motionSampleTime, const pxr::UsdPrim &prim, const pxr::TfToken fallback_attr_name, T *r_value)
static float get_intensity(const T &dome_light, float motionSampleTime)
static const pxr::TfToken intensity("intensity", pxr::TfToken::Immortal)
static const pxr::TfToken texture_file("texture:file", pxr::TfToken::Immortal)
static const pxr::TfToken pole_axis("poleAxis", pxr::TfToken::Immortal)
static const pxr::TfToken color("color", pxr::TfToken::Immortal)