Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/geometry_component_mesh.cc
| Show First 20 Lines • Show All 817 Lines • ▼ Show 20 Lines | |||||
| class VertexGroupsAttributeProvider final : public DynamicAttributesProvider { | class VertexGroupsAttributeProvider final : public DynamicAttributesProvider { | ||||
| public: | public: | ||||
| ReadAttributeLookup try_get_for_read(const GeometryComponent &component, | ReadAttributeLookup try_get_for_read(const GeometryComponent &component, | ||||
| const StringRef attribute_name) const final | const StringRef attribute_name) const final | ||||
| { | { | ||||
| BLI_assert(component.type() == GEO_COMPONENT_TYPE_MESH); | BLI_assert(component.type() == GEO_COMPONENT_TYPE_MESH); | ||||
| const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component); | const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component); | ||||
| const Mesh *mesh = mesh_component.get_for_read(); | const Mesh *mesh = mesh_component.get_for_read(); | ||||
| if (mesh == nullptr) { | |||||
| return {}; | |||||
| } | |||||
| const int vertex_group_index = BLI_findstringindex( | const int vertex_group_index = BLI_findstringindex( | ||||
| &mesh->vertex_group_names, attribute_name.data(), offsetof(bDeformGroup, name)); | &mesh->vertex_group_names, attribute_name.data(), offsetof(bDeformGroup, name)); | ||||
| if (vertex_group_index < 0) { | if (vertex_group_index < 0) { | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| if (mesh == nullptr || mesh->dvert == nullptr) { | if (mesh->dvert == nullptr) { | ||||
| static const float default_value = 0.0f; | static const float default_value = 0.0f; | ||||
| return {std::make_unique<fn::GVArray_For_SingleValueRef>( | return {std::make_unique<fn::GVArray_For_SingleValueRef>( | ||||
| CPPType::get<float>(), mesh->totvert, &default_value), | CPPType::get<float>(), mesh->totvert, &default_value), | ||||
| ATTR_DOMAIN_POINT}; | ATTR_DOMAIN_POINT}; | ||||
| } | } | ||||
| return {std::make_unique<fn::GVArray_For_EmbeddedVArray<float, VArray_For_VertexWeights>>( | return {std::make_unique<fn::GVArray_For_EmbeddedVArray<float, VArray_For_VertexWeights>>( | ||||
| mesh->totvert, mesh->dvert, mesh->totvert, vertex_group_index), | mesh->totvert, mesh->dvert, mesh->totvert, vertex_group_index), | ||||
| ATTR_DOMAIN_POINT}; | ATTR_DOMAIN_POINT}; | ||||
| Show All 29 Lines | return { | ||||
| ATTR_DOMAIN_POINT}; | ATTR_DOMAIN_POINT}; | ||||
| } | } | ||||
| bool try_delete(GeometryComponent &component, const StringRef attribute_name) const final | bool try_delete(GeometryComponent &component, const StringRef attribute_name) const final | ||||
| { | { | ||||
| BLI_assert(component.type() == GEO_COMPONENT_TYPE_MESH); | BLI_assert(component.type() == GEO_COMPONENT_TYPE_MESH); | ||||
| MeshComponent &mesh_component = static_cast<MeshComponent &>(component); | MeshComponent &mesh_component = static_cast<MeshComponent &>(component); | ||||
| Mesh *mesh = mesh_component.get_for_write(); | Mesh *mesh = mesh_component.get_for_write(); | ||||
| if (mesh == nullptr) { | |||||
| return true; | |||||
| } | |||||
| const int vertex_group_index = BLI_findstringindex( | const int vertex_group_index = BLI_findstringindex( | ||||
| &mesh->vertex_group_names, attribute_name.data(), offsetof(bDeformGroup, name)); | &mesh->vertex_group_names, attribute_name.data(), offsetof(bDeformGroup, name)); | ||||
| if (vertex_group_index < 0) { | if (vertex_group_index < 0) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (mesh == nullptr) { | |||||
| return true; | |||||
| } | |||||
| if (mesh->dvert == nullptr) { | if (mesh->dvert == nullptr) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| for (MDeformVert &dvert : MutableSpan(mesh->dvert, mesh->totvert)) { | for (MDeformVert &dvert : MutableSpan(mesh->dvert, mesh->totvert)) { | ||||
| MDeformWeight *weight = BKE_defvert_find_index(&dvert, vertex_group_index); | MDeformWeight *weight = BKE_defvert_find_index(&dvert, vertex_group_index); | ||||
| BKE_defvert_remove_group(&dvert, weight); | BKE_defvert_remove_group(&dvert, weight); | ||||
| } | } | ||||
| return true; | return true; | ||||
| ▲ Show 20 Lines • Show All 221 Lines • Show Last 20 Lines | |||||