Partition elements (geometry islands)

Forums: Partition elements (geometry islands)
Forum for OctaneRender Lua scripting examples, discussion and support.

Partition elements (geometry islands)

Postby jobigoud » Tue Sep 14, 2021 4:00 pm

jobigoud Tue Sep 14, 2021 4:00 pm
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 6 times


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


Random map OSL:
randommap.osl
(1.95 KiB) Downloaded 13 times
Last edited by jobigoud on Tue Sep 21, 2021 9:26 am, edited 1 time in total.
User avatar
jobigoud
OctaneRender Team
OctaneRender Team
 
Posts: 93
Joined: Sat Aug 15, 2015 1:28 pm

Re: Partition elements (geometry islands)

Postby whersmy » Tue Sep 14, 2021 4:25 pm

whersmy Tue Sep 14, 2021 4:25 pm
Wow! This is massive! Gonna try it out right away, thanks guys! :D
mac pro g5| pentium g2030 iGPU| maximus extreme V| 2x gtx590 - 8gb - SSD - win7-x64- 1500W Silverstone|
x201t - gtx580 - egpu ec
Dell G5 - 8GB - dgpu GTX1060 - TB3 egpu @ GTX1060
Octane Render experiments
User avatar
whersmy
Licensed Customer
Licensed Customer
 
Posts: 671
Joined: Thu Aug 30, 2012 7:40 am

Re: Partition elements (geometry islands)

Postby jobigoud » Tue Sep 21, 2021 9:28 am

jobigoud Tue Sep 21, 2021 9:28 am
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.
User avatar
jobigoud
OctaneRender Team
OctaneRender Team
 
Posts: 93
Joined: Sat Aug 15, 2015 1:28 pm

Re: Partition elements (geometry islands)

Postby AndreasBergmann » Wed Sep 22, 2021 9:56 am

AndreasBergmann Wed Sep 22, 2021 9:56 am
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
AndreasBergmann
Licensed Customer
Licensed Customer
 
Posts: 12
Joined: Fri May 20, 2016 7:49 am

Re: Partition elements (geometry islands)

Postby jobigoud » Wed Sep 22, 2021 10:57 am

jobigoud Wed Sep 22, 2021 10:57 am
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".
User avatar
jobigoud
OctaneRender Team
OctaneRender Team
 
Posts: 93
Joined: Sat Aug 15, 2015 1:28 pm

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 2 guests

Fri Sep 24, 2021 4:00 am [ UTC ]