Random switch :

   885   2   1
User Avatar
Member
1 posts
Joined: 10月 2019
Offline
Hello all :
I am new to Houdini, and I am trying to do the following :
I want to spawn a random polygon on the scene.
But I don't know how to do it...

any idea? leads? thank you!

Attachments:
spawn.jpg (313.7 KB)

User Avatar
Member
478 posts
Joined: 8月 2014
Offline
How random this polygon needs to be?

The code below, when pasted into a detail wrangle node will create a random polygon within a (-1, 1) range of XYZ. Point count and seed are regulated by spare parameters. They need to be created first (hit the plus button in the wrangle's UI).
int point_count = chi("points") + npoints(0);
int points[];
int seed = chi("seed");
for(int i = npoints(0); i < point_count; i++)
{
    vector pos = set(
        fit(rand(seed + i - npoints(0)), 0, 1, -1, 1),
        fit(rand(seed + i + 1 - npoints(0)), 0, 1, -1, 1),
        fit(rand(seed + i + 2 - npoints(0)), 0, 1, -1, 1)
    );
    addpoint(0, pos);
    push(points, i);
}
if(len(points) > 0)
    addprim(0, "poly", points);
Edited by ajz3d - 2023年7月4日 15:06:35
User Avatar
Member
131 posts
Joined: 8月 2012
Online
Create a variant attribute for each different object, Merge all of them before Copy To Points. Set a variant attribute on the points before the loop that matches the range of possible variant values. Enable variant and select correct attribute in Copy node.
  • Quick Links