Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc46
1 files changed, 29 insertions, 17 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
index 3b348dd0136..69a4fad10e2 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
@@ -45,7 +45,7 @@ static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
{
const NodeGeometryStoreNamedAttribute &storage = node_storage(*node);
- const CustomDataType data_type = static_cast<CustomDataType>(storage.data_type);
+ const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
bNodeSocket *socket_geometry = (bNodeSocket *)node->inputs.first;
bNodeSocket *socket_name = socket_geometry->next;
@@ -69,7 +69,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
search_link_ops_for_declarations(params, declaration.inputs().take_front(2));
if (params.in_out() == SOCK_OUT) {
- const std::optional<CustomDataType> type = node_data_type_to_custom_data_type(
+ const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
static_cast<eNodeSocketDatatype>(params.other_socket().type));
if (type && *type != CD_PROP_STRING) {
/* The input and output sockets have the same name. */
@@ -84,41 +84,48 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
static void try_capture_field_on_geometry(GeometryComponent &component,
const StringRef name,
- const AttributeDomain domain,
+ const eAttrDomain domain,
const GField &field)
{
+ const int domain_size = component.attribute_domain_size(domain);
+ if (domain_size == 0) {
+ return;
+ }
+ MutableAttributeAccessor attributes = *component.attributes_for_write();
+
GeometryComponentFieldContext field_context{component, domain};
- const int domain_num = component.attribute_domain_num(domain);
- const IndexMask mask{IndexMask(domain_num)};
+ const IndexMask mask{IndexMask(domain_size)};
const CPPType &type = field.cpp_type();
- const CustomDataType data_type = bke::cpp_type_to_custom_data_type(type);
+ const eCustomDataType data_type = bke::cpp_type_to_custom_data_type(type);
/* Could avoid allocating a new buffer if:
* - We are writing to an attribute that exists already.
* - The field does not depend on that attribute (we can't easily check for that yet). */
- void *buffer = MEM_mallocN(type.size() * domain_num, __func__);
+ void *buffer = MEM_mallocN(type.size() * domain_size, __func__);
fn::FieldEvaluator evaluator{field_context, &mask};
- evaluator.add_with_destination(field, GMutableSpan{type, buffer, domain_num});
+ evaluator.add_with_destination(field, GMutableSpan{type, buffer, domain_size});
evaluator.evaluate();
- component.attribute_try_delete(name);
- if (component.attribute_exists(name)) {
- WriteAttributeLookup write_attribute = component.attribute_try_get_for_write(name);
+ attributes.remove(name);
+ if (attributes.contains(name)) {
+ GAttributeWriter write_attribute = attributes.lookup_for_write(name);
if (write_attribute && write_attribute.domain == domain &&
write_attribute.varray.type() == type) {
write_attribute.varray.set_all(buffer);
- write_attribute.tag_modified_fn();
+ write_attribute.finish();
}
else {
/* Cannot change type of built-in attribute. */
}
- type.destruct_n(buffer, domain_num);
+ type.destruct_n(buffer, domain_size);
MEM_freeN(buffer);
}
else {
- component.attribute_try_create(name, domain, data_type, AttributeInitMove{buffer});
+ if (!attributes.add(name, domain, data_type, bke::AttributeInitMove{buffer})) {
+ MEM_freeN(buffer);
+ }
}
}
@@ -131,12 +138,17 @@ static void node_geo_exec(GeoNodeExecParams params)
params.set_output("Geometry", std::move(geometry_set));
return;
}
+ if (!bke::allow_procedural_attribute_access(name)) {
+ params.error_message_add(NodeWarningType::Info, TIP_(bke::no_procedural_access_message));
+ params.set_output("Geometry", std::move(geometry_set));
+ return;
+ }
- params.used_named_attribute(name, NamedAttributeUsage::Write);
+ params.used_named_attribute(name, eNamedAttrUsage::Write);
const NodeGeometryStoreNamedAttribute &storage = node_storage(params.node());
- const CustomDataType data_type = static_cast<CustomDataType>(storage.data_type);
- const AttributeDomain domain = static_cast<AttributeDomain>(storage.domain);
+ const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
+ const eAttrDomain domain = static_cast<eAttrDomain>(storage.domain);
GField field;
switch (data_type) {