Differential D11056 Diff 36442 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
| Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | void GeometryDataSource::foreach_default_column_ids( | ||||
| FunctionRef<void(const SpreadsheetColumnID &)> fn) const | FunctionRef<void(const SpreadsheetColumnID &)> fn) const | ||||
| { | { | ||||
| component_->attribute_foreach([&](StringRefNull name, const AttributeMetaData &meta_data) { | component_->attribute_foreach([&](StringRefNull name, const AttributeMetaData &meta_data) { | ||||
| if (meta_data.domain != domain_) { | if (meta_data.domain != domain_) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| SpreadsheetColumnID column_id; | SpreadsheetColumnID column_id; | ||||
| column_id.name = (char *)name.c_str(); | column_id.name = (char *)name.c_str(); | ||||
| if (meta_data.data_type == CD_PROP_FLOAT3) { | |||||
| for (const int i : {0, 1, 2}) { | |||||
| column_id.index = i; | |||||
| fn(column_id); | fn(column_id); | ||||
| } | |||||
| } | |||||
| else if (meta_data.data_type == CD_PROP_FLOAT2) { | |||||
| for (const int i : {0, 1}) { | |||||
| column_id.index = i; | |||||
| fn(column_id); | |||||
| } | |||||
| } | |||||
| else if (meta_data.data_type == CD_PROP_COLOR) { | |||||
| for (const int i : {0, 1, 2, 3}) { | |||||
| column_id.index = i; | |||||
| fn(column_id); | |||||
| } | |||||
| } | |||||
| else { | |||||
| column_id.index = -1; | |||||
| fn(column_id); | |||||
| } | |||||
| return true; | return true; | ||||
| }); | }); | ||||
| } | } | ||||
| std::unique_ptr<ColumnValues> GeometryDataSource::get_column_values( | std::unique_ptr<ColumnValues> GeometryDataSource::get_column_values( | ||||
| const SpreadsheetColumnID &column_id) const | const SpreadsheetColumnID &column_id) const | ||||
| { | { | ||||
| std::lock_guard lock{mutex_}; | std::lock_guard lock{mutex_}; | ||||
| bke::ReadAttributePtr attribute_ptr = component_->attribute_try_get_for_read(column_id.name); | bke::ReadAttributePtr attribute_ptr = component_->attribute_try_get_for_read(column_id.name); | ||||
| if (!attribute_ptr) { | if (!attribute_ptr) { | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| const bke::ReadAttribute *attribute = scope_.add(std::move(attribute_ptr), __func__); | const bke::ReadAttribute *attribute = scope_.add(std::move(attribute_ptr), __func__); | ||||
| if (attribute->domain() != domain_) { | if (attribute->domain() != domain_) { | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| int domain_size = attribute->size(); | int domain_size = attribute->size(); | ||||
| switch (attribute->custom_data_type()) { | switch (attribute->custom_data_type()) { | ||||
| case CD_PROP_FLOAT: | case CD_PROP_FLOAT: | ||||
| if (column_id.index != -1) { | |||||
| return {}; | |||||
| } | |||||
| return column_values_from_function( | return column_values_from_function( | ||||
| column_id.name, domain_size, [attribute](int index, CellValue &r_cell_value) { | column_id.name, domain_size, [attribute](int index, CellValue &r_cell_value) { | ||||
| float value; | float value; | ||||
| attribute->get(index, &value); | attribute->get(index, &value); | ||||
| r_cell_value.value_float = value; | r_cell_value.value_float = value; | ||||
| }); | }); | ||||
| case CD_PROP_INT32: | case CD_PROP_INT32: | ||||
| if (column_id.index != -1) { | |||||
| return {}; | |||||
| } | |||||
| return column_values_from_function( | return column_values_from_function( | ||||
| column_id.name, domain_size, [attribute](int index, CellValue &r_cell_value) { | column_id.name, domain_size, [attribute](int index, CellValue &r_cell_value) { | ||||
| int value; | int value; | ||||
| attribute->get(index, &value); | attribute->get(index, &value); | ||||
| r_cell_value.value_int = value; | r_cell_value.value_int = value; | ||||
| }); | }); | ||||
| case CD_PROP_BOOL: | case CD_PROP_BOOL: | ||||
| if (column_id.index != -1) { | |||||
| return {}; | |||||
| } | |||||
| return column_values_from_function( | return column_values_from_function( | ||||
| column_id.name, domain_size, [attribute](int index, CellValue &r_cell_value) { | column_id.name, domain_size, [attribute](int index, CellValue &r_cell_value) { | ||||
| bool value; | bool value; | ||||
| attribute->get(index, &value); | attribute->get(index, &value); | ||||
| r_cell_value.value_bool = value; | r_cell_value.value_bool = value; | ||||
| }); | }); | ||||
| case CD_PROP_FLOAT2: { | case CD_PROP_FLOAT2: { | ||||
| if (column_id.index < 0 || column_id.index > 1) { | |||||
| return {}; | |||||
| } | |||||
| const std::array<const char *, 2> suffixes = {" X", " Y"}; | |||||
| const std::string name = StringRef(column_id.name) + suffixes[column_id.index]; | |||||
| return column_values_from_function( | return column_values_from_function( | ||||
| name, | column_id.name, | ||||
| domain_size, | domain_size, | ||||
| [attribute, axis = column_id.index](int index, CellValue &r_cell_value) { | [attribute](int index, CellValue &r_cell_value) { | ||||
| float2 value; | float2 value; | ||||
| attribute->get(index, &value); | attribute->get(index, &value); | ||||
| r_cell_value.value_float = value[axis]; | r_cell_value.value_float2 = value; | ||||
| }); | }, | ||||
| default_float2_column_width); | |||||
| } | } | ||||
| case CD_PROP_FLOAT3: { | case CD_PROP_FLOAT3: { | ||||
| if (column_id.index < 0 || column_id.index > 2) { | |||||
| return {}; | |||||
| } | |||||
| const std::array<const char *, 3> suffixes = {" X", " Y", " Z"}; | |||||
| const std::string name = StringRef(column_id.name) + suffixes[column_id.index]; | |||||
| return column_values_from_function( | return column_values_from_function( | ||||
| name, | column_id.name, | ||||
| domain_size, | domain_size, | ||||
| [attribute, axis = column_id.index](int index, CellValue &r_cell_value) { | [attribute](int index, CellValue &r_cell_value) { | ||||
| float3 value; | float3 value; | ||||
| attribute->get(index, &value); | attribute->get(index, &value); | ||||
| r_cell_value.value_float = value[axis]; | r_cell_value.value_float3 = value; | ||||
| }); | }, | ||||
| default_float3_column_width); | |||||
| } | } | ||||
| case CD_PROP_COLOR: { | case CD_PROP_COLOR: { | ||||
| if (column_id.index < 0 || column_id.index > 3) { | |||||
| return {}; | |||||
| } | |||||
| const std::array<const char *, 4> suffixes = {" R", " G", " B", " A"}; | |||||
| const std::string name = StringRef(column_id.name) + suffixes[column_id.index]; | |||||
| return column_values_from_function( | return column_values_from_function( | ||||
| name, | column_id.name, | ||||
| domain_size, | domain_size, | ||||
| [attribute, axis = column_id.index](int index, CellValue &r_cell_value) { | [attribute](int index, CellValue &r_cell_value) { | ||||
| Color4f value; | Color4f value; | ||||
| attribute->get(index, &value); | attribute->get(index, &value); | ||||
| r_cell_value.value_float = value[axis]; | r_cell_value.value_color = value; | ||||
| }); | }, | ||||
| default_color_column_width); | |||||
| } | } | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| int GeometryDataSource::tot_rows() const | int GeometryDataSource::tot_rows() const | ||||
| ▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | |||||
| void InstancesDataSource::foreach_default_column_ids( | void InstancesDataSource::foreach_default_column_ids( | ||||
| FunctionRef<void(const SpreadsheetColumnID &)> fn) const | FunctionRef<void(const SpreadsheetColumnID &)> fn) const | ||||
| { | { | ||||
| if (component_->instances_amount() == 0) { | if (component_->instances_amount() == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| SpreadsheetColumnID column_id; | SpreadsheetColumnID column_id; | ||||
| column_id.index = -1; | |||||
| column_id.name = (char *)"Name"; | column_id.name = (char *)"Name"; | ||||
| fn(column_id); | fn(column_id); | ||||
| for (const char *name : {"Position", "Rotation", "Scale"}) { | for (const char *name : {"Position", "Rotation", "Scale"}) { | ||||
| for (const int i : {0, 1, 2}) { | |||||
| column_id.name = (char *)name; | column_id.name = (char *)name; | ||||
| column_id.index = i; | |||||
| fn(column_id); | fn(column_id); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| std::unique_ptr<ColumnValues> InstancesDataSource::get_column_values( | std::unique_ptr<ColumnValues> InstancesDataSource::get_column_values( | ||||
| const SpreadsheetColumnID &column_id) const | const SpreadsheetColumnID &column_id) const | ||||
| { | { | ||||
| if (component_->instances_amount() == 0) { | if (component_->instances_amount() == 0) { | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| const std::array<const char *, 3> suffixes = {" X", " Y", " Z"}; | |||||
| const int size = this->tot_rows(); | const int size = this->tot_rows(); | ||||
| if (STREQ(column_id.name, "Name")) { | if (STREQ(column_id.name, "Name")) { | ||||
| Span<InstancedData> instance_data = component_->instanced_data(); | Span<InstancedData> instance_data = component_->instanced_data(); | ||||
| std::unique_ptr<ColumnValues> values = column_values_from_function( | std::unique_ptr<ColumnValues> values = column_values_from_function( | ||||
| "Name", size, [instance_data](int index, CellValue &r_cell_value) { | "Name", size, [instance_data](int index, CellValue &r_cell_value) { | ||||
| const InstancedData &data = instance_data[index]; | const InstancedData &data = instance_data[index]; | ||||
| if (data.type == INSTANCE_DATA_TYPE_OBJECT) { | if (data.type == INSTANCE_DATA_TYPE_OBJECT) { | ||||
| if (data.data.object != nullptr) { | if (data.data.object != nullptr) { | ||||
| r_cell_value.value_object = ObjectCellValue{data.data.object}; | r_cell_value.value_object = ObjectCellValue{data.data.object}; | ||||
| } | } | ||||
| } | } | ||||
| else if (data.type == INSTANCE_DATA_TYPE_COLLECTION) { | else if (data.type == INSTANCE_DATA_TYPE_COLLECTION) { | ||||
| if (data.data.collection != nullptr) { | if (data.data.collection != nullptr) { | ||||
| r_cell_value.value_collection = CollectionCellValue{data.data.collection}; | r_cell_value.value_collection = CollectionCellValue{data.data.collection}; | ||||
| } | } | ||||
| } | } | ||||
| }); | }); | ||||
| values->default_width = 8.0f; | values->default_width = 8.0f; | ||||
| return values; | return values; | ||||
| } | } | ||||
| if (column_id.index < 0 || column_id.index > 2) { | |||||
| return {}; | |||||
| } | |||||
| Span<float4x4> transforms = component_->transforms(); | Span<float4x4> transforms = component_->transforms(); | ||||
| if (STREQ(column_id.name, "Position")) { | if (STREQ(column_id.name, "Position")) { | ||||
| std::string name = StringRef("Position") + suffixes[column_id.index]; | |||||
| return column_values_from_function( | return column_values_from_function( | ||||
| name, size, [transforms, axis = column_id.index](int index, CellValue &r_cell_value) { | column_id.name, | ||||
| r_cell_value.value_float = transforms[index].translation()[axis]; | size, | ||||
| }); | [transforms](int index, CellValue &r_cell_value) { | ||||
| r_cell_value.value_float3 = transforms[index].translation(); | |||||
| }, | |||||
| default_float3_column_width); | |||||
| } | } | ||||
| if (STREQ(column_id.name, "Rotation")) { | if (STREQ(column_id.name, "Rotation")) { | ||||
| std::string name = StringRef("Rotation") + suffixes[column_id.index]; | |||||
| return column_values_from_function( | return column_values_from_function( | ||||
| name, size, [transforms, axis = column_id.index](int index, CellValue &r_cell_value) { | column_id.name, | ||||
| r_cell_value.value_float = transforms[index].to_euler()[axis]; | size, | ||||
| }); | [transforms](int index, CellValue &r_cell_value) { | ||||
| r_cell_value.value_float3 = transforms[index].to_euler(); | |||||
| }, | |||||
| default_float3_column_width); | |||||
| } | } | ||||
| if (STREQ(column_id.name, "Scale")) { | if (STREQ(column_id.name, "Scale")) { | ||||
| std::string name = StringRef("Scale") + suffixes[column_id.index]; | |||||
| return column_values_from_function( | return column_values_from_function( | ||||
| name, size, [transforms, axis = column_id.index](int index, CellValue &r_cell_value) { | column_id.name, | ||||
| r_cell_value.value_float = transforms[index].scale()[axis]; | size, | ||||
| }); | [transforms](int index, CellValue &r_cell_value) { | ||||
| r_cell_value.value_float3 = transforms[index].scale(); | |||||
| }, | |||||
| default_float3_column_width); | |||||
| } | } | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| int InstancesDataSource::tot_rows() const | int InstancesDataSource::tot_rows() const | ||||
| { | { | ||||
| return component_->instances_amount(); | return component_->instances_amount(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines | |||||