Blender V5.3
util.hh
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#pragma once
6
7#include <pxr/base/gf/matrix4d.h>
8#include <pxr/base/tf/token.h>
9#include <pxr/base/vt/array.h>
10#include <pxr/imaging/hd/dataSource.h>
11#include <pxr/imaging/hd/retainedDataSource.h>
12#include <pxr/usd/sdf/path.h>
13
14#include "BLI_vector.hh"
15
16namespace blender {
17
18namespace io::hydra {
19
20inline pxr::GfMatrix4d gf_matrix_from_transform(const float m[4][4])
21{
22 pxr::GfMatrix4d ret;
23 for (int i = 0; i < 4; i++) {
24 for (int j = 0; j < 4; j++) {
25 ret[i][j] = m[i][j];
26 }
27 }
28 return ret;
29}
30
32template<typename T> inline void resize_uninitialized(pxr::VtArray<T> &array, const int new_size)
33{
34 static_assert(std::is_trivial_v<T>);
35 array.resize(new_size, [](auto /*begin*/, auto /*end*/) {});
36}
37
38/* Helper for building flat name -> value Hydra container data sources. */
42
44 {
45 names.reserve(n);
46 values.reserve(n);
47 }
48
49 /* Append a value, wrapping raw scalar/vector values in a typed sampled
50 * data source. Pre-built data source handles are appended as-is. */
51 template<typename T> void add(const pxr::TfToken &name, const T &value)
52 {
53 using U = std::decay_t<T>;
54 names.append(name);
55 if constexpr (std::is_convertible_v<U, pxr::HdDataSourceBaseHandle>) {
56 values.append(value);
57 }
58 else {
59 values.append(pxr::HdRetainedTypedSampledDataSource<U>::New(value));
60 }
61 }
62
63 pxr::HdContainerDataSourceHandle build() const
64 {
65 return pxr::HdRetainedContainerDataSource::New(names.size(), names.data(), values.data());
66 }
67};
68
69} // namespace io::hydra
70} // namespace blender
T * resize(const size_t newsize)
int64_t size() const
void append(const T &value)
void reserve(const int64_t min_capacity)
#define T
pxr::GfMatrix4d gf_matrix_from_transform(const float m[4][4])
Definition util.hh:20
void resize_uninitialized(pxr::VtArray< T > &array, const int new_size)
Definition util.hh:32
BMesh Iterators.
UserDef U
Definition blender.cc:58
__int64 int64_t
Definition BKE_text.h:90
Vector< pxr::HdDataSourceBaseHandle > values
Definition util.hh:41
void add(const pxr::TfToken &name, const T &value)
Definition util.hh:51
Vector< pxr::TfToken > names
Definition util.hh:40
pxr::HdContainerDataSourceHandle build() const
Definition util.hh:63