1
$\begingroup$

As far as I understand, in Geometry Nodes in Blender 2.9* it is possible to add custom attributes to vertices (to have not just the XYZ position, but say density_tree). For instance, this video (14mn) shows how Attribute Vector can be used to create a new attribute, visualized in the spreadsheet as a new column. However, in Blender 3.0 this node does not exist anymore. What is the 3.0 way of creating/reading custom attributes in Geometry Nodes?

EDIT

For instance, I may like to use it to interface my nodes with an external python script: the python script would add custom attributes to each point depending on some potentially complex procedures, and the Geometry node could then read these attributes and proceed accordingly.

EDIT

The proposed answer does not solve my problem, I'm looking for a way to set/get a per vertex attribute (I think it is called sometimes layer in the python API).

For instance, let's say that I have a cube selected in edit mode. Then I can do:

import bmesh
mesh = bpy.context.view_layer.objects.active.data
bm = bmesh.from_edit_mesh(mesh)
layer_kind = bm.verts.layers.int.new("mykind")
bm.verts[0][layer_kind] = 42

and it will create a new column mykind, with the first vertex having the value 42 and the others 0:

enter image description here

Now, could I get/set this custom per-vertex attribute, using Geometry Nodes in Blender 3.0? For instance, to draw a cylinder at the vertex position when the kind is 42 and a cube otherwise?

EDIT

Thanks to Chris and Blunder, I can now do more or less what I want... Here is basically the picture given by Blunder where I added the important parts in red:

enter image description here

However, the user of the modifier needs to configure the name of the attribute (rightmost part) while I would prefer to have it hardcoded into my Geometry Node. Do you know if it's possible?

I also tried to create a new attribute instead, and it works similarly (in fact, no need to use python to create a new attribute, I can just write any name and it will be created automatically. But again, it would be cool to hardcode the name in the node directly (or at least provide a default name for the attribute).

enter image description here

$\endgroup$
5
  • $\begingroup$ As a quick answer without going in-depth: the Capture Attribute can create custom attributes shown in a new column. But I'm not working much with it at the moment so I can't give a full answer on that. I guess it also depends on what kind of custom attributes you want to create to give an answer how to do this now. $\endgroup$ Mar 8, 2022 at 7:03
  • $\begingroup$ @GordonBrinkmann Thanks for your answer, it seems indeed to be quite close to what I need. Sadly, it does not support strings nor named attributes since this is an anonymous attributes. Being able to read/set a named attribute may be interesting for interfacing it with a Python script. $\endgroup$
    – tobiasBora
    Mar 8, 2022 at 7:20
  • 1
    $\begingroup$ You can connect any custom attribute as shown in Chris' answer to the Capture Attribute's value slot. It supports strings, Material IDs, UV maps, etc. $\endgroup$
    – Blunder
    Mar 8, 2022 at 9:40
  • $\begingroup$ @Blunder I'm not sure to see how it is useful, this won't be usable for per vertex attribute right? I tried to give a more complete explanation in my edit. $\endgroup$
    – tobiasBora
    Mar 8, 2022 at 14:09
  • 1
    $\begingroup$ Yes, you don't need the Capture Attribute node for your (updated) example. Just plug the custom attribute into a Field input slot and it will be usable per vertex (point). See my comment below Chris' answer. $\endgroup$
    – Blunder
    Mar 8, 2022 at 14:12

1 Answer 1

2
$\begingroup$

You can use "custom" attributes like this:

enter image description here

So you have to define them now in the group input node and you can do whatever you wanna do with them and even plug them in the output node and do something in the shader with it (if you want)

$\endgroup$
4
  • $\begingroup$ Thanks, but this is not what I was asking for, I want a per vertex attribute. See my edit, I added some python code that do what I want, and I need to translate it in Geometry node (getter/setter). $\endgroup$
    – tobiasBora
    Mar 8, 2022 at 11:04
  • 2
    $\begingroup$ The answer is (almost) correct. Just drag the custom slot into a Field input slot and select "mykind" in the modifier settings: i.stack.imgur.com/gOzRj.jpg $\endgroup$
    – Blunder
    Mar 8, 2022 at 14:07
  • $\begingroup$ @Blunder Whoo, interesting, thanks a lot... So the trick is to set "Value" to Mykind directly in the modifier panel... But can't I choose the attribute inside the Nodes as it were possible in 2.93? I don't want to ask to the user of my Geometry node to go through the process of configuring the attributes... I also tried to apply a similar method to create a new attribute by plugging it on the output and configuring it in the Modifier tab, but it's similarly annoying (the user needs to configure it) and I need to use python to create the new layer/attribute or it won't appear in the list. $\endgroup$
    – tobiasBora
    Mar 8, 2022 at 14:36
  • $\begingroup$ I see. That's a good point! I don't know if there's a way to choose an attribute inside the Nodes as it was possible in 2.93. In Geo Nodes 3 the Group Input & Group Output define the interface. This interface is exposed in the modifier setting. There the values are set (a float value, custom attribute, image, UV map, vertex group, etc) - (Edit, correction): It looks like the settings of the GN modifier are stored with the Node tree. Once you have configured the settings in the modifier tab you can remove the modifier and add it to any object, choose the GN tree => the settings are back! $\endgroup$
    – Blunder
    Mar 8, 2022 at 17:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .