Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
| Show All 40 Lines | static void execute_on_component(const GeoNodeExecParams ¶ms, GeometryComponent &component) | ||||
| * Using the type of an existing attribute could work, but does not have a real benefit | * Using the type of an existing attribute could work, but does not have a real benefit | ||||
| * currently. */ | * currently. */ | ||||
| const CustomDataType result_type = CD_PROP_COLOR; | const CustomDataType result_type = CD_PROP_COLOR; | ||||
| const std::string result_name = params.get_input<std::string>("Result"); | const std::string result_name = params.get_input<std::string>("Result"); | ||||
| /* Once we support more domains at the user level, we have to decide how the result domain is | /* Once we support more domains at the user level, we have to decide how the result domain is | ||||
| * chosen. */ | * chosen. */ | ||||
| const AttributeDomain result_domain = ATTR_DOMAIN_POINT; | const AttributeDomain result_domain = ATTR_DOMAIN_POINT; | ||||
| WriteAttributePtr attribute_result = component.attribute_try_ensure_for_write( | OutputAttributePtr attribute_result = component.attribute_try_get_for_output( | ||||
| result_name, result_domain, result_type); | result_name, result_domain, result_type); | ||||
| if (!attribute_result) { | if (!attribute_result) { | ||||
| return; | return; | ||||
| } | } | ||||
| const std::string input_name = params.get_input<std::string>("Attribute"); | const std::string input_name = params.get_input<std::string>("Attribute"); | ||||
| FloatReadAttribute attribute_in = component.attribute_get_for_read<float>( | FloatReadAttribute attribute_in = component.attribute_get_for_read<float>( | ||||
| input_name, result_domain, 0.0f); | input_name, result_domain, 0.0f); | ||||
| Span<float> data_in = attribute_in.get_span(); | Span<float> data_in = attribute_in.get_span(); | ||||
| MutableSpan<Color4f> data_out = attribute_result->get_span_for_write_only<Color4f>(); | MutableSpan<Color4f> data_out = attribute_result->get_span_for_write_only<Color4f>(); | ||||
| ColorBand *color_ramp = &node_storage->color_ramp; | ColorBand *color_ramp = &node_storage->color_ramp; | ||||
| for (const int i : data_in.index_range()) { | for (const int i : data_in.index_range()) { | ||||
| BKE_colorband_evaluate(color_ramp, data_in[i], data_out[i]); | BKE_colorband_evaluate(color_ramp, data_in[i], data_out[i]); | ||||
| } | } | ||||
| attribute_result->apply_span(); | attribute_result.apply_span_and_save(); | ||||
| } | } | ||||
| static void geo_node_attribute_color_ramp_exec(GeoNodeExecParams params) | static void geo_node_attribute_color_ramp_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | ||||
| if (geometry_set.has<MeshComponent>()) { | if (geometry_set.has<MeshComponent>()) { | ||||
| execute_on_component(params, geometry_set.get_component_for_write<MeshComponent>()); | execute_on_component(params, geometry_set.get_component_for_write<MeshComponent>()); | ||||
| Show All 33 Lines | |||||