diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc
index a29e26dfe0a..4799ff903a28e4f71dd03b 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc
@@ -54,6 +54,7 @@ static AttributeDomain get_result_domain(const GeometryComponent &component,
{
/* Use the domain of the result attribute if it already exists. */
ReadAttributePtr result_attribute = component.attribute_try_get_for_read(result_attribute_name);
+
if (result_attribute) {
return result_attribute->domain();
}
@@ -87,248 +88,6117 @@ static void execute_on_component(GeometryComponent &component, const GeoNodeExec
const AttributeDomain result_domain = get_result_domain(
component, result_attribute_name, mapping_name);
+ ReadAttributePtr result_attribute = component.attribute_try_get_for_read(result_attribute_name);
+
+ CustomDataType data_type = CD_PROP_COLOR;
+
+ if (result_attribute && result_attribute->custom_data_type() == CD_PROP_FLOAT3) {
+ data_type = CD_PROP_FLOAT3;
+ }
+
OutputAttributePtr attribute_out = component.attribute_try_get_for_output(
- result_attribute_name, result_domain, CD_PROP_COLOR);
+ result_attribute_name, result_domain, data_type);
+
if (!attribute_out) {
+ params.error_message_add(NodeWarningType::Error,
+ "No writeable attribute with name '" + result_attribute_name + "'.");
return;
}
@@ -96,15 +106,41 @@ static void execute_on_component(GeometryComponent &component, const GeoNodeExec
Float3ReadAttribute mapping_attribute = component.attribute_get_for_read<float3>(
mapping_name, result_domain, {0, 0, 0});
- MutableSpan<Color4f> colors = attribute_out->get_span<Color4f>();
- for (const int i : IndexRange(mapping_attribute.size())) {
- TexResult texture_result = {0};
- const float3 position = mapping_attribute[i];
- /* For legacy reasons we have to map [0, 1] to [-1, 1] to support uv mappings. */
- const float3 remapped_position = position * 2.0f - float3(1.0f);
- BKE_texture_get_value(nullptr, texture, remapped_position, &texture_result, false);
- colors[i] = {texture_result.tr, texture_result.tg, texture_result.tb, texture_result.ta};
+ if (data_type == CD_PROP_FLOAT3) {
+ MutableSpan<float3> colors = attribute_out->get_span<float3>();
+ if (colors.is_empty()) {
+ params.error_message_add(NodeWarningType::Info, "No attribute data to write to.");
+ return;
+ }
+
+ for (const int i : colors.index_range()) {
+ TexResult texture_result = {0};
+ const float3 position = mapping_attribute[i];
+ /* For legacy reasons we have to map [0, 1] to [-1, 1] to support uv mappings. */
+ const float3 remapped_position = position * 2.0f - float3(1.0f);
+ BKE_texture_get_value(nullptr, texture, remapped_position, &texture_result, false);
+
+ colors[i] = {texture_result.tr, texture_result.tg, texture_result.tb};
+ }
}
+ else {
+ MutableSpan<Color4f> colors = attribute_out->get_span<Color4f>();
+ if (colors.is_empty()) {
+ params.error_message_add(NodeWarningType::Info, "No attribute data to write to.");
+ return;
+ }
+
+ for (const int i : colors.index_range()) {
+ TexResult texture_result = {0};
+ const float3 position = mapping_attribute[i];
+ /* For legacy reasons we have to map [0, 1] to [-1, 1] to support uv mappings. */
+ const float3 remapped_position = position * 2.0f - float3(1.0f);
+ BKE_texture_get_value(nullptr, texture, remapped_position, &texture_result, false);
+
+ colors[i] = {texture_result.tr, texture_result.tg, texture_result.tb, texture_result.ta};
+ }
+ }
+
attribute_out.apply_span_and_save();
}