Blender V5.3
MOD_surfacedeform.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2017 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_bvh.hh"
10#include "BLI_math_geom_c.hh"
11#include "BLI_math_matrix_c.hh"
12#include "BLI_task_c.hh"
13
14#include "BLT_translation.hh"
15
16#include "DNA_mesh_types.h"
17#include "DNA_meshdata_types.h"
18#include "DNA_object_types.h"
19#include "DNA_screen_types.h"
20
21#include "BKE_bvhutils.hh"
22#include "BKE_deform.hh"
23#include "BKE_lib_query.hh"
24#include "BKE_mesh.hh"
25#include "BKE_mesh_wrapper.hh"
26#include "BKE_modifier.hh"
27
29#include "UI_resources.hh"
30
31#include "BLO_read_write.hh"
32
33#include "RNA_access.hh"
34#include "RNA_prototypes.hh"
35
36#include "DEG_depsgraph.hh"
37
38#include "MEM_guardedalloc.h"
39
40#include "MOD_ui_common.hh"
41#include "MOD_util.hh"
42
43namespace blender {
44
49
52 uint num; /* Careful, this is twice the number of faces (avoids an extra loop) */
53};
54
60};
61
87
160
166
176
177/* Bind result values */
178enum {
185};
186
187/* Infinite weight flags */
188enum {
192};
193
194static void init_data(ModifierData *md)
195{
196 SurfaceDeformModifierData *smd = reinterpret_cast<SurfaceDeformModifierData *>(md);
198}
199
200static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
201{
202 SurfaceDeformModifierData *smd = reinterpret_cast<SurfaceDeformModifierData *>(md);
203
204 /* Ask for vertex groups if we need them. */
205 if (smd->defgrp_name[0] != '\0') {
206 r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
207 }
208}
209
211 public:
214
219
220 private:
221 void delete_self_with_data() override
222 {
223 for (int i = 0; i < this->bind_verts_num; i++) {
224 if (this->verts[i].binds) {
225 for (int j = 0; j < this->verts[i].binds_num; j++) {
226 MEM_SAFE_DELETE(this->verts[i].binds[j].vert_inds);
227 MEM_SAFE_DELETE(this->verts[i].binds[j].vert_weights);
228 }
229 MEM_delete(this->verts[i].binds);
230 }
231 }
232 MEM_delete(verts);
233 MEM_delete(this);
234 }
235};
236
237static void free_data(ModifierData *md)
238{
239 SurfaceDeformModifierData *smd = reinterpret_cast<SurfaceDeformModifierData *>(md);
241}
242
243static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
244{
245 const SurfaceDeformModifierData *smd = reinterpret_cast<const SurfaceDeformModifierData *>(md);
246 SurfaceDeformModifierData *tsmd = reinterpret_cast<SurfaceDeformModifierData *>(target);
247
248 BKE_modifier_copydata_generic(md, target, flag);
249
251 smd->verts, smd->verts_sharing_info, &tsmd->verts, &tsmd->verts_sharing_info);
252}
253
254static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
255{
256 SurfaceDeformModifierData *smd = reinterpret_cast<SurfaceDeformModifierData *>(md);
257
258 walk(user_data, ob, reinterpret_cast<ID **>(&smd->target), IDWALK_CB_NOP);
259}
260
262{
263 SurfaceDeformModifierData *smd = reinterpret_cast<SurfaceDeformModifierData *>(md);
264 if (smd->target != nullptr) {
266 ctx->node, smd->target, DEG_OB_COMP_GEOMETRY, "Surface Deform Modifier");
267 }
268}
269
270static void freeAdjacencyMap(SDefAdjacencyArray *const vert_edges,
271 SDefAdjacency *const adj_ref,
272 SDefEdgePolys *const edge_polys)
273{
274 MEM_delete(edge_polys);
275
276 MEM_delete(adj_ref);
277
278 MEM_delete(vert_edges);
279}
280
282 const Span<int2> edges,
283 const Span<int> corner_edges,
284 SDefAdjacencyArray *const vert_edges,
285 SDefAdjacency *adj,
286 SDefEdgePolys *const edge_polys)
287{
288 /* Find polygons adjacent to edges. */
289 for (const int i : polys.index_range()) {
290 for (const int edge_i : corner_edges.slice(polys[i])) {
291 if (edge_polys[edge_i].num == 0) {
292 edge_polys[edge_i].polys[0] = i;
293 edge_polys[edge_i].polys[1] = -1;
294 edge_polys[edge_i].num++;
295 }
296 else if (edge_polys[edge_i].num == 1) {
297 edge_polys[edge_i].polys[1] = i;
298 edge_polys[edge_i].num++;
299 }
300 else {
302 }
303 }
304 }
305
306 /* Find edges adjacent to vertices */
307 for (const int i : edges.index_range()) {
308 const int2 &edge = edges[i];
309 adj->next = vert_edges[edge[0]].first;
310 adj->index = i;
311 vert_edges[edge[0]].first = adj;
312 vert_edges[edge[0]].num += edge_polys[i].num;
313 adj++;
314
315 adj->next = vert_edges[edge[1]].first;
316 adj->index = i;
317 vert_edges[edge[1]].first = adj;
318 vert_edges[edge[1]].num += edge_polys[i].num;
319 adj++;
320 }
321
323}
324
326 const int *const corner_verts,
327 const int *const corner_edges,
328 const uint edge,
329 const uint num)
330{
331 bool found = false;
332
333 for (int i = 0; i < num; i++) {
334 if (corner_edges[i] == edge) {
335 found = true;
336 }
337 if (found) {
338 *indices = corner_verts[i];
339 indices++;
340 }
341 }
342
343 /* Fill in remaining vertex indices that occur before the edge */
344 for (int i = 0; corner_edges[i] != edge; i++) {
345 *indices = corner_verts[i];
346 indices++;
347 }
348}
349
351 const int *const corner_verts,
352 const uint loopstart,
353 const uint num)
354{
355 for (int i = loopstart; i < num; i++) {
356 *indices = corner_verts[i];
357 indices++;
358 }
359
360 for (int i = 0; i < loopstart; i++) {
361 *indices = corner_verts[i];
362 indices++;
363 }
364}
365
366BLI_INLINE uint nearestVert(SDefBindCalcData *const data, const float point_co[3])
367{
368 float t_point[3];
369 float max_dist = FLT_MAX;
370 float dist;
371 uint index = 0;
372
373 mul_v3_m4v3(t_point, data->imat, point_co);
374
375 const std::optional<bke::bvh::ClosestPointResult> nearest = data->treeData->closest_point(
376 t_point);
377 BLI_assert(nearest.has_value());
378
379 const IndexRange face = data->polys[data->tri_faces[nearest->index]];
380
381 for (int i = 0; i < face.size(); i++) {
382 const int edge_i = data->corner_edges[face.start() + i];
383 const int2 &edge = data->edges[edge_i];
385 point_co, data->targetCos[edge[0]], data->targetCos[edge[1]]);
386
387 if (dist < max_dist) {
388 max_dist = dist;
389 index = edge_i;
390 }
391 }
392
393 const int2 &edge = data->edges[index];
394 if (len_squared_v3v3(point_co, data->targetCos[edge[0]]) <
395 len_squared_v3v3(point_co, data->targetCos[edge[1]]))
396 {
397 return edge[0];
398 }
399
400 return edge[1];
401}
402
403BLI_INLINE int isPolyValid(const float coords[][2], const uint nr)
404{
405 float prev_co[2], prev_prev_co[2];
406 float curr_vec[2], prev_vec[2];
407
408 if (!is_poly_convex_v2(coords, nr)) {
410 }
411
412 copy_v2_v2(prev_prev_co, coords[nr - 2]);
413 copy_v2_v2(prev_co, coords[nr - 1]);
414 sub_v2_v2v2(prev_vec, prev_co, coords[nr - 2]);
415 normalize_v2(prev_vec);
416
417 for (int i = 0; i < nr; i++) {
418 sub_v2_v2v2(curr_vec, coords[i], prev_co);
419
420 /* Check overlap between directly adjacent vertices. */
421 const float curr_len = normalize_v2(curr_vec);
422 if (curr_len < FLT_EPSILON) {
424 }
425
426 /* Check overlap between vertices skipping one. */
427 if (len_squared_v2v2(prev_prev_co, coords[i]) < FLT_EPSILON * FLT_EPSILON) {
429 }
430
431 /* Check for adjacent parallel edges. */
432 if (1.0f - dot_v2v2(prev_vec, curr_vec) < FLT_EPSILON) {
434 }
435
436 copy_v2_v2(prev_prev_co, prev_co);
437 copy_v2_v2(prev_co, coords[i]);
438 copy_v2_v2(prev_vec, curr_vec);
439 }
440
442}
443
444static void freeBindData(SDefBindWeightData *const bwdata)
445{
446 SDefBindPoly *bpoly = bwdata->bind_polys;
447
448 if (bwdata->bind_polys) {
449 for (int i = 0; i < bwdata->faces_num; bpoly++, i++) {
450 MEM_SAFE_DELETE(bpoly->coords);
451 MEM_SAFE_DELETE(bpoly->coords_v2);
452 }
453
454 MEM_delete(bwdata->bind_polys);
455 }
456
457 MEM_delete(bwdata);
458}
459
460BLI_INLINE float computeAngularWeight(const float point_angle, const float edgemid_angle)
461{
462 return sinf(min_ff(point_angle / edgemid_angle, 1) * M_PI_2);
463}
464
466 const float point_co[3])
467{
468 const uint nearest = nearestVert(data, point_co);
469 const SDefAdjacency *const vert_edges = data->vert_edges[nearest].first;
470 const SDefEdgePolys *const edge_polys = data->edge_polys;
471
472 const SDefAdjacency *vedge;
473
474 SDefBindWeightData *bwdata;
475 SDefBindPoly *bpoly;
476
477 const float world[3] = {0.0f, 0.0f, 1.0f};
478 float avg_point_dist = 0.0f;
479 float tot_weight = 0.0f;
480 int inf_weight_flags = 0;
481
482 bwdata = MEM_new_zeroed<SDefBindWeightData>("SDefBindWeightData");
483 if (bwdata == nullptr) {
485 return nullptr;
486 }
487
488 bwdata->faces_num = data->vert_edges[nearest].num / 2;
489
490 bpoly = MEM_new_array_zeroed<SDefBindPoly>(bwdata->faces_num, "SDefBindPoly");
491 if (bpoly == nullptr) {
492 freeBindData(bwdata);
494 return nullptr;
495 }
496
497 bwdata->bind_polys = bpoly;
498
499 /* Loop over all adjacent edges,
500 * and build the #SDefBindPoly data for each face adjacent to those. */
501 for (vedge = vert_edges; vedge; vedge = vedge->next) {
502 uint edge_ind = vedge->index;
503
504 for (int i = 0; i < edge_polys[edge_ind].num; i++) {
505 {
506 bpoly = bwdata->bind_polys;
507
508 for (int j = 0; j < bwdata->faces_num; bpoly++, j++) {
509 /* If coords isn't allocated, we have reached the first uninitialized `bpoly`. */
510 if ((bpoly->index == edge_polys[edge_ind].polys[i]) || (!bpoly->coords)) {
511 break;
512 }
513 }
514 }
515
516 /* Check if face was already created by another edge or still has to be initialized */
517 if (!bpoly->coords) {
518 float angle;
519 float axis[3];
520 float tmp_vec_v2[2];
521 int is_poly_valid;
522
523 bpoly->index = edge_polys[edge_ind].polys[i];
524 bpoly->coords = nullptr;
525 bpoly->coords_v2 = nullptr;
526
527 /* Copy face data */
528 const IndexRange face = data->polys[bpoly->index];
529
530 bpoly->verts_num = face.size();
531 bpoly->loopstart = face.start();
532
533 bpoly->coords = MEM_new_array_uninitialized<float[3]>(size_t(face.size()),
534 "SDefBindPolyCoords");
535 if (bpoly->coords == nullptr) {
536 freeBindData(bwdata);
538 return nullptr;
539 }
540
542 "SDefBindPolyCoords_v2");
543 if (bpoly->coords_v2 == nullptr) {
544 freeBindData(bwdata);
546 return nullptr;
547 }
548
549 for (int j = 0; j < face.size(); j++) {
550 const int vert_i = data->corner_verts[face.start() + j];
551 const int edge_i = data->corner_edges[face.start() + j];
552 copy_v3_v3(bpoly->coords[j], data->targetCos[vert_i]);
553
554 /* Find corner and edge indices within face loop array */
555 if (vert_i == nearest) {
556 bpoly->corner_ind = j;
557 bpoly->edge_vert_inds[0] = (j == 0) ? (face.size() - 1) : (j - 1);
558 bpoly->edge_vert_inds[1] = (j == face.size() - 1) ? (0) : (j + 1);
559
560 bpoly->edge_inds[0] = data->corner_edges[face.start() + bpoly->edge_vert_inds[0]];
561 bpoly->edge_inds[1] = edge_i;
562 }
563 }
564
565 /* Compute polygons parametric data. */
566 mid_v3_v3_array(bpoly->centroid, bpoly->coords, face.size());
567 normal_poly_v3(bpoly->normal, bpoly->coords, face.size());
568
569 /* Compute face skew angle and axis */
570 angle = angle_normalized_v3v3(bpoly->normal, world);
571
572 cross_v3_v3v3(axis, bpoly->normal, world);
573 normalize_v3(axis);
574
575 /* Map coords onto 2d normal plane. */
576 map_to_plane_axis_angle_v2_v3v3fl(bpoly->point_v2, point_co, axis, angle);
577
578 zero_v2(bpoly->centroid_v2);
579 for (int j = 0; j < face.size(); j++) {
580 map_to_plane_axis_angle_v2_v3v3fl(bpoly->coords_v2[j], bpoly->coords[j], axis, angle);
581 madd_v2_v2fl(bpoly->centroid_v2, bpoly->coords_v2[j], 1.0f / face.size());
582 }
583
584 is_poly_valid = isPolyValid(bpoly->coords_v2, face.size());
585
586 if (is_poly_valid != MOD_SDEF_BIND_RESULT_SUCCESS) {
587 freeBindData(bwdata);
588 data->success = is_poly_valid;
589 return nullptr;
590 }
591
592 bpoly->inside = isect_point_poly_v2(bpoly->point_v2, bpoly->coords_v2, face.size());
593
594 /* Initialize weight components */
595 bpoly->weight_angular = 1.0f;
596 bpoly->weight_dist_proj = len_v2v2(bpoly->centroid_v2, bpoly->point_v2);
597 bpoly->weight_dist = len_v3v3(bpoly->centroid, point_co);
598
599 avg_point_dist += bpoly->weight_dist;
600
601 /* Common vertex coordinates. */
602 const float *const vert0_v2 = bpoly->coords_v2[bpoly->edge_vert_inds[0]];
603 const float *const vert1_v2 = bpoly->coords_v2[bpoly->edge_vert_inds[1]];
604 const float *const corner_v2 = bpoly->coords_v2[bpoly->corner_ind];
605
606 /* Compute centroid to mid-edge vectors */
607 mid_v2_v2v2(bpoly->cent_edgemid_vecs_v2[0], vert0_v2, corner_v2);
608 mid_v2_v2v2(bpoly->cent_edgemid_vecs_v2[1], vert1_v2, corner_v2);
609
610 sub_v2_v2(bpoly->cent_edgemid_vecs_v2[0], bpoly->centroid_v2);
611 sub_v2_v2(bpoly->cent_edgemid_vecs_v2[1], bpoly->centroid_v2);
612
615
616 /* Compute face scales with respect to the two edges. */
617 bpoly->scales[0] = dist_to_line_v2(bpoly->centroid_v2, vert0_v2, corner_v2);
618 bpoly->scales[1] = dist_to_line_v2(bpoly->centroid_v2, vert1_v2, corner_v2);
619
620 /* Compute the angle between the edge mid vectors. */
622 bpoly->cent_edgemid_vecs_v2[1]);
623
624 /* Compute the angles between the corner and the edge mid vectors. The angles
625 * are computed signed in order to correctly clamp point_edgemid_angles later. */
626 float corner_angles[2];
627
628 sub_v2_v2v2(tmp_vec_v2, corner_v2, bpoly->centroid_v2);
629 normalize_v2(tmp_vec_v2);
630
631 corner_angles[0] = angle_signed_v2v2(tmp_vec_v2, bpoly->cent_edgemid_vecs_v2[0]);
632 corner_angles[1] = angle_signed_v2v2(tmp_vec_v2, bpoly->cent_edgemid_vecs_v2[1]);
633
634 bpoly->corner_edgemid_angles[0] = fabsf(corner_angles[0]);
635 bpoly->corner_edgemid_angles[1] = fabsf(corner_angles[1]);
636
637 /* Verify that the computed values are valid (the face isn't somehow
638 * degenerate despite having passed isPolyValid). */
639 if (bpoly->scales[0] < FLT_EPSILON || bpoly->scales[1] < FLT_EPSILON ||
642 {
643 freeBindData(bwdata);
645 return nullptr;
646 }
647
648 /* Check for infinite weights, and compute angular data otherwise. */
649 if (bpoly->weight_dist < FLT_EPSILON) {
650 inf_weight_flags |= MOD_SDEF_INFINITE_WEIGHT_DIST_PROJ;
651 inf_weight_flags |= MOD_SDEF_INFINITE_WEIGHT_DIST;
652 }
653 else if (bpoly->weight_dist_proj < FLT_EPSILON) {
654 inf_weight_flags |= MOD_SDEF_INFINITE_WEIGHT_DIST_PROJ;
655 }
656 else {
657 /* Compute angles between the point and the edge mid vectors. */
658 float cent_point_vec[2], point_angles[2];
659
660 sub_v2_v2v2(cent_point_vec, bpoly->point_v2, bpoly->centroid_v2);
661 normalize_v2(cent_point_vec);
662
663 point_angles[0] = angle_signed_v2v2(cent_point_vec, bpoly->cent_edgemid_vecs_v2[0]) *
664 signf(corner_angles[0]);
665 point_angles[1] = angle_signed_v2v2(cent_point_vec, bpoly->cent_edgemid_vecs_v2[1]) *
666 signf(corner_angles[1]);
667
668 if (point_angles[0] <= 0 && point_angles[1] <= 0) {
669 /* If the point is outside the corner formed by the edge mid vectors,
670 * choose to clamp the closest side and flip the other. */
671 if (point_angles[0] < point_angles[1]) {
672 point_angles[0] = bpoly->edgemid_angle - point_angles[1];
673 }
674 else {
675 point_angles[1] = bpoly->edgemid_angle - point_angles[0];
676 }
677 }
678
679 bpoly->point_edgemid_angles[0] = max_ff(0, point_angles[0]);
680 bpoly->point_edgemid_angles[1] = max_ff(0, point_angles[1]);
681
682 /* Compute the distance scale for the corner. The base value is the orthogonal
683 * distance from the corner to the chord, scaled by `sqrt(2)` to preserve the old
684 * values in case of a square grid. This doesn't use the centroid because the
685 * corner_triS method only uses these three vertices. */
686 bpoly->scale_mid = area_tri_v2(vert0_v2, corner_v2, vert1_v2) /
687 len_v2v2(vert0_v2, vert1_v2) * sqrtf(2);
688
689 if (bpoly->inside) {
690 /* When inside, interpolate to centroid-based scale close to the center. */
691 float min_dist = min_ff(bpoly->scales[0], bpoly->scales[1]);
692
693 bpoly->scale_mid = interpf(bpoly->scale_mid,
694 (bpoly->scales[0] + bpoly->scales[1]) / 2,
695 min_ff(bpoly->weight_dist_proj / min_dist, 1));
696 }
697
698 /* Verify that the additional computed values are valid. */
699 if (bpoly->scale_mid < FLT_EPSILON ||
701 {
702 freeBindData(bwdata);
704 return nullptr;
705 }
706 }
707 }
708 }
709 }
710
711 avg_point_dist /= bwdata->faces_num;
712
713 /* If weights 1 and 2 are not infinite, loop over all adjacent edges again,
714 * and build adjacency dependent angle data (depends on all polygons having been computed) */
715 if (!inf_weight_flags) {
716 for (vedge = vert_edges; vedge; vedge = vedge->next) {
717 SDefBindPoly *bpolys[2];
718 const SDefEdgePolys *epolys;
719 float ang_weights[2];
720 uint edge_ind = vedge->index;
721 uint edge_on_poly[2];
722
723 epolys = &edge_polys[edge_ind];
724
725 /* Find bind polys corresponding to the edge's adjacent polys */
726 bpoly = bwdata->bind_polys;
727
728 for (int i = 0, j = 0; (i < bwdata->faces_num) && (j < epolys->num); bpoly++, i++) {
729 if (ELEM(bpoly->index, epolys->polys[0], epolys->polys[1])) {
730 bpolys[j] = bpoly;
731
732 if (bpoly->edge_inds[0] == edge_ind) {
733 edge_on_poly[j] = 0;
734 }
735 else {
736 edge_on_poly[j] = 1;
737 }
738
739 j++;
740 }
741 }
742
743 /* Compute angular weight component */
744 if (epolys->num == 1) {
745 ang_weights[0] = computeAngularWeight(bpolys[0]->point_edgemid_angles[edge_on_poly[0]],
746 bpolys[0]->edgemid_angle);
747 bpolys[0]->weight_angular *= ang_weights[0] * ang_weights[0];
748 }
749 else if (epolys->num == 2) {
750 ang_weights[0] = computeAngularWeight(bpolys[0]->point_edgemid_angles[edge_on_poly[0]],
751 bpolys[0]->edgemid_angle);
752 ang_weights[1] = computeAngularWeight(bpolys[1]->point_edgemid_angles[edge_on_poly[1]],
753 bpolys[1]->edgemid_angle);
754
755 bpolys[0]->weight_angular *= ang_weights[0] * ang_weights[1];
756 bpolys[1]->weight_angular *= ang_weights[0] * ang_weights[1];
757 }
758 }
759 }
760
761 /* Compute scaling and falloff:
762 * - Scale all weights if no infinite weight is found.
763 * - Scale only un-projected weight if projected weight is infinite.
764 * - Scale none if both are infinite. */
765 if (!inf_weight_flags) {
766 bpoly = bwdata->bind_polys;
767
768 for (int i = 0; i < bwdata->faces_num; bpoly++, i++) {
769 float corner_angle_weights[2];
770 float scale_weight, sqr, inv_sqr;
771
772 corner_angle_weights[0] = bpoly->point_edgemid_angles[0] / bpoly->corner_edgemid_angles[0];
773 corner_angle_weights[1] = bpoly->point_edgemid_angles[1] / bpoly->corner_edgemid_angles[1];
774
775 if (isnan(corner_angle_weights[0]) || isnan(corner_angle_weights[1])) {
776 freeBindData(bwdata);
778 return nullptr;
779 }
780
781 /* Find which edge the point is closer to */
782 if (corner_angle_weights[0] < corner_angle_weights[1]) {
783 bpoly->dominant_edge = 0;
784 bpoly->dominant_angle_weight = corner_angle_weights[0];
785 }
786 else {
787 bpoly->dominant_edge = 1;
788 bpoly->dominant_angle_weight = corner_angle_weights[1];
789 }
790
791 /* Check for invalid weights just in case computations fail. */
792 if (bpoly->dominant_angle_weight < 0 || bpoly->dominant_angle_weight > 1) {
793 freeBindData(bwdata);
795 return nullptr;
796 }
797
799
800 /* Compute quadratic angular scale interpolation weight */
801 {
802 const float edge_angle_a = bpoly->point_edgemid_angles[bpoly->dominant_edge];
803 const float edge_angle_b = bpoly->point_edgemid_angles[!bpoly->dominant_edge];
804 /* Clamp so skinny faces with near zero `edgemid_angle`
805 * won't cause numeric problems. see #81988. */
806 scale_weight = edge_angle_a / max_ff(edge_angle_a, bpoly->edgemid_angle);
807 scale_weight /= scale_weight + (edge_angle_b / max_ff(edge_angle_b, bpoly->edgemid_angle));
808 }
809
810 sqr = scale_weight * scale_weight;
811 inv_sqr = 1.0f - scale_weight;
812 inv_sqr *= inv_sqr;
813 scale_weight = sqr / (sqr + inv_sqr);
814
815 BLI_assert(scale_weight >= 0 && scale_weight <= 1);
816
817 /* Compute interpolated scale (no longer need the individual scales,
818 * so simply storing the result over the scale in index zero) */
819 bpoly->scales[0] = interpf(bpoly->scale_mid,
820 interpf(bpoly->scales[!bpoly->dominant_edge],
821 bpoly->scales[bpoly->dominant_edge],
822 scale_weight),
823 bpoly->dominant_angle_weight);
824
825 /* Scale the point distance weights, and introduce falloff */
826 bpoly->weight_dist_proj /= bpoly->scales[0];
827 bpoly->weight_dist_proj = powf(bpoly->weight_dist_proj, data->falloff);
828
829 bpoly->weight_dist /= avg_point_dist;
830 bpoly->weight_dist = powf(bpoly->weight_dist, data->falloff);
831
832 /* Re-check for infinite weights, now that all scalings and interpolations are computed */
833 if (bpoly->weight_dist < FLT_EPSILON) {
834 inf_weight_flags |= MOD_SDEF_INFINITE_WEIGHT_DIST_PROJ;
835 inf_weight_flags |= MOD_SDEF_INFINITE_WEIGHT_DIST;
836 }
837 else if (bpoly->weight_dist_proj < FLT_EPSILON) {
838 inf_weight_flags |= MOD_SDEF_INFINITE_WEIGHT_DIST_PROJ;
839 }
840 else if (bpoly->weight_angular < FLT_EPSILON) {
841 inf_weight_flags |= MOD_SDEF_INFINITE_WEIGHT_ANGULAR;
842 }
843 }
844 }
845 else if (!(inf_weight_flags & MOD_SDEF_INFINITE_WEIGHT_DIST)) {
846 bpoly = bwdata->bind_polys;
847
848 for (int i = 0; i < bwdata->faces_num; bpoly++, i++) {
849 /* Scale the point distance weight by average point distance, and introduce falloff */
850 bpoly->weight_dist /= avg_point_dist;
851 bpoly->weight_dist = powf(bpoly->weight_dist, data->falloff);
852
853 /* Re-check for infinite weights, now that all scalings and interpolations are computed */
854 if (bpoly->weight_dist < FLT_EPSILON) {
855 inf_weight_flags |= MOD_SDEF_INFINITE_WEIGHT_DIST;
856 }
857 }
858 }
859
860 /* Final loop, to compute actual weights */
861 bpoly = bwdata->bind_polys;
862
863 for (int i = 0; i < bwdata->faces_num; bpoly++, i++) {
864 /* Weight computation from components */
865 if (inf_weight_flags & MOD_SDEF_INFINITE_WEIGHT_DIST) {
866 bpoly->weight = bpoly->weight_dist < FLT_EPSILON ? 1.0f : 0.0f;
867 }
868 else if (inf_weight_flags & MOD_SDEF_INFINITE_WEIGHT_DIST_PROJ) {
869 bpoly->weight = bpoly->weight_dist_proj < FLT_EPSILON ? 1.0f / bpoly->weight_dist : 0.0f;
870 }
871 else if (inf_weight_flags & MOD_SDEF_INFINITE_WEIGHT_ANGULAR) {
872 bpoly->weight = bpoly->weight_angular < FLT_EPSILON ?
873 1.0f / bpoly->weight_dist_proj / bpoly->weight_dist :
874 0.0f;
875 }
876 else {
877 bpoly->weight = 1.0f / bpoly->weight_angular / bpoly->weight_dist_proj / bpoly->weight_dist;
878 }
879
880 /* Apply after other kinds of scaling so the faces corner angle is always
881 * scaled in a uniform way, preventing heavily sub-divided triangle fans
882 * from having a lop-sided influence on the weighting, see #81988. */
883 bpoly->weight *= bpoly->edgemid_angle / M_PI;
884
885 tot_weight += bpoly->weight;
886 }
887
888 bpoly = bwdata->bind_polys;
889
890 for (int i = 0; i < bwdata->faces_num; bpoly++, i++) {
891 bpoly->weight /= tot_weight;
892
893 /* Evaluate if this face is relevant to bind */
894 /* Even though the weights should add up to 1.0,
895 * the losses of weights smaller than epsilon here
896 * should be negligible... */
897 if (bpoly->weight >= FLT_EPSILON) {
898 if (bpoly->inside) {
899 bwdata->binds_num += 1;
900 }
901 else {
902 if (bpoly->dominant_angle_weight < FLT_EPSILON ||
903 1.0f - bpoly->dominant_angle_weight < FLT_EPSILON)
904 {
905 bwdata->binds_num += 1;
906 }
907 else {
908 bwdata->binds_num += 2;
909 }
910 }
911 }
912 }
913
914 return bwdata;
915}
916
917BLI_INLINE float computeNormalDisplacement(const float point_co[3],
918 const float point_co_proj[3],
919 const float normal[3])
920{
921 float disp_vec[3];
922 float normal_dist;
923
924 sub_v3_v3v3(disp_vec, point_co, point_co_proj);
925 normal_dist = len_v3(disp_vec);
926
927 if (dot_v3v3(disp_vec, normal) < 0) {
928 normal_dist *= -1;
929 }
930
931 return normal_dist;
932}
933
934static void bindVert(void *__restrict userdata,
935 const int index,
936 const TaskParallelTLS *__restrict /*tls*/)
937{
938 SDefBindCalcData *const data = static_cast<SDefBindCalcData *>(userdata);
939 float point_co[3];
940 float point_co_proj[3];
941
942 SDefBindWeightData *bwdata;
943 SDefVert *sdvert = data->bind_verts + index;
944 SDefBindPoly *bpoly;
945 SDefBind *sdbind;
946
947 sdvert->vertex_idx = index;
948
949 if (data->success != MOD_SDEF_BIND_RESULT_SUCCESS) {
950 sdvert->binds = nullptr;
951 sdvert->binds_num = 0;
952 return;
953 }
954
955 if (data->sparse_bind) {
956 float weight = 0.0f;
957
958 if (data->dvert && data->defgrp_index != -1) {
959 weight = BKE_defvert_find_weight(&data->dvert[index], data->defgrp_index);
960 }
961
962 if (data->invert_vgroup) {
963 weight = 1.0f - weight;
964 }
965
966 if (weight <= 0) {
967 sdvert->binds = nullptr;
968 sdvert->binds_num = 0;
969 return;
970 }
971 }
972
973 copy_v3_v3(point_co, data->vertexCos[index]);
974 bwdata = computeBindWeights(data, point_co);
975
976 if (bwdata == nullptr) {
977 sdvert->binds = nullptr;
978 sdvert->binds_num = 0;
979 return;
980 }
981
982 sdvert->binds = MEM_new_array<SDefBind>(bwdata->binds_num, "SDefVertBindData");
983 if (sdvert->binds == nullptr) {
985 sdvert->binds_num = 0;
986 return;
987 }
988
989 sdvert->binds_num = bwdata->binds_num;
990
991 sdbind = sdvert->binds;
992
993 bpoly = bwdata->bind_polys;
994
995 for (int i = 0; i < bwdata->binds_num; bpoly++) {
996 if (bpoly->weight >= FLT_EPSILON) {
997 if (bpoly->inside) {
998 sdbind->influence = bpoly->weight;
999 sdbind->verts_num = bpoly->verts_num;
1000
1001 sdbind->mode = MOD_SDEF_MODE_NGONS;
1003 "SDefNgonVertWeights");
1004 if (sdbind->vert_weights == nullptr) {
1006 return;
1007 }
1008
1009 sdbind->vert_inds = MEM_new_array_uninitialized<uint>(size_t(bpoly->verts_num),
1010 "SDefNgonVertInds");
1011 if (sdbind->vert_inds == nullptr) {
1013 return;
1014 }
1015
1017 sdbind->vert_weights, bpoly->coords_v2, bpoly->verts_num, bpoly->point_v2);
1018
1019 /* Re-project vert based on weights and original face verts,
1020 * to reintroduce face non-planarity */
1021 zero_v3(point_co_proj);
1022 for (int j = 0; j < bpoly->verts_num; j++) {
1023 const int vert_i = data->corner_verts[bpoly->loopstart + j];
1024 madd_v3_v3fl(point_co_proj, bpoly->coords[j], sdbind->vert_weights[j]);
1025 sdbind->vert_inds[j] = vert_i;
1026 }
1027
1028 sdbind->normal_dist = computeNormalDisplacement(point_co, point_co_proj, bpoly->normal);
1029
1030 sdbind++;
1031 i++;
1032 }
1033 else {
1034 float tmp_vec[3];
1035 float cent[3], norm[3];
1036 float v1[3], v2[3], v3[3];
1037
1038 if (1.0f - bpoly->dominant_angle_weight >= FLT_EPSILON) {
1039 sdbind->influence = bpoly->weight * (1.0f - bpoly->dominant_angle_weight);
1040 sdbind->verts_num = bpoly->verts_num;
1041
1042 sdbind->mode = MOD_SDEF_MODE_CENTROID;
1043 sdbind->vert_weights = MEM_new_array_uninitialized<float>(3, "SDefCentVertWeights");
1044 if (sdbind->vert_weights == nullptr) {
1046 return;
1047 }
1048
1049 sdbind->vert_inds = MEM_new_array_uninitialized<uint>(size_t(bpoly->verts_num),
1050 "SDefCentVertInds");
1051 if (sdbind->vert_inds == nullptr) {
1053 return;
1054 }
1055
1057 &data->corner_verts[bpoly->loopstart],
1058 &data->corner_edges[bpoly->loopstart],
1059 bpoly->edge_inds[bpoly->dominant_edge],
1060 bpoly->verts_num);
1061
1062 copy_v3_v3(v1, data->targetCos[sdbind->vert_inds[0]]);
1063 copy_v3_v3(v2, data->targetCos[sdbind->vert_inds[1]]);
1064 copy_v3_v3(v3, bpoly->centroid);
1065
1066 mid_v3_v3v3v3(cent, v1, v2, v3);
1067 normal_tri_v3(norm, v1, v2, v3);
1068
1069 add_v3_v3v3(tmp_vec, point_co, bpoly->normal);
1070
1071 /* We are sure the line is not parallel to the plane.
1072 * Checking return value just to avoid warning... */
1073 if (!isect_line_plane_v3(point_co_proj, point_co, tmp_vec, cent, norm)) {
1074 BLI_assert(false);
1075 }
1076
1077 interp_weights_tri_v3(sdbind->vert_weights, v1, v2, v3, point_co_proj);
1078
1079 sdbind->normal_dist = computeNormalDisplacement(point_co, point_co_proj, bpoly->normal);
1080
1081 sdbind++;
1082 i++;
1083 }
1084
1085 if (bpoly->dominant_angle_weight >= FLT_EPSILON) {
1086 sdbind->influence = bpoly->weight * bpoly->dominant_angle_weight;
1087 sdbind->verts_num = bpoly->verts_num;
1088
1090 sdbind->vert_weights = MEM_new_array_uninitialized<float>(3, "SDefTriVertWeights");
1091 if (sdbind->vert_weights == nullptr) {
1093 return;
1094 }
1095
1096 sdbind->vert_inds = MEM_new_array_uninitialized<uint>(size_t(bpoly->verts_num),
1097 "SDefTriVertInds");
1098 if (sdbind->vert_inds == nullptr) {
1100 return;
1101 }
1102
1104 &data->corner_verts[bpoly->loopstart],
1105 bpoly->edge_vert_inds[0],
1106 bpoly->verts_num);
1107
1108 copy_v3_v3(v1, data->targetCos[sdbind->vert_inds[0]]);
1109 copy_v3_v3(v2, data->targetCos[sdbind->vert_inds[1]]);
1110 copy_v3_v3(v3, data->targetCos[sdbind->vert_inds[2]]);
1111
1112 mid_v3_v3v3v3(cent, v1, v2, v3);
1113 normal_tri_v3(norm, v1, v2, v3);
1114
1115 add_v3_v3v3(tmp_vec, point_co, bpoly->normal);
1116
1117 /* We are sure the line is not parallel to the plane.
1118 * Checking return value just to avoid warning... */
1119 if (!isect_line_plane_v3(point_co_proj, point_co, tmp_vec, cent, norm)) {
1120 BLI_assert(false);
1121 }
1122
1123 interp_weights_tri_v3(sdbind->vert_weights, v1, v2, v3, point_co_proj);
1124
1125 sdbind->normal_dist = computeNormalDisplacement(point_co, point_co_proj, bpoly->normal);
1126
1127 sdbind++;
1128 i++;
1129 }
1130 }
1131 }
1132 }
1133
1134 freeBindData(bwdata);
1135}
1136
1137/* Remove vertices without bind data from the bind array. */
1139{
1140 smd->bind_verts_num = 0;
1141
1142 for (uint i = 0; i < smd->mesh_verts_num; i++) {
1143 if (smd->verts[i].binds_num > 0) {
1144 smd->bind_verts_num++;
1145 }
1146 }
1147
1148 SDefVert *new_verts = MEM_new_array<SDefVert>(size_t(smd->bind_verts_num), __func__);
1149
1150 /* Move data to new_verts. */
1152 int dst_index = 0;
1153 for (uint i = 0; i < smd->mesh_verts_num; i++) {
1154 if (smd->verts[i].binds_num > 0) {
1155 new_verts[dst_index++] = smd->verts[i];
1156 smd->verts[i] = {};
1157 }
1158 }
1159
1161 smd->verts = new_verts;
1162 smd->verts_sharing_info = MEM_new<BindVertsImplicitSharing>(
1163 __func__, smd->verts, smd->bind_verts_num);
1164}
1165
1167 SurfaceDeformModifierData *smd_orig,
1168 SurfaceDeformModifierData *smd_eval,
1169 float (*vertexCos)[3],
1170 uint verts_num,
1171 uint target_faces_num,
1172 uint target_verts_num,
1173 Mesh *target,
1174 Mesh *mesh)
1175{
1176 const Span<float3> positions = target->vert_positions();
1177 const Span<int2> edges = target->edges();
1178 const OffsetIndices polys = target->faces();
1179 const Span<int> corner_verts = target->corner_verts();
1180 const Span<int> corner_edges = target->corner_edges();
1181 uint tedges_num = target->edges_num;
1182 int adj_result;
1183
1184 if (target->faces_num == 0) {
1185 BKE_modifier_set_error(ob, reinterpret_cast<ModifierData *>(smd_eval), "Target has no faces");
1186 return false;
1187 }
1188
1189 SDefAdjacencyArray *vert_edges = MEM_new_array_zeroed<SDefAdjacencyArray>(target_verts_num,
1190 "SDefVertEdgeMap");
1191 if (vert_edges == nullptr) {
1192 BKE_modifier_set_error(ob, reinterpret_cast<ModifierData *>(smd_eval), "Out of memory");
1193 return false;
1194 }
1195
1196 SDefAdjacency *adj_array = MEM_new_array_uninitialized<SDefAdjacency>(2 * size_t(tedges_num),
1197 "SDefVertEdge");
1198 if (adj_array == nullptr) {
1199 BKE_modifier_set_error(ob, reinterpret_cast<ModifierData *>(smd_eval), "Out of memory");
1200 MEM_delete(vert_edges);
1201 return false;
1202 }
1203
1204 SDefEdgePolys *edge_polys = MEM_new_array_zeroed<SDefEdgePolys>(tedges_num, "SDefEdgeFaceMap");
1205 if (edge_polys == nullptr) {
1206 BKE_modifier_set_error(ob, reinterpret_cast<ModifierData *>(smd_eval), "Out of memory");
1207 MEM_delete(vert_edges);
1208 MEM_delete(adj_array);
1209 return false;
1210 }
1211
1212 smd_orig->verts = MEM_new_array<SDefVert>(size_t(verts_num), "SDefBindVerts");
1213 if (smd_orig->verts == nullptr) {
1214 BKE_modifier_set_error(ob, reinterpret_cast<ModifierData *>(smd_eval), "Out of memory");
1215 freeAdjacencyMap(vert_edges, adj_array, edge_polys);
1216 return false;
1217 }
1218 smd_orig->verts_sharing_info = MEM_new<BindVertsImplicitSharing>(
1219 __func__, smd_orig->verts, verts_num);
1220
1221 const bke::bvh::Tree &treeData = target->bvh_tris();
1222
1223 adj_result = buildAdjacencyMap(polys, edges, corner_edges, vert_edges, adj_array, edge_polys);
1224
1225 if (adj_result == MOD_SDEF_BIND_RESULT_NONMANY_ERR) {
1227 reinterpret_cast<ModifierData *>(smd_eval),
1228 "Target has edges with more than two polygons");
1229 freeAdjacencyMap(vert_edges, adj_array, edge_polys);
1231 return false;
1232 }
1233
1234 smd_orig->mesh_verts_num = verts_num;
1235 smd_orig->target_verts_num = target_verts_num;
1236 smd_orig->target_polys_num = target_faces_num;
1237
1238 int defgrp_index;
1239 const MDeformVert *dvert;
1240 MOD_get_vgroup(ob, mesh, smd_orig->defgrp_name, &dvert, &defgrp_index);
1241 const bool invert_vgroup = (smd_orig->flags & MOD_SDEF_INVERT_VGROUP) != 0;
1242 const bool sparse_bind = (smd_orig->flags & MOD_SDEF_SPARSE_BIND) != 0;
1243
1245 data.treeData = &treeData;
1246 data.vert_edges = vert_edges;
1247 data.edge_polys = edge_polys;
1248 data.polys = polys;
1249 data.edges = edges;
1250 data.corner_verts = corner_verts;
1251 data.corner_edges = corner_edges;
1252 data.corner_tris = target->corner_tris();
1253 data.tri_faces = target->corner_tri_faces();
1254 data.targetCos = MEM_new_array_uninitialized<float[3]>(size_t(target_verts_num),
1255 "SDefTargetBindVertArray");
1256 data.bind_verts = smd_orig->verts;
1257 data.vertexCos = vertexCos;
1258 data.falloff = smd_orig->falloff;
1260 data.dvert = dvert;
1261 data.defgrp_index = defgrp_index;
1262 data.invert_vgroup = invert_vgroup;
1263 data.sparse_bind = sparse_bind;
1264
1265 if (data.targetCos == nullptr) {
1266 BKE_modifier_set_error(ob, reinterpret_cast<ModifierData *>(smd_eval), "Out of memory");
1267 free_data(reinterpret_cast<ModifierData *>(smd_orig));
1268 return false;
1269 }
1270
1271 invert_m4_m4(data.imat, smd_orig->mat);
1272
1273 for (int i = 0; i < target_verts_num; i++) {
1274 mul_v3_m4v3(data.targetCos[i], smd_orig->mat, positions[i]);
1275 }
1276
1277 TaskParallelSettings settings;
1279 settings.use_threading = (verts_num > 10000);
1280 BLI_task_parallel_range(0, verts_num, &data, bindVert, &settings);
1281
1282 MEM_delete(data.targetCos);
1283
1284 if (sparse_bind) {
1285 compactSparseBinds(smd_orig);
1286 }
1287 else {
1288 smd_orig->bind_verts_num = verts_num;
1289 }
1290
1291 if (data.success == MOD_SDEF_BIND_RESULT_MEM_ERR) {
1292 BKE_modifier_set_error(ob, reinterpret_cast<ModifierData *>(smd_eval), "Out of memory");
1293 free_data(reinterpret_cast<ModifierData *>(smd_orig));
1294 }
1295 else if (data.success == MOD_SDEF_BIND_RESULT_NONMANY_ERR) {
1297 reinterpret_cast<ModifierData *>(smd_eval),
1298 "Target has edges with more than two polygons");
1299 free_data(reinterpret_cast<ModifierData *>(smd_orig));
1300 }
1301 else if (data.success == MOD_SDEF_BIND_RESULT_CONCAVE_ERR) {
1303 ob, reinterpret_cast<ModifierData *>(smd_eval), "Target contains concave polygons");
1304 free_data(reinterpret_cast<ModifierData *>(smd_orig));
1305 }
1306 else if (data.success == MOD_SDEF_BIND_RESULT_OVERLAP_ERR) {
1308 ob, reinterpret_cast<ModifierData *>(smd_eval), "Target contains overlapping vertices");
1309 free_data(reinterpret_cast<ModifierData *>(smd_orig));
1310 }
1311 else if (data.success == MOD_SDEF_BIND_RESULT_GENERIC_ERR) {
1312 /* I know this message is vague, but I could not think of a way
1313 * to explain this with a reasonably sized message.
1314 * Though it shouldn't really matter all that much,
1315 * because this is very unlikely to occur */
1317 ob, reinterpret_cast<ModifierData *>(smd_eval), "Target contains invalid polygons");
1318 free_data(reinterpret_cast<ModifierData *>(smd_orig));
1319 }
1320 else if (smd_orig->bind_verts_num == 0 || !smd_orig->verts) {
1323 ob, reinterpret_cast<ModifierData *>(smd_eval), "No vertices were bound");
1324 free_data(reinterpret_cast<ModifierData *>(smd_orig));
1325 }
1326
1327 freeAdjacencyMap(vert_edges, adj_array, edge_polys);
1328
1329 return data.success == 1;
1330}
1331
1332static void deformVert(void *__restrict userdata,
1333 const int index,
1334 const TaskParallelTLS *__restrict /*tls*/)
1335{
1336 const SDefDeformData *const data = static_cast<SDefDeformData *>(userdata);
1337 const SDefBind *sdbind = data->bind_verts[index].binds;
1338 const int sdbind_num = data->bind_verts[index].binds_num;
1339 const uint vertex_idx = data->bind_verts[index].vertex_idx;
1340 float *const vertexCos = data->vertexCos[vertex_idx];
1341 float norm[3], temp[3], offset[3];
1342
1343 /* Retrieve the value of the weight vertex group if specified. */
1344 float weight = 1.0f;
1345
1346 if (data->dvert && data->defgrp_index != -1) {
1347 weight = BKE_defvert_find_weight(&data->dvert[vertex_idx], data->defgrp_index);
1348
1349 if (data->invert_vgroup) {
1350 weight = 1.0f - weight;
1351 }
1352 }
1353
1354 /* Check if this vertex will be deformed. If it is not deformed we return and avoid
1355 * unnecessary calculations. */
1356 if (weight == 0.0f) {
1357 return;
1358 }
1359
1360 zero_v3(offset);
1361
1362 int max_verts = 0;
1363 for (int j = 0; j < sdbind_num; j++) {
1364 max_verts = std::max(max_verts, int(sdbind[j].verts_num));
1365 }
1366
1367 /* Allocate a `coords_buffer` that fits all the temp-data. */
1368 Array<float3, 256> coords_buffer(max_verts);
1369
1370 for (int j = 0; j < sdbind_num; j++, sdbind++) {
1371 for (int k = 0; k < sdbind->verts_num; k++) {
1372 copy_v3_v3(coords_buffer[k], data->targetCos[sdbind->vert_inds[k]]);
1373 }
1374
1376 norm, reinterpret_cast<const float (*)[3]>(coords_buffer.data()), sdbind->verts_num);
1377 zero_v3(temp);
1378
1379 switch (sdbind->mode) {
1380 /* ---------- corner_tri mode ---------- */
1382 madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[0]], sdbind->vert_weights[0]);
1383 madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[1]], sdbind->vert_weights[1]);
1384 madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[2]], sdbind->vert_weights[2]);
1385 break;
1386 }
1387
1388 /* ---------- ngon mode ---------- */
1389 case MOD_SDEF_MODE_NGONS: {
1390 for (int k = 0; k < sdbind->verts_num; k++) {
1391 madd_v3_v3fl(temp, coords_buffer[k], sdbind->vert_weights[k]);
1392 }
1393 break;
1394 }
1395
1396 /* ---------- centroid mode ---------- */
1398 float cent[3];
1400 cent, reinterpret_cast<const float (*)[3]>(coords_buffer.data()), sdbind->verts_num);
1401
1402 madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[0]], sdbind->vert_weights[0]);
1403 madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[1]], sdbind->vert_weights[1]);
1404 madd_v3_v3fl(temp, cent, sdbind->vert_weights[2]);
1405 break;
1406 }
1407 }
1408
1409 /* Apply normal offset (generic for all modes) */
1410 madd_v3_v3fl(temp, norm, sdbind->normal_dist);
1411
1412 madd_v3_v3fl(offset, temp, sdbind->influence);
1413 }
1414 /* Subtract the vertex coord to get the deformation offset. */
1415 sub_v3_v3(offset, vertexCos);
1416
1417 /* Add the offset to start coord multiplied by the strength and weight values. */
1418 madd_v3_v3fl(vertexCos, offset, data->strength * weight);
1419}
1420
1422 const ModifierEvalContext *ctx,
1423 float (*vertexCos)[3],
1424 uint verts_num,
1425 Object *ob,
1426 Mesh *mesh)
1427{
1428 SurfaceDeformModifierData *smd = reinterpret_cast<SurfaceDeformModifierData *>(md);
1429 Mesh *target;
1430 uint target_verts_num, target_faces_num;
1431
1432 /* Exit function if bind flag is not set (free bind data if any). */
1433 if (!(smd->flags & MOD_SDEF_BIND)) {
1434 if (smd->verts != nullptr) {
1435 if (!DEG_is_active(ctx->depsgraph)) {
1436 BKE_modifier_set_error(ob, md, "Attempt to bind from inactive dependency graph");
1437 return;
1438 }
1439 ModifierData *md_orig = BKE_modifier_get_original(ob, md);
1440 free_data(md_orig);
1441 }
1442 return;
1443 }
1444
1445 Object *ob_target = smd->target;
1447 if (!target) {
1448 BKE_modifier_set_error(ob, md, "No valid target mesh");
1449 return;
1450 }
1451
1452 target_verts_num = BKE_mesh_wrapper_vert_len(target);
1453 target_faces_num = BKE_mesh_wrapper_face_len(target);
1454
1455 /* If not bound, execute bind. */
1456 if (smd->verts == nullptr) {
1457 if (!DEG_is_active(ctx->depsgraph)) {
1458 BKE_modifier_set_error(ob, md, "Attempt to unbind from inactive dependency graph");
1459 return;
1460 }
1461
1462 SurfaceDeformModifierData *smd_orig = reinterpret_cast<SurfaceDeformModifierData *>(
1464 float tmp_mat[4][4];
1465
1466 invert_m4_m4(tmp_mat, ob->object_to_world().ptr());
1467 mul_m4_m4m4(smd_orig->mat, tmp_mat, ob_target->object_to_world().ptr());
1468
1469 /* Avoid converting edit-mesh data, binding is an exception. */
1471
1472 if (!surfacedeformBind(ob,
1473 smd_orig,
1474 smd,
1475 vertexCos,
1476 verts_num,
1477 target_faces_num,
1478 target_verts_num,
1479 target,
1480 mesh))
1481 {
1482 smd->flags &= ~MOD_SDEF_BIND;
1483 }
1484 /* Early abort, this is binding 'call', no need to perform whole evaluation. */
1485 return;
1486 }
1487
1488 /* Geometry count on the deforming mesh. */
1489 if (smd->mesh_verts_num != verts_num) {
1491 ob, md, "Vertices changed from %u to %u", smd->mesh_verts_num, verts_num);
1492 return;
1493 }
1494
1495 /* Geometry count on the target mesh. */
1496 if (smd->target_polys_num != target_faces_num && smd->target_verts_num == 0) {
1497 /* Change in the number of polygons does not really imply change in the vertex count, but
1498 * this is how the modifier worked before the vertex count was known. Follow the legacy
1499 * logic without requirement to re-bind the mesh. */
1501 ob, md, "Target polygons changed from %u to %u", smd->target_polys_num, target_faces_num);
1502 return;
1503 }
1504 if (!ELEM(smd->target_verts_num, 0, target_verts_num)) {
1505 if (smd->target_verts_num > target_verts_num) {
1506 /* Number of vertices on the target did reduce. There is no usable recovery from this. */
1508 md,
1509 "Target vertices changed from %u to %u",
1510 smd->target_verts_num,
1511 target_verts_num);
1512 return;
1513 }
1514
1515 /* Assume the increase in the vertex count means that the "new" vertices in the target mesh are
1516 * added after the original ones. This covers typical case when target was at the subdivision
1517 * level 0 and then subdivision was increased (i.e. for the render purposes). */
1518
1520 md,
1521 "Target vertices changed from %u to %u, continuing anyway",
1522 smd->target_verts_num,
1523 target_verts_num);
1524
1525 /* In theory we only need the `smd->verts_num` vertices in the `targetCos` for evaluation, but
1526 * it is not currently possible to request a subset of coordinates: the API expects that the
1527 * caller needs coordinates of all vertices and asserts for it. */
1528 }
1529
1530 /* Early out if modifier would not affect input at all - still *after* the sanity checks
1531 * (and potential binding) above. */
1532 if (smd->strength == 0.0f) {
1533 return;
1534 }
1535
1536 int defgrp_index;
1537 const MDeformVert *dvert;
1538 MOD_get_vgroup(ob, mesh, smd->defgrp_name, &dvert, &defgrp_index);
1539 const bool invert_vgroup = (smd->flags & MOD_SDEF_INVERT_VGROUP) != 0;
1540
1541 /* Actual vertex location update starts here */
1543 data.bind_verts = smd->verts;
1544 data.targetCos = MEM_new_array_uninitialized<float[3]>(size_t(target_verts_num),
1545 "SDefTargetVertArray");
1546 data.vertexCos = vertexCos;
1547 data.dvert = dvert;
1548 data.defgrp_index = defgrp_index;
1549 data.invert_vgroup = invert_vgroup;
1550 data.strength = smd->strength;
1551
1552 if (data.targetCos != nullptr) {
1554 target, data.targetCos, target_verts_num, smd->mat);
1555
1556 TaskParallelSettings settings;
1558 settings.use_threading = (smd->bind_verts_num > 10000);
1560
1561 MEM_delete(data.targetCos);
1562 }
1563}
1564
1566 const ModifierEvalContext *ctx,
1567 Mesh *mesh,
1568 MutableSpan<float3> positions)
1569{
1571 ctx,
1572 reinterpret_cast<float (*)[3]>(positions.data()),
1573 positions.size(),
1574 ctx->object,
1575 mesh);
1576}
1577
1578static bool is_disabled(const Scene * /*scene*/, ModifierData *md, bool /*use_render_params*/)
1579{
1580 SurfaceDeformModifierData *smd = reinterpret_cast<SurfaceDeformModifierData *>(md);
1581
1582 /* The object type check is only needed here in case we have a placeholder
1583 * object assigned (because the library containing the mesh is missing).
1584 *
1585 * In other cases it should be impossible to have a type mismatch.
1586 */
1587 return (smd->target == nullptr || smd->target->type != OB_MESH) &&
1588 !(smd->verts != nullptr && !(smd->flags & MOD_SDEF_BIND));
1589}
1590
1591static void panel_draw(const bContext * /*C*/, Panel *panel)
1592{
1593 ui::Layout &layout = *panel->layout;
1594
1595 PointerRNA ob_ptr;
1596 PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr);
1597
1598 PointerRNA target_ptr = RNA_pointer_get(ptr, "target");
1599
1600 bool is_bound = RNA_boolean_get(ptr, "is_bound");
1601
1602 layout.use_property_split_set(true);
1603
1604 ui::Layout *col = &layout.column(false);
1605 col->active_set(!is_bound);
1606 col->prop(ptr, "target", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1607 col->prop(ptr, "falloff", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1608
1609 layout.prop(ptr, "strength", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1610
1611 modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", std::nullopt);
1612
1613 col = &layout.column(false);
1614 col->enabled_set(!is_bound);
1615 col->active_set(!is_bound && RNA_string_length(ptr, "vertex_group") != 0);
1616 col->prop(ptr, "use_sparse_bind", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1617
1618 layout.separator();
1619
1620 col = &layout.column(false);
1621 if (is_bound) {
1622 col->op("OBJECT_OT_surfacedeform_bind", IFACE_("Unbind"), ICON_NONE);
1623 }
1624 else {
1625 col->active_set(target_ptr);
1626 col->op("OBJECT_OT_surfacedeform_bind", IFACE_("Bind"), ICON_NONE);
1627 }
1628 modifier_error_message_draw(layout, ptr);
1629}
1630
1631static void panel_register(ARegionType *region_type)
1632{
1634}
1635
1636static void blend_write(BlendWriter *writer, const ID *id_owner, const ModifierData *md)
1637{
1638 const SurfaceDeformModifierData *smd = reinterpret_cast<const SurfaceDeformModifierData *>(md);
1639 const bool is_undo = writer->is_undo();
1640 const bool without_bind_data = ID_IS_OVERRIDE_LIBRARY(id_owner) && !is_undo &&
1642 if (without_bind_data) {
1643 /* Modifier coming from linked data cannot be bound from an override, so we can remove all
1644 * binding data, can save a significant amount of memory. */
1645 BLI_assert(!ID_IS_LINKED(id_owner));
1646 writer->write_struct(smd, [](BlendStructWriter<SurfaceDeformModifierData> &struct_writer) {
1647 struct_writer.shallow_data.bind_verts_num = 0;
1648 struct_writer.shallow_data.verts = nullptr;
1649 struct_writer.shallow_data.verts_sharing_info = nullptr;
1650 });
1651 return;
1652 }
1653
1654 if (smd->verts != nullptr) {
1655 writer->write_shared(
1656 smd->verts, sizeof(SDefVert) * smd->bind_verts_num, smd->verts_sharing_info, [&]() {
1657 const SDefVert *bind_verts = smd->verts;
1658 writer->write_struct_array(smd->bind_verts_num, bind_verts);
1659
1660 for (int i = 0; i < smd->bind_verts_num; i++) {
1661 writer->write_struct_array(bind_verts[i].binds_num, bind_verts[i].binds);
1662
1663 if (bind_verts[i].binds) {
1664 for (int j = 0; j < bind_verts[i].binds_num; j++) {
1665 writer->write_uint32_array(bind_verts[i].binds[j].verts_num,
1666 bind_verts[i].binds[j].vert_inds);
1667
1668 if (ELEM(bind_verts[i].binds[j].mode,
1669 MOD_SDEF_MODE_CENTROID,
1670 MOD_SDEF_MODE_CORNER_TRIS))
1671 {
1672 writer->write_float3_array(1, bind_verts[i].binds[j].vert_weights);
1673 }
1674 else {
1675 writer->write_float_array(bind_verts[i].binds[j].verts_num,
1676 bind_verts[i].binds[j].vert_weights);
1677 }
1678 }
1679 }
1680 }
1681 });
1682 }
1683
1684 writer->write_struct(smd);
1685}
1686
1687static void blend_read(BlendDataReader *reader, ModifierData *md)
1688{
1689 SurfaceDeformModifierData *smd = reinterpret_cast<SurfaceDeformModifierData *>(md);
1690
1691 if (smd->verts) {
1692 smd->verts_sharing_info = BLO_read_shared(reader, &smd->verts, [&]() {
1693 BLO_read_array_and_validate_size(reader, &smd->verts, &smd->bind_verts_num);
1694 for (int i = 0; i < smd->bind_verts_num; i++) {
1695 BLO_read_array_and_validate_size(reader, &smd->verts[i].binds, &smd->verts[i].binds_num);
1696
1697 if (smd->verts[i].binds) {
1698 for (int j = 0; j < smd->verts[i].binds_num; j++) {
1699 SDefBind &bind = smd->verts[i].binds[j];
1700 bool ok = BLO_read_array(reader, &bind.vert_inds, bind.verts_num);
1701 if (ELEM(bind.mode, MOD_SDEF_MODE_CENTROID, MOD_SDEF_MODE_CORNER_TRIS)) {
1702 ok &= BLO_read_array(reader, &bind.vert_weights, 1, 3);
1703 }
1704 else {
1705 ok &= BLO_read_array(reader, &bind.vert_weights, bind.verts_num);
1706 }
1707 if (!ok) {
1708 bind.verts_num = 0;
1709 bind.vert_inds = nullptr;
1710 bind.vert_weights = nullptr;
1711 }
1712 }
1713 }
1714 }
1715 return MEM_new<BindVertsImplicitSharing>(
1716 "BindVertsImplicitSharing", smd->verts, smd->bind_verts_num);
1717 });
1718 }
1719}
1720
1722 /*idname*/ "SurfaceDeform",
1723 /*name*/ N_("SurfaceDeform"),
1724 /*struct_name*/ "SurfaceDeformModifierData",
1725 /*struct_size*/ sizeof(SurfaceDeformModifierData),
1726 /*srna*/ &RNA_SurfaceDeformModifier,
1729 /*icon*/ ICON_MOD_MESHDEFORM,
1730
1731 /*copy_data*/ copy_data,
1732
1733 /*deform_verts*/ deform_verts,
1734 /*deform_matrices*/ nullptr,
1735 /*deform_verts_EM*/ nullptr,
1736 /*deform_matrices_EM*/ nullptr,
1737 /*modify_mesh*/ nullptr,
1738 /*modify_geometry_set*/ nullptr,
1739
1740 /*init_data*/ init_data,
1741 /*required_data_mask*/ required_data_mask,
1742 /*free_data*/ free_data,
1743 /*is_disabled*/ is_disabled,
1744 /*update_depsgraph*/ update_depsgraph,
1745 /*depends_on_time*/ nullptr,
1746 /*depends_on_normals*/ nullptr,
1747 /*foreach_ID_link*/ foreach_ID_link,
1748 /*foreach_tex_link*/ nullptr,
1749 /*free_runtime_data*/ nullptr,
1750 /*panel_register*/ panel_register,
1751 /*blend_write*/ blend_write,
1752 /*blend_read*/ blend_read,
1753 /*foreach_cache*/ nullptr,
1754 /*foreach_working_space_color*/ nullptr,
1755};
1756
1757} // namespace blender
support for deformation groups and hooks.
#define M_PI_2
#define M_PI
#define IFACE_(msgid)
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define UI_ITEM_NONE
#define BLI_INLINE
#define INIT_DEFAULT_STRUCT_AFTER(struct_dst, member)
#define ELEM(...)
#define CD_MASK_MDEFORMVERT
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Definition btVector3.h:263
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
const T * data() const
Definition BLI_array.hh:323
BindVertsImplicitSharing(SDefVert *data, int bind_verts_num)
constexpr int64_t size() const
constexpr int64_t start() const
constexpr int64_t size() const
Definition BLI_span.hh:499
constexpr T * data() const
Definition BLI_span.hh:545
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
#define powf(x, y)
#define FLT_MAX
#define FLT_EPSILON
#define isnan
void copy_shared_pointer(T *src_ptr, const ImplicitSharingInfo *src_sharing_info, T **r_dst_ptr, const ImplicitSharingInfo **r_dst_sharing_info)
void free_shared_data(T **data, const ImplicitSharingInfo **sharing_info)
BMesh Iterators.
MINLINE float min_ff(float a, float b)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
const ImplicitSharingInfo * BLO_read_shared(BlendDataReader *reader, T **data_ptr, FunctionRef< const ImplicitSharingInfo *()> read_fn)
static void blend_write(BlendWriter *writer, const ID *, const ModifierData *md)
Definition MOD_bevel.cc:454
void BKE_modifier_set_error(const Object *ob, ModifierData *md, const char *format,...) ATTR_PRINTF_FORMAT(3
PointerRNA * modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
void void BKE_modifier_set_warning(const Object *ob, ModifierData *md, const char *format,...) ATTR_PRINTF_FORMAT(3
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static int buildAdjacencyMap(const OffsetIndices< int > polys, const Span< int2 > edges, const Span< int > corner_edges, SDefAdjacencyArray *const vert_edges, SDefAdjacency *adj, SDefEdgePolys *const edge_polys)
bool DEG_is_active(const Depsgraph *depsgraph)
Definition depsgraph.cc:324
BLI_INLINE void sortPolyVertsTri(uint *indices, const int *const corner_verts, const uint loopstart, const uint num)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
static void surfacedeformModifier_do(ModifierData *md, const ModifierEvalContext *ctx, float(*vertexCos)[3], uint verts_num, Object *ob, Mesh *mesh)
void mid_v3_v3v3v3(float v[3], const float v1[3], const float v2[3], const float v3[3])
static bool surfacedeformBind(Object *ob, SurfaceDeformModifierData *smd_orig, SurfaceDeformModifierData *smd_eval, float(*vertexCos)[3], uint verts_num, uint target_faces_num, uint target_verts_num, Mesh *target, Mesh *mesh)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
MINLINE void copy_v2_v2(float r[2], const float a[2])
BLI_INLINE float computeAngularWeight(const float point_angle, const float edgemid_angle)
float normal_poly_v3(float n[3], const float verts[][3], unsigned int nr)
Definition math_geom.cc:83
void MOD_get_vgroup(const Object *ob, const Mesh *mesh, const char *name, const MDeformVert **dvert, int *defgrp_index)
Definition MOD_util.cc:158
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
@ eModifierType_SurfaceDeform
static void init_data(ModifierData *md)
void(*)(void *user_data, Object *ob, ID **idpoin, LibraryForeachIDCallbackFlag cb_flag) IDWalkFunc
static void update_depsgraph(tGraphSliderOp *gso)
BLI_INLINE uint nearestVert(SDefBindCalcData *const data, const float point_co[3])
float angle_signed_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
void BKE_mesh_wrapper_ensure_mdata(Mesh *mesh)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
MINLINE float normalize_v2(float n[2])
void BKE_mesh_wrapper_vert_coords_copy_with_mat4(const Mesh *mesh, float(*vert_coords)[3], int vert_coords_len, const float mat[4][4])
int BKE_mesh_wrapper_face_len(const Mesh *mesh)
void BLI_task_parallel_range(int start, int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
void DEG_add_object_relation(DepsNodeHandle *node_handle, Object *object, eDepsObjectComponentType component, const char *description)
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
Definition math_geom.cc:45
BLI_INLINE float computeNormalDisplacement(const float point_co[3], const float point_co_proj[3], const float normal[3])
ModifierTypeInfo modifierType_SurfaceDeform
static void required_data_mask(ModifierData *, CustomData_MeshMasks *r_cddata_masks)
static void freeBindData(SDefBindWeightData *const bwdata)
MINLINE void sub_v3_v3(float r[3], const float a[3])
Mesh * BKE_modifier_get_evaluated_mesh_from_evaluated_object(Object *ob_eval)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
void modifier_error_message_draw(ui::Layout &layout, PointerRNA *ptr)
float BKE_defvert_find_weight(const MDeformVert *dvert, int defgroup)
Definition deform.cc:779
float angle_normalized_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
void modifier_vgroup_ui(ui::Layout &layout, PointerRNA *ptr, PointerRNA *ob_ptr, const StringRefNull vgroup_prop, const std::optional< StringRefNull > invert_vgroup_prop, const std::optional< StringRefNull > text)
VecBase< int32_t, 2 > int2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
@ MOD_SDEF_INFINITE_WEIGHT_DIST_PROJ
@ MOD_SDEF_INFINITE_WEIGHT_DIST
@ MOD_SDEF_INFINITE_WEIGHT_ANGULAR
@ MOD_SDEF_BIND_RESULT_OVERLAP_ERR
@ MOD_SDEF_BIND_RESULT_MEM_ERR
@ MOD_SDEF_BIND_RESULT_CONCAVE_ERR
@ MOD_SDEF_BIND_RESULT_GENERIC_ERR
@ MOD_SDEF_BIND_RESULT_SUCCESS
@ MOD_SDEF_BIND_RESULT_NONMANY_ERR
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE float area_tri_v2(const float v1[2], const float v2[2], const float v3[2])
BMesh const char void * data
MINLINE float signf(float f)
static void free_data(ModifierData *md)
float dist_to_line_v2(const float p[2], const float l1[2], const float l2[2])
Definition math_geom.cc:302
static void panel_register(ARegionType *region_type)
void interp_weights_tri_v3(float w[3], const float v1[3], const float v2[3], const float v3[3], const float co[3])
bool isect_point_poly_v2(const float pt[2], const float verts[][2], unsigned int nr)
ATTR_WARN_UNUSED_RESULT const size_t num
int BKE_mesh_wrapper_vert_len(const Mesh *mesh)
float dist_squared_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3])
Definition math_geom.cc:535
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static void bindVert(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
MINLINE void zero_v3(float r[3])
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
void interp_weights_poly_v2(float w[], float v[][2], int n, const float co[2])
@ eModifierTypeFlag_SupportsEditmode
@ eModifierTypeFlag_AcceptsMesh
bool isect_line_plane_v3(float r_isect_co[3], const float l1[3], const float l2[3], const float plane_co[3], const float plane_no[3]) ATTR_WARN_UNUSED_RESULT
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
int RNA_string_length(PointerRNA *ptr, const char *name)
static void blend_read(BlendDataReader *, ModifierData *md)
MINLINE float normalize_v3(float n[3])
BLI_INLINE int isPolyValid(const float coords[][2], const uint nr)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
bool is_poly_convex_v2(const float verts[][2], unsigned int nr)
MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f)
BLI_INLINE void sortPolyVertsEdge(uint *indices, const int *const corner_verts, const int *const corner_edges, const uint edge, const uint num)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
MINLINE float max_ff(float a, float b)
static void freeAdjacencyMap(SDefAdjacencyArray *const vert_edges, SDefAdjacency *const adj_ref, SDefEdgePolys *const edge_polys)
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
PanelType * modifier_panel_register(ARegionType *region_type, ModifierType type, PanelDrawFn draw)
void mid_v2_v2v2(float r[2], const float a[2], const float b[2])
@ eModifierFlag_OverrideLibrary_Local
static void compactSparseBinds(SurfaceDeformModifierData *smd)
static void deformVert(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
static void panel_draw(const bContext *, Panel *panel)
MINLINE float interpf(float target, float origin, float t)
static void deform_verts(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, MutableSpan< float3 > positions)
MINLINE void sub_v2_v2(float r[2], const float a[2])
static bool is_disabled(const Scene *, ModifierData *md, bool)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
BLI_INLINE SDefBindWeightData * computeBindWeights(SDefBindCalcData *const data, const float point_co[3])
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
ModifierData * BKE_modifier_get_original(const Object *object, ModifierData *md)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void map_to_plane_axis_angle_v2_v3v3fl(float r_co[2], const float co[3], const float axis[3], float angle)
MINLINE void zero_v2(float r[2])
void mid_v3_v3_array(float r[3], const float(*vec_arr)[3], unsigned int vec_arr_num)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BKE_modifier_copydata_generic(const ModifierData *md, ModifierData *md_dst, int flag)
#define sqr
#define fabsf
#define sqrtf
#define sinf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
void write_shared(const void *data, size_t approximate_size_in_bytes, const ImplicitSharingInfo *sharing_info, FunctionRef< void()> write_fn)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
bool is_undo() const
ui::Layout * layout
const bke::bvh::Tree * treeData
const SDefAdjacencyArray * vert_edges
const SDefEdgePolys * edge_polys
OffsetIndices< int > polys
SurfaceDeformModifierBindMode mode
const MDeformVert * dvert
const ImplicitSharingInfoHandle * verts_sharing_info
void enabled_set(bool enabled)
void use_property_split_set(bool is_sep)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void active_set(bool active)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
#define N_(msgid)