Page 1 of 1

Partition elements (geometry islands)

PostPosted: Tue Sep 14, 2021 4:00 pm
by jobigoud
Hi everyone,

This is a script to partition a geometry into isolated elements and tag these elements with an attribute.
This can be used to randomly assign textures to the various disconnected parts of a single mesh.

random-texture-wood.png


What does it do?
It goes through the input geometry and figures out which polygons are connected together. It then creates a vertex attribute and assigns a value to each vertex based on the geometry island the vertex belongs to.

Usage
For this example I will use this floor geometry created in 3DSMax with the FloorGenerator plugin. This is a single OBJ file.

basemesh.png


1. Add a Scripted graph node and load the script "partition.lua" into it.

2. Plug the geometry node you want to partition into the Geometry input.

3. Choose a name for the attribute using the Attribute name input, for example "elementid".
We will use this later to control texturing.
Remember that there is a limit to 4 float attributes for Mesh nodes, you need to have at least one empty slot in your source mesh for this to work.
The attribute values will range from 1 to the number of islands found.

4. Texturing
Any texturing applied to the input geometry will also be applied to the modified copy.

4.1 Add a Greyscale vertex attribute texture node and set its Name input to the chosen attribute name.

4.2 Add a Random map texture node (If you don't have this node an OSL version is provided below.). Plug the Greyscale vertex attribute node into it and set the Noise function to Hash.
This will convert our attribute from integers into a number between 0 and 1 that we can use in a Gradient map.

4.3 Add a Gradient map texture node. Plug the Random map into it. Set the interpolation to Constant and add some control points.
You should get something like the following.
We have assigned colors randomly to the isolated elements of the geometry.

random-texture.png


Instead of simple colors, you can use actual textures as the values of the Gradient map's control points, as in the first image.

The final graph looks like this:

nodegraph.png


Tip: The Input scale field in the Random map node can be used as a seed to change the result.

Note: It will work with Alembic scenes and more complex input trees, but if the input contains a scripted graph or a wrapped scripted graph (e.g: Scatter tools), it may not work. I am working on fixing this issue.

Feedback, bug reports and suggestions are highly appreciated.

Lua script:
partition.lua
(12.61 KiB) Downloaded 215 times


Demo ORBX:
partition_demo.orbx
(217.03 KiB) Downloaded 228 times


Random map OSL:
randommap.osl
(1.95 KiB) Downloaded 240 times

Re: Partition elements (geometry islands)

PostPosted: Tue Sep 14, 2021 4:25 pm
by whersmy
Wow! This is massive! Gonna try it out right away, thanks guys! :D

Re: Partition elements (geometry islands)

PostPosted: Tue Sep 21, 2021 9:28 am
by jobigoud
I updated the scripts in the OP to better support Octane 2020 and Octane X.
I also added a raw OSL equivalent to the Random map texture.

Re: Partition elements (geometry islands)

PostPosted: Wed Sep 22, 2021 9:56 am
by AndreasBergmann
210922_random_partition.jpg


Hi,
great script, thanks!
I see some color fading into partitions when hash noise function is applied. I don't see this when other functions (eg unsigned perlin) are used but it's the same behaviour when a gradient texture is applied with hash. I'm using the OSL random map you have provided with 2020.2.1 standalone.

Any advice on what I am doing wrong is much appreciated.

Best, Andreas

Re: Partition elements (geometry islands)

PostPosted: Wed Sep 22, 2021 10:57 am
by jobigoud
Thanks, I can see it as well. It's still there in 2020.2.5 unfortunately. It was fixed somewhere between 2021.1.RC1 and 2021.1.RC2.
Probably this change from the log:
"Changed interpolation of vertex attributes so if the vertices have the same value it returns that exact value".