Blender V5.3
draw_resource.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
13
14#include "BLI_bounds.hh"
15#include "BLI_math_base_c.hh"
16#include "BLI_math_matrix.hh"
17
18#include "BKE_curve.hh"
19#include "BKE_duplilist.hh"
20#include "BKE_mesh.h"
21#include "BKE_object.hh"
22#include "BKE_volume.hh"
23#include "BLI_hash_c.hh"
24#include "DNA_curve_types.h"
25#include "DNA_layer_types.h"
26#include "DNA_meta_types.h"
27#include "DNA_object_types.h"
28
29#include "DRW_render.hh"
30#include "draw_handle.hh"
31#include "draw_shader_shared.hh"
32
33namespace blender {
34
35/* -------------------------------------------------------------------- */
38
39inline void ObjectMatrices::sync(const Object &object)
40{
41 model = object.object_to_world();
42 model_inverse = object.world_to_object();
43}
44
45inline void ObjectMatrices::sync(const float4x4 &model_matrix)
46{
47 model = model_matrix;
48 model_inverse = math::invert(model_matrix);
49}
50
51inline std::ostream &operator<<(std::ostream &stream, const ObjectMatrices &matrices)
52{
53 stream << "ObjectMatrices(" << std::endl;
54 stream << "model=" << matrices.model << ", " << std::endl;
55 stream << "model_inverse=" << matrices.model_inverse << ")" << std::endl;
56 return stream;
57}
58
60
61/* -------------------------------------------------------------------- */
64
66 const float4x4 &object_to_world)
67{
68 if (object.shadow_terminator_normal_offset == 0.0f) {
69 return 0.0f;
70 }
71 using namespace blender::math;
72 return object.shadow_terminator_normal_offset * reduce_max(to_scale(object_to_world));
73}
74
75inline void ObjectInfos::sync()
76{
79 /* Zero-Initialize since this data might still be accessible (See #154105). */
80 orco_add = float3(0.0f);
81 orco_mul = float3(0.0f);
82 ob_color = float4(0.0f);
83 index = 0;
85 random = 0.0f;
89}
90
91inline void ObjectInfos::sync(const draw::ObjectRef ref,
92 bool is_active_object,
93 bool is_active_edit_mode)
94{
100
101 bool is_holdout = (ref.object->base_flag & BASE_HOLDOUT) ||
103
104 ob_color = ref.object->color;
105 index = ref.object->index;
117
118 if (ref.object->shadow_terminator_normal_offset > 0.0f) {
121 if (!ref.is_dupli()) {
122 /* Normal offset is scaled by world transform, so it must be computed per instance. */
124 *ref.object, ref.object->object_to_world());
125 }
126 }
127 else {
130 }
131
132 random = ref.random(0);
133
134 if (ref.object->data == nullptr) {
135 orco_add = float3(0.0f);
136 orco_mul = float3(1.0f);
137 return;
138 }
139
140 switch (GS(reinterpret_cast<ID *>(ref.object->data)->name)) {
141 case ID_VO: {
142 std::optional<const Bounds<float3>> bounds = BKE_volume_min_max(
144 if (bounds) {
145 orco_add = math::midpoint(bounds->min, bounds->max);
146 orco_mul = (bounds->max - bounds->min) * 0.5f;
147 }
148 else {
149 orco_add = float3(0.0f);
150 orco_mul = float3(1.0f);
151 }
152 break;
153 }
154 case ID_ME: {
157 break;
158 }
159 case ID_CU_LEGACY: {
164 break;
165 }
166 case ID_MB: {
170 break;
171 }
172 default:
173 orco_add = float3(0.0f);
174 orco_mul = float3(1.0f);
175 break;
176 }
177}
178
179inline std::ostream &operator<<(std::ostream &stream, const ObjectInfos &infos)
180{
181 stream << "ObjectInfos(";
183 stream << "skipped)" << std::endl;
184 return stream;
185 }
186 stream << "orco_add=" << infos.orco_add << ", ";
187 stream << "orco_mul=" << infos.orco_mul << ", ";
188 stream << "ob_color=" << infos.ob_color << ", ";
189 stream << "index=" << infos.index << ", ";
190 stream << "random=" << infos.random << ", ";
191 stream << "flag=" << infos.flag << ")" << std::endl;
192 return stream;
193}
194
196
197/* -------------------------------------------------------------------- */
200
202{
203#ifndef NDEBUG
204 /* Initialize to NaN for easier debugging of uninitialized data usage. */
210#endif
211 bounding_sphere.w = -1.0f; /* Disable test. */
212}
213
214inline void ObjectBounds::sync(const Object &ob, float inflate_bounds)
215{
216 const std::optional<Bounds<float3>> bounds = BKE_object_boundbox_get(&ob);
217 if (!bounds) {
218#ifndef NDEBUG
219 /* Initialize to NaN for easier debugging of uninitialized data usage. */
225#endif
226 bounding_sphere.w = -1.0f; /* Disable test. */
227 return;
228 }
229 const std::array<float3, 8> corners = bounds::corners(*bounds);
230 *reinterpret_cast<float3 *>(&bounding_corners[0]) = corners[0];
231 *reinterpret_cast<float3 *>(&bounding_corners[1]) = corners[4];
232 *reinterpret_cast<float3 *>(&bounding_corners[2]) = corners[3];
233 *reinterpret_cast<float3 *>(&bounding_corners[3]) = corners[1];
234 bounding_sphere.w = 0.0f; /* Enable test. */
235
236 if (inflate_bounds != 0.0f) {
237 BLI_assert(inflate_bounds >= 0.0f);
238 float p = inflate_bounds;
239 float n = -inflate_bounds;
240 bounding_corners[0] += float4(n, n, n, 0.0f);
241 bounding_corners[1] += float4(p, n, n, 0.0f);
242 bounding_corners[2] += float4(n, p, n, 0.0f);
243 bounding_corners[3] += float4(n, n, p, 0.0f);
244 }
245}
246
247inline void ObjectBounds::sync(const float3 &center, const float3 &size)
248{
249 *reinterpret_cast<float3 *>(&bounding_corners[0]) = center - size;
250 *reinterpret_cast<float3 *>(&bounding_corners[1]) = center + float3(+size.x, -size.y, -size.z);
251 *reinterpret_cast<float3 *>(&bounding_corners[2]) = center + float3(-size.x, +size.y, -size.z);
252 *reinterpret_cast<float3 *>(&bounding_corners[3]) = center + float3(-size.x, -size.y, +size.z);
253 bounding_sphere.w = 0.0; /* Enable test. */
254}
255
256inline std::ostream &operator<<(std::ostream &stream, const ObjectBounds &bounds)
257{
258 stream << "ObjectBounds(";
259 if (bounds.bounding_sphere.w == -1.0f) {
260 stream << "skipped)" << std::endl;
261 return stream;
262 }
263 stream << std::endl;
264 stream << ".bounding_corners[0]"
265 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[0]) << std::endl;
266 stream << ".bounding_corners[1]"
267 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[1]) << std::endl;
268 stream << ".bounding_corners[2]"
269 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[2]) << std::endl;
270 stream << ".bounding_corners[3]"
271 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[3]) << std::endl;
272 stream << ".sphere=(pos=" << float3(bounds.bounding_sphere)
273 << ", rad=" << bounds.bounding_sphere.w << std::endl;
274 stream << ")" << std::endl;
275 return stream;
276}
277
279
280} // namespace blender
General operations, lookup, etc. for blender objects.
Volume data-block.
#define NAN_FLT
Object is a sort of wrapper for general info.
#define BASE_SELECTED(v3d, base)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define BLI_assert(a)
uint8_t get_receiver_light_set() const
uint8_t get_blocker_shadow_set() const
float random(int instance_index) const
@ OBJECT_NO_INFO
@ OBJECT_SELECTED
@ OBJECT_FROM_DUPLI
@ OBJECT_ACTIVE
@ OBJECT_ACTIVE_EDIT_MODE
@ OBJECT_FROM_SET
@ OBJECT_HOLDOUT
@ OBJECT_NEGATIVE_SCALE
float3 to_scale(float3x3 mat)
float reduce_max(float2 a)
std::ostream & operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append)
std::array< VecBase< T, 3 >, 8 > corners(const Bounds< VecBase< T, 3 > > &bounds)
CartesianBasis invert(const CartesianBasis &basis)
T midpoint(const T &a, const T &b)
BMesh Iterators.
std::optional< Bounds< float3 > > BKE_volume_min_max(const Volume *volume)
MatBase< float, 4, 4 > float4x4
float shadow_terminator_normal_offset_get(const Object &object, const float4x4 &object_to_world)
void BKE_curve_texspace_ensure(Curve *cu)
Definition curve.cc:524
VecBase< float, 4 > float4
T & DRW_object_get_data_for_drawing(const Object &object)
void BKE_mesh_texspace_get(Mesh *mesh, float r_texspace_location[3], float r_texspace_size[3])
ID_Type GS(const char *name)
Definition DNA_ID.h:410
std::optional< Bounds< float3 > > BKE_object_boundbox_get(const Object *ob)
Definition object.cc:3726
VecBase< float, 3 > float3
float4 bounding_corners[4]
enum eObjectInfoFlag flag
packed_float3 orco_add
float shadow_terminator_normal_offset
uint light_and_shadow_set_membership
float shadow_terminator_geometry_offset
packed_float3 orco_mul
void sync(const Object &object)
float texspace_location[3]
char name[258]
Definition DNA_ID.h:433
float shadow_terminator_geometry_offset
eObject_VisibilityFlag visibility_flag
float shadow_terminator_normal_offset
eObject_TransFlag transflag