Random Color to Packed Geometry

   641   3   1
User Avatar
Member
2 posts
Joined: Oct. 2022
Offline
Hi guys,

Relative newcomer to Houdini (roughly 1 year) and I have a system where a POP solver is generating particles which then have geo assigned to them with copy to points. This is then fed into an RBD Bullet Solver so the geo bounces off the floor and interacts with itself (file attached). I followed a tutorial to get to this stage but now I want all the created geometry to have a random color attribute. Been wracking my head and looking at the internet for a couple of days to no avail.

I'm pretty sure this would be something Houdini could do but however much I play I don't get anywhere. Any ideas? Attached file will explain everything!

Attachments:
AddColorPackedGeo.hiplc (446.5 KB)

User Avatar
Member
1007 posts
Joined: April 2017
Offline
Hey!

My method was to use Attribute Promote sop to get the name on primitives. After that, I used a wrangle set to primitive with this code:
@Cd = rand(atoi(s@name[+5:]));

the
s@name[+5:]
means to remove the first 5 letters. that way, if I have piece12 it will give me 12
atoi is the function to take a string and convert it to integer
rand is to generate the random color. (*the rand function doesnt work with a string)
Edited by olivierth - Feb. 5, 2024 13:37:45
User Avatar
Member
93 posts
Joined: Dec. 2019
Offline
Hello,

The issue here is that there's no name attribute to use as a source in the color node.

Two simple quick options :
1. Create a name attribute for each kind of geometry. You will get a different color for each kind of geometry.
2. Use the id attribute coming from the pop simulation. You will get a different color for each instance.

In both cases, I suggest to set the color before the copy to points node, it's more simple to setup.

Attachments:
AddColorPackedGeo_Fix.hiplc (575.6 KB)

Houdini Pipeline Supervisor @ TAT Studio
User Avatar
Member
2 posts
Joined: Oct. 2022
Offline
Great thank you both for your ideas I appreciate it. Now it's time for me to work out exactly what's going on under the hood to make these methods work hah, that's fun of learning Houdini I guess. I swear it will take me years to get competent
  • Quick Links