[Bf-blender-cvs] [9a157d65321] attribute-accessor: initial attribute creation

Jacques Lucke noreply at git.blender.org
Tue Nov 17 17:20:27 CET 2020


Commit: 9a157d65321af49304024d2e24c7700dff9fed71
Author: Jacques Lucke
Date:   Tue Nov 17 16:58:52 2020 +0100
Branches: attribute-accessor
https://developer.blender.org/rB9a157d65321af49304024d2e24c7700dff9fed71

initial attribute creation

===================================================================

M	source/blender/nodes/geometry/nodes/node_geo_random_attribute.cc

===================================================================

diff --git a/source/blender/nodes/geometry/nodes/node_geo_random_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_random_attribute.cc
index ca40ac0b51a..c743cc31a94 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_random_attribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_random_attribute.cc
@@ -18,6 +18,8 @@
 
 #include "BLI_rand.hh"
 
+#include "DNA_mesh_types.h"
+
 static bNodeSocketTemplate geo_node_random_attribute_in[] = {
     {SOCK_GEOMETRY, N_("Geometry")},
     {SOCK_STRING, N_("Attribute")},
@@ -43,9 +45,21 @@ static void geo_random_attribute_exec(GeoNodeExecParams params)
   const int seed = params.extract_input<int>("Seed");
 
   MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
+  Mesh *mesh = mesh_component.get_for_write();
+  if (mesh == nullptr) {
+    params.set_output("Geometry", geometry_set);
+    return;
+  }
+
   std::optional<WriteAttributePtr> attribute_opt = bke::mesh_attribute_get_for_write(
       mesh_component, attribute_name);
 
+  if (!attribute_opt.has_value()) {
+    BKE_id_attribute_new(
+        &mesh->id, attribute_name.c_str(), CD_PROP_FLOAT3, ATTR_DOMAIN_VERTEX, nullptr);
+    attribute_opt = bke::mesh_attribute_get_for_write(mesh_component, attribute_name);
+  }
+
   RandomNumberGenerator rng;
   rng.seed_random(seed);



More information about the Bf-blender-cvs mailing list