Vex normals and degrees qustions for scatter system

   1547   2   1
User Avatar
Member
25 posts
Joined: June 2020
Offline
Hi there,

I'm working on a scatter system to place objects on a terrain. I'd like to be able to provide some parameters for the objects scattered so they show up in the right place and in the right orientation. I have two questions around the same theme:

Scatter by slope:
I'm trying to provide a max/min value (in degrees) that will only scatter points on a surface within that range. Ex: 0 - 45. I've created a terrain and passed it through the LabsCalculateSlope node. When messing around with it, it gives me values I wasn't expecting. I would guess that a grid rotated 45 degrees would give a slope of .5 but it gives .707 instead. My temp solution is remapping the values from what it gives to what I expected and it sort of works but it's still pretty inaccurate. I'm sure there is a mathematical solution or something I just don't understand!

The second question is similar... I'd like to scatter objects on a surface and align them with the normal of the surface, but provide a maximum deviation from "up" in degrees. ex: a point lands on a surface that is at a 5 degree angle but the max is set to 3 so it would be oriented at 3 degrees rather than 5.

Any help or pointing in the right direction is greatly appreciated! Thank you all.

Attachments:
SlopeIssue01.jpg (187.7 KB)
SlopeIssue02.jpg (78.0 KB)

User Avatar
Member
5204 posts
Joined: Feb. 2012
Offline
Hi,

You can do this using a Point Wrangle:

float GetAngleBetweenVectors ( vector v0; vector v1 )
{
    vector v0n = normalize ( v0 );
    vector v1n = normalize ( v1 );
    return degrees ( atan2 ( length ( cross ( v0n, v1n ) ), dot ( v0n, v1n ) ) );
}


vector up = { 0, 1, 0 };
@angle = GetAngleBetweenVectors ( @N, up );

float maxangle = radians ( ch("maxangle") );

if ( @angle > maxangle )
{
    matrix3 m = ident ( );
    vector z = normalize ( cross ( up, normalize ( @N ) ) );
    rotate ( m, maxangle, z );
    
    @N = up * m;
}

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
User Avatar
Member
25 posts
Joined: June 2020
Offline
Wow, I've been struggling to build a system that does this on-and-off for a long while now. I can't tell you how grateful I Animatrix! Thanks!
  • Quick Links