diff options
Diffstat (limited to 'source/blender/editors')
6 files changed, 76 insertions, 35 deletions
diff --git a/source/blender/editors/geometry/geometry_attributes.cc b/source/blender/editors/geometry/geometry_attributes.cc index 446aabd13c8..452f1df86fb 100644 --- a/source/blender/editors/geometry/geometry_attributes.cc +++ b/source/blender/editors/geometry/geometry_attributes.cc @@ -241,7 +241,6 @@ enum class ConvertAttributeMode { Generic, UVMap, VertexGroup, - VertexColor, }; static bool geometry_attribute_convert_poll(bContext *C) @@ -288,7 +287,7 @@ static int geometry_attribute_convert_exec(bContext *C, wmOperator *op) const CustomDataType dst_type = static_cast<CustomDataType>( RNA_enum_get(op->ptr, "data_type")); - if (ELEM(dst_type, CD_PROP_STRING, CD_PROP_BYTE_COLOR)) { + if (ELEM(dst_type, CD_PROP_STRING)) { BKE_report(op->reports, RPT_ERROR, "Cannot convert to the selected type"); return OPERATOR_CANCELLED; } @@ -314,20 +313,6 @@ static int geometry_attribute_convert_exec(bContext *C, wmOperator *op) &mesh->ldata, CD_MLOOPUV, CD_ASSIGN, dst_uvs, mesh->totloop, name.c_str()); break; } - case ConvertAttributeMode::VertexColor: { - MLoopCol *dst_colors = static_cast<MLoopCol *>( - MEM_calloc_arrayN(mesh->totloop, sizeof(MLoopCol), __func__)); - VArray<ColorGeometry4f> src_varray = mesh_component.attribute_get_for_read<ColorGeometry4f>( - name, ATTR_DOMAIN_CORNER, ColorGeometry4f{0.0f, 0.0f, 0.0f, 1.0f}); - for (const int i : IndexRange(mesh->totloop)) { - ColorGeometry4b encoded_color = src_varray[i].encode(); - copy_v4_v4_uchar(&dst_colors[i].r, &encoded_color.r); - } - mesh_component.attribute_try_delete(name); - CustomData_add_layer_named( - &mesh->ldata, CD_PROP_BYTE_COLOR, CD_ASSIGN, dst_colors, mesh->totloop, name.c_str()); - break; - } case ConvertAttributeMode::VertexGroup: { Array<float> src_weights(mesh->totvert); VArray<float> src_varray = mesh_component.attribute_get_for_read<float>( @@ -550,7 +535,6 @@ void GEOMETRY_OT_attribute_convert(wmOperatorType *ot) {int(ConvertAttributeMode::Generic), "GENERIC", 0, "Generic", ""}, {int(ConvertAttributeMode::UVMap), "UV_MAP", 0, "UV Map", ""}, {int(ConvertAttributeMode::VertexGroup), "VERTEX_GROUP", 0, "Vertex Group", ""}, - {int(ConvertAttributeMode::VertexColor), "VERTEX_COLOR", 0, "Color Attribute", ""}, {0, nullptr, 0, nullptr, nullptr}, }; diff --git a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc index 14b9dbe4b44..b3d6c395e89 100644 --- a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc +++ b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc @@ -300,6 +300,7 @@ static float get_default_column_width(const ColumnValues &values) return values.default_width; } static const float float_width = 3; + static const float int_width = 2; switch (values.type()) { case SPREADSHEET_VALUE_TYPE_BOOL: return 2.0f; @@ -317,6 +318,8 @@ static float get_default_column_width(const ColumnValues &values) return 8.0f; case SPREADSHEET_VALUE_TYPE_STRING: return 5.0f; + case SPREADSHEET_VALUE_TYPE_BYTE_COLOR: + return 4.0f * int_width; case SPREADSHEET_VALUE_TYPE_UNKNOWN: return 2.0f; } diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc index 19fe61f0ed3..a29aa1fd026 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc @@ -44,6 +44,9 @@ eSpreadsheetColumnValueType cpp_type_to_column_type(const CPPType &type) if (type.is<InstanceReference>()) { return SPREADSHEET_VALUE_TYPE_INSTANCES; } + if (type.is<ColorGeometry4b>()) { + return SPREADSHEET_VALUE_TYPE_BYTE_COLOR; + } return SPREADSHEET_VALUE_TYPE_UNKNOWN; } diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc index db466f8ccf3..e19a343335a 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc @@ -191,6 +191,10 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer { const ColorGeometry4f value = data.get<ColorGeometry4f>(real_index); this->draw_float_vector(params, Span(&value.r, 4)); } + else if (data.type().is<ColorGeometry4b>()) { + const ColorGeometry4b value = data.get<ColorGeometry4b>(real_index); + this->draw_int_vector(params, {value.r, value.g, value.b, value.a}); + } else if (data.type().is<InstanceReference>()) { const InstanceReference value = data.get<InstanceReference>(real_index); switch (value.type()) { @@ -304,6 +308,34 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer { } } + void draw_int_vector(const CellDrawParams ¶ms, const Span<int> values) const + { + BLI_assert(!values.is_empty()); + const float segment_width = (float)params.width / values.size(); + for (const int i : values.index_range()) { + const int value = values[i]; + const std::string value_str = std::to_string(value); + uiBut *but = uiDefIconTextBut(params.block, + UI_BTYPE_LABEL, + 0, + ICON_NONE, + value_str.c_str(), + params.xmin + i * segment_width, + params.ymin, + segment_width, + params.height, + nullptr, + 0, + 0, + 0, + 0, + nullptr); + /* Right-align Ints. */ + UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); + UI_but_drawflag_enable(but, UI_BUT_TEXT_RIGHT); + } + } + int column_width(int column_index) const final { return spreadsheet_layout_.columns[column_index].width; diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc index e45317c2a5c..eb8f111baa0 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc @@ -106,10 +106,10 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, const float2 value = row_filter.value_float2; switch (row_filter.operation) { case SPREADSHEET_ROW_FILTER_EQUAL: { - const float threshold_sq = row_filter.threshold; + const float threshold_sq = pow2f(row_filter.threshold); apply_filter_operation( column_data.typed<float2>(), - [&](const float2 cell) { return math::distance_squared(cell, value) > threshold_sq; }, + [&](const float2 cell) { return math::distance_squared(cell, value) <= threshold_sq; }, prev_mask, new_indices); break; @@ -136,10 +136,10 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, const float3 value = row_filter.value_float3; switch (row_filter.operation) { case SPREADSHEET_ROW_FILTER_EQUAL: { - const float threshold_sq = row_filter.threshold; + const float threshold_sq = pow2f(row_filter.threshold); apply_filter_operation( column_data.typed<float3>(), - [&](const float3 cell) { return math::distance_squared(cell, value) > threshold_sq; }, + [&](const float3 cell) { return math::distance_squared(cell, value) <= threshold_sq; }, prev_mask, new_indices); break; @@ -168,19 +168,25 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter, } else if (column_data.type().is<ColorGeometry4f>()) { const ColorGeometry4f value = row_filter.value_color; - switch (row_filter.operation) { - case SPREADSHEET_ROW_FILTER_EQUAL: { - const float threshold_sq = row_filter.threshold; - apply_filter_operation( - column_data.typed<ColorGeometry4f>(), - [&](const ColorGeometry4f cell) { - return len_squared_v4v4(cell, value) > threshold_sq; - }, - prev_mask, - new_indices); - break; - } - } + const float threshold_sq = pow2f(row_filter.threshold); + apply_filter_operation( + column_data.typed<ColorGeometry4f>(), + [&](const ColorGeometry4f cell) { return len_squared_v4v4(cell, value) <= threshold_sq; }, + prev_mask, + new_indices); + } + else if (column_data.type().is<ColorGeometry4b>()) { + const ColorGeometry4b value = row_filter.value_byte_color; + const float4 value_floats = {(float)value.r, (float)value.g, (float)value.b, (float)value.a}; + const float threshold_sq = pow2f(row_filter.threshold); + apply_filter_operation( + column_data.typed<ColorGeometry4b>(), + [&](const ColorGeometry4b cell) { + const float4 cell_floats = {(float)cell.r, (float)cell.g, (float)cell.b, (float)cell.a}; + return len_squared_v4v4(value_floats, cell_floats) <= threshold_sq; + }, + prev_mask, + new_indices); } else if (column_data.type().is<InstanceReference>()) { const StringRef value = row_filter.value_string; diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter_ui.cc b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter_ui.cc index 6206b2d0c03..7c1ac024c12 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter_ui.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter_ui.cc @@ -42,7 +42,8 @@ static std::string operation_string(const eSpreadsheetColumnValueType data_type, if (ELEM(data_type, SPREADSHEET_VALUE_TYPE_BOOL, SPREADSHEET_VALUE_TYPE_INSTANCES, - SPREADSHEET_VALUE_TYPE_COLOR)) { + SPREADSHEET_VALUE_TYPE_COLOR, + SPREADSHEET_VALUE_TYPE_BYTE_COLOR)) { return "="; } @@ -101,6 +102,14 @@ static std::string value_string(const SpreadsheetRowFilter &row_filter, } case SPREADSHEET_VALUE_TYPE_STRING: return row_filter.value_string; + case SPREADSHEET_VALUE_TYPE_BYTE_COLOR: { + std::ostringstream result; + result.precision(3); + result << std::fixed << "(" << (int)row_filter.value_byte_color[0] << ", " + << (int)row_filter.value_byte_color[1] << ", " << (int)row_filter.value_byte_color[2] + << ", " << (int)row_filter.value_byte_color[3] << ")"; + return result.str(); + } case SPREADSHEET_VALUE_TYPE_UNKNOWN: return ""; } @@ -229,6 +238,10 @@ static void spreadsheet_filter_panel_draw(const bContext *C, Panel *panel) case SPREADSHEET_VALUE_TYPE_STRING: uiItemR(layout, filter_ptr, "value_string", 0, IFACE_("Value"), ICON_NONE); break; + case SPREADSHEET_VALUE_TYPE_BYTE_COLOR: + uiItemR(layout, filter_ptr, "value_byte_color", 0, IFACE_("Value"), ICON_NONE); + uiItemR(layout, filter_ptr, "threshold", 0, nullptr, ICON_NONE); + break; case SPREADSHEET_VALUE_TYPE_UNKNOWN: uiItemL(layout, IFACE_("Unknown column type"), ICON_ERROR); break; |