Blender V5.3
subdiv_mesh.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2018 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_key_types.h"
10#include "DNA_mesh_types.h"
11#include "DNA_meshdata_types.h"
12#include "DNA_object_types.h"
13
14#include "BLI_array.hh"
15#include "BLI_array_utils.hh"
17#include "BLI_math_vector.hh"
18#include "BLI_math_vector_c.hh"
20
21#include "BKE_attribute.hh"
22#include "BKE_attribute_math.hh"
23#include "BKE_customdata.hh"
24#include "BKE_deform.hh"
25#include "BKE_key.hh"
26#include "BKE_mesh.hh"
27#include "BKE_mesh_mapping.hh"
28#include "BKE_subdiv.hh"
29#include "BKE_subdiv_deform.hh"
30#include "BKE_subdiv_eval.hh"
31#include "BKE_subdiv_foreach.hh"
32#include "BKE_subdiv_mesh.hh"
33
34#include "MEM_guardedalloc.h"
35
36namespace blender::bke::subdiv {
37
38/* -------------------------------------------------------------------- */
41
49
56
57 /* Generic attributes on each domain. */
62
63 /* Spans referencing the attribute arrays above, to avoid leaking #GVArraySpan elsewhere. */
68
69 /* Attribute writers for generic attributes on the result. */
74
75 /* Spans referencing the writers above, for simpler usage. */
80
81 /* Original index layers on base and result meshes. */
88
89 /* UV maps on the result mesh. Base mesh data was prepared in #eval_begin_from_mesh. */
91
92 /* CD_ORCO/CD_CLOTH_ORCO interpolation. Base mesh data was prepared in #eval_begin_from_mesh. */
93 float (*orco)[3];
95
96 /* Base and result mesh vertex group data. */
99
100 /* Base and result mesh data for interpolating custom normals. */
103
104 /* Base and result mesh data for interpolating particle system data. */
107
108 /* Per-subdivided vertex counter of averaged values. */
111
112 /* Write optimal display edge tags into a boolean array rather than the final bit vector
113 * to avoid race conditions when setting bits. */
115
116 /* Write face dot tags into a boolean array rather than the final bit vector to avoid race
117 * conditions when setting bits. */
119
120 /* Lazily initialize a map from vertices to connected edges. */
124};
125
127{
128 const Mesh &coarse_mesh = *ctx->coarse_mesh;
129 Mesh *subdiv_mesh = ctx->subdiv_mesh;
130 bke::MutableAttributeAccessor attributes = subdiv_mesh->attributes_for_write();
131 for (const StringRef name : coarse_mesh.uv_map_names()) {
133 name, AttrDomain::Corner);
134 if (!uv_map) {
135 /* Attribute lookup can fail because of name collisions with vertex groups. */
136 continue;
137 }
138 ctx->uv_maps.append(std::move(uv_map));
139 }
140}
141
143{
144 const Mesh &coarse_mesh = *ctx->coarse_mesh;
145 Mesh *subdiv_mesh = ctx->subdiv_mesh;
146 ctx->subdiv_positions = subdiv_mesh->vert_positions_for_write();
147 ctx->subdiv_edges = subdiv_mesh->edges_for_write();
148 ctx->subdiv_corner_verts = subdiv_mesh->corner_verts_for_write();
149 ctx->subdiv_corner_edges = subdiv_mesh->corner_edges_for_write();
150
151 ctx->coarse_dverts = coarse_mesh.deform_verts();
152 if (!ctx->coarse_dverts.is_empty()) {
153 ctx->subdiv_dverts = subdiv_mesh->deform_verts_for_write();
154 }
155 if (const auto *src = static_cast<const float3 *>(
157 {
158 ctx->coarse_CD_NORMAL = {src, coarse_mesh.corners_num};
159 ctx->subdiv_CD_NORMAL = {
160 static_cast<float3 *>(CustomData_add_layer(
161 &subdiv_mesh->corner_data, CD_NORMAL, CD_CONSTRUCT, subdiv_mesh->corners_num)),
162 subdiv_mesh->corners_num};
163 }
164 if (const auto *src = static_cast<const float2 *>(
166 {
167 ctx->coarse_CD_ORIGSPACE_MLOOP = {src, coarse_mesh.corners_num};
169 static_cast<float2 *>(CustomData_add_layer(&subdiv_mesh->corner_data,
172 subdiv_mesh->corners_num)),
173 subdiv_mesh->corners_num};
174 }
175 if (const auto *src = static_cast<const int *>(
177 {
178 ctx->coarse_vert_origindex = {src, coarse_mesh.verts_num};
179 ctx->subdiv_vert_origindex = {
180 static_cast<int *>(CustomData_add_layer(
181 &subdiv_mesh->vert_data, CD_ORIGINDEX, CD_CONSTRUCT, subdiv_mesh->verts_num)),
182 subdiv_mesh->verts_num};
183 }
184 if (const auto *src = static_cast<const int *>(
186 {
187 ctx->coarse_edge_origindex = {src, coarse_mesh.edges_num};
188 ctx->subdiv_edge_origindex = {
189 static_cast<int *>(CustomData_add_layer(
190 &subdiv_mesh->edge_data, CD_ORIGINDEX, CD_CONSTRUCT, subdiv_mesh->edges_num)),
191 subdiv_mesh->edges_num};
192 }
193 if (const auto *src = static_cast<const int *>(
195 {
196 ctx->coarse_face_origindex = {src, coarse_mesh.faces_num};
197 ctx->subdiv_face_origindex = {
198 static_cast<int *>(CustomData_add_layer(
199 &subdiv_mesh->face_data, CD_ORIGINDEX, CD_CONSTRUCT, subdiv_mesh->faces_num)),
200 subdiv_mesh->faces_num};
201 }
202 /* UV layers interpolation. */
204 /* Orco interpolation. */
205 if (CustomData_has_layer(&coarse_mesh.vert_data, CD_ORCO)) {
206 ctx->orco = static_cast<float (*)[3]>(CustomData_add_layer(
207 &subdiv_mesh->vert_data, CD_ORCO, CD_CONSTRUCT, subdiv_mesh->verts_num));
208 }
209 if (CustomData_has_layer(&coarse_mesh.vert_data, CD_CLOTH_ORCO)) {
210 ctx->cloth_orco = static_cast<float (*)[3]>(CustomData_add_layer(
211 &subdiv_mesh->vert_data, CD_CLOTH_ORCO, CD_CONSTRUCT, subdiv_mesh->verts_num));
212 }
213}
214
215static void subdiv_mesh_prepare_accumulator(SubdivMeshContext *ctx, int num_vertices)
216{
217 if (!ctx->have_displacement) {
218 return;
219 }
220 /* #subdiv_accumulate_vert_displacement requires zero initialization of positions so the
221 * displacements can be accumulated into the array from a per-vertex-per-corner/edge callback. */
222 ctx->subdiv_positions.fill(float3(0));
223 ctx->accumulated_counters = MEM_new_array_zeroed<int>(num_vertices, __func__);
224}
225
227{
228 MEM_SAFE_DELETE(ctx->accumulated_counters);
229}
230
232
233/* -------------------------------------------------------------------- */
236
238 /* First loop of the ptex, starts at ptex (0, 0) and goes in u direction. */
240 /* Last loop of the ptex, starts at ptex (0, 0) and goes in v direction. */
242 /* For quad coarse faces only. */
245};
246
247static void loops_of_ptex_get(LoopsOfPtex *loops_of_ptex,
248 const IndexRange coarse_face,
249 const int ptex_of_face_index)
250{
251 const int first_ptex_loop_index = coarse_face.start() + ptex_of_face_index;
252 /* Loop which look in the (opposite) V direction of the current
253 * ptex face.
254 *
255 * TODO(sergey): Get rid of using module on every iteration. */
256 const int last_ptex_loop_index = coarse_face.start() +
257 (ptex_of_face_index + coarse_face.size() - 1) %
258 coarse_face.size();
259 loops_of_ptex->first_loop = first_ptex_loop_index;
260 loops_of_ptex->last_loop = last_ptex_loop_index;
261 if (coarse_face.size() == 4) {
262 loops_of_ptex->second_loop = loops_of_ptex->first_loop + 1;
263 loops_of_ptex->third_loop = loops_of_ptex->first_loop + 2;
264 }
265 else {
266 loops_of_ptex->second_loop = -1;
267 loops_of_ptex->third_loop = -1;
268 }
269}
270
272
273/* -------------------------------------------------------------------- */
276
278 const Span<int> src_indices,
279 const Span<float> weights)
280{
281 float3 result(0);
282 for (const int i : src_indices.index_range()) {
283 result += src[src_indices[i]] * weights[i];
284 }
285 return math::normalize(result);
286}
287
289 const std::array<int, 4> &src_indices,
290 const float4 &weights)
291{
292 float3 result(0);
293 for (const int i : IndexRange(src_indices.size())) {
294 result += src[src_indices[i]] * weights[i];
295 }
296 return math::normalize(result);
297}
298
300 const std::array<int, 2> &src_indices,
301 const float factor)
302{
303 return math::normalize(math::interpolate(src[src_indices[0]], src[src_indices[1]], factor));
304}
305
306static void mix_attrs(const Span<GSpan> src,
307 const std::array<int, 2> &src_indices,
308 const float factor,
309 const int dst_index,
310 const Span<GMutableSpan> dst)
311{
312 for (const int attr : src.index_range()) {
313 attribute_math::to_static_type(src[attr].type(), [&]<typename T>() {
314 if constexpr (!std::is_same_v<T, std::string>) {
315 const Span<T> src_attr = src[attr].typed<T>();
316 MutableSpan<T> dst_attr = dst[attr].typed<T>();
317 if constexpr (std::is_same_v<T, bool>) {
318 dst_attr[dst_index] = bke::attribute_math::mix_indices(
319 src_attr, src_indices, {1.0f - factor, factor});
320 }
321 else {
322 dst_attr[dst_index] = attribute_math::mix2(
323 factor, src_attr[src_indices[0]], src_attr[src_indices[1]]);
324 }
325 }
326 });
327 }
328}
329
330static void mix_attrs(const Span<GSpan> src,
331 const std::array<int, 4> &src_indices,
332 const float4 &weights,
333 const int dst_index,
334 const Span<GMutableSpan> dst)
335{
336 for (const int attr : src.index_range()) {
337 attribute_math::to_static_type(src[attr].type(), [&]<typename T>() {
338 if constexpr (!std::is_same_v<T, std::string>) {
339 const Span<T> src_attr = src[attr].typed<T>();
340 MutableSpan<T> dst_attr = dst[attr].typed<T>();
341 if constexpr (std::is_same_v<T, bool>) {
342 dst_attr[dst_index] = bke::attribute_math::mix_indices(
343 src_attr, src_indices, Span(&weights.x, 4));
344 }
345 else {
346 dst_attr[dst_index] = attribute_math::mix4(weights,
347 src_attr[src_indices[0]],
348 src_attr[src_indices[1]],
349 src_attr[src_indices[2]],
350 src_attr[src_indices[3]]);
351 }
352 }
353 });
354 }
355}
356
357static void mix_attrs(const Span<GSpan> src,
358 const Span<int> src_indices,
359 const Span<float> weights,
360 const int dst_index,
361 const Span<GMutableSpan> dst)
362{
363 for (const int attr : src.index_range()) {
364 attribute_math::to_static_type(src[attr].type(), [&]<typename T>() {
365 if constexpr (!std::is_same_v<T, std::string>) {
366 const Span<T> src_attr = src[attr].typed<T>();
367 MutableSpan<T> dst_attr = dst[attr].typed<T>();
368 dst_attr[dst_index] = bke::attribute_math::mix_indices(src_attr, src_indices, weights);
369 }
370 });
371 }
372}
373
374static void copy_attrs(const Span<GSpan> src,
375 const int src_index,
376 const int dst_index,
377 const Span<GMutableSpan> dst)
378{
379 for (const int attr : src.index_range()) {
380 const CPPType &type = src[attr].type();
381 type.copy_construct(src[attr][src_index], dst[attr][dst_index]);
382 }
383}
384
385/* TODO(sergey): Somehow de-duplicate with loops storage, without too much
386 * exception cases all over the code. */
387
389 /* This field points to a vertex data which is to be used for interpolation. The idea is to avoid
390 * unnecessary copies for regular faces, where we can simply use base vertices. */
393 /* Vertices data calculated for ptex corners. There are always 4 elements
394 * in these arrays, aligned the following way:
395 *
396 * index 0 -> uv (0, 0)
397 * index 1 -> uv (0, 1)
398 * index 2 -> uv (1, 1)
399 * index 3 -> uv (1, 0)
400 *
401 * Is allocated for non-regular faces (triangles and n-gons). */
405 std::array<MDeformVert, 4> dverts_storage = {};
406 /* Indices within vert_data to interpolate for. The indices are aligned
407 * with uv coordinates in a similar way as indices in storage_spans. */
408 std::array<int, 4> vert_indices;
409
411
413 : storage_spans(ctx.coarse_vert_attr_spans.size())
414 {
415 this->allocator.provide_buffer(this->buffer);
416 for (const int i : ctx.coarse_vert_attr_spans.index_range()) {
417 const CPPType &type = ctx.coarse_vert_attr_spans[i].type();
418 void *data = this->allocator.allocate_array(type, 4);
419 this->storage_spans[i] = {type, data, 4};
420 }
421 }
423 {
424 BKE_defvert_array_free_elems(this->dverts_storage.data(), this->dverts_storage.size());
425 }
426};
427
429 VerticesForInterpolation *vert_interpolation,
430 const IndexRange coarse_face)
431{
432 if (coarse_face.size() == 4) {
433 vert_interpolation->vert_data = ctx->coarse_vert_attr_spans;
434 vert_interpolation->dverts_data = ctx->coarse_dverts;
435 vert_interpolation->vert_indices[0] = ctx->coarse_corner_verts[coarse_face.start() + 0];
436 vert_interpolation->vert_indices[1] = ctx->coarse_corner_verts[coarse_face.start() + 1];
437 vert_interpolation->vert_indices[2] = ctx->coarse_corner_verts[coarse_face.start() + 2];
438 vert_interpolation->vert_indices[3] = ctx->coarse_corner_verts[coarse_face.start() + 3];
439 }
440 else {
441 vert_interpolation->vert_data = vert_interpolation->storage_spans;
442 vert_interpolation->dverts_data = vert_interpolation->dverts_storage;
443 vert_interpolation->vert_indices[0] = 0;
444 vert_interpolation->vert_indices[1] = 1;
445 vert_interpolation->vert_indices[2] = 2;
446 vert_interpolation->vert_indices[3] = 3;
447 /* Interpolate center of face right away, it stays unchanged for all
448 * ptex faces. */
449 const float weight = 1.0f / float(coarse_face.size());
450 Array<float, 32> weights(coarse_face.size());
451 Span<int> indices = ctx->coarse_corner_verts.slice(coarse_face);
452 for (int i = 0; i < coarse_face.size(); i++) {
453 weights[i] = weight;
454 }
456 indices,
457 weights.as_span(),
458 2,
459 vert_interpolation->storage_spans.as_span().cast<GMutableSpan>());
460 if (!ctx->coarse_dverts.is_empty()) {
461 BKE_defvert_array_free_elems(&vert_interpolation->dverts_storage[2], 1);
462 vert_interpolation->dverts_storage[2] = mix_deform_verts(
463 ctx->coarse_dverts, indices, weights, vert_interpolation->dvert_mix_buffer);
464 }
465 }
466}
467
469 VerticesForInterpolation *vert_interpolation,
470 const IndexRange coarse_face,
471 const int corner)
472{
473 if (coarse_face.size() == 4) {
474 /* Nothing to do, all indices and data is already assigned. */
475 }
476 else {
477 LoopsOfPtex loops_of_ptex;
478 loops_of_ptex_get(&loops_of_ptex, coarse_face, corner);
479 /* PTEX face corner corresponds to a face loop with same index. */
480 const int vert = ctx->coarse_corner_verts[coarse_face.start() + corner];
482 vert,
483 0,
484 vert_interpolation->storage_spans.as_span().cast<GMutableSpan>());
485 if (!ctx->coarse_dverts.is_empty()) {
486 BKE_defvert_array_free_elems(vert_interpolation->dverts_storage.data(), 1);
488 vert_interpolation->dverts_storage.data(), &ctx->coarse_dverts[vert], 1);
489 }
490 /* Interpolate remaining ptex face corners, which hits loops
491 * middle points.
492 *
493 * TODO(sergey): Re-use one of interpolation results from previous
494 * iteration. */
495 const int first_loop_index = loops_of_ptex.first_loop;
496 const int last_loop_index = loops_of_ptex.last_loop;
497 const std::array<int, 2> first_indices{
498 ctx->coarse_corner_verts[first_loop_index],
499 ctx->coarse_corner_verts[coarse_face.start() +
500 (first_loop_index - coarse_face.start() + 1) %
501 coarse_face.size()]};
502 const std::array<int, 2> last_indices{ctx->coarse_corner_verts[first_loop_index],
503 ctx->coarse_corner_verts[last_loop_index]};
505 first_indices,
506 0.5f,
507 1,
508 vert_interpolation->storage_spans.as_span().cast<GMutableSpan>());
509 if (!ctx->coarse_dverts.is_empty()) {
510 BKE_defvert_array_free_elems(&vert_interpolation->dverts_storage[1], 1);
511 vert_interpolation->dverts_storage[1] = mix_deform_verts(
512 ctx->coarse_dverts, first_indices, {0.5f, 0.5f}, vert_interpolation->dvert_mix_buffer);
513 }
515 last_indices,
516 0.5f,
517 3,
518 vert_interpolation->storage_spans.as_span().cast<GMutableSpan>());
519 if (!ctx->coarse_dverts.is_empty()) {
520 BKE_defvert_array_free_elems(&vert_interpolation->dverts_storage[3], 1);
521 vert_interpolation->dverts_storage[3] = mix_deform_verts(
522 ctx->coarse_dverts, last_indices, {0.5f, 0.5f}, vert_interpolation->dvert_mix_buffer);
523 }
524 }
525}
526
528
529/* -------------------------------------------------------------------- */
532
534 /* This field points to a loop data which is to be used for interpolation. The idea is to avoid
535 * unnecessary copies for regular faces, where we can simply interpolate base corners. */
539 /* Loops data calculated for ptex corners. There are always 4 elements
540 * in these arrays, aligned the following way:
541 *
542 * index 0 -> uv (0, 0)
543 * index 1 -> uv (0, 1)
544 * index 2 -> uv (1, 1)
545 * index 3 -> uv (1, 0)
546 *
547 * Is allocated for non-regular faces (triangles and n-gons). */
551 std::array<float3, 4> CD_NORMAL_storage;
552 std::array<float2, 4> CD_ORIGSPACE_MLOOP_storage;
553
554 /* Indices within corner_data to interpolate for. The indices are aligned with
555 * uv coordinates in a similar way as indices in storage_spans. */
556 std::array<int, 4> loop_indices;
557
559 : storage_spans(ctx.coarse_corner_attr_spans.size())
560 {
561 this->allocator.provide_buffer(this->buffer);
562 for (const int i : ctx.coarse_corner_attr_spans.index_range()) {
563 const CPPType &type = ctx.coarse_corner_attr_spans[i].type();
564 void *data = this->allocator.allocate_array(type, 4);
565 this->storage_spans[i] = {type, data, 4};
566 }
567 }
568};
569
571 LoopsForInterpolation *loop_interpolation,
572 const IndexRange coarse_face)
573{
574 if (coarse_face.size() == 4) {
575 loop_interpolation->corner_data = ctx->coarse_corner_attr_spans;
576 loop_interpolation->CD_NORMAL_data = ctx->coarse_CD_NORMAL;
577 loop_interpolation->CD_ORIGSPACE_MLOOP_data = ctx->coarse_CD_ORIGSPACE_MLOOP;
578 loop_interpolation->loop_indices[0] = coarse_face.start() + 0;
579 loop_interpolation->loop_indices[1] = coarse_face.start() + 1;
580 loop_interpolation->loop_indices[2] = coarse_face.start() + 2;
581 loop_interpolation->loop_indices[3] = coarse_face.start() + 3;
582 }
583 else {
584 loop_interpolation->corner_data = loop_interpolation->storage_spans;
585 loop_interpolation->CD_NORMAL_data = loop_interpolation->CD_NORMAL_storage;
586 loop_interpolation->CD_ORIGSPACE_MLOOP_data = loop_interpolation->CD_ORIGSPACE_MLOOP_storage;
587 loop_interpolation->loop_indices[0] = 0;
588 loop_interpolation->loop_indices[1] = 1;
589 loop_interpolation->loop_indices[2] = 2;
590 loop_interpolation->loop_indices[3] = 3;
591 /* Interpolate center of face right away, it stays unchanged for all
592 * ptex faces. */
593 const float weight = 1.0f / float(coarse_face.size());
594 Array<float, 32> weights(coarse_face.size());
595 Array<int, 32> indices(coarse_face.size());
596 for (int i = 0; i < coarse_face.size(); i++) {
597 weights[i] = weight;
598 indices[i] = coarse_face.start() + i;
599 }
601 indices,
602 weights.as_span(),
603 2,
604 loop_interpolation->storage_spans.as_span().cast<GMutableSpan>());
605 if (!ctx->coarse_CD_NORMAL.is_empty()) {
606 loop_interpolation->CD_NORMAL_storage[2] = mix_normals(
607 ctx->coarse_CD_NORMAL, indices, weights.as_span());
608 }
609 if (!ctx->coarse_CD_ORIGSPACE_MLOOP.is_empty()) {
611 ctx->coarse_CD_ORIGSPACE_MLOOP, indices, weights.as_span());
612 }
613 }
614}
615
617 LoopsForInterpolation *loop_interpolation,
618 const IndexRange coarse_face,
619 const int corner)
620{
621 if (coarse_face.size() == 4) {
622 /* Nothing to do, all indices and data is already assigned. */
623 }
624 else {
625 LoopsOfPtex loops_of_ptex;
626 loops_of_ptex_get(&loops_of_ptex, coarse_face, corner);
627 /* PTEX face corner corresponds to a face loop with same index. */
629 coarse_face.start() + corner,
630 0,
631 loop_interpolation->storage_spans.as_span().cast<GMutableSpan>());
632 if (!ctx->coarse_CD_NORMAL.is_empty()) {
633 loop_interpolation->CD_NORMAL_storage[0] =
634 ctx->coarse_CD_NORMAL[coarse_face.start() + corner];
635 }
636 if (!ctx->coarse_CD_ORIGSPACE_MLOOP.is_empty()) {
637 loop_interpolation->CD_ORIGSPACE_MLOOP_storage[0] =
638 ctx->coarse_CD_ORIGSPACE_MLOOP[coarse_face.start() + corner];
639 }
640 /* Interpolate remaining ptex face corners, which hits loops
641 * middle points.
642 *
643 * TODO(sergey): Re-use one of interpolation results from previous
644 * iteration. */
645 const int base_loop_index = coarse_face.start();
646 const int first_loop_index = loops_of_ptex.first_loop;
647 const int second_loop_index = base_loop_index +
648 (first_loop_index - base_loop_index + 1) % coarse_face.size();
649 const std::array<int, 2> first_indices{first_loop_index, second_loop_index};
650 const std::array<int, 2> last_indices{loops_of_ptex.last_loop, loops_of_ptex.first_loop};
652 first_indices,
653 0.5f,
654 1,
655 loop_interpolation->storage_spans.as_span().cast<GMutableSpan>());
656 if (!ctx->coarse_CD_NORMAL.is_empty()) {
657 loop_interpolation->CD_NORMAL_storage[1] = mix_normals(
658 ctx->coarse_CD_NORMAL, first_indices, 0.5f);
659 }
660 if (!ctx->coarse_CD_ORIGSPACE_MLOOP.is_empty()) {
661 loop_interpolation->CD_ORIGSPACE_MLOOP_storage[1] = attribute_math::mix2(
662 0.5f,
663 ctx->coarse_CD_ORIGSPACE_MLOOP[first_indices[0]],
664 ctx->coarse_CD_ORIGSPACE_MLOOP[first_indices[1]]);
665 }
667 last_indices,
668 0.5f,
669 3,
670 loop_interpolation->storage_spans.as_span().cast<GMutableSpan>());
671 if (!ctx->coarse_CD_NORMAL.is_empty()) {
672 loop_interpolation->CD_NORMAL_storage[3] = mix_normals(
673 ctx->coarse_CD_NORMAL, last_indices, 0.5f);
674 }
675 if (!ctx->coarse_CD_ORIGSPACE_MLOOP.is_empty()) {
676 loop_interpolation->CD_ORIGSPACE_MLOOP_storage[3] = attribute_math::mix2(
677 0.5f,
678 ctx->coarse_CD_ORIGSPACE_MLOOP[last_indices[0]],
679 ctx->coarse_CD_ORIGSPACE_MLOOP[last_indices[1]]);
680 }
681 }
682}
683
685
686/* -------------------------------------------------------------------- */
689
699
700static void subdiv_mesh_tls_free(void *tls_v)
701{
702 SubdivMeshTLS *tls = static_cast<SubdivMeshTLS *>(tls_v);
703 delete tls->vert_interpolation;
704 delete tls->loop_interpolation;
705 tls->vert_interpolation = nullptr;
706 tls->loop_interpolation = nullptr;
707}
708
710
711/* -------------------------------------------------------------------- */
714
716 const int ptex_face_index,
717 const float u,
718 const float v,
719 const int subdiv_vert_index)
720{
721 if (ctx->orco || ctx->cloth_orco) {
722 float vert_data[6];
723 eval_vert_data(ctx->subdiv, ptex_face_index, u, v, vert_data);
724
725 if (ctx->orco) {
726 copy_v3_v3(ctx->orco[subdiv_vert_index], vert_data);
727 if (ctx->cloth_orco) {
728 copy_v3_v3(ctx->cloth_orco[subdiv_vert_index], vert_data + 3);
729 }
730 }
731 else if (ctx->cloth_orco) {
732 copy_v3_v3(ctx->cloth_orco[subdiv_vert_index], vert_data);
733 }
734 }
735}
736
738
739/* -------------------------------------------------------------------- */
742
744 const int ptex_face_index,
745 const float u,
746 const float v,
747 const int subdiv_vert_index)
748{
749 /* Accumulate displacement. */
750 Subdiv *subdiv = ctx->subdiv;
751 float3 dummy_P;
752 float3 dPdu;
753 float3 dPdv;
754 float3 D;
755 eval_limit_point_and_derivatives(subdiv, ptex_face_index, u, v, dummy_P, dPdu, dPdv);
756
757 eval_displacement(subdiv, ptex_face_index, u, v, dPdu, dPdv, D);
758 ctx->subdiv_positions[subdiv_vert_index] += D;
759
760 if (ctx->accumulated_counters) {
761 ++ctx->accumulated_counters[subdiv_vert_index];
762 }
763}
764
766
767/* -------------------------------------------------------------------- */
770
772 const bke::AttrDomain domain,
773 const Set<StringRef> &skip_names,
774 MutableAttributeAccessor dst_attrs,
775 Vector<GVArraySpan> &coarse_varray_spans,
776 Vector<GSpan> &coarse_spans,
777 Vector<GSpanAttributeWriter> &dst_writers,
778 Vector<GMutableSpan> &dst_spans)
779
780{
781 src_attrs.foreach_attribute([&](const AttributeIter &iter) {
782 if (iter.domain != domain) {
783 return;
784 }
785 if (iter.data_type == bke::AttrType::String) {
786 return;
787 }
788 if (skip_names.contains(iter.name)) {
789 return;
790 }
791 GVArray src = *iter.get();
792 {
793 const CommonVArrayInfo info = src.common_info();
795 const GPointer value(src.type(), info.data);
796 if (dst_attrs.add(iter.name, domain, iter.data_type, bke::AttributeInitValue(value))) {
797 return;
798 }
799 }
800 }
802 iter.name, domain, iter.data_type);
803 if (!dst) {
804 /* Attribute creation can fail with a vertex group name conflict. */
805 return;
806 }
807 coarse_varray_spans.append(std::move(src));
808 coarse_spans.append(coarse_varray_spans.last());
809 dst_writers.append(std::move(dst));
810 dst_spans.append(dst_writers.last().span);
811 });
812}
813
814static bool subdiv_mesh_topology_info(const ForeachContext *foreach_context,
815 const int num_vertices,
816 const int num_edges,
817 const int num_loops,
818 const int num_faces,
819 const Span<int> /*subdiv_face_offset*/)
820{
821 /* Multi-resolution grid data will be applied or become invalid after subdivision,
822 * so don't try to preserve it and use memory. Crease values should also not be interpolated. */
825
826 SubdivMeshContext *subdiv_context = static_cast<SubdivMeshContext *>(foreach_context->user_data);
827
828 const Mesh &coarse_mesh = *subdiv_context->coarse_mesh;
829 subdiv_context->subdiv_mesh = BKE_mesh_new_nomain(num_vertices, num_edges, num_faces, num_loops);
830 Mesh &subdiv_mesh = *subdiv_context->subdiv_mesh;
831 BKE_mesh_copy_parameters_for_eval(subdiv_context->subdiv_mesh, &coarse_mesh);
832
833 if (num_faces != 0) {
834 offset_indices::fill_constant_group_size(4, 0, subdiv_mesh.face_offsets_for_write());
835 }
836
837 /* Create corner data for interpolation without topology attributes. */
838 const AttributeAccessor coarse_attrs = coarse_mesh.attributes();
839 MutableAttributeAccessor attributes = subdiv_mesh.attributes_for_write();
840
841 Set<StringRef> vert_skip_names{{"position"}};
842 for (const bDeformGroup &group : coarse_mesh.vertex_group_names) {
843 vert_skip_names.add(group.name);
844 }
847 vert_skip_names,
848 attributes,
849 subdiv_context->coarse_vert_attrs,
850 subdiv_context->coarse_vert_attr_spans,
851 subdiv_context->subdiv_vert_attrs,
852 subdiv_context->subdiv_vert_attr_spans);
853
856 {".edge_verts"},
857 attributes,
858 subdiv_context->coarse_edge_attrs,
859 subdiv_context->coarse_edge_attr_spans,
860 subdiv_context->subdiv_edge_attrs,
861 subdiv_context->subdiv_edge_attr_spans);
862
865 {},
866 attributes,
867 subdiv_context->coarse_face_attrs,
868 subdiv_context->coarse_face_attr_spans,
869 subdiv_context->subdiv_face_attrs,
870 subdiv_context->subdiv_face_attr_spans);
871
872 /* Rely on #CD_NORMAL to propagate normals to subdivision surfaces.
873 * These are converted into "custom_normals" afterwards, otherwise these normals
874 * would interpolated without being normalized, see: #152277. */
875 Set<StringRef> corner_skip_names{".corner_vert", ".corner_edge", "custom_normal"};
876 /* UV map names are interpolated separately. */
877 for (const StringRef name : coarse_mesh.uv_map_names()) {
878 corner_skip_names.add_new(name);
879 }
882 corner_skip_names,
883 attributes,
884 subdiv_context->coarse_corner_attrs,
885 subdiv_context->coarse_corner_attr_spans,
886 subdiv_context->subdiv_corner_attrs,
887 subdiv_context->subdiv_corner_attr_spans);
888
890 subdiv_mesh_prepare_accumulator(subdiv_context, num_vertices);
891 subdiv_context->subdiv_face_dot_tags = Array<bool>(num_vertices, false);
892 if (subdiv_context->settings->use_optimal_display) {
893 subdiv_context->subdiv_display_edges = Array<bool>(num_edges, false);
894 }
895 return true;
896}
897
899
900/* -------------------------------------------------------------------- */
903
905 const int coarse_vert_index,
906 const int subdiv_vert_index)
907{
909 coarse_vert_index,
910 subdiv_vert_index,
912 if (!ctx->coarse_vert_origindex.is_empty()) {
913 ctx->subdiv_vert_origindex[subdiv_vert_index] = ctx->coarse_vert_origindex[coarse_vert_index];
914 }
915 if (!ctx->coarse_dverts.is_empty()) {
917 &ctx->subdiv_dverts[subdiv_vert_index], &ctx->coarse_dverts[coarse_vert_index], 1);
918 }
919}
920
922 const int subdiv_vert_index,
923 VerticesForInterpolation *vert_interpolation,
924 const float u,
925 const float v)
926{
927 const float4 weights = quad_weights_from_uv(u, v);
928 mix_attrs(vert_interpolation->vert_data,
929 vert_interpolation->vert_indices,
930 weights,
931 subdiv_vert_index,
933 if (!ctx->coarse_vert_origindex.is_empty()) {
934 ctx->subdiv_vert_origindex[subdiv_vert_index] = ORIGINDEX_NONE;
935 }
936 if (!ctx->coarse_dverts.is_empty()) {
937 ctx->subdiv_dverts[subdiv_vert_index] = mix_deform_verts(vert_interpolation->dverts_data,
938 vert_interpolation->vert_indices,
939 Span(&weights.x, 4),
940 vert_interpolation->dvert_mix_buffer);
941 }
942}
943
945 const int ptex_face_index,
946 const float u,
947 const float v,
948 const int coarse_vert_index,
949 const int subdiv_vert_index)
950{
951 float3 &subdiv_position = ctx->subdiv_positions[subdiv_vert_index];
952 /* Displacement is accumulated in subdiv vertex position.
953 * Needs to be backed up before copying data from original vertex. */
954 float D[3] = {0.0f, 0.0f, 0.0f};
955 if (ctx->have_displacement) {
956 const float inv_num_accumulated = 1.0f / ctx->accumulated_counters[subdiv_vert_index];
957 copy_v3_v3(D, subdiv_position);
958 mul_v3_fl(D, inv_num_accumulated);
959 }
960 /* Copy custom data and evaluate position. */
961 subdiv_vert_data_copy(ctx, coarse_vert_index, subdiv_vert_index);
962 subdiv_position = eval_limit_point(ctx->subdiv, ptex_face_index, u, v);
963 /* Apply displacement. */
964 subdiv_position += D;
965 /* Evaluate undeformed texture coordinate. */
966 subdiv_vert_orco_evaluate(ctx, ptex_face_index, u, v, subdiv_vert_index);
967}
968
970 const SubdivMeshContext *ctx,
971 const int ptex_face_index,
972 const float u,
973 const float v,
974 VerticesForInterpolation *vert_interpolation,
975 const int subdiv_vert_index)
976{
977 float3 &subdiv_position = ctx->subdiv_positions[subdiv_vert_index];
978 /* Displacement is accumulated in subdiv vertex position.
979 * Needs to be backed up before copying data from original vertex. */
980 float D[3] = {0.0f, 0.0f, 0.0f};
981 if (ctx->have_displacement) {
982 const float inv_num_accumulated = 1.0f / ctx->accumulated_counters[subdiv_vert_index];
983 copy_v3_v3(D, subdiv_position);
984 mul_v3_fl(D, inv_num_accumulated);
985 }
986 /* Interpolate custom data and evaluate position. */
987 subdiv_vert_data_interpolate(ctx, subdiv_vert_index, vert_interpolation, u, v);
988 subdiv_position = eval_limit_point(ctx->subdiv, ptex_face_index, u, v);
989 /* Apply displacement. */
990 add_v3_v3(subdiv_position, D);
991 /* Evaluate undeformed texture coordinate. */
992 subdiv_vert_orco_evaluate(ctx, ptex_face_index, u, v, subdiv_vert_index);
993}
994
996 const ForeachContext *foreach_context,
997 void * /*tls*/,
998 const int ptex_face_index,
999 const float u,
1000 const float v,
1001 const int subdiv_vert_index)
1002{
1003 SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
1004 subdiv_accumulate_vert_displacement(ctx, ptex_face_index, u, v, subdiv_vert_index);
1005}
1006
1008 void *tls,
1009 const int ptex_face_index,
1010 const float u,
1011 const float v,
1012 const int /*coarse_vert_index*/,
1013 const int /*coarse_face_index*/,
1014 const int /*coarse_corner*/,
1015 const int subdiv_vert_index)
1016{
1018 foreach_context, tls, ptex_face_index, u, v, subdiv_vert_index);
1019}
1020
1022 void *tls,
1023 const int ptex_face_index,
1024 const float u,
1025 const float v,
1026 const int /*coarse_edge_index*/,
1027 const int /*coarse_face_index*/,
1028 const int /*coarse_corner*/,
1029 const int subdiv_vert_index)
1030{
1032 foreach_context, tls, ptex_face_index, u, v, subdiv_vert_index);
1033}
1034
1035static void subdiv_mesh_vert_corner(const ForeachContext *foreach_context,
1036 void * /*tls*/,
1037 const int ptex_face_index,
1038 const float u,
1039 const float v,
1040 const int coarse_vert_index,
1041 const int /*coarse_face_index*/,
1042 const int /*coarse_corner*/,
1043 const int subdiv_vert_index)
1044{
1045 BLI_assert(coarse_vert_index != ORIGINDEX_NONE);
1046 SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
1048 ctx, ptex_face_index, u, v, coarse_vert_index, subdiv_vert_index);
1049}
1050
1052 SubdivMeshTLS *tls,
1053 const int coarse_face_index,
1054 const int coarse_corner)
1055{
1056 const IndexRange coarse_face = ctx->coarse_faces[coarse_face_index];
1057 if (!tls->vert_interpolation) {
1059 }
1060 if (tls->vert_interpolation_coarse_face_index != coarse_face_index) {
1061 vert_interpolation_from_face(ctx, tls->vert_interpolation, coarse_face);
1062 vert_interpolation_from_corner(ctx, tls->vert_interpolation, coarse_face, coarse_corner);
1063 }
1064 else if (tls->vert_interpolation_coarse_corner != coarse_corner) {
1065 vert_interpolation_from_corner(ctx, tls->vert_interpolation, coarse_face, coarse_corner);
1066 }
1067 tls->vert_interpolation_coarse_face_index = coarse_face_index;
1068 tls->vert_interpolation_coarse_corner = coarse_corner;
1069}
1070
1071static void subdiv_mesh_vert_edge(const ForeachContext *foreach_context,
1072 void *tls_v,
1073 const int ptex_face_index,
1074 const float u,
1075 const float v,
1076 const int /*coarse_edge_index*/,
1077 const int coarse_face_index,
1078 const int coarse_corner,
1079 const int subdiv_vert_index)
1080{
1081 SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
1082 SubdivMeshTLS *tls = static_cast<SubdivMeshTLS *>(tls_v);
1083 subdiv_mesh_ensure_vert_interpolation(ctx, tls, coarse_face_index, coarse_corner);
1085 ctx, ptex_face_index, u, v, tls->vert_interpolation, subdiv_vert_index);
1086}
1087
1088static bool subdiv_mesh_is_center_vert(const IndexRange coarse_face, const float u, const float v)
1089{
1090 if (coarse_face.size() == 4) {
1091 if (u == 0.5f && v == 0.5f) {
1092 return true;
1093 }
1094 }
1095 else {
1096 if (u == 1.0f && v == 1.0f) {
1097 return true;
1098 }
1099 }
1100 return false;
1101}
1102
1103static void subdiv_mesh_tag_center_vert(const IndexRange coarse_face,
1104 const int subdiv_vert_index,
1105 const float u,
1106 const float v,
1107 SubdivMeshContext *ctx)
1108{
1109 if (subdiv_mesh_is_center_vert(coarse_face, u, v)) {
1110 ctx->subdiv_face_dot_tags[subdiv_vert_index] = true;
1111 }
1112}
1113
1114static void subdiv_mesh_vert_inner(const ForeachContext *foreach_context,
1115 void *tls_v,
1116 const int ptex_face_index,
1117 const float u,
1118 const float v,
1119 const int coarse_face_index,
1120 const int coarse_corner,
1121 const int subdiv_vert_index)
1122{
1123 SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
1124 SubdivMeshTLS *tls = static_cast<SubdivMeshTLS *>(tls_v);
1125 Subdiv *subdiv = ctx->subdiv;
1126 const IndexRange coarse_face = ctx->coarse_faces[coarse_face_index];
1127 subdiv_mesh_ensure_vert_interpolation(ctx, tls, coarse_face_index, coarse_corner);
1128 subdiv_vert_data_interpolate(ctx, subdiv_vert_index, tls->vert_interpolation, u, v);
1129 ctx->subdiv_positions[subdiv_vert_index] = eval_final_point(subdiv, ptex_face_index, u, v);
1130 subdiv_mesh_tag_center_vert(coarse_face, subdiv_vert_index, u, v, ctx);
1131 subdiv_vert_orco_evaluate(ctx, ptex_face_index, u, v, subdiv_vert_index);
1132}
1133
1135
1136/* -------------------------------------------------------------------- */
1139
1141 const int subdiv_edge_index,
1142 const int coarse_edge_index)
1143{
1144 if (coarse_edge_index == ORIGINDEX_NONE) {
1145 if (!ctx->coarse_edge_origindex.is_empty()) {
1146 ctx->subdiv_edge_origindex[subdiv_edge_index] = ORIGINDEX_NONE;
1147 }
1148 for (const int attr : ctx->coarse_edge_attrs.index_range()) {
1149 const CPPType &type = ctx->coarse_edge_attrs[attr].type();
1150 type.copy_construct(type.default_value(),
1151 ctx->subdiv_edge_attr_spans[attr][subdiv_edge_index]);
1152 }
1153 return;
1154 }
1156 coarse_edge_index,
1157 subdiv_edge_index,
1159 if (!ctx->coarse_edge_origindex.is_empty()) {
1160 ctx->subdiv_edge_origindex[subdiv_edge_index] = ctx->coarse_edge_origindex[coarse_edge_index];
1161 }
1162 if (ctx->settings->use_optimal_display) {
1163 ctx->subdiv_display_edges[subdiv_edge_index] = true;
1164 }
1165}
1166
1167static void subdiv_mesh_edge(const ForeachContext *foreach_context,
1168 void * /*tls*/,
1169 const int coarse_edge_index,
1170 const int subdiv_edge_index,
1171 const bool /*is_loose*/,
1172 const int subdiv_v1,
1173 const int subdiv_v2)
1174{
1175 SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
1176 subdiv_copy_edge_data(ctx, subdiv_edge_index, coarse_edge_index);
1177 ctx->subdiv_edges[subdiv_edge_index][0] = subdiv_v1;
1178 ctx->subdiv_edges[subdiv_edge_index][1] = subdiv_v2;
1179}
1180
1182
1183/* -------------------------------------------------------------------- */
1186
1188 const int subdiv_loop_index,
1189 const LoopsForInterpolation *loop_interpolation,
1190 const float u,
1191 const float v)
1192{
1193 const float4 weights = quad_weights_from_uv(u, v);
1194 mix_attrs(loop_interpolation->corner_data,
1195 loop_interpolation->loop_indices,
1196 weights,
1197 subdiv_loop_index,
1199 if (!ctx->coarse_CD_NORMAL.is_empty()) {
1200 ctx->subdiv_CD_NORMAL[subdiv_loop_index] = mix_normals(
1201 loop_interpolation->CD_NORMAL_data, loop_interpolation->loop_indices, weights);
1202 }
1203 if (!ctx->coarse_CD_ORIGSPACE_MLOOP.is_empty()) {
1204 ctx->subdiv_CD_ORIGSPACE_MLOOP[subdiv_loop_index] = attribute_math::mix4(
1205 weights,
1206 loop_interpolation->CD_ORIGSPACE_MLOOP_data[loop_interpolation->loop_indices[0]],
1207 loop_interpolation->CD_ORIGSPACE_MLOOP_data[loop_interpolation->loop_indices[1]],
1208 loop_interpolation->CD_ORIGSPACE_MLOOP_data[loop_interpolation->loop_indices[2]],
1209 loop_interpolation->CD_ORIGSPACE_MLOOP_data[loop_interpolation->loop_indices[3]]);
1210 }
1211}
1212
1214 const int corner_index,
1215 const int ptex_face_index,
1216 const float u,
1217 const float v)
1218{
1219 Subdiv *subdiv = ctx->subdiv;
1220 for (const int i : ctx->uv_maps.index_range()) {
1221 eval_face_varying(subdiv, i, ptex_face_index, u, v, ctx->uv_maps[i].span[corner_index]);
1222 }
1223}
1224
1226 SubdivMeshTLS *tls,
1227 const int coarse_face_index,
1228 const int coarse_corner)
1229{
1230 const IndexRange coarse_face = ctx->coarse_faces[coarse_face_index];
1231 if (!tls->loop_interpolation) {
1233 }
1234 if (tls->loop_interpolation_coarse_face_index != coarse_face_index) {
1235 loop_interpolation_from_face(ctx, tls->loop_interpolation, coarse_face);
1236 loop_interpolation_from_corner(ctx, tls->loop_interpolation, coarse_face, coarse_corner);
1237 }
1238 else if (tls->loop_interpolation_coarse_corner != coarse_corner) {
1239 loop_interpolation_from_corner(ctx, tls->loop_interpolation, coarse_face, coarse_corner);
1240 }
1241 tls->loop_interpolation_coarse_face_index = coarse_face_index;
1242 tls->loop_interpolation_coarse_corner = coarse_corner;
1243}
1244
1245static void subdiv_mesh_loop(const ForeachContext *foreach_context,
1246 void *tls_v,
1247 const int ptex_face_index,
1248 const float u,
1249 const float v,
1250 const int /*coarse_loop_index*/,
1251 const int coarse_face_index,
1252 const int coarse_corner,
1253 const int subdiv_loop_index,
1254 const int subdiv_vert_index,
1255 const int subdiv_edge_index)
1256{
1257 SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
1258 SubdivMeshTLS *tls = static_cast<SubdivMeshTLS *>(tls_v);
1259 subdiv_mesh_ensure_loop_interpolation(ctx, tls, coarse_face_index, coarse_corner);
1260 subdiv_interpolate_corner_data(ctx, subdiv_loop_index, tls->loop_interpolation, u, v);
1261 subdiv_eval_uv_layer(ctx, subdiv_loop_index, ptex_face_index, u, v);
1262 ctx->subdiv_corner_verts[subdiv_loop_index] = subdiv_vert_index;
1263 ctx->subdiv_corner_edges[subdiv_loop_index] = subdiv_edge_index;
1264}
1265
1267
1268/* -------------------------------------------------------------------- */
1271
1272static void subdiv_mesh_face(const ForeachContext *foreach_context,
1273 OffsetIndices<int> subdiv_faces_by_base_face)
1274{
1275 SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
1277 for (const int i : ctx->coarse_face_attrs.index_range()) {
1278 bke::attribute_math::gather_to_groups(subdiv_faces_by_base_face,
1279 ctx->coarse_faces.index_range(),
1280 ctx->coarse_face_attr_spans[i],
1281 ctx->subdiv_face_attr_spans[i]);
1282 }
1283 if (!ctx->coarse_face_origindex.is_empty()) {
1284 array_utils::gather_to_groups(subdiv_faces_by_base_face,
1285 ctx->coarse_faces.index_range(),
1286 ctx->coarse_face_origindex,
1287 ctx->subdiv_face_origindex);
1288 }
1289 });
1290}
1291
1293
1294/* -------------------------------------------------------------------- */
1297
1298static void subdiv_mesh_vert_loose(const ForeachContext *foreach_context,
1299 void * /*tls*/,
1300 const int coarse_vert_index,
1301 const int subdiv_vert_index)
1302{
1303 SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
1304 subdiv_vert_data_copy(ctx, coarse_vert_index, subdiv_vert_index);
1305 ctx->subdiv_positions[subdiv_vert_index] = ctx->coarse_positions[coarse_vert_index];
1306}
1307
1308/* Get neighbor edges of the given one.
1309 * - neighbors[0] is an edge adjacent to edge->v1.
1310 * - neighbors[1] is an edge adjacent to edge->v2. */
1311static std::array<std::optional<int2>, 2> find_edge_neighbors(
1312 const Span<int2> coarse_edges, const GroupedSpan<int> vert_to_edge_map, const int edge_index)
1313{
1314 /* Vertices which has more than one neighbor are considered infinitely
1315 * sharp. This is also how topology factory treats vertices of a surface
1316 * which are adjacent to a loose edge. */
1317 const auto neighbor_edge_if_single = [&](const int vert) -> std::optional<int2> {
1318 const Span<int> neighbors = vert_to_edge_map[vert];
1319 if (neighbors.size() != 2) {
1320 return std::nullopt;
1321 }
1322 return neighbors[0] == edge_index ? coarse_edges[neighbors[1]] : coarse_edges[neighbors[0]];
1323 };
1324 const int2 edge = coarse_edges[edge_index];
1325 return {neighbor_edge_if_single(edge[0]), neighbor_edge_if_single(edge[1])};
1326}
1327
1328static std::array<float3, 4> find_loose_edge_interpolation_positions(
1329 const Span<float3> coarse_positions,
1330 const int2 &coarse_edge,
1331 const std::array<std::optional<int2>, 2> &neighbors)
1332{
1333 std::array<float3, 4> result;
1334 /* Middle points corresponds to the edge. */
1335 result[1] = coarse_positions[coarse_edge[0]];
1336 result[2] = coarse_positions[coarse_edge[1]];
1337 /* Start point, duplicate from edge start if no neighbor. */
1338 if (const std::optional<int2> &other = neighbors[0]) {
1339 result[0] = coarse_positions[mesh::edge_other_vert(*other, coarse_edge[0])];
1340 }
1341 else {
1342 result[0] = result[1] * 2.0f - result[2];
1343 }
1344 /* End point, duplicate from edge end if no neighbor. */
1345 if (const std::optional<int2> &other = neighbors[1]) {
1346 result[3] = coarse_positions[mesh::edge_other_vert(*other, coarse_edge[1])];
1347 }
1348 else {
1349 result[3] = result[2] * 2.0f - result[1];
1350 }
1351 return result;
1352}
1353
1355 const Span<int2> coarse_edges,
1356 const GroupedSpan<int> vert_to_edge_map,
1357 const int coarse_edge_index,
1358 const bool is_simple,
1359 const float u)
1360{
1361 const int2 edge = coarse_edges[coarse_edge_index];
1362 if (is_simple) {
1363 return math::interpolate(coarse_positions[edge[0]], coarse_positions[edge[1]], u);
1364 }
1365 /* Find neighbors of the coarse edge. */
1366 const std::array<std::optional<int2>, 2> neighbors = find_edge_neighbors(
1367 coarse_edges, vert_to_edge_map, coarse_edge_index);
1368 const std::array<float3, 4> points = find_loose_edge_interpolation_positions(
1369 coarse_positions, edge, neighbors);
1370 float4 weights;
1372 return bke::attribute_math::mix4(weights, points[0], points[1], points[2], points[3]);
1373}
1374
1376 const int2 &coarse_edge,
1377 const float u,
1378 const int subdiv_vert_index)
1379{
1380 /* This is never used for end-points (which are copied from the original). */
1381 BLI_assert(u > 0.0f);
1382 BLI_assert(u < 1.0f);
1383 const std::array<int, 2> coarse_vert_indices{coarse_edge[0], coarse_edge[1]};
1385 coarse_vert_indices,
1386 u,
1387 subdiv_vert_index,
1389 if (!ctx->coarse_vert_origindex.is_empty()) {
1390 ctx->subdiv_vert_origindex[subdiv_vert_index] = ORIGINDEX_NONE;
1391 }
1392 if (!ctx->coarse_dverts.is_empty()) {
1393 MDeformWeightSet dvert_mix_buffer;
1394 ctx->subdiv_dverts[subdiv_vert_index] = mix_deform_verts(
1395 ctx->coarse_dverts, coarse_vert_indices, {1.0f - u, u}, dvert_mix_buffer);
1396 }
1397}
1398
1399static void subdiv_mesh_vert_of_loose_edge(const ForeachContext *foreach_context,
1400 void * /*tls*/,
1401 const int coarse_edge_index,
1402 const float u,
1403 const int subdiv_vert_index)
1404{
1405 SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
1406 const int2 &coarse_edge = ctx->coarse_edges[coarse_edge_index];
1407 const bool is_simple = ctx->subdiv->settings.is_simple;
1408
1409 /* Interpolate custom data when not an end point.
1410 * This data has already been copied from the original vertex by #subdiv_mesh_vert_loose. */
1411 if (!ELEM(u, 0.0, 1.0)) {
1412 subdiv_mesh_vert_of_loose_edge_interpolate(ctx, coarse_edge, u, subdiv_vert_index);
1413 }
1414 /* Interpolate coordinate. */
1415 ctx->subdiv_positions[subdiv_vert_index] = mesh_interpolate_position_on_edge(
1416 ctx->coarse_positions,
1417 ctx->coarse_edges,
1418 ctx->vert_to_edge_map,
1419 coarse_edge_index,
1420 is_simple,
1421 u);
1422}
1423
1425
1426/* -------------------------------------------------------------------- */
1429
1430static void setup_foreach_callbacks(const SubdivMeshContext *subdiv_context,
1431 ForeachContext *foreach_context)
1432{
1433 *foreach_context = {};
1434 /* General information. */
1435 foreach_context->topology_info = subdiv_mesh_topology_info;
1436 /* Every boundary geometry. Used for displacement averaging. */
1437 if (subdiv_context->have_displacement) {
1440 }
1441 foreach_context->vert_corner = subdiv_mesh_vert_corner;
1442 foreach_context->vert_edge = subdiv_mesh_vert_edge;
1443 foreach_context->vert_inner = subdiv_mesh_vert_inner;
1444 foreach_context->edge = subdiv_mesh_edge;
1445 foreach_context->loop = subdiv_mesh_loop;
1446 foreach_context->faces = subdiv_mesh_face;
1447 foreach_context->vert_loose = subdiv_mesh_vert_loose;
1449 foreach_context->user_data_tls_free = subdiv_mesh_tls_free;
1450}
1451
1453
1454/* -------------------------------------------------------------------- */
1457
1458Mesh *subdiv_to_mesh(Subdiv *subdiv, const ToMeshSettings *settings, const Mesh *coarse_mesh)
1459{
1460
1462 /* Make sure evaluator is up to date with possible new topology, and that
1463 * it is refined for the new positions of coarse vertices. */
1465 /* This could happen in two situations:
1466 * - OpenSubdiv is disabled.
1467 * - Something totally bad happened, and OpenSubdiv rejected our topology.
1468 * In either way, we can't safely continue. */
1469 if (coarse_mesh->faces_num) {
1471 return nullptr;
1472 }
1473 }
1474 /* Initialize subdivision mesh creation context. */
1475 SubdivMeshContext subdiv_context{};
1476 subdiv_context.settings = settings;
1477
1478 subdiv_context.coarse_mesh = coarse_mesh;
1479 subdiv_context.coarse_positions = coarse_mesh->vert_positions();
1480 subdiv_context.coarse_edges = coarse_mesh->edges();
1481 subdiv_context.coarse_faces = coarse_mesh->faces();
1482 subdiv_context.coarse_corner_verts = coarse_mesh->corner_verts();
1483 if (!coarse_mesh->loose_edges().is_empty()) {
1485 subdiv_context.coarse_edges,
1486 coarse_mesh->verts_num,
1487 subdiv_context.vert_to_edge_offsets,
1488 subdiv_context.vert_to_edge_indices);
1489 }
1490
1491 subdiv_context.subdiv = subdiv;
1492 subdiv_context.have_displacement = (subdiv->displacement_evaluator != nullptr);
1493 /* Multi-threaded traversal/evaluation. */
1495 ForeachContext foreach_context;
1496 setup_foreach_callbacks(&subdiv_context, &foreach_context);
1497 SubdivMeshTLS tls{};
1498 foreach_context.user_data = &subdiv_context;
1499 foreach_context.user_data_tls_size = sizeof(SubdivMeshTLS);
1500 foreach_context.user_data_tls = &tls;
1501 foreach_subdiv_geometry(subdiv, &foreach_context, settings, coarse_mesh);
1503 Mesh *result = subdiv_context.subdiv_mesh;
1504
1505 /* NOTE: Using normals from the limit surface gives different results than Blender's vertex
1506 * normal calculation. Since vertex normals are supposed to be a consistent cache, don't bother
1507 * calculating them here. The work may have been pointless anyway if the mesh is deformed or
1508 * changed afterwards. */
1509
1510 result->runtime->subsurf_face_dot_tags = BitVector<>(subdiv_context.subdiv_face_dot_tags);
1511
1512 /* Move the optimal display edge array to the final bit vector. */
1513 if (!subdiv_context.subdiv_display_edges.is_empty()) {
1514 result->runtime->subsurf_optimal_display_edges = BitVector<>(
1515 subdiv_context.subdiv_display_edges);
1516 }
1517
1518 if (coarse_mesh->verts_no_face().is_empty()) {
1519 result->tag_loose_verts_none();
1520 }
1521 if (coarse_mesh->loose_edges().is_empty()) {
1522 result->tag_loose_edges_none();
1523 }
1524 result->tag_overlapping_none();
1525
1526 if (subdiv->settings.is_simple) {
1527 /* In simple subdivision, min and max positions are not changed, avoid recomputing bounds. */
1528 result->runtime->bounds_cache = coarse_mesh->runtime->bounds_cache;
1529 }
1530
1531 for (bke::SpanAttributeWriter<float2> &attr : subdiv_context.uv_maps) {
1532 attr.finish();
1533 }
1534 for (bke::GSpanAttributeWriter &attr : subdiv_context.subdiv_vert_attrs) {
1535 attr.finish();
1536 }
1537 for (bke::GSpanAttributeWriter &attr : subdiv_context.subdiv_edge_attrs) {
1538 attr.finish();
1539 }
1540 for (bke::GSpanAttributeWriter &attr : subdiv_context.subdiv_face_attrs) {
1541 attr.finish();
1542 }
1543 for (bke::GSpanAttributeWriter &attr : subdiv_context.subdiv_corner_attrs) {
1544 attr.finish();
1545 }
1546
1547 bke::MutableAttributeAccessor attributes = result->attributes_for_write();
1548 for (const StringRef name : {"skin_modifier_root", "skin_modifier_loose"}) {
1549 bke::SpanAttributeWriter<bool> attr = attributes.lookup_for_write_span<bool>(name);
1550 if (attr && attr.domain == AttrDomain::Point) {
1551 attr.span.drop_front(coarse_mesh->verts_num).fill(false);
1552 attr.finish();
1553 }
1554 }
1555
1557 subdiv_mesh_context_free(&subdiv_context);
1558 return result;
1559}
1560
1562
1563/* -------------------------------------------------------------------- */
1566
1568{
1569 BLI_assert(mesh->verts_num == limit_positions.size());
1570
1571 limit_positions.copy_from(mesh->vert_positions());
1572
1573 Settings settings{};
1574 settings.is_simple = false;
1575 settings.is_adaptive = true;
1576 settings.level = 1;
1577 settings.use_creases = true;
1578
1579 /* Default subdivision surface modifier settings:
1580 * - UV Smooth:Keep Corners.
1581 * - BoundarySmooth: All. */
1584
1585 Subdiv *subdiv = update_from_mesh(nullptr, &settings, mesh);
1586 if (subdiv) {
1587 deform_coarse_vertices(subdiv, mesh, limit_positions);
1588 free(subdiv);
1589 }
1590}
1591
1593
1594} // namespace blender::bke::subdiv
CustomData interface, see also DNA_customdata_types.h.
#define ORIGINDEX_NONE
support for deformation groups and hooks.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define ELEM(...)
#define CD_MASK_MULTIRES_GRIDS
Span< T > as_span() const
Definition BLI_array.hh:254
bool is_empty() const
Definition BLI_array.hh:275
void copy_construct(const void *src, void *dst) const
const void * default_value() const
CommonVArrayInfo common_info() const
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr int64_t start() const
void provide_buffer(void *buffer, const int64_t size)
constexpr int64_t size() const
Definition BLI_span.hh:499
constexpr void copy_from(Span< T > values) const
Definition BLI_span.hh:745
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr Span()=default
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
void append(const T &value)
const T & last(const int64_t n=0) const
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
GAttributeReader get() const
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
GSpanAttributeWriter lookup_for_write_span(StringRef name)
#define T
T mix_indices(const Span< T > src, const Span< int > indices)
T mix4(const float4 &weights, const T &v0, const T &v1, const T &v2, const T &v3)
void to_static_type(const CPPType &cpp_type, Fn &&fn)
T mix2(float factor, const T &a, const T &b)
int edge_other_vert(const int2 edge, const int vert)
Definition BKE_mesh.hh:370
GroupedSpan< int > build_vert_to_edge_map(Span< int2 > edges, int verts_num, Array< int > &r_offsets, Array< int > &r_indices)
static bool subdiv_mesh_topology_info(const ForeachContext *foreach_context, const int, const int, const int, const int, const Span< int >)
static void subdiv_mesh_vert_displacement_every_edge(const ForeachContext *foreach_context, void *tls, const int ptex_face_index, const float u, const float v, const int, const int, const int, const int subdiv_vert_index)
void free(Subdiv *subdiv)
Definition subdiv.cc:192
static void subdiv_mesh_ensure_loop_interpolation(SubdivMeshContext *ctx, SubdivMeshTLS *tls, const int coarse_face_index, const int coarse_corner)
static void subdiv_mesh_vert_of_loose_edge_interpolate(SubdivMeshContext *ctx, const int2 &coarse_edge, const float u, const int subdiv_vert_index)
float3 eval_final_point(Subdiv *subdiv, int ptex_face_index, float u, float v)
BLI_INLINE float4 quad_weights_from_uv(float u, float v)
static void subdiv_vert_data_copy(const SubdivMeshContext *ctx, const int coarse_vert_index, const int subdiv_vert_index)
static void evaluate_vert_and_apply_displacement_interpolate(const SubdivMeshContext *ctx, const int ptex_face_index, const float u, const float v, VerticesForInterpolation *vert_interpolation, const int subdiv_vert_index)
static void subdiv_mesh_ctx_cache_uv_layers(SubdivMeshContext *ctx)
static void subdiv_mesh_vert_displacement_every_corner_or_edge(const ForeachContext *foreach_context, void *, const int ptex_face_index, const float u, const float v, const int subdiv_vert_index)
static void loop_interpolation_from_corner(const SubdivMeshContext *ctx, LoopsForInterpolation *loop_interpolation, const IndexRange coarse_face, const int corner)
bool eval_begin_from_mesh(Subdiv *subdiv, const Mesh *mesh, eSubdivEvaluatorType evaluator_type, Span< float3 > coarse_vert_positions={}, OpenSubdiv_EvaluatorCache *evaluator_cache=nullptr)
static void subdiv_mesh_vert_corner(const ForeachContext *foreach_context, void *, const int ptex_face_index, const float u, const float v, const int coarse_vert_index, const int, const int, const int)
static void create_attrs_and_retrieve_interp_spans(const AttributeAccessor src_attrs, const bke::AttrDomain domain, const Set< StringRef > &skip_names, MutableAttributeAccessor dst_attrs, Vector< GVArraySpan > &coarse_varray_spans, Vector< GSpan > &coarse_spans, Vector< GSpanAttributeWriter > &dst_writers, Vector< GMutableSpan > &dst_spans)
float3 mesh_interpolate_position_on_edge(Span< float3 > coarse_positions, Span< int2 > coarse_edges, GroupedSpan< int > vert_to_edge_map, int coarse_edge_index, bool is_simple, float u)
float3 eval_limit_point(Subdiv *subdiv, int ptex_face_index, float u, float v)
static void evaluate_vert_and_apply_displacement_copy(const SubdivMeshContext *ctx, const int ptex_face_index, const float u, const float v, const int coarse_vert_index, const int subdiv_vert_index)
static void subdiv_vert_orco_evaluate(const SubdivMeshContext *ctx, const int ptex_face_index, const float u, const float v, const int subdiv_vert_index)
bool foreach_subdiv_geometry(Subdiv *subdiv, const ForeachContext *context, const ToMeshSettings *mesh_settings, const Mesh *coarse_mesh)
static void subdiv_mesh_vert_inner(const ForeachContext *foreach_context, void *tls_v, const int ptex_face_index, const float u, const float v, const int coarse_face_index, const int coarse_corner, const int subdiv_vert_index)
void calculate_limit_positions(Mesh *mesh, MutableSpan< float3 > limit_positions)
static bool subdiv_mesh_is_center_vert(const IndexRange coarse_face, const float u, const float v)
static void loop_interpolation_from_face(const SubdivMeshContext *ctx, LoopsForInterpolation *loop_interpolation, const IndexRange coarse_face)
@ SUBDIV_FVAR_LINEAR_INTERPOLATION_CORNERS_AND_JUNCTIONS
Definition BKE_subdiv.hh:43
static void subdiv_mesh_vert_displacement_every_corner(const ForeachContext *foreach_context, void *tls, const int ptex_face_index, const float u, const float v, const int, const int, const int, const int subdiv_vert_index)
static void subdiv_mesh_face(const ForeachContext *foreach_context, OffsetIndices< int > subdiv_faces_by_base_face)
static float3 mix_normals(const Span< float3 > src, const Span< int > src_indices, const Span< float > weights)
static void subdiv_mesh_edge(const ForeachContext *foreach_context, void *, const int coarse_edge_index, const int subdiv_edge_index, const bool, const int subdiv_v1, const int subdiv_v2)
static void subdiv_mesh_vert_loose(const ForeachContext *foreach_context, void *, const int coarse_vert_index, const int subdiv_vert_index)
static void vert_interpolation_from_corner(const SubdivMeshContext *ctx, VerticesForInterpolation *vert_interpolation, const IndexRange coarse_face, const int corner)
static void subdiv_mesh_vert_of_loose_edge(const ForeachContext *foreach_context, void *, const int coarse_edge_index, const float u, const int subdiv_vert_index)
void deform_coarse_vertices(Subdiv *subdiv, const Mesh *coarse_mesh, MutableSpan< float3 > vert_positions)
static void loops_of_ptex_get(LoopsOfPtex *loops_of_ptex, const IndexRange coarse_face, const int ptex_of_face_index)
static void mix_attrs(const Span< GSpan > src, const std::array< int, 2 > &src_indices, const float factor, const int dst_index, const Span< GMutableSpan > dst)
static void subdiv_eval_uv_layer(SubdivMeshContext *ctx, const int corner_index, const int ptex_face_index, const float u, const float v)
void eval_limit_point_and_derivatives(Subdiv *subdiv, int ptex_face_index, float u, float v, float3 &r_P, float3 &r_dPdu, float3 &r_dPdv)
static void subdiv_mesh_ensure_vert_interpolation(SubdivMeshContext *ctx, SubdivMeshTLS *tls, const int coarse_face_index, const int coarse_corner)
static void setup_foreach_callbacks(const SubdivDeformContext *subdiv_context, ForeachContext *foreach_context)
static void subdiv_mesh_prepare_accumulator(SubdivDeformContext *ctx, int num_vertices)
void eval_displacement(Subdiv *subdiv, int ptex_face_index, float u, float v, const float3 &dPdu, const float3 &dPdv, float3 &r_D)
static std::array< std::optional< int2 >, 2 > find_edge_neighbors(const Span< int2 > coarse_edges, const GroupedSpan< int > vert_to_edge_map, const int edge_index)
static void subdiv_mesh_tls_free(void *tls_v)
static void subdiv_vert_data_interpolate(const SubdivMeshContext *ctx, const int subdiv_vert_index, VerticesForInterpolation *vert_interpolation, const float u, const float v)
static void copy_attrs(const Span< GSpan > src, const int src_index, const int dst_index, const Span< GMutableSpan > dst)
void stats_begin(SubdivStats *stats, StatsValue value)
void stats_end(SubdivStats *stats, StatsValue value)
void eval_vert_data(Subdiv *subdiv, int ptex_face_index, float u, float v, float r_vert_data[])
void eval_face_varying(Subdiv *subdiv, int face_varying_channel, int ptex_face_index, float u, float v, float2 &r_face_varying)
Mesh * subdiv_to_mesh(Subdiv *subdiv, const ToMeshSettings *settings, const Mesh *coarse_mesh)
static void subdiv_accumulate_vert_displacement(SubdivDeformContext *ctx, const int ptex_face_index, const float u, const float v, int vert_index)
static std::array< float3, 4 > find_loose_edge_interpolation_positions(const Span< float3 > coarse_positions, const int2 &coarse_edge, const std::array< std::optional< int2 >, 2 > &neighbors)
static void subdiv_mesh_tag_center_vert(const IndexRange coarse_face, const int subdiv_vert_index, const float u, const float v, SubdivMeshContext *ctx)
Subdiv * update_from_mesh(Subdiv *subdiv, const Settings *settings, const Mesh *mesh)
Definition subdiv.cc:181
static void subdiv_mesh_ctx_cache_custom_data_layers(SubdivMeshContext *ctx)
static void subdiv_interpolate_corner_data(const SubdivMeshContext *ctx, const int subdiv_loop_index, const LoopsForInterpolation *loop_interpolation, const float u, const float v)
static void subdiv_mesh_context_free(SubdivDeformContext *ctx)
static void subdiv_mesh_loop(const ForeachContext *foreach_context, void *tls_v, const int ptex_face_index, const float u, const float v, const int, const int coarse_face_index, const int coarse_corner, const int subdiv_loop_index, const int subdiv_vert_index, const int subdiv_edge_index)
static void subdiv_mesh_vert_edge(const ForeachContext *foreach_context, void *tls_v, const int ptex_face_index, const float u, const float v, const int, const int coarse_face_index, const int coarse_corner, const int subdiv_vert_index)
static void vert_interpolation_from_face(const SubdivMeshContext *ctx, VerticesForInterpolation *vert_interpolation, const IndexRange coarse_face)
static void subdiv_copy_edge_data(SubdivMeshContext *ctx, const int subdiv_edge_index, const int coarse_edge_index)
MDeformVert mix_deform_verts(const Span< MDeformVert > src, const Span< int > indices, const Span< float > weights, MDeformWeightSet &dw_buffer)
Definition deform.cc:1809
CustomIDVectorSet< MDeformWeight, WeightIndexGetter, 64 > MDeformWeightSet
T interpolate(const T &a, const T &b, const FactorT &t)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
void fill_constant_group_size(int size, int start_offset, MutableSpan< int > offsets)
void memory_bandwidth_bound_task(const int64_t approximate_bytes_touched, const Function &function)
Definition BLI_task.hh:251
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)
Definition voxel.cc:16
MINLINE void copy_v3_v3(float r[3], const float a[3])
void BKE_defvert_array_copy(MDeformVert *dst, const MDeformVert *src, int totvert)
Definition deform.cc:1043
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
void BKE_defvert_array_free_elems(MDeformVert *dvert, int totvert)
Definition deform.cc:1061
ATTR_WARN_UNUSED_RESULT const BMVert * v
MINLINE void mul_v3_fl(float r[3], float f)
VecBase< float, 4 > float4
void BKE_mesh_copy_parameters_for_eval(Mesh *me_dst, const Mesh *me_src)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
MINLINE void add_v3_v3(float r[3], const float a[3])
void key_curve_position_weights(float t, float data[4], KeyInterpolationType type)
Definition key.cc:310
VecBase< float, 3 > float3
const CustomData_MeshMasks CD_MASK_EVERYTHING
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void * CustomData_add_layer(CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< bDeformGroup > vertex_group_names
bke::MeshRuntime * runtime
CustomData corner_data
CustomData face_data
CustomData edge_data
CustomData vert_data
SharedCache< Bounds< float3 > > bounds_cache
ForeachTopologyInformationCb topology_info
ForeachVertOfLooseEdgeCb vert_of_loose_edge
LoopsForInterpolation(const SubdivMeshContext &ctx)
std::array< float2, 4 > CD_ORIGSPACE_MLOOP_storage
VtxBoundaryInterpolation vtx_boundary_interpolation
Definition BKE_subdiv.hh:83
FVarLinearInterpolation fvar_linear_interpolation
Definition BKE_subdiv.hh:84
Vector< GVArraySpan > coarse_edge_attrs
Vector< GSpanAttributeWriter > subdiv_vert_attrs
Vector< GMutableSpan > subdiv_edge_attr_spans
MutableSpan< float2 > subdiv_CD_ORIGSPACE_MLOOP
Vector< GSpanAttributeWriter > subdiv_edge_attrs
Vector< GSpanAttributeWriter > subdiv_face_attrs
Vector< GMutableSpan > subdiv_corner_attr_spans
Vector< GMutableSpan > subdiv_face_attr_spans
Vector< GVArraySpan > coarse_face_attrs
Vector< GVArraySpan > coarse_corner_attrs
Vector< GVArraySpan > coarse_vert_attrs
Vector< GSpanAttributeWriter > subdiv_corner_attrs
MutableSpan< MDeformVert > subdiv_dverts
Vector< GMutableSpan > subdiv_vert_attr_spans
Vector< bke::SpanAttributeWriter< float2 > > uv_maps
LoopsForInterpolation * loop_interpolation
VerticesForInterpolation * vert_interpolation
std::array< MDeformVert, 4 > dverts_storage
VerticesForInterpolation(const SubdivMeshContext &ctx)