2
$\begingroup$

Hi geometry nodes friends.

I have a index field with instance values, sampled by an "Sample Index" node. I would like to "shift" the starting index like this:

Let's say I have a index field with values like this (Index, Value):

0 = 2
1 = 4
2 = 6
3 = 8

Now I want to shift the values to get a new field with this:

0 = 4
1 = 6
2 = 8
3 = ...
$\endgroup$

1 Answer 1

5
$\begingroup$

Well, the exact setup might differ from how you obtain the values stored per index and so it might differ from how you transfer it to a different position. For example, if these values were position data, you might change them by using a Set Position node. I'm just using an example where I store an attribute along with the instance index and try to "pass it on" to the lower index.

So let's say I multiply and convert Z positions of cubes to integers just to get some arbitrary numbers and use a Store Named Attribute node to assign these to the attribute "values" with the cube instances, this is the initial situation:

initial situation

The values are stored automatically in index order from 0 to 4. What you now need to do is sample the Named Attribute "values" from the index + 1 via Sample Index node and overwrite the attribute by using another Store Named Attribute node with the same name - since the values are stored in order starting at index 0 you have shifted the values by 1.

shifted index

Only problem here is, on the last index 4 this would need a value from index 4 + 1 = 5 which does not exist so it gets the value 0. If you instead want a cyclic shift with the last index getting the original value of index 0 (which is not clear in your question because the series ends with an ellipsis), you can fix this with a slight modification.

Instead of sampling the Named Attribute at index + 1, plug the index + 1 into a Math node set to Modulo and the Count of a Domain Size node set to Instances into the second input. This way the last index will be set to 0 instead of 5 and you store the original attribute of the first index.

cyclic shift

This works because the index count is 5, but the indices are numbered 0 to 4. So for the modulo of index + 1 with a count of 5 you get:

  • (0 + 1) mod 5 = 1
  • (1 + 1) mod 5 = 2
  • (2 + 1) mod 5 = 3
  • (3 + 1) mod 5 = 4
  • (4 + 1) mod 5 = 0

By the way, I used these random values because I don't know how in your example the values were obtained, but since they could have been easily calculated by using 2 * (index + 1), one could argue a complex setup with real shifting would not have been necessary, you could have simply stored 2 * (index + 2) instead. So I used random values to make sure they were unconnected to the index and had to be shifted in some way.

$\endgroup$
4
  • $\begingroup$ Thank you a lot for your time, Gordon. I guess, being an artist, I've to dive deep into your example first, before understanding what you're actually doing here.... :) $\endgroup$ Commented May 5, 2023 at 9:07
  • $\begingroup$ @ChristophWerner Maybe I could have been more specific regarding your problem if I knew what those values are which you have there, how you got them, where they are stored and where you want to transfer them to. But the shifting process should be usable for other values as well. $\endgroup$ Commented May 5, 2023 at 9:16
  • $\begingroup$ All is fine. I expected a global easy way to shift indexes of fields. $\endgroup$ Commented May 5, 2023 at 10:06
  • $\begingroup$ @ChristophWerner Well, not really since fields themselves have no indices. The parts of geometry like vertices, faces, instances etc. have indices - everything that is on the left in the Spreadsheet has indices. All these parts can hold multiple values and fields, either inherent ones like position, scale and so on or attributes assigned to them. But the indices belong to the geometry. $\endgroup$ Commented May 5, 2023 at 10:26

You must log in to answer this question.

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