Blender V4.3
BKE_volume_grid_type_traits.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Foundation
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11#ifdef WITH_OPENVDB
12
15
16# include "BKE_volume_enums.hh"
17# include "openvdb_fwd.hh"
18
19namespace blender::bke {
20
31template<typename T> struct VolumeGridTraits {
35 using BlenderType = void;
39 using PrimitiveType = void;
43 using TreeType = void;
47 static constexpr VolumeGridType EnumType = VOLUME_GRID_UNKNOWN;
48};
49
50template<> struct VolumeGridTraits<bool> {
51 using BlenderType = bool;
52 using PrimitiveType = bool;
53 using TreeType = openvdb::BoolTree;
54 static constexpr VolumeGridType EnumType = VOLUME_GRID_BOOLEAN;
55
56 static bool to_openvdb(const bool &value)
57 {
58 return value;
59 }
60 static bool to_blender(const bool &value)
61 {
62 return value;
63 }
64};
65
66template<> struct VolumeGridTraits<int> {
67 using BlenderType = int;
68 using PrimitiveType = int;
69 using TreeType = openvdb::Int32Tree;
70 static constexpr VolumeGridType EnumType = VOLUME_GRID_INT;
71
72 static int to_openvdb(const int &value)
73 {
74 return value;
75 }
76 static int to_blender(const int &value)
77 {
78 return value;
79 }
80};
81
82template<> struct VolumeGridTraits<float> {
83 using BlenderType = float;
84 using PrimitiveType = float;
85 using TreeType = openvdb::FloatTree;
86 static constexpr VolumeGridType EnumType = VOLUME_GRID_FLOAT;
87
88 static float to_openvdb(const float &value)
89 {
90 return value;
91 }
92 static float to_blender(const float &value)
93 {
94 return value;
95 }
96};
97
98template<> struct VolumeGridTraits<float3> {
99 using BlenderType = float3;
100 using PrimitiveType = openvdb::Vec3f;
101 using TreeType = openvdb::Vec3STree;
102 static constexpr VolumeGridType EnumType = VOLUME_GRID_VECTOR_FLOAT;
103
104 static openvdb::Vec3f to_openvdb(const float3 &value)
105 {
106 return openvdb::Vec3f(*value);
107 }
108 static float3 to_blender(const openvdb::Vec3f &value)
109 {
110 return float3(value.asV());
111 }
112};
113
114template<typename T> using OpenvdbTreeType = typename VolumeGridTraits<T>::TreeType;
115template<typename T> using OpenvdbGridType = openvdb::Grid<OpenvdbTreeType<T>>;
116
117} // namespace blender::bke
118
119#endif /* WITH_OPENVDB */
VolumeGridType
@ VOLUME_GRID_VECTOR_FLOAT
@ VOLUME_GRID_UNKNOWN
@ VOLUME_GRID_BOOLEAN
@ VOLUME_GRID_INT
@ VOLUME_GRID_FLOAT
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
PrimitiveType