Blender V5.3
BKE_ccg.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 by Nicholas Bishop. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#include "BLI_assert.hh"
13
14struct CCGSubSurf;
15
16/* Each CCGElem is CCGSubSurf's representation of a subdivided
17 * vertex. All CCGElems in a particular CCGSubSurf have the same
18 * layout, but the layout can vary from one CCGSubSurf to another. For
19 * this reason, CCGElem is presented as an opaque pointer, and
20 * elements should always be accompanied by a CCGKey, which provides
21 * the necessary offsets to access components of a CCGElem.
22 */
23struct CCGElem;
24
25namespace blender {
26
27struct CCGKey {
28 int level;
29
30 /* number of bytes in each element (one float per layer, plus
31 * three floats for normals if enabled) */
33
34 /* number of elements along each side of grid */
36 /* number of elements in the grid (grid size squared) */
38 /* number of bytes in each grid (grid_area * elem_size) */
40
41 /* currently always the last three floats, unless normals are
42 * disabled */
44
45 /* offset in bytes of mask value; only valid if 'has_mask' is
46 * true */
48
51};
52
53inline float3 &CCG_elem_co(const CCGKey & /*key*/, CCGElem *elem)
54{
55 return *reinterpret_cast<float3 *>(elem);
56}
57
58inline float3 &CCG_elem_no(const CCGKey &key, CCGElem *elem)
59{
61 return *reinterpret_cast<float3 *>(reinterpret_cast<char *>(elem) + key.normal_offset);
62}
63
64inline float &CCG_elem_mask(const CCGKey &key, CCGElem *elem)
65{
67 return *reinterpret_cast<float *>(reinterpret_cast<char *>(elem) + (key.mask_offset));
68}
69
70inline CCGElem *CCG_elem_offset(const CCGKey &key, CCGElem *elem, int offset)
71{
72 return reinterpret_cast<CCGElem *>((reinterpret_cast<char *>(elem)) + key.elem_size * offset);
73}
74
75inline int CCG_grid_xy_to_index(const int grid_size, const int x, const int y)
76{
77 return y * grid_size + x;
78}
79
80inline CCGElem *CCG_grid_elem(const CCGKey &key, CCGElem *elem, int x, int y)
81{
82 // BLI_assert(x < key.grid_size && y < key.grid_size);
83 return CCG_elem_offset(key, elem, CCG_grid_xy_to_index(key.grid_size, x, y));
84}
85
86inline float3 &CCG_grid_elem_co(const CCGKey &key, CCGElem *elem, int x, int y)
87{
88 return CCG_elem_co(key, CCG_grid_elem(key, elem, x, y));
89}
90
91inline float3 &CCG_grid_elem_no(const CCGKey &key, CCGElem *elem, int x, int y)
92{
93 return CCG_elem_no(key, CCG_grid_elem(key, elem, x, y));
94}
95
96inline float &CCG_grid_elem_mask(const CCGKey &key, CCGElem *elem, int x, int y)
97{
98 return CCG_elem_mask(key, CCG_grid_elem(key, elem, x, y));
99}
100
101inline float3 &CCG_elem_offset_co(const CCGKey &key, CCGElem *elem, int offset)
102{
103 return CCG_elem_co(key, CCG_elem_offset(key, elem, offset));
104}
105
106inline int CCG_grid_size(const int level)
107{
108 BLI_assert(level > 0);
109 return (1 << (level - 1)) + 1;
110}
111
112inline int CCG_grid_factor(int low_level, int high_level)
113{
114 BLI_assert(low_level > 0 && high_level > 0);
115 BLI_assert(low_level <= high_level);
116 return 1 << (high_level - low_level);
117}
118
119} // namespace blender
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
float & CCG_grid_elem_mask(const CCGKey &key, CCGElem *elem, int x, int y)
Definition BKE_ccg.hh:96
float3 & CCG_grid_elem_co(const CCGKey &key, CCGElem *elem, int x, int y)
Definition BKE_ccg.hh:86
float3 & CCG_elem_no(const CCGKey &key, CCGElem *elem)
Definition BKE_ccg.hh:58
float3 & CCG_grid_elem_no(const CCGKey &key, CCGElem *elem, int x, int y)
Definition BKE_ccg.hh:91
int CCG_grid_factor(int low_level, int high_level)
Definition BKE_ccg.hh:112
float3 & CCG_elem_co(const CCGKey &, CCGElem *elem)
Definition BKE_ccg.hh:53
CCGElem * CCG_elem_offset(const CCGKey &key, CCGElem *elem, int offset)
Definition BKE_ccg.hh:70
int CCG_grid_xy_to_index(const int grid_size, const int x, const int y)
Definition BKE_ccg.hh:75
int CCG_grid_size(const int level)
Definition BKE_ccg.hh:106
CCGElem * CCG_grid_elem(const CCGKey &key, CCGElem *elem, int x, int y)
Definition BKE_ccg.hh:80
float & CCG_elem_mask(const CCGKey &key, CCGElem *elem)
Definition BKE_ccg.hh:64
float3 & CCG_elem_offset_co(const CCGKey &key, CCGElem *elem, int offset)
Definition BKE_ccg.hh:101
VecBase< float, 3 > float3