CurvesGeometry: Add initial vertex group support #106944

Merged
Falk David merged 24 commits from filedescriptor/blender:curves-deform-verts into main 2023-09-27 10:26:16 +02:00
3 changed files with 41 additions and 0 deletions
Showing only changes of commit 17aea2a753 - Show all commits

View File

@ -25,6 +25,8 @@
#include "BKE_attribute_math.hh"
#include "BKE_curves.h"
#include "DNA_meshdata_types.h"
filedescriptor marked this conversation as resolved Outdated

Does it work to forward declare MDeformVert? It would be nice not to include DNA_meshdata_types.h in the curves header.

Does it work to forward declare `MDeformVert`? It would be nice not to include `DNA_meshdata_types.h` in the curves header.
namespace blender::bke {
namespace curves::nurbs {
@ -257,6 +259,13 @@ class CurvesGeometry : public ::CurvesGeometry {
Span<float2> surface_uv_coords() const;
MutableSpan<float2> surface_uv_coords_for_write();
/**
* Vertex group data, encoded as an array of indices and weights for every vertex.
* \warning: May be empty.
*/
Span<MDeformVert> deform_verts() const;
MutableSpan<MDeformVert> deform_verts_for_write();
/**
* The largest and smallest position values of evaluated points.
*/

View File

@ -458,6 +458,28 @@ MutableSpan<float2> CurvesGeometry::surface_uv_coords_for_write()
return get_mutable_attribute<float2>(*this, ATTR_DOMAIN_CURVE, ATTR_SURFACE_UV_COORDINATE);
}
Span<MDeformVert> CurvesGeometry::deform_verts() const
{
const MDeformVert *dverts = (const MDeformVert *)CustomData_get_layer(&this->point_data,
CD_MDEFORMVERT);
if (dverts == nullptr) {
return {};
}
return {dverts, this->point_num};
}
MutableSpan<MDeformVert> CurvesGeometry::deform_verts_for_write()
{
MDeformVert *dvert = (MDeformVert *)CustomData_get_layer_for_write(
&this->point_data, CD_MDEFORMVERT, this->point_num);
if (dvert != nullptr) {
return {dvert, this->point_num};
}
return {(MDeformVert *)CustomData_add_layer(
&this->point_data, CD_MDEFORMVERT, CD_SET_DEFAULT, this->point_num),
this->point_num};
}
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -10,7 +10,9 @@
#include "DNA_ID.h"
#include "DNA_customdata_types.h"
#include "DNA_object_types.h"
#include "BLI_listbase.h"
#include "BLI_utildefines.h"
#ifdef __cplusplus
@ -132,6 +134,14 @@ typedef struct CurvesGeometry {
*/
int curve_num;
/**
* List of vertex group (#bDeformGroup) names and flags only.
*/
ListBase vertex_group_names;
/** The active index in the #vertex_group_names list. */
int vertex_group_active_index;
char _pad[4];
/**
* Runtime data for curves, stored as a pointer to allow defining this as a C++ class.
*/