Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc
| Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | else { | ||||
| bNode &node = params.add_node(node_type); | bNode &node = params.add_node(node_type); | ||||
| node_storage(node).data_type = *type; | node_storage(node).data_type = *type; | ||||
| params.update_and_connect_available_socket(node, "Value"); | params.update_and_connect_available_socket(node, "Value"); | ||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void try_capture_field_on_geometry(GeometryComponent &component, | |||||
| const AttributeIDRef &attribute_id, | |||||
| const eAttrDomain domain, | |||||
| const GField &field) | |||||
| { | |||||
| const int domain_size = component.attribute_domain_size(domain); | |||||
| if (domain_size == 0) { | |||||
| return; | |||||
| } | |||||
| bke::GeometryFieldContext field_context{component, domain}; | |||||
| MutableAttributeAccessor attributes = *component.attributes_for_write(); | |||||
| const IndexMask mask{IndexMask(domain_size)}; | |||||
| const eCustomDataType data_type = bke::cpp_type_to_custom_data_type(field.cpp_type()); | |||||
| GAttributeWriter output_attribute = attributes.lookup_or_add_for_write( | |||||
| attribute_id, domain, data_type); | |||||
| if (!output_attribute) { | |||||
| return; | |||||
| } | |||||
| fn::FieldEvaluator evaluator{field_context, &mask}; | |||||
| evaluator.add_with_destination(field, output_attribute.varray); | |||||
| evaluator.evaluate(); | |||||
| output_attribute.finish(); | |||||
| } | |||||
| static StringRefNull identifier_suffix(eCustomDataType data_type) | static StringRefNull identifier_suffix(eCustomDataType data_type) | ||||
| { | { | ||||
| switch (data_type) { | switch (data_type) { | ||||
| case CD_PROP_FLOAT: | case CD_PROP_FLOAT: | ||||
| return "_001"; | return "_001"; | ||||
| case CD_PROP_INT32: | case CD_PROP_INT32: | ||||
| return "_004"; | return "_004"; | ||||
| case CD_PROP_COLOR: | case CD_PROP_COLOR: | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | static void node_geo_exec(GeoNodeExecParams params) | ||||
| WeakAnonymousAttributeID anonymous_id{"Attribute"}; | WeakAnonymousAttributeID anonymous_id{"Attribute"}; | ||||
| const CPPType &type = field.cpp_type(); | const CPPType &type = field.cpp_type(); | ||||
| /* Run on the instances component separately to only affect the top level of instances. */ | /* Run on the instances component separately to only affect the top level of instances. */ | ||||
| if (domain == ATTR_DOMAIN_INSTANCE) { | if (domain == ATTR_DOMAIN_INSTANCE) { | ||||
| if (geometry_set.has_instances()) { | if (geometry_set.has_instances()) { | ||||
| GeometryComponent &component = geometry_set.get_component_for_write( | GeometryComponent &component = geometry_set.get_component_for_write( | ||||
| GEO_COMPONENT_TYPE_INSTANCES); | GEO_COMPONENT_TYPE_INSTANCES); | ||||
| try_capture_field_on_geometry(component, anonymous_id.get(), domain, field); | bke::try_capture_field_on_geometry(component, anonymous_id.get(), domain, field); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| static const Array<GeometryComponentType> types = { | static const Array<GeometryComponentType> types = { | ||||
| GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_POINT_CLOUD, GEO_COMPONENT_TYPE_CURVE}; | GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_POINT_CLOUD, GEO_COMPONENT_TYPE_CURVE}; | ||||
| geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | ||||
| for (const GeometryComponentType type : types) { | for (const GeometryComponentType type : types) { | ||||
| if (geometry_set.has(type)) { | if (geometry_set.has(type)) { | ||||
| GeometryComponent &component = geometry_set.get_component_for_write(type); | GeometryComponent &component = geometry_set.get_component_for_write(type); | ||||
| try_capture_field_on_geometry(component, anonymous_id.get(), domain, field); | bke::try_capture_field_on_geometry(component, anonymous_id.get(), domain, field); | ||||
| } | } | ||||
| } | } | ||||
| }); | }); | ||||
| } | } | ||||
| GField output_field{std::make_shared<bke::AnonymousAttributeFieldInput>( | GField output_field{std::make_shared<bke::AnonymousAttributeFieldInput>( | ||||
| std::move(anonymous_id), type, params.attribute_producer_name())}; | std::move(anonymous_id), type, params.attribute_producer_name())}; | ||||
| ▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines | |||||