diff options
author | Jacques Lucke <jacques@blender.org> | 2021-10-26 13:48:29 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-10-26 13:48:43 +0300 |
commit | d20fa6c4d48580bf5fc140cf83fd7d8829bd8e09 (patch) | |
tree | 48de1a2888711af95ac13870c15f1cb234d0036e /source/blender/editors/space_node | |
parent | 41a4c62c315508f1da8f5b020dd4e2304828453e (diff) |
Geometry Nodes: don't log full fields when not necessary
Previously, the field on every socket was logged for later use. This had
two main negative consequences:
* Increased memory usage, because the fields may contain a lot of data
under some circumstances (e.g. a Ray Cast field contains the target geometry).
* Decreased performance, because anonymous attributes could not be
removed from geometry automatically, because there were still fields that
referenced them.
Now most fields are not logged anymore. Only those that are viewed by a
spreadsheet and constant fields. The required inputs of a field are still
logged in string form to keep socket inspection working.
Diffstat (limited to 'source/blender/editors/space_node')
-rw-r--r-- | source/blender/editors/space_node/node_draw.cc | 124 |
1 files changed, 70 insertions, 54 deletions
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 8029eb5e0fa..3a307777d0a 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -854,60 +854,7 @@ static void create_inspection_string_for_generic_value(const geo_log::GenericVal const GPointer value = value_log.value(); const CPPType &type = *value.type(); - if (const FieldCPPType *field_type = dynamic_cast<const FieldCPPType *>(&type)) { - const CPPType &base_type = field_type->field_type(); - BUFFER_FOR_CPP_TYPE_VALUE(base_type, buffer); - const GField &field = field_type->get_gfield(value.get()); - if (field.node().depends_on_input()) { - if (base_type.is<int>()) { - ss << TIP_("Integer Field"); - } - else if (base_type.is<float>()) { - ss << TIP_("Float Field"); - } - else if (base_type.is<blender::float3>()) { - ss << TIP_("Vector Field"); - } - else if (base_type.is<bool>()) { - ss << TIP_("Boolean Field"); - } - else if (base_type.is<std::string>()) { - ss << TIP_("String Field"); - } - ss << TIP_(" based on:\n"); - - /* Use vector set to deduplicate inputs. */ - VectorSet<std::reference_wrapper<const FieldInput>> field_inputs; - field.node().foreach_field_input( - [&](const FieldInput &field_input) { field_inputs.add(field_input); }); - for (const FieldInput &field_input : field_inputs) { - ss << "\u2022 " << field_input.socket_inspection_name(); - if (field_input != field_inputs.as_span().last().get()) { - ss << ".\n"; - } - } - } - else { - blender::fn::evaluate_constant_field(field, buffer); - if (base_type.is<int>()) { - ss << *(int *)buffer << TIP_(" (Integer)"); - } - else if (base_type.is<float>()) { - ss << *(float *)buffer << TIP_(" (Float)"); - } - else if (base_type.is<blender::float3>()) { - ss << *(blender::float3 *)buffer << TIP_(" (Vector)"); - } - else if (base_type.is<bool>()) { - ss << ((*(bool *)buffer) ? TIP_("True") : TIP_("False")) << TIP_(" (Boolean)"); - } - else if (base_type.is<std::string>()) { - ss << *(std::string *)buffer << TIP_(" (String)"); - } - base_type.destruct(buffer); - } - } - else if (type.is<Object *>()) { + if (type.is<Object *>()) { id_to_inspection_string((ID *)*value.get<Object *>(), ID_OB); } else if (type.is<Material *>()) { @@ -924,6 +871,71 @@ static void create_inspection_string_for_generic_value(const geo_log::GenericVal } } +static void create_inspection_string_for_gfield(const geo_log::GFieldValueLog &value_log, + std::stringstream &ss) +{ + const CPPType &type = value_log.type(); + const GField &field = value_log.field(); + const Span<std::string> input_tooltips = value_log.input_tooltips(); + + if (input_tooltips.is_empty()) { + if (field) { + BUFFER_FOR_CPP_TYPE_VALUE(type, buffer); + blender::fn::evaluate_constant_field(field, buffer); + if (type.is<int>()) { + ss << *(int *)buffer << TIP_(" (Integer)"); + } + else if (type.is<float>()) { + ss << *(float *)buffer << TIP_(" (Float)"); + } + else if (type.is<blender::float3>()) { + ss << *(blender::float3 *)buffer << TIP_(" (Vector)"); + } + else if (type.is<bool>()) { + ss << ((*(bool *)buffer) ? TIP_("True") : TIP_("False")) << TIP_(" (Boolean)"); + } + else if (type.is<std::string>()) { + ss << *(std::string *)buffer << TIP_(" (String)"); + } + type.destruct(buffer); + } + else { + /* Constant values should always be logged. */ + BLI_assert_unreachable(); + ss << "Value has not been logged"; + } + } + else { + if (type.is<int>()) { + ss << TIP_("Integer Field"); + } + else if (type.is<float>()) { + ss << TIP_("Float Field"); + } + else if (type.is<blender::float3>()) { + ss << TIP_("Vector Field"); + } + else if (type.is<bool>()) { + ss << TIP_("Boolean Field"); + } + else if (type.is<std::string>()) { + ss << TIP_("String Field"); + } + else if (type.is<blender::ColorGeometry4f>()) { + ss << TIP_("Color Field"); + } + ss << TIP_(" based on:\n"); + + for (const int i : input_tooltips.index_range()) { + const blender::StringRef tooltip = input_tooltips[i]; + ss << "\u2022 " << tooltip; + if (i < input_tooltips.size() - 1) { + ss << ".\n"; + } + } + } +} + static void create_inspection_string_for_geometry(const geo_log::GeometryValueLog &value_log, std::stringstream &ss) { @@ -1015,6 +1027,10 @@ static std::optional<std::string> create_socket_inspection_string(bContext *C, dynamic_cast<const geo_log::GenericValueLog *>(value_log)) { create_inspection_string_for_generic_value(*generic_value_log, ss); } + if (const geo_log::GFieldValueLog *gfield_value_log = + dynamic_cast<const geo_log::GFieldValueLog *>(value_log)) { + create_inspection_string_for_gfield(*gfield_value_log, ss); + } else if (const geo_log::GeometryValueLog *geo_value_log = dynamic_cast<const geo_log::GeometryValueLog *>(value_log)) { create_inspection_string_for_geometry(*geo_value_log, ss); |