Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/attribute.c
| Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| typedef struct DomainInfo { | typedef struct DomainInfo { | ||||
| CustomData *customdata; | CustomData *customdata; | ||||
| int length; | int length; | ||||
| } DomainInfo; | } DomainInfo; | ||||
| static void get_domains(ID *id, DomainInfo info[ATTR_DOMAIN_NUM]) | static void get_domains(const ID *id, DomainInfo info[ATTR_DOMAIN_NUM]) | ||||
| { | { | ||||
| memset(info, 0, sizeof(DomainInfo) * ATTR_DOMAIN_NUM); | memset(info, 0, sizeof(DomainInfo) * ATTR_DOMAIN_NUM); | ||||
| switch (GS(id->name)) { | switch (GS(id->name)) { | ||||
| case ID_PT: { | case ID_PT: { | ||||
| PointCloud *pointcloud = (PointCloud *)id; | PointCloud *pointcloud = (PointCloud *)id; | ||||
| info[ATTR_DOMAIN_POINT].customdata = &pointcloud->pdata; | info[ATTR_DOMAIN_POINT].customdata = &pointcloud->pdata; | ||||
| info[ATTR_DOMAIN_POINT].length = pointcloud->totpoint; | info[ATTR_DOMAIN_POINT].length = pointcloud->totpoint; | ||||
| ▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | default: { | ||||
| CustomData_free_layer(customdata, layer->type, length, index); | CustomData_free_layer(customdata, layer->type, length, index); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| CustomDataLayer *BKE_id_attribute_find(const ID *id, | |||||
HooglyBoogly: Not sure your thoughts on this, but this could use the C++ attribute API, like the following… | |||||
Done Inline ActionsI think that automatic domain interpolation or datatype conversion in this case is likely to generate bad velocity vectors. I'd rather it only works for float vectors on vertices, better to have no motion blur than broken motion blur. brecht: I think that automatic domain interpolation or datatype conversion in this case is likely to… | |||||
| const char *name, | |||||
| const int type, | |||||
| const AttributeDomain domain) | |||||
| { | |||||
| DomainInfo info[ATTR_DOMAIN_NUM]; | |||||
| get_domains(id, info); | |||||
| CustomData *customdata = info[domain].customdata; | |||||
| if (customdata == NULL) { | |||||
| return NULL; | |||||
| } | |||||
| for (int i = 0; i < customdata->totlayer; i++) { | |||||
| CustomDataLayer *layer = &customdata->layers[i]; | |||||
| if (layer->type == type && STREQ(layer->name, name)) { | |||||
| return layer; | |||||
| } | |||||
| } | |||||
| return NULL; | |||||
| } | |||||
| int BKE_id_attributes_length(ID *id, const CustomDataMask mask) | int BKE_id_attributes_length(ID *id, const CustomDataMask mask) | ||||
| { | { | ||||
| DomainInfo info[ATTR_DOMAIN_NUM]; | DomainInfo info[ATTR_DOMAIN_NUM]; | ||||
| get_domains(id, info); | get_domains(id, info); | ||||
| int length = 0; | int length = 0; | ||||
| for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) { | for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) { | ||||
| ▲ Show 20 Lines • Show All 147 Lines • Show Last 20 Lines | |||||
Not sure your thoughts on this, but this could use the C++ attribute API, like the following:
MeshComponent component; component.replace(result, GeometryOwnershipType::Editable); GVArrayPtr attribute = component.attribute_try_get_for_read(velocity_name, ATTR_DOMAIN_POINT, CD_PROP_FLOAT3); if (!attribute) { return; } VArray_Span<float3> velocities{attribute->typed<float3>()};Benefits: