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:
authorJacques Lucke <jacques@blender.org>2021-01-14 17:52:08 +0300
committerJacques Lucke <jacques@blender.org>2021-01-14 17:52:08 +0300
commite5ee7e9a2df93d7f28f9e1f8bc0eb2d33dfadfb4 (patch)
treef36c7d02bc3441c75b6233fcaa4b0611df883248 /source/blender/nodes/geometry
parent53bd58993e2f6d35452242762402c20343d6eef3 (diff)
Geometry Nodes: don't delete existing attribute before new attribute is computed
This fixes the behavior of some nodes when the same attribute name is used for input and output. If both attributes have a different type, they can't exist at the same time. Therefore, the input attribute has to be removed in order to create the output attribute. Previously, the input attribute was remove before it was used in any computations. Now, the output is written to a temporary buffer and only later saved in the geometry component. This allows both attributes to coexist within the node. The temporary attribute is only create when necessary. The normal case without name collisions still works the same as before. Differential Revision: https://developer.blender.org/D10109 Ref T83793.
Diffstat (limited to 'source/blender/nodes/geometry')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc6
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc4
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc7
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc8
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc3
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc3
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc4
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_vector_math.cc3
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc18
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_point_rotate.cc6
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_point_scale.cc6
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_point_translate.cc6
12 files changed, 38 insertions, 36 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc b/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
index c38f54ce7f7..eac77b25bd6 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
@@ -41,12 +41,12 @@ static void align_rotations_on_component(GeometryComponent &component,
const NodeGeometryAlignRotationToVector &storage = *(const NodeGeometryAlignRotationToVector *)
node.storage;
- WriteAttributePtr rotation_attribute = component.attribute_try_ensure_for_write(
+ OutputAttributePtr rotation_attribute = component.attribute_try_get_for_output(
"rotation", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
if (!rotation_attribute) {
return;
}
- MutableSpan<float3> rotations = rotation_attribute->get_span().typed<float3>();
+ MutableSpan<float3> rotations = rotation_attribute->get_span<float3>();
FloatReadAttribute factors = params.get_input_attribute<float>(
"Factor", component, ATTR_DOMAIN_POINT, 1.0f);
@@ -85,7 +85,7 @@ static void align_rotations_on_component(GeometryComponent &component,
rotations[i] = new_rotation;
}
- rotation_attribute->apply_span();
+ rotation_attribute.apply_span_and_save();
}
static void geo_node_align_rotation_to_vector_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
index 2aca9ed581c..9b0900e19ab 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
@@ -46,7 +46,7 @@ static void execute_on_component(const GeoNodeExecParams &params, GeometryCompon
/* Once we support more domains at the user level, we have to decide how the result domain is
* chosen. */
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);
if (!attribute_result) {
return;
@@ -64,7 +64,7 @@ static void execute_on_component(const GeoNodeExecParams &params, GeometryCompon
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)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
index 8ea88e7153d..20a2b2127c2 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
@@ -242,7 +242,7 @@ static void attribute_compare_calc(GeometryComponent &component, const GeoNodeEx
/* Get result attribute first, in case it has to overwrite one of the existing attributes. */
const std::string result_name = params.get_input<std::string>("Result");
- WriteAttributePtr attribute_result = component.attribute_try_ensure_for_write(
+ OutputAttributePtr attribute_result = component.attribute_try_get_for_output(
result_name, result_domain, result_type);
if (!attribute_result) {
return;
@@ -260,8 +260,7 @@ static void attribute_compare_calc(GeometryComponent &component, const GeoNodeEx
return;
}
- BooleanWriteAttribute attribute_result_bool = *attribute_result;
- MutableSpan<bool> result_span = attribute_result_bool.get_span_for_write_only();
+ MutableSpan<bool> result_span = attribute_result->get_span_for_write_only<bool>();
/* Use specific types for correct equality operations, but for other operations we use implicit
* conversions and float comparison. In other words, the comparison is not element-wise. */
@@ -300,7 +299,7 @@ static void attribute_compare_calc(GeometryComponent &component, const GeoNodeEx
do_math_operation(*attribute_a, *attribute_b, operation, result_span);
}
- attribute_result_bool.apply_span();
+ attribute_result.apply_span_and_save();
}
static void geo_node_attribute_compare_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
index 96685196917..9cec4070f89 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
@@ -68,7 +68,7 @@ static void fill_attribute(GeometryComponent &component, const GeoNodeExecParams
return;
}
- WriteAttributePtr attribute = component.attribute_try_ensure_for_write(
+ OutputAttributePtr attribute = component.attribute_try_get_for_output(
attribute_name, domain, data_type);
if (!attribute) {
return;
@@ -79,33 +79,31 @@ static void fill_attribute(GeometryComponent &component, const GeoNodeExecParams
const float value = params.get_input<float>("Value_001");
MutableSpan<float> attribute_span = attribute->get_span_for_write_only<float>();
attribute_span.fill(value);
- attribute->apply_span();
break;
}
case CD_PROP_FLOAT3: {
const float3 value = params.get_input<float3>("Value");
MutableSpan<float3> attribute_span = attribute->get_span_for_write_only<float3>();
attribute_span.fill(value);
- attribute->apply_span();
break;
}
case CD_PROP_COLOR: {
const Color4f value = params.get_input<Color4f>("Value_002");
MutableSpan<Color4f> attribute_span = attribute->get_span_for_write_only<Color4f>();
attribute_span.fill(value);
- attribute->apply_span();
break;
}
case CD_PROP_BOOL: {
const bool value = params.get_input<bool>("Value_003");
MutableSpan<bool> attribute_span = attribute->get_span_for_write_only<bool>();
attribute_span.fill(value);
- attribute->apply_span();
break;
}
default:
break;
}
+
+ attribute.apply_span_and_save();
}
static void geo_node_attribute_fill_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc
index 6e3b34f702a..f8ec9124db3 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc
@@ -107,7 +107,7 @@ static void attribute_math_calc(GeometryComponent &component, const GeoNodeExecP
/* Get result attribute first, in case it has to overwrite one of the existing attributes. */
const std::string result_name = params.get_input<std::string>("Result");
- WriteAttributePtr attribute_result = component.attribute_try_ensure_for_write(
+ OutputAttributePtr attribute_result = component.attribute_try_get_for_output(
result_name, result_domain, result_type);
if (!attribute_result) {
return;
@@ -123,6 +123,7 @@ static void attribute_math_calc(GeometryComponent &component, const GeoNodeExecP
}
do_math_operation(*attribute_a, *attribute_b, *attribute_result, operation);
+ attribute_result.save();
}
static void geo_node_attribute_math_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
index 4d8645b3b25..58d67145e75 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
@@ -136,7 +136,7 @@ static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecPa
result_domain = result_attribute_read->domain();
}
- WriteAttributePtr attribute_result = component.attribute_try_ensure_for_write(
+ OutputAttributePtr attribute_result = component.attribute_try_get_for_output(
result_name, result_domain, result_type);
if (!attribute_result) {
return;
@@ -155,6 +155,7 @@ static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecPa
*attribute_a,
*attribute_b,
*attribute_result);
+ attribute_result.save();
}
static void geo_node_attribute_mix_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
index 60e1441e363..0e7bb25e659 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
@@ -151,7 +151,7 @@ static void randomize_attribute(GeometryComponent &component,
return;
}
- WriteAttributePtr attribute = component.attribute_try_ensure_for_write(
+ OutputAttributePtr attribute = component.attribute_try_get_for_output(
attribute_name, domain, data_type);
if (!attribute) {
return;
@@ -179,6 +179,8 @@ static void randomize_attribute(GeometryComponent &component,
default:
break;
}
+
+ attribute.save();
}
static void geo_node_random_attribute_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_vector_math.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_vector_math.cc
index de377e8bc87..529906a35e7 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_vector_math.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_vector_math.cc
@@ -345,7 +345,7 @@ static void attribute_vector_math_calc(GeometryComponent &component,
/* Get result attribute first, in case it has to overwrite one of the existing attributes. */
const std::string result_name = params.get_input<std::string>("Result");
- WriteAttributePtr attribute_result = component.attribute_try_ensure_for_write(
+ OutputAttributePtr attribute_result = component.attribute_try_get_for_output(
result_name, result_domain, result_type);
if (!attribute_result) {
return;
@@ -390,6 +390,7 @@ static void attribute_vector_math_calc(GeometryComponent &component,
*attribute_a, *attribute_b, *attribute_c, *attribute_result, operation);
break;
}
+ attribute_result.save();
}
static void geo_node_attribute_vector_math_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
index 1370f45877d..2f1aa276532 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
@@ -333,27 +333,27 @@ static void geo_node_point_distribute_exec(GeoNodeExecParams params)
point_component.replace(pointcloud);
{
- Int32WriteAttribute stable_id_attribute = point_component.attribute_try_ensure_for_write(
+ OutputAttributePtr stable_id_attribute = point_component.attribute_try_get_for_output(
"id", ATTR_DOMAIN_POINT, CD_PROP_INT32);
- MutableSpan<int> stable_ids_span = stable_id_attribute.get_span();
+ MutableSpan<int> stable_ids_span = stable_id_attribute->get_span<int>();
stable_ids_span.copy_from(stable_ids);
- stable_id_attribute.apply_span();
+ stable_id_attribute.apply_span_and_save();
}
{
- Float3WriteAttribute normals_attribute = point_component.attribute_try_ensure_for_write(
+ OutputAttributePtr normals_attribute = point_component.attribute_try_get_for_output(
"normal", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
- MutableSpan<float3> normals_span = normals_attribute.get_span();
+ MutableSpan<float3> normals_span = normals_attribute->get_span<float3>();
normals_span.copy_from(normals);
- normals_attribute.apply_span();
+ normals_attribute.apply_span_and_save();
}
{
- Float3WriteAttribute rotations_attribute = point_component.attribute_try_ensure_for_write(
+ OutputAttributePtr rotations_attribute = point_component.attribute_try_get_for_output(
"rotation", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
- MutableSpan<float3> rotations_span = rotations_attribute.get_span();
+ MutableSpan<float3> rotations_span = rotations_attribute->get_span<float3>();
rotations_span.copy_from(rotations);
- rotations_attribute.apply_span();
+ rotations_attribute.apply_span_and_save();
}
params.set_output("Geometry", std::move(geometry_set_out));
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_rotate.cc b/source/blender/nodes/geometry/nodes/node_geo_point_rotate.cc
index f22036ffe62..b1451dfb89e 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_rotate.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_rotate.cc
@@ -104,13 +104,13 @@ static void point_rotate_on_component(GeometryComponent &component,
const bNode &node = params.node();
const NodeGeometryRotatePoints &storage = *(const NodeGeometryRotatePoints *)node.storage;
- WriteAttributePtr rotation_attribute = component.attribute_try_ensure_for_write(
+ OutputAttributePtr rotation_attribute = component.attribute_try_get_for_output(
"rotation", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
if (!rotation_attribute) {
return;
}
- MutableSpan<float3> rotations = rotation_attribute->get_span().typed<float3>();
+ MutableSpan<float3> rotations = rotation_attribute->get_span<float3>();
const int domain_size = rotations.size();
if (storage.type == GEO_NODE_POINT_ROTATE_TYPE_AXIS_ANGLE) {
@@ -138,7 +138,7 @@ static void point_rotate_on_component(GeometryComponent &component,
}
}
- rotation_attribute->apply_span();
+ rotation_attribute.apply_span_and_save();
}
static void geo_node_point_rotate_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_scale.cc b/source/blender/nodes/geometry/nodes/node_geo_point_scale.cc
index 165f467fef0..e5cbe27768d 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_scale.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_scale.cc
@@ -34,7 +34,7 @@ namespace blender::nodes {
static void execute_on_component(GeoNodeExecParams params, GeometryComponent &component)
{
- Float3WriteAttribute scale_attribute = component.attribute_try_ensure_for_write(
+ OutputAttributePtr scale_attribute = component.attribute_try_get_for_output(
"scale", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
ReadAttributePtr attribute = params.get_input_attribute(
"Factor", component, ATTR_DOMAIN_POINT, CD_PROP_FLOAT3, nullptr);
@@ -43,12 +43,12 @@ static void execute_on_component(GeoNodeExecParams params, GeometryComponent &co
}
Span<float3> data = attribute->get_span<float3>();
- MutableSpan<float3> scale_span = scale_attribute.get_span();
+ MutableSpan<float3> scale_span = scale_attribute->get_span<float3>();
for (const int i : scale_span.index_range()) {
scale_span[i] = scale_span[i] * data[i];
}
- scale_attribute.apply_span();
+ scale_attribute.apply_span_and_save();
}
static void geo_node_point_scale_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_translate.cc b/source/blender/nodes/geometry/nodes/node_geo_point_translate.cc
index 1dbc6016024..72176b11fdb 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_translate.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_translate.cc
@@ -34,7 +34,7 @@ namespace blender::nodes {
static void execute_on_component(GeoNodeExecParams params, GeometryComponent &component)
{
- Float3WriteAttribute position_attribute = component.attribute_try_ensure_for_write(
+ OutputAttributePtr position_attribute = component.attribute_try_get_for_output(
"position", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
ReadAttributePtr attribute = params.get_input_attribute(
"Translation", component, ATTR_DOMAIN_POINT, CD_PROP_FLOAT3, nullptr);
@@ -43,12 +43,12 @@ static void execute_on_component(GeoNodeExecParams params, GeometryComponent &co
}
Span<float3> data = attribute->get_span<float3>();
- MutableSpan<float3> scale_span = position_attribute.get_span();
+ MutableSpan<float3> scale_span = position_attribute->get_span<float3>();
for (const int i : scale_span.index_range()) {
scale_span[i] = scale_span[i] + data[i];
}
- position_attribute.apply_span();
+ position_attribute.apply_span_and_save();
}
static void geo_node_point_translate_exec(GeoNodeExecParams params)