Blender V5.3
armature_deform.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <cctype>
12#include <cfloat>
13#include <cmath>
14#include <cstdlib>
15#include <cstring>
16
17#include "BLI_listbase.hh"
19#include "BLI_math_matrix_c.hh"
22#include "BLI_math_vector_c.hh"
23#include "BLI_task.hh"
24#include "BLI_task_c.hh"
25
26#include "DNA_action_types.h"
27#include "DNA_armature_types.h"
28#include "DNA_lattice_types.h"
29#include "DNA_listBase.h"
30#include "DNA_mesh_types.h"
31#include "DNA_meshdata_types.h"
32#include "DNA_object_types.h"
33
34#include "BKE_action.hh"
35#include "BKE_armature.hh"
36#include "BKE_customdata.hh"
37#include "BKE_deform.hh"
38#include "BKE_editmesh.hh"
39#include "BKE_lattice.hh"
40#include "BKE_mesh.hh"
41#include "BKE_pose.hh"
42
43#include "MEM_guardedalloc.h"
44
45#include "CLG_log.h"
46
47namespace blender {
48
49static CLG_LogRef LOG = {"geom.armature_deform"};
50
51/* -------------------------------------------------------------------- */
54
55static float bone_envelope_falloff(const float distance_squared,
56 const float closest_radius,
57 const float falloff_distance)
58{
59 if (distance_squared < closest_radius * closest_radius) {
60 return 1.0f;
61 }
62
63 /* Zero influence beyond falloff distance. */
64 if (falloff_distance == 0.0f ||
65 distance_squared >= math::square(closest_radius + falloff_distance))
66 {
67 return 0.0f;
68 }
69
70 /* Compute influence from envelope over the falloff distance. */
71 const float dist_envelope = sqrtf(distance_squared) - closest_radius;
72 return 1.0f - (dist_envelope * dist_envelope) / (falloff_distance * falloff_distance);
73}
74
76 const float3 &head,
77 const float3 &tail,
78 const float radius_head,
79 const float radius_tail,
80 const float falloff_distance)
81{
82 float bone_length;
83 const float3 bone_axis = math::normalize_and_get_length(tail - head, bone_length);
84 /* Distance along the bone axis from head. */
85 const float height = math::dot(position - head, bone_axis);
86
87 if (height < 0.0f) {
88 /* Below the start of the bone use the head radius. */
90 return bone_envelope_falloff(distance_squared, radius_head, falloff_distance);
91 }
92 if (height > bone_length) {
93 /* After the end of the bone use the tail radius. */
95 return bone_envelope_falloff(distance_squared, radius_tail, falloff_distance);
96 }
97 /* Interpolate radius. */
98 const float distance_squared = math::distance_squared(position, head) - height * height;
99 const float closest_radius = bone_length != 0.0f ? math::interpolate(radius_head,
100 radius_tail,
101 height / bone_length) :
102 radius_head;
103 return bone_envelope_falloff(distance_squared, closest_radius, falloff_distance);
104}
105
106namespace bke {
107
112template<bool full_deform> struct BoneDeformLinearMixer {
113
116
117 void accumulate(const bPoseChannel &pchan, const float3 &co, const float weight)
118 {
119 const float4x4 &pose_mat = float4x4(pchan.chan_mat);
120
121 position_delta += weight * (math::transform_point(pose_mat, co) - co);
122 if constexpr (full_deform) {
123 deform += weight * pose_mat.view<3, 3>();
124 }
125 }
126
128 const float3 &co,
129 const float weight,
130 const int index)
131 {
132 const Span<float4x4> pose_mats = Span<Mat4>(pchan.runtime.bbone_deform_mats,
133 pchan.runtime.bbone_segments + 2)
134 .cast<float4x4>();
135 const float4x4 &pose_mat = pose_mats[index + 1];
136
137 position_delta += weight * (math::transform_point(pose_mat, co) - co);
138 if constexpr (full_deform) {
139 deform += weight * pose_mat.view<3, 3>();
140 }
141 }
142
143 void finalize(const float3 & /*co*/,
144 float total,
145 float armature_weight,
146 float3 &r_delta_co,
147 float3x3 &r_deform_mat)
148 {
149 const float scale_factor = armature_weight / total;
150 r_delta_co = position_delta * scale_factor;
151 r_deform_mat = deform * scale_factor;
152 };
153};
154
159template<bool full_deform> struct BoneDeformDualQuaternionMixer {
161
162 void accumulate(const bPoseChannel &pchan, const float3 &co, const float weight)
163 {
164 const DualQuat &deform_quat = pchan.runtime.deform_dual_quat;
165
166 add_weighted_dq_dq_pivot(&dq, &deform_quat, co, weight, full_deform);
167 }
168
170 const float3 &co,
171 const float weight,
172 const int index)
173 {
174 const Span<DualQuat> quats = {pchan.runtime.bbone_dual_quats,
175 pchan.runtime.bbone_segments + 1};
176 const DualQuat &deform_quat = quats[index];
177
178 add_weighted_dq_dq_pivot(&dq, &deform_quat, co, weight, full_deform);
179 }
180
181 void finalize(const float3 &co,
182 float total,
183 float armature_weight,
184 float3 &r_delta_co,
185 float3x3 &r_deform_mat)
186 {
187 normalize_dq(&dq, total);
188 float3 dco = co;
189 float3x3 dmat;
190 mul_v3m3_dq(dco, dmat.ptr(), &dq);
191 r_delta_co = (dco - co) * armature_weight;
192 /* Quaternion already is scale corrected. */
193 r_deform_mat = dmat;
194 }
195};
196
197/* Add interpolated deformation along a b-bone segment of the pose channel. */
198template<typename MixerT>
199static void b_bone_deform(const bke::PChanBoneConst pchanbone,
200 const float3 &co,
201 const float weight,
202 MixerT &mixer)
203{
204 /* Calculate the indices of the 2 affecting b_bone segments. */
205 int index;
206 float blend;
207 BKE_pchan_bbone_deform_segment_index(pchanbone, co, &index, &blend);
208
209 mixer.accumulate_bbone(*pchanbone.pchan, co, weight * (1.0f - blend), index);
210 mixer.accumulate_bbone(*pchanbone.pchan, co, weight * blend, index + 1);
211}
212
213/* Add bone deformation based on envelope distance. */
214template<typename MixerT>
215static float dist_bone_deform(const bke::PChanBoneConst pchanbone, const float3 &co, MixerT &mixer)
216{
217 const Bone *bone = pchanbone.bone;
218 const bPoseChannel &pchan = *pchanbone.pchan;
219
220 if (bone == nullptr || bone->weight == 0.0f) {
221 return 0.0f;
222 }
223
224 const float fac = distfactor_to_bone(co,
225 float3(bone->arm_head),
226 float3(bone->arm_tail),
227 bone->rad_head,
228 bone->rad_tail,
229 bone->dist);
230 if (fac == 0.0f) {
231 return 0.0f;
232 }
233
234 const float weight = fac * bone->weight;
235 if (bone->segments > 1 && pchan.runtime.bbone_segments == bone->segments) {
236 b_bone_deform(pchanbone, co, weight, mixer);
237 }
238 else {
239 mixer.accumulate(pchan, co, weight);
240 }
241
242 return weight;
243}
244
245/* Add bone deformation based on vertex group weight. */
246template<typename MixerT>
247static float pchan_bone_deform(const PChanBone pchanbone,
248 const float weight,
249 const float3 &co,
250 MixerT &mixer)
251{
252 const Bone *bone = pchanbone.bone;
253
254 if (!weight) {
255 return 0.0f;
256 }
257
258 if (bone->segments > 1 && pchanbone.pchan->runtime.bbone_segments == bone->segments) {
259 b_bone_deform(pchanbone, co, weight, mixer);
260 }
261 else {
262 mixer.accumulate(*pchanbone.pchan, co, weight);
263 }
264
265 return weight;
266}
267
268} // namespace bke
269
271
272/* -------------------------------------------------------------------- */
277
278namespace bke {
279
283 std::optional<MutableSpan<float3x3>> vert_deform_mats;
284 std::optional<Span<float3>> vert_coords_prev;
285
289
291
292 /* List of all pose channels on the target object. */
294 /* Maps vertex group index (def_nr) to pose channels, if vertex groups are used.
295 * Vertex groups used for deform can be different from the target object vertex groups list,
296 * the def_nr needs to be mapped to the correct pose channel first. */
298
301};
302
304 const Object &ob_arm,
305 const Object &ob_target,
306 const ListBaseT<bDeformGroup> *defbase,
307 MutableSpan<float3> vert_coords,
308 std::optional<Span<float3>> vert_coords_prev,
309 std::optional<MutableSpan<float3x3>> vert_deform_mats,
310 const int deformflag,
311 StringRefNull defgrp_name,
312 const bool try_use_dverts)
313{
314 const bool dverts_supported = BKE_object_supports_vertex_groups(&ob_target);
315
316 /* TODO(Sybren): call the still-to-be-written function to assert that the pose is up to date. The
317 * armature deform code doesn't use pchan->bone_get(object) but rather takes the armature (for
318 * speed), and so cannot assert this itself. */
319
320 bArmature *armature = id_cast<bArmature *>(ob_arm.data);
321 ArmatureDeformParams deform_params;
322 deform_params.armature = armature;
323 deform_params.vert_coords = vert_coords;
324 deform_params.vert_deform_mats = vert_deform_mats;
325 deform_params.vert_coords_prev = vert_coords_prev;
326 deform_params.use_envelope = bool(deformflag & ARM_DEF_ENVELOPE);
327 deform_params.invert_vgroup = bool(deformflag & ARM_DEF_INVERT_VGROUP);
328
329 deform_params.pose_channels = {ob_arm.pose->chanbase};
330 deform_params.use_dverts = try_use_dverts && dverts_supported && (deformflag & ARM_DEF_VGROUP);
331 if (deform_params.use_dverts) {
332 const int defbase_len = defbase->count();
333 deform_params.pose_channel_by_vertex_group.reinitialize(defbase_len);
334 /* TODO(sergey): Some considerations here:
335 *
336 * - Check whether keeping this consistent across frames gives speedup.
337 */
338
340 for (const auto [i, dg] : (defbase)->enumerate()) {
341 bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm.pose, dg.name);
342 /* Exclude non-deforming bones. */
343 Bone *bone = pchan ? pchan->bone_get(*armature) : nullptr;
344 if (pchan && !(bone->flag & BONE_NO_DEFORM)) {
345 deform_params.pose_channel_by_vertex_group[i] = {pchan, bone};
346 }
347 }
348 }
349
350 /* Index of singular vertex group, if used. */
351 deform_params.armature_def_nr = dverts_supported ?
352 BKE_defgroup_name_index(defbase, defgrp_name) :
353 -1;
354
355/* TODO using the existing matrices directly is better, but fails tests because old code was
356 * doing a double-inverse of the object matrix, leading to small differences on the order of 10^-5.
357 * Test data needs to be updated if the transforms change. */
358#if 0
359 deform_params.target_to_armature = ob_arm.world_to_object() * ob_target.object_to_world();
360 deform_params.armature_to_target = ob_target.world_to_object() * ob_arm.object_to_world();
361#else
362 deform_params.armature_to_target = ob_target.world_to_object() * ob_arm.object_to_world();
363 deform_params.target_to_armature = math::invert(deform_params.armature_to_target);
364#endif
365
366 return deform_params;
367}
368
369/* Accumulate bone deformations using the mixer implementation. */
370template<typename MixerT>
372 const int i,
373 const MDeformVert *dvert,
374 MixerT &mixer)
375{
376 const bool full_deform = params.vert_deform_mats.has_value();
377
378 /* Overall influence, can change by masking with a vertex group. */
379 float armature_weight = 1.0f;
380 float prevco_weight = 0.0f; /* weight for optional cached vertexcos */
381 if (params.armature_def_nr != -1 && dvert) {
382 const float mask_weight = BKE_defvert_find_weight(dvert, params.armature_def_nr);
383 /* On multi-modifier the mask is used to blend with previous coordinates. */
384 if (params.vert_coords_prev) {
385 prevco_weight = params.invert_vgroup ? mask_weight : 1.0f - mask_weight;
386 if (prevco_weight == 1.0f) {
387 return;
388 }
389 }
390 else {
391 armature_weight = params.invert_vgroup ? 1.0f - mask_weight : mask_weight;
392 if (armature_weight == 0.0f) {
393 return;
394 }
395 }
396 }
397
398 /* Input coordinates to start from. */
399 float3 co = params.vert_coords_prev ? (*params.vert_coords_prev)[i] : params.vert_coords[i];
400 /* Transform to armature space. */
402
403 float contrib = 0.0f;
404 bool deformed = false;
405 /* Apply vertex group deformation if enabled. */
406 if (params.use_dverts && dvert) {
407 /* Range of valid def_nr in MDeformWeight. */
408 const IndexRange def_nr_range = params.pose_channel_by_vertex_group.index_range();
409 const Span<MDeformWeight> dweights(dvert->dw, dvert->totweight);
410 for (const auto &dw : dweights) {
411 const PChanBone pchanbone = def_nr_range.contains(dw.def_nr) ?
412 params.pose_channel_by_vertex_group[dw.def_nr] :
413 PChanBone(nullptr, nullptr);
414 const bPoseChannel *pchan = pchanbone.pchan;
415 if (pchan == nullptr) {
416 continue;
417 }
418
419 float weight = dw.weight;
420
421 /* Bone option to mix with envelope weight. */
422 const Bone *bone = pchanbone.bone;
423 if (bone && bone->flag & BONE_MULT_VG_ENV) {
424 weight *= distfactor_to_bone(co,
425 float3(bone->arm_head),
426 float3(bone->arm_tail),
427 bone->rad_head,
428 bone->rad_tail,
429 bone->dist);
430 }
431
432 contrib += pchan_bone_deform(pchanbone, weight, co, mixer);
433 deformed = true;
434 }
435 }
436 /* Use envelope if enabled and no bone deformed the vertex yet. */
437 if (!deformed && params.use_envelope) {
438 for (const bPoseChannel *pchan : params.pose_channels) {
439 const Bone *bone = pchan->bone_get(*params.armature);
440 if (!(bone->flag & BONE_NO_DEFORM)) {
441 contrib += dist_bone_deform({pchan, bone}, co, mixer);
442 }
443 }
444 }
445
446 /* TODO Actually should be EPSILON? Weight values and contrib can be like 10e-39 small. */
447 constexpr float contrib_threshold = 0.0001f;
448 if (contrib > contrib_threshold) {
449 float3 delta_co;
450 float3x3 local_deform_mat;
451 mixer.finalize(co, contrib, armature_weight, delta_co, local_deform_mat);
452
453 co += delta_co;
454 if (full_deform) {
455 float3x3 &deform_mat = (*params.vert_deform_mats)[i];
456 const float3x3 armature_to_target = params.armature_to_target.view<3, 3>();
457 const float3x3 target_to_armature = params.target_to_armature.view<3, 3>();
458 deform_mat = armature_to_target * local_deform_mat * target_to_armature * deform_mat;
459 }
460 }
461
462 /* Transform back to target object space. */
464
465 /* Multi-modifier: Interpolate with previous modifier position using the vertex group mask. */
466 if (params.vert_coords_prev) {
467 copy_v3_v3(params.vert_coords[i], math::interpolate(co, params.vert_coords[i], prevco_weight));
468 }
469 else {
470 copy_v3_v3(params.vert_coords[i], co);
471 }
472}
473
474/* Accumulate bone deformations for a vertex. */
476 const int i,
477 const MDeformVert *dvert,
478 const bool use_quaternion)
479{
480 const bool full_deform = deform_params.vert_deform_mats.has_value();
481 if (use_quaternion) {
482 if (full_deform) {
484 armature_vert_task_with_mixer(deform_params, i, dvert, mixer);
485 }
486 else {
488 armature_vert_task_with_mixer(deform_params, i, dvert, mixer);
489 }
490 }
491 else {
492 if (full_deform) {
494 armature_vert_task_with_mixer(deform_params, i, dvert, mixer);
495 }
496 else {
498 armature_vert_task_with_mixer(deform_params, i, dvert, mixer);
499 }
500 }
501}
502
503static void armature_deform_coords(const Object &ob_arm,
504 const Object &ob_target,
505 const ListBaseT<bDeformGroup> *defbase,
506 const MutableSpan<float3> vert_coords,
507 const std::optional<MutableSpan<float3x3>> vert_deform_mats,
508 const int deformflag,
509 const std::optional<Span<float3>> vert_coords_prev,
510 StringRefNull defgrp_name,
511 const std::optional<Span<MDeformVert>> dverts,
512 const Mesh *me_target)
513{
515 ob_target,
516 defbase,
517 vert_coords,
518 vert_coords_prev,
519 vert_deform_mats,
520 deformflag,
521 defgrp_name,
522 dverts.has_value());
523
524 const bool use_quaternion = bool(deformflag & ARM_DEF_QUATERNION);
525 constexpr int grain_size = 32;
526 threading::parallel_for(vert_coords.index_range(), grain_size, [&](const IndexRange range) {
527 for (const int i : range) {
528 const MDeformVert *dvert = nullptr;
529 if (deform_params.use_dverts || deform_params.armature_def_nr >= 0) {
530 if (me_target) {
531 BLI_assert(i < me_target->verts_num);
532 if (dverts) {
533 dvert = &(*dverts)[i];
534 }
535 }
536 else if (dverts && i < dverts->size()) {
537 dvert = &(*dverts)[i];
538 }
539 }
540
541 armature_vert_task_with_dvert(deform_params, i, dvert, use_quaternion);
542 }
543 });
544}
545
552
553template<bool use_dvert>
554static void armature_vert_task_editmesh(void *__restrict userdata,
555 MempoolIterData *iter,
556 const TaskParallelTLS *__restrict /*tls*/)
557{
558 const ArmatureEditMeshUserdata &data = *static_cast<const ArmatureEditMeshUserdata *>(userdata);
559 BMVert *v = reinterpret_cast<BMVert *>(iter);
560 const MDeformVert *dvert = use_dvert ? static_cast<const MDeformVert *>(
561 BM_ELEM_CD_GET_VOID_P(v, data.cd_dvert_offset)) :
562 nullptr;
564 data.deform_params, BM_elem_index_get(v), dvert, data.use_quaternion);
565}
566
567static void armature_deform_editmesh(const Object &ob_arm,
568 const Object &ob_target,
569 const ListBaseT<bDeformGroup> *defbase,
570 const MutableSpan<float3> vert_coords,
571 const std::optional<MutableSpan<float3x3>> vert_deform_mats,
572 const int deformflag,
573 const std::optional<Span<float3>> vert_coords_prev,
574 StringRefNull defgrp_name,
575 const BMesh &bm_target,
576 const int cd_dvert_offset)
577{
579 ob_target,
580 defbase,
581 vert_coords,
582 vert_coords_prev,
583 vert_deform_mats,
584 deformflag,
585 defgrp_name,
586 cd_dvert_offset >= 0);
587
589 data.use_quaternion = bool(deformflag & ARM_DEF_QUATERNION);
590 data.cd_dvert_offset = cd_dvert_offset;
591 data.deform_params = std::move(deform_params);
592
593 BMesh *bm = const_cast<BMesh *>(&bm_target);
594
595 /* While this could cause an extra loop over mesh data, in most cases this will
596 * have already been properly set. */
598
599 TaskParallelSettings settings;
601
602 if (data.deform_params.use_dverts) {
604 }
605 else {
607 }
608}
609
610static bool verify_armature_deform_valid(const Object &ob_arm)
611{
612 /* Not supported in armature edit mode or without pose data. */
613 const bArmature *arm = id_cast<const bArmature *>(ob_arm.data);
614 if (arm->edbo || (ob_arm.pose == nullptr)) {
615 return false;
616 }
617 if ((ob_arm.pose->flag & POSE_RECALC) != 0) {
619 "Trying to evaluate influence of armature '%s' which needs Pose recalc!",
620 ob_arm.id.name);
622 }
623 return true;
624}
625
626} // namespace bke
627
629 const Object &ob_target,
630 const ListBaseT<bDeformGroup> *defbase,
631 MutableSpan<float3> vert_coords,
632 std::optional<Span<float3>> vert_coords_prev,
633 std::optional<MutableSpan<float3x3>> vert_deform_mats,
634 Span<MDeformVert> dverts,
635 int deformflag,
636 StringRefNull defgrp_name)
637{
639 return;
640 }
641
642 /* Vertex groups must be provided explicitly, cannot rely on object vertex groups since this is
643 * used for Grease Pencil layers as well. */
644 BLI_assert(dverts.size() == vert_coords.size());
645
647 ob_target,
648 defbase,
649 vert_coords,
650 vert_deform_mats,
651 deformflag,
652 vert_coords_prev,
653 defgrp_name,
654 dverts,
655 nullptr);
656}
657
659 const Object &ob_target,
660 MutableSpan<float3> vert_coords,
661 std::optional<Span<float3>> vert_coords_prev,
662 std::optional<MutableSpan<float3x3>> vert_deform_mats,
663 int deformflag,
664 StringRefNull defgrp_name,
665 const Mesh *me_target)
666{
668 return;
669 }
670
671 /* Note armature modifier on legacy curves calls this, so vertex groups are not guaranteed to
672 * exist. */
673 const ID *id_target = static_cast<const ID *>(ob_target.data);
674 const ListBaseT<bDeformGroup> *defbase = nullptr;
675 if (me_target) {
676 /* Use the vertex groups from the evaluated mesh that is being deformed. */
677 defbase = BKE_id_defgroup_list_get(&me_target->id);
678 }
679 else if (BKE_id_supports_vertex_groups(id_target)) {
680 /* Take the vertex groups from the original object data. */
681 defbase = BKE_id_defgroup_list_get(id_target);
682 }
683
684 Span<MDeformVert> dverts;
685 if (ob_target.type == OB_MESH) {
686 if (me_target == nullptr) {
687 me_target = id_cast<const Mesh *>(ob_target.data);
688 }
689 dverts = me_target->deform_verts();
690 }
691 else if (ob_target.type == OB_LATTICE) {
692 const Lattice *lt = id_cast<const Lattice *>(ob_target.data);
693 if (lt->dvert != nullptr) {
694 dverts = Span<MDeformVert>(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw);
695 }
696 }
697
698 std::optional<Span<MDeformVert>> dverts_opt;
699 if ((me_target && !me_target->deform_verts().is_empty()) || dverts.size() == vert_coords.size())
700 {
701 dverts_opt = dverts;
702 }
703
705 ob_target,
706 defbase,
707 vert_coords,
708 vert_deform_mats,
709 deformflag,
710 vert_coords_prev,
711 defgrp_name,
712 dverts_opt,
713 me_target);
714}
715
717 const Object &ob_arm,
718 const Object &ob_target,
719 MutableSpan<float3> vert_coords,
720 std::optional<Span<float3>> vert_coords_prev,
721 std::optional<MutableSpan<float3x3>> vert_deform_mats,
722 int deformflag,
723 StringRefNull defgrp_name,
724 const BMesh &bm_target)
725{
727 return;
728 }
729
730 const ListBaseT<bDeformGroup> *defbase = BKE_id_defgroup_list_get(
731 static_cast<const ID *>(ob_target.data));
732 const int cd_dvert_offset = CustomData_get_offset(&bm_target.vdata, CD_MDEFORMVERT);
734 ob_target,
735 defbase,
736 vert_coords,
737 vert_deform_mats,
738 deformflag,
739 vert_coords_prev,
740 defgrp_name,
741 bm_target,
742 cd_dvert_offset);
743}
744
746
747} // namespace blender
Blender kernel action and pose functionality.
CustomData interface, see also DNA_customdata_types.h.
support for deformation groups and hooks.
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
These structs are the foundation for all linked lists in the library system.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
#define BM_elem_index_get(ele)
constexpr Span()=default
constexpr bool contains(int64_t value) const
constexpr int64_t size() const
Definition BLI_span.hh:499
constexpr IndexRange index_range() const
Definition BLI_span.hh:676
Span< NewT > constexpr cast() const
Definition BLI_span.hh:422
constexpr Span()=default
constexpr int64_t size() const
Definition BLI_span.hh:256
#define position
float distance_squared(VecT a, VecT b)
PChanBoneT< bPoseChannel, Bone > PChanBone
Definition BKE_pose.hh:88
static void armature_vert_task_editmesh(void *__restrict userdata, MempoolIterData *iter, const TaskParallelTLS *__restrict)
static void armature_vert_task_with_mixer(const ArmatureDeformParams &params, const int i, const MDeformVert *dvert, MixerT &mixer)
static void armature_vert_task_with_dvert(const ArmatureDeformParams &deform_params, const int i, const MDeformVert *dvert, const bool use_quaternion)
static bool verify_armature_deform_valid(const Object &ob_arm)
PChanBoneT< const bPoseChannel, const Bone > PChanBoneConst
Definition BKE_pose.hh:89
static float pchan_bone_deform(const PChanBone pchanbone, const float weight, const float3 &co, MixerT &mixer)
static void armature_deform_editmesh(const Object &ob_arm, const Object &ob_target, const ListBaseT< bDeformGroup > *defbase, const MutableSpan< float3 > vert_coords, const std::optional< MutableSpan< float3x3 > > vert_deform_mats, const int deformflag, const std::optional< Span< float3 > > vert_coords_prev, StringRefNull defgrp_name, const BMesh &bm_target, const int cd_dvert_offset)
static void armature_deform_coords(const Object &ob_arm, const Object &ob_target, const ListBaseT< bDeformGroup > *defbase, const MutableSpan< float3 > vert_coords, const std::optional< MutableSpan< float3x3 > > vert_deform_mats, const int deformflag, const std::optional< Span< float3 > > vert_coords_prev, StringRefNull defgrp_name, const std::optional< Span< MDeformVert > > dverts, const Mesh *me_target)
static float dist_bone_deform(const bke::PChanBoneConst pchanbone, const float3 &co, MixerT &mixer)
static void b_bone_deform(const bke::PChanBoneConst pchanbone, const float3 &co, const float weight, MixerT &mixer)
static ArmatureDeformParams get_armature_deform_params(const Object &ob_arm, const Object &ob_target, const ListBaseT< bDeformGroup > *defbase, MutableSpan< float3 > vert_coords, std::optional< Span< float3 > > vert_coords_prev, std::optional< MutableSpan< float3x3 > > vert_deform_mats, const int deformflag, StringRefNull defgrp_name, const bool try_use_dverts)
QuaternionBase< T > normalize_and_get_length(const QuaternionBase< T > &q, T &out_length)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
CartesianBasis invert(const CartesianBasis &basis)
T interpolate(const T &a, const T &b, const FactorT &t)
T square(const T &a)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
BMesh Iterators.
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
MINLINE void copy_v3_v3(float r[3], const float a[3])
const ListBaseT< bDeformGroup > * BKE_id_defgroup_list_get(const ID *id)
Definition deform.cc:472
void add_weighted_dq_dq_pivot(DualQuat *dq_sum, const DualQuat *dq, const float pivot[3], float weight, bool compute_scale_matrix)
ATTR_WARN_UNUSED_RESULT const BMVert * v
MatBase< float, 4, 4 > float4x4
void BKE_pose_ensure_bone_indices(const Object &pose_object)
int BKE_defgroup_name_index(const ListBaseT< bDeformGroup > *defbase, StringRef name)
Definition deform.cc:544
ListBaseWrapperTemplate< const ListBase, const T > ConstListBaseWrapper
BLI_INLINE void BLI_parallel_mempool_settings_defaults(TaskParallelSettings *settings)
float distfactor_to_bone(const float3 &position, const float3 &head, const float3 &tail, float radius_head, float radius_tail, float falloff_distance)
void normalize_dq(DualQuat *dq, float totweight)
float BKE_defvert_find_weight(const MDeformVert *dvert, int defgroup)
Definition deform.cc:779
bool BKE_object_supports_vertex_groups(const Object *ob)
Definition deform.cc:465
void BLI_task_parallel_mempool(struct BLI_mempool *mempool, void *userdata, TaskParallelMempoolFunc func, const TaskParallelSettings *settings)
void BKE_pchan_bbone_deform_segment_index(bke::PChanBoneConst pchanbone, const float *co, int *r_index, float *r_blend_next)
BMesh const char void * data
void BKE_armature_deform_coords_with_curves(const Object &ob_arm, const Object &ob_target, const ListBaseT< bDeformGroup > *defbase, MutableSpan< float3 > vert_coords, std::optional< Span< float3 > > vert_coords_prev, std::optional< MutableSpan< float3x3 > > vert_deform_mats, Span< MDeformVert > dverts, int deformflag, StringRefNull defgrp_name)
bool BKE_id_supports_vertex_groups(const ID *id)
Definition deform.cc:457
void BKE_armature_deform_coords_with_mesh(const Object &ob_arm, const Object &ob_target, MutableSpan< float3 > vert_coords, std::optional< Span< float3 > > vert_coords_prev, std::optional< MutableSpan< float3x3 > > vert_deform_mats, int deformflag, StringRefNull defgrp_name, const Mesh *me_target)
MatBase< float, 3, 3 > float3x3
static float bone_envelope_falloff(const float distance_squared, const float closest_radius, const float falloff_distance)
void BKE_armature_deform_coords_with_editmesh(const Object &ob_arm, const Object &ob_target, MutableSpan< float3 > vert_coords, std::optional< Span< float3 > > vert_coords_prev, std::optional< MutableSpan< float3x3 > > vert_deform_mats, int deformflag, StringRefNull defgrp_name, const BMesh &bm_target)
static CLG_LogRef LOG
Definition logging.cpp:12
VecBase< float, 3 > float3
void mul_v3m3_dq(float r[3], float R[3][3], DualQuat *dq)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
#define sqrtf
CustomData vdata
char name[258]
Definition DNA_ID.h:433
struct MDeformVert * dvert
struct MDeformWeight * dw
const c_style_mat & ptr() const
const MatView< T, ViewNumCol, ViewNumRow, NumCol, NumRow, SrcStartCol, SrcStartRow, Alignment > view() const
struct bPose * pose
ListBaseT< EditBone > * edbo
struct bPoseChannel_Runtime runtime
ListBaseT< bPoseChannel > chanbase
std::optional< Span< float3 > > vert_coords_prev
ConstListBaseWrapper< bPoseChannel > pose_channels
Array< bke::PChanBone > pose_channel_by_vertex_group
std::optional< MutableSpan< float3x3 > > vert_deform_mats
void accumulate_bbone(const bPoseChannel &pchan, const float3 &co, const float weight, const int index)
void accumulate(const bPoseChannel &pchan, const float3 &co, const float weight)
void finalize(const float3 &co, float total, float armature_weight, float3 &r_delta_co, float3x3 &r_deform_mat)
void accumulate_bbone(const bPoseChannel &pchan, const float3 &co, const float weight, const int index)
void finalize(const float3 &, float total, float armature_weight, float3 &r_delta_co, float3x3 &r_deform_mat)
void accumulate(const bPoseChannel &pchan, const float3 &co, const float weight)
PoseChannelT * pchan
Definition BKE_pose.hh:61