Blender V5.0
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.h"
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.h"
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
33/* -------------------------------------------------------------------- */
36
37inline void ObjectMatrices::sync(const Object &object)
38{
39 model = object.object_to_world();
40 model_inverse = object.world_to_object();
41}
42
43inline void ObjectMatrices::sync(const float4x4 &model_matrix)
44{
45 model = model_matrix;
47}
48
49inline std::ostream &operator<<(std::ostream &stream, const ObjectMatrices &matrices)
50{
51 stream << "ObjectMatrices(" << std::endl;
52 stream << "model=" << matrices.model << ", " << std::endl;
53 stream << "model_inverse=" << matrices.model_inverse << ")" << std::endl;
54 return stream;
55}
56
58
59/* -------------------------------------------------------------------- */
62
70
72 bool is_active_object,
73 bool is_active_edit_mode)
74{
78
79 LightLinking *light_linking = ref.light_linking();
80 if (light_linking) {
83 }
84
85 bool is_holdout = (ref.object->base_flag & BASE_HOLDOUT) ||
87
88 ob_color = ref.object->color;
89 index = ref.object->index;
101
102 if (ref.object->shadow_terminator_normal_offset > 0.0f) {
103 using namespace blender::math;
106 reduce_max(to_scale(ref.object->object_to_world()));
107 }
108 else {
111 }
112
113 random = ref.random();
114
115 if (ref.object->data == nullptr) {
116 orco_add = float3(0.0f);
117 orco_mul = float3(1.0f);
118 return;
119 }
120
121 switch (GS(reinterpret_cast<ID *>(ref.object->data)->name)) {
122 case ID_VO: {
123 std::optional<const blender::Bounds<float3>> bounds = BKE_volume_min_max(
125 if (bounds) {
127 orco_mul = (bounds->max - bounds->min) * 0.5f;
128 }
129 else {
130 orco_add = float3(0.0f);
131 orco_mul = float3(1.0f);
132 }
133 break;
134 }
135 case ID_ME: {
138 break;
139 }
140 case ID_CU_LEGACY: {
145 break;
146 }
147 case ID_MB: {
151 break;
152 }
153 default:
154 orco_add = float3(0.0f);
155 orco_mul = float3(1.0f);
156 break;
157 }
158}
159
160inline std::ostream &operator<<(std::ostream &stream, const ObjectInfos &infos)
161{
162 stream << "ObjectInfos(";
164 stream << "skipped)" << std::endl;
165 return stream;
166 }
167 stream << "orco_add=" << infos.orco_add << ", ";
168 stream << "orco_mul=" << infos.orco_mul << ", ";
169 stream << "ob_color=" << infos.ob_color << ", ";
170 stream << "index=" << infos.index << ", ";
171 stream << "random=" << infos.random << ", ";
172 stream << "flag=" << infos.flag << ")" << std::endl;
173 return stream;
174}
175
177
178/* -------------------------------------------------------------------- */
181
183{
184#ifndef NDEBUG
185 /* Initialize to NaN for easier debugging of uninitialized data usage. */
191#endif
192 bounding_sphere.w = -1.0f; /* Disable test. */
193}
194
195inline void ObjectBounds::sync(const Object &ob, float inflate_bounds)
196{
197 const std::optional<blender::Bounds<float3>> bounds = BKE_object_boundbox_get(&ob);
198 if (!bounds) {
199#ifndef NDEBUG
200 /* Initialize to NaN for easier debugging of uninitialized data usage. */
206#endif
207 bounding_sphere.w = -1.0f; /* Disable test. */
208 return;
209 }
210 const std::array<float3, 8> corners = blender::bounds::corners(*bounds);
211 *reinterpret_cast<float3 *>(&bounding_corners[0]) = corners[0];
212 *reinterpret_cast<float3 *>(&bounding_corners[1]) = corners[4];
213 *reinterpret_cast<float3 *>(&bounding_corners[2]) = corners[3];
214 *reinterpret_cast<float3 *>(&bounding_corners[3]) = corners[1];
215 bounding_sphere.w = 0.0f; /* Enable test. */
216
217 if (inflate_bounds != 0.0f) {
218 BLI_assert(inflate_bounds >= 0.0f);
219 float p = inflate_bounds;
220 float n = -inflate_bounds;
221 bounding_corners[0] += float4(n, n, n, 0.0f);
222 bounding_corners[1] += float4(p, n, n, 0.0f);
223 bounding_corners[2] += float4(n, p, n, 0.0f);
224 bounding_corners[3] += float4(n, n, p, 0.0f);
225 }
226}
227
228inline void ObjectBounds::sync(const float3 &center, const float3 &size)
229{
230 *reinterpret_cast<float3 *>(&bounding_corners[0]) = center - size;
231 *reinterpret_cast<float3 *>(&bounding_corners[1]) = center + float3(+size.x, -size.y, -size.z);
232 *reinterpret_cast<float3 *>(&bounding_corners[2]) = center + float3(-size.x, +size.y, -size.z);
233 *reinterpret_cast<float3 *>(&bounding_corners[3]) = center + float3(-size.x, -size.y, +size.z);
234 bounding_sphere.w = 0.0; /* Enable test. */
235}
236
237inline std::ostream &operator<<(std::ostream &stream, const ObjectBounds &bounds)
238{
239 stream << "ObjectBounds(";
240 if (bounds.bounding_sphere.w == -1.0f) {
241 stream << "skipped)" << std::endl;
242 return stream;
243 }
244 stream << std::endl;
245 stream << ".bounding_corners[0]"
246 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[0]) << std::endl;
247 stream << ".bounding_corners[1]"
248 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[1]) << std::endl;
249 stream << ".bounding_corners[2]"
250 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[2]) << std::endl;
251 stream << ".bounding_corners[3]"
252 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[3]) << std::endl;
253 stream << ".sphere=(pos=" << float3(bounds.bounding_sphere)
254 << ", rad=" << bounds.bounding_sphere.w << std::endl;
255 stream << ")" << std::endl;
256 return stream;
257}
258
void BKE_curve_texspace_ensure(Curve *cu)
Definition curve.cc:502
void BKE_mesh_texspace_get(Mesh *mesh, float r_texspace_location[3], float r_texspace_size[3])
General operations, lookup, etc. for blender objects.
std::optional< blender::Bounds< blender::float3 > > BKE_object_boundbox_get(const Object *ob)
Volume data-block.
std::optional< blender::Bounds< blender::float3 > > BKE_volume_min_max(const Volume *volume)
#define BLI_assert(a)
Definition BLI_assert.h:46
#define NAN_FLT
#define SET_FLAG_FROM_TEST(value, test, flag)
@ ID_VO
@ ID_CU_LEGACY
@ ID_ME
@ ID_MB
@ BASE_FROM_DUPLI
@ BASE_FROM_SET
@ BASE_HOLDOUT
Object is a sort of wrapper for general info.
@ OB_HOLDOUT
@ OB_NEG_SCALE
#define BASE_SELECTED(v3d, base)
T & DRW_object_get_data_for_drawing(const Object &object)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
Definition btDbvt.cpp:299
LightLinking * light_linking() const
reduce_max(value.rgb)") DEFINE_VALUE("REDUCE(lhs
std::ostream & operator<<(std::ostream &stream, const ObjectMatrices &matrices)
@ OBJECT_NO_INFO
@ OBJECT_SELECTED
@ OBJECT_FROM_DUPLI
@ OBJECT_ACTIVE
@ OBJECT_ACTIVE_EDIT_MODE
@ OBJECT_FROM_SET
@ OBJECT_HOLDOUT
@ OBJECT_NEGATIVE_SCALE
#define GS(x)
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)
VecBase< T, 3 > to_scale(const MatBase< T, NumCol, NumRow > &mat)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< float, 3 > float3
float texspace_size[3]
float texspace_location[3]
Definition DNA_ID.h:414
char name[258]
Definition DNA_ID.h:432
LightLinkingRuntime runtime
float texspace_size[3]
float texspace_location[3]
float4 bounding_corners[4]
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)
short transflag
short base_flag
short visibility_flag
float shadow_terminator_geometry_offset
float color[4]
float shadow_terminator_normal_offset