17#include <pxr/base/gf/quatf.h>
18#include <pxr/base/gf/vec2f.h>
19#include <pxr/base/gf/vec3f.h>
20#include <pxr/base/vt/array.h>
22#include <pxr/usd/sdf/types.h>
23#include <pxr/usd/sdf/valueTypeName.h>
24#include <pxr/usd/usd/timeCode.h>
25#include <pxr/usd/usdGeom/primvar.h>
26#include <pxr/usd/usdUtils/sparseValueWriter.h>
33inline const pxr::TfToken
displayColor(
"displayColor", pxr::TfToken::Immortal);
52template<
typename From,
typename To>
inline To
convert_value(
const From value)
59 return pxr::GfVec2f(value[0], value[1]);
63 return pxr::GfVec3f(value[0], value[1], value[2]);
67 return pxr::GfVec3f(value.
r, value.
g, value.
b);
71 return pxr::GfVec4f(value.
r, value.
g, value.
b, value.
a);
76 return pxr::GfVec3f(color4f.
r, color4f.
g, color4f.
b);
81 return pxr::GfVec4f(color4f.
r, color4f.
g, color4f.
b, color4f.
a);
85 return pxr::GfQuatf(value.
w, value.
x, value.
y, value.
z);
90 return float2(value[0], value[1]);
94 return float3(value[0], value[1], value[2]);
106 const pxr::GfVec3f &img = value.GetImaginary();
118template<
typename BlenderT,
typename USDT>
120 const pxr::UsdTimeCode timecode,
121 const pxr::UsdGeomPrimvar &primvar,
122 pxr::UsdUtilsSparseValueWriter &value_writer)
124 constexpr bool is_same = std::is_same_v<BlenderT, USDT>;
127 pxr::VtArray<USDT> usd_data;
128 if (
const std::optional<BlenderT> value = buffer.
get_if_single()) {
133 if constexpr (is_same || is_compatible) {
137 usd_data.resize(
data.size());
138 for (
const int i :
data.index_range()) {
144 if (!primvar.HasValue()) {
145 primvar.Set(usd_data, pxr::UsdTimeCode::Default());
148 value_writer.SetAttribute(primvar.GetAttr(), usd_data, timecode);
153 const pxr::UsdTimeCode timecode,
154 const pxr::UsdGeomPrimvar &primvar,
155 pxr::UsdUtilsSparseValueWriter &value_writer);
159 const pxr::UsdTimeCode timecode)
161 pxr::VtValue primvar_val;
162 if (!primvar.ComputeFlattened(&primvar_val, timecode)) {
166 if (!primvar_val.CanCast<pxr::VtArray<T>>()) {
170 return primvar_val.Cast<pxr::VtArray<T>>().
template UncheckedGet<pxr::VtArray<T>>();
173template<
typename USDT,
typename BlenderT>
175 const pxr::UsdTimeCode timecode,
180 if (usd_data.empty()) {
184 constexpr bool is_same = std::is_same_v<USDT, BlenderT>;
187 const pxr::TfToken pv_interp = primvar.GetInterpolation();
188 if (pv_interp == pxr::UsdGeomTokens->constant) {
192 else if (pv_interp == pxr::UsdGeomTokens->faceVarying) {
193 if (!
faces.is_empty()) {
195 for (
const int i :
faces.index_range()) {
198 const int rev_index = face.
last(j);
204 if constexpr (is_same || is_compatible) {
205 const Span<USDT> src(usd_data.data(), usd_data.size());
217 if (usd_data.size() ==
attribute.size()) {
218 if constexpr (is_same || is_compatible) {
219 const Span<USDT> src(usd_data.data(), usd_data.size());
232 const pxr::UsdTimeCode timecode,
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color attribute
ColorSceneLinear4f< Alpha > decode() const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t start() const
constexpr IndexRange index_range() const
std::optional< T > get_if_single() const
ccl_device_inline int4 cast(const float4 a)
To convert_value(const From value)
pxr::VtArray< T > get_primvar_array(const pxr::UsdGeomPrimvar &primvar, const pxr::UsdTimeCode timecode)
void copy_blender_attribute_to_primvar(const GVArray &attribute, const eCustomDataType data_type, const pxr::UsdTimeCode timecode, const pxr::UsdGeomPrimvar &primvar, pxr::UsdUtilsSparseValueWriter &value_writer)
void copy_primvar_to_blender_buffer(const pxr::UsdGeomPrimvar &primvar, const pxr::UsdTimeCode timecode, const OffsetIndices< int > faces, MutableSpan< BlenderT > attribute)
std::optional< eCustomDataType > convert_usd_type_to_blender(const pxr::SdfValueTypeName usd_type)
std::optional< pxr::SdfValueTypeName > convert_blender_type_to_usd(const eCustomDataType blender_type, bool use_color3f_type)
void copy_blender_buffer_to_primvar(const VArray< BlenderT > &buffer, const pxr::UsdTimeCode timecode, const pxr::UsdGeomPrimvar &primvar, pxr::UsdUtilsSparseValueWriter &value_writer)
void copy_primvar_to_blender_attribute(const pxr::UsdGeomPrimvar &primvar, const pxr::UsdTimeCode timecode, const eCustomDataType data_type, const bke::AttrDomain domain, const OffsetIndices< int > face_indices, bke::MutableAttributeAccessor attributes)
QuaternionBase< float > Quaternion
VecBase< float, 2 > float2
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
const pxr::TfToken displayColor("displayColor", pxr::TfToken::Immortal)