Differential D15393 Diff 53824 source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| #include "BLI_index_mask_ops.hh" | #include "BLI_index_mask_ops.hh" | ||||
| #include "BLI_virtual_array.hh" | #include "BLI_virtual_array.hh" | ||||
| #include "BKE_attribute.hh" | #include "BKE_attribute.hh" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_curves.hh" | |||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_geometry_fields.hh" | #include "BKE_geometry_fields.hh" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_mesh_wrapper.h" | #include "BKE_mesh_wrapper.h" | ||||
| #include "BKE_modifier.h" | #include "BKE_modifier.h" | ||||
| #include "BKE_volume.h" | #include "BKE_volume.h" | ||||
| #include "DNA_ID.h" | #include "DNA_ID.h" | ||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "DNA_space_types.h" | #include "DNA_space_types.h" | ||||
| #include "DNA_userdef_types.h" | #include "DNA_userdef_types.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "ED_curves_sculpt.h" | |||||
| #include "ED_spreadsheet.h" | #include "ED_spreadsheet.h" | ||||
| #include "NOD_geometry_nodes_eval_log.hh" | #include "NOD_geometry_nodes_eval_log.hh" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_enum_types.h" | #include "RNA_enum_types.h" | ||||
| ▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| if (!component_->attributes().has_value()) { | if (!component_->attributes().has_value()) { | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| const bke::AttributeAccessor attributes = *component_->attributes(); | const bke::AttributeAccessor attributes = *component_->attributes(); | ||||
| return attributes.domain_size(domain_); | return attributes.domain_size(domain_); | ||||
| } | } | ||||
| /** | |||||
| * Only data sets corresponding to mesh objects in edit mode currently support selection filtering. | |||||
| */ | |||||
| bool GeometryDataSource::has_selection_filter() const | bool GeometryDataSource::has_selection_filter() const | ||||
| { | { | ||||
| Object *object_orig = DEG_get_original_object(object_eval_); | Object *object_orig = DEG_get_original_object(object_eval_); | ||||
| switch (component_->type()) { | |||||
| case GEO_COMPONENT_TYPE_MESH: { | |||||
| if (object_orig->type != OB_MESH) { | if (object_orig->type != OB_MESH) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (object_orig->mode != OB_MODE_EDIT) { | if (object_orig->mode != OB_MODE_EDIT) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (component_->type() != GEO_COMPONENT_TYPE_MESH) { | return true; | ||||
| } | |||||
| case GEO_COMPONENT_TYPE_CURVE: { | |||||
| if (object_orig->type != OB_CURVES) { | |||||
| return false; | |||||
| } | |||||
| if (object_orig->mode != OB_MODE_SCULPT_CURVES) { | |||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| default: | |||||
| return false; | |||||
| } | |||||
| } | |||||
| IndexMask GeometryDataSource::apply_selection_filter(Vector<int64_t> &indices) const | IndexMask GeometryDataSource::apply_selection_filter(Vector<int64_t> &indices) const | ||||
| { | { | ||||
| std::lock_guard lock{mutex_}; | std::lock_guard lock{mutex_}; | ||||
| const IndexMask full_range(this->tot_rows()); | const IndexMask full_range(this->tot_rows()); | ||||
| switch (component_->type()) { | |||||
| case GEO_COMPONENT_TYPE_MESH: { | |||||
| BLI_assert(object_eval_->type == OB_MESH); | |||||
| BLI_assert(object_eval_->mode == OB_MODE_EDIT); | BLI_assert(object_eval_->mode == OB_MODE_EDIT); | ||||
| BLI_assert(component_->type() == GEO_COMPONENT_TYPE_MESH); | |||||
| Object *object_orig = DEG_get_original_object(object_eval_); | Object *object_orig = DEG_get_original_object(object_eval_); | ||||
| const MeshComponent *mesh_component = static_cast<const MeshComponent *>(component_); | const Mesh *mesh_eval = geometry_set_.get_mesh_for_read(); | ||||
| const Mesh *mesh_eval = mesh_component->get_for_read(); | const bke::AttributeAccessor attributes_eval = bke::mesh_attributes(*mesh_eval); | ||||
| Mesh *mesh_orig = (Mesh *)object_orig->data; | Mesh *mesh_orig = (Mesh *)object_orig->data; | ||||
| BMesh *bm = mesh_orig->edit_mesh->bm; | BMesh *bm = mesh_orig->edit_mesh->bm; | ||||
| BM_mesh_elem_table_ensure(bm, BM_VERT); | BM_mesh_elem_table_ensure(bm, BM_VERT); | ||||
| const int *orig_indices = (int *)CustomData_get_layer(&mesh_eval->vdata, CD_ORIGINDEX); | const int *orig_indices = (int *)CustomData_get_layer(&mesh_eval->vdata, CD_ORIGINDEX); | ||||
| if (orig_indices != nullptr) { | if (orig_indices != nullptr) { | ||||
| /* Use CD_ORIGINDEX layer if it exists. */ | /* Use CD_ORIGINDEX layer if it exists. */ | ||||
| VArray<bool> selection = mesh_component->attributes()->adapt_domain<bool>( | VArray<bool> selection = attributes_eval.adapt_domain<bool>( | ||||
| VArray<bool>::ForFunc(mesh_eval->totvert, | VArray<bool>::ForFunc(mesh_eval->totvert, | ||||
| [bm, orig_indices](int vertex_index) -> bool { | [bm, orig_indices](int vertex_index) -> bool { | ||||
| const int i_orig = orig_indices[vertex_index]; | const int i_orig = orig_indices[vertex_index]; | ||||
| if (i_orig < 0) { | if (i_orig < 0) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (i_orig >= bm->totvert) { | if (i_orig >= bm->totvert) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| BMVert *vert = bm->vtable[i_orig]; | const BMVert *vert = BM_vert_at_index(bm, i_orig); | ||||
| return BM_elem_flag_test(vert, BM_ELEM_SELECT); | return BM_elem_flag_test(vert, BM_ELEM_SELECT); | ||||
| }), | }), | ||||
| ATTR_DOMAIN_POINT, | ATTR_DOMAIN_POINT, | ||||
| domain_); | domain_); | ||||
| return index_mask_ops::find_indices_from_virtual_array(full_range, selection, 1024, indices); | return index_mask_ops::find_indices_from_virtual_array( | ||||
| full_range, selection, 1024, indices); | |||||
| } | } | ||||
| if (mesh_eval->totvert == bm->totvert) { | if (mesh_eval->totvert == bm->totvert) { | ||||
| /* Use a simple heuristic to match original vertices to evaluated ones. */ | /* Use a simple heuristic to match original vertices to evaluated ones. */ | ||||
| VArray<bool> selection = mesh_component->attributes()->adapt_domain<bool>( | VArray<bool> selection = attributes_eval.adapt_domain<bool>( | ||||
| VArray<bool>::ForFunc(mesh_eval->totvert, | VArray<bool>::ForFunc(mesh_eval->totvert, | ||||
| [bm](int vertex_index) -> bool { | [bm](int vertex_index) -> bool { | ||||
| BMVert *vert = bm->vtable[vertex_index]; | const BMVert *vert = BM_vert_at_index(bm, vertex_index); | ||||
| return BM_elem_flag_test(vert, BM_ELEM_SELECT); | return BM_elem_flag_test(vert, BM_ELEM_SELECT); | ||||
| }), | }), | ||||
| ATTR_DOMAIN_POINT, | ATTR_DOMAIN_POINT, | ||||
| domain_); | domain_); | ||||
| return index_mask_ops::find_indices_from_virtual_array(full_range, selection, 2048, indices); | return index_mask_ops::find_indices_from_virtual_array( | ||||
| full_range, selection, 2048, indices); | |||||
| } | } | ||||
| return full_range; | return full_range; | ||||
| } | } | ||||
| case GEO_COMPONENT_TYPE_CURVE: { | |||||
| BLI_assert(object_eval_->type == OB_CURVES); | |||||
| BLI_assert(object_eval_->mode == OB_MODE_SCULPT_CURVES); | |||||
| const CurveComponent &component = static_cast<const CurveComponent &>(*component_); | |||||
| const Curves &curves_id = *component.get_for_read(); | |||||
| switch (domain_) { | |||||
| case ATTR_DOMAIN_POINT: | |||||
| return sculpt_paint::retrieve_selected_points(curves_id, indices); | |||||
| case ATTR_DOMAIN_CURVE: | |||||
| return sculpt_paint::retrieve_selected_curves(curves_id, indices); | |||||
| default: | |||||
| BLI_assert_unreachable(); | |||||
| } | |||||
| return full_range; | |||||
| } | |||||
| default: | |||||
| return full_range; | |||||
| } | |||||
| } | |||||
| void VolumeDataSource::foreach_default_column_ids( | void VolumeDataSource::foreach_default_column_ids( | ||||
| FunctionRef<void(const SpreadsheetColumnID &, bool is_extra)> fn) const | FunctionRef<void(const SpreadsheetColumnID &, bool is_extra)> fn) const | ||||
| { | { | ||||
| if (component_->is_empty()) { | if (component_->is_empty()) { | ||||
| return; | return; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 260 Lines • Show Last 20 Lines | |||||