19template<
typename GPUType>
29template<
typename GPUType>
35 for (const int face : range) {
36 normals.slice(faces[face]).fill(gpu::convert_normal<GPUType>(face_normals[face]));
41template<
typename GPUType>
44 const auto get_vert_normals = [&]() {
66 for (const int face : range) {
67 if (sharp_faces[face]) {
68 normals.slice(faces[face]).fill(gpu::convert_normal<GPUType>(face_normals[face]));
71 for (const int corner : faces[face]) {
72 normals[corner] = gpu::convert_normal<GPUType>(vert_normals[corner_verts[corner]]);
80template<
typename GPUType>
96 if (!selection.is_empty()) {
97 if (use_face_select) {
98 for (const int face : range) {
99 if (selection[face]) {
100 for (const int corner : faces[face]) {
101 normals[corner].w = 1;
107 const Span<int> corner_verts = mr.corner_verts;
108 for (const int face : range) {
109 for (const int corner : faces[face]) {
110 if (selection[corner_verts[corner]]) {
111 normals[corner].w = 1;
118 const Span<bool> hide_poly = mr.hide_poly;
119 for (const int face : range) {
120 if (hide_poly[face]) {
121 for (const int corner : faces[face]) {
122 normals[corner].w = -1;
127 if (mr.edit_bmesh && mr.orig_index_vert) {
128 const Span<int> corner_verts = mr.corner_verts;
129 const Span<int> orig_indices(mr.orig_index_vert, mr.verts_num);
130 for (const int face : range) {
131 for (const int corner : faces[face]) {
132 if (orig_indices[corner_verts[corner]] == ORIGINDEX_NONE) {
133 normals[corner].w = -1;
141template<
typename GPUType>
147 for (const int face_index : range) {
148 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
149 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
150 const IndexRange face_range(BM_elem_index_get(loop), face.len);
151 for (const int corner : face_range) {
152 normals[corner] = gpu::convert_normal<GPUType>(
153 BM_ELEM_CD_GET_FLOAT_P(loop->v, mr.bm_free_normal_offset_vert));
159 else if (!mr.bm_vert_normals.is_empty()) {
163 for (const int face_index : range) {
164 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
165 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
166 const IndexRange face_range(BM_elem_index_get(loop), face.len);
167 for (const int corner : face_range) {
168 normals[corner] = vert_normals_converted[BM_elem_index_get(loop->v)];
176 for (const int face_index : range) {
177 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
178 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
179 const IndexRange face_range(BM_elem_index_get(loop), face.len);
180 for (const int corner : face_range) {
181 normals[corner] = gpu::convert_normal<GPUType>(loop->v->no);
189template<
typename GPUType>
195 for (const int face_index : range) {
196 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
197 const IndexRange face_range(BM_elem_index_get(BM_FACE_FIRST_LOOP(&face)), face.len);
198 normals.slice(face_range)
199 .fill(gpu::convert_normal<GPUType>(
200 BM_ELEM_CD_GET_FLOAT_P(&face, mr.bm_free_normal_offset_face)));
204 else if (!mr.bm_face_normals.is_empty()) {
206 for (const int face_index : range) {
207 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
208 const IndexRange face_range(BM_elem_index_get(BM_FACE_FIRST_LOOP(&face)), face.len);
209 normals.slice(face_range)
210 .fill(gpu::convert_normal<GPUType>(mr.bm_face_normals[face_index]));
216 for (const int face_index : range) {
217 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
218 const IndexRange face_range(BM_elem_index_get(BM_FACE_FIRST_LOOP(&face)), face.len);
219 normals.slice(face_range).fill(gpu::convert_normal<GPUType>(face.no));
225template<
typename GPUType>
231 for (const int face_index : range) {
232 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
233 if (BM_elem_flag_test(&face, BM_ELEM_HIDDEN)) {
234 const IndexRange face_range(BM_elem_index_get(BM_FACE_FIRST_LOOP(&face)), face.len);
235 for (GPUType &value : normals.slice(face_range)) {
243template<
typename GPUType>
255 for (const int face_index : range) {
256 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
257 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
258 const IndexRange face_range(BM_elem_index_get(loop), face.len);
259 for (const int corner : face_range) {
260 normals[corner] = gpu::convert_normal<GPUType>(
261 BM_ELEM_CD_GET_FLOAT_P(loop, mr.bm_free_normal_offset_corner));
267 else if (!mr.bm_loop_normals.is_empty()) {
272 for (const int face_index : range) {
273 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
274 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
275 const IndexRange face_range(BM_elem_index_get(loop), face.len);
277 if (!BM_elem_flag_test(&face, BM_ELEM_SMOOTH)) {
278 if (!mr.bm_face_normals.is_empty()) {
279 normals.slice(face_range)
280 .fill(gpu::convert_normal<GPUType>(mr.bm_face_normals[face_index]));
283 normals.slice(face_range).fill(gpu::convert_normal<GPUType>(face.no));
287 if (!mr.bm_vert_normals.is_empty()) {
288 for (const int corner : face_range) {
289 normals[corner] = gpu::convert_normal<GPUType>(
290 mr.bm_vert_normals[BM_elem_index_get(loop->v)]);
295 for (const int corner : face_range) {
296 normals[corner] = gpu::convert_normal<GPUType>(loop->v->no);
387 const float4 default_normal(0.0f, 0.0f, 0.0f, 0.0f);
blender::gpu::VertBuf * GPU_vertbuf_create_on_device(const GPUVertFormat &format, uint v_len)
#define GPU_vertbuf_create_with_format(format)
void GPU_vertbuf_use(blender::gpu::VertBuf *)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
void GPU_vertbuf_update_sub(blender::gpu::VertBuf *verts, uint start, uint len, const void *data)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
constexpr bool is_empty() const
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
static constexpr IndexRange from_begin_end(const int64_t begin, const int64_t end)
constexpr MutableSpan take_back(const int64_t n) const
constexpr T * data() const
constexpr void fill(const T &value) const
constexpr MutableSpan take_front(const int64_t n) const
constexpr int64_t size() const
constexpr bool is_empty() const
static float normals[][3]
VecBase< short, 4 > short4
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, int64_t grain_size=4096)
static void extract_face_normals_bm(const MeshRenderData &mr, MutableSpan< GPUType > normals)
gpu::VertBufPtr extract_vert_normals(const MeshRenderData &mr)
gpu::VertBufPtr extract_normals_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache, gpu::VertBuf &pos_nor)
static const GPUVertFormat & get_subdiv_lnor_format()
static void extract_vert_normals_bm(const MeshRenderData &mr, MutableSpan< GPUType > normals)
void draw_subdiv_build_lnor_buffer(const DRWSubdivCache &cache, gpu::VertBuf *pos_nor, gpu::VertBuf *lnor)
gpu::VertBufPtr extract_normals(const MeshRenderData &mr, bool use_hq)
int subdiv_full_vbo_size(const MeshRenderData &mr, const DRWSubdivCache &cache)
static void extract_paint_overlay_flags(const MeshRenderData &mr, MutableSpan< GPUType > normals)
static void extract_normals_mesh(const MeshRenderData &mr, MutableSpan< GPUType > normals)
static void extract_normals_bm(const MeshRenderData &mr, MutableSpan< GPUType > normals)
static void extract_face_normals(const MeshRenderData &mr, MutableSpan< GPUType > normals)
static void extract_edit_flags_bm(const MeshRenderData &mr, MutableSpan< GPUType > normals)
void convert_normals(Span< float3 > src, MutableSpan< GPUType > dst)
std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > VertBufPtr
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
blender::VecBase< int16_t, 4 > short4
VecBase< float, 4 > float4
const int * orig_index_vert
bool use_simplify_normals
MeshExtractType extract_type
VArraySpan< bool > select_vert
VArraySpan< bool > sharp_faces
int bm_free_normal_offset_face
VArraySpan< bool > select_poly
Span< float3 > face_normals
int bm_free_normal_offset_corner
Span< float3 > corner_normals
VArraySpan< bool > hide_poly
OffsetIndices< int > faces
bke::MeshNormalDomain normals_domain
int bm_free_normal_offset_vert