How does one rotate scatter objects randomly within a range with VEX

   18169   5   1
User Avatar
Member
109 posts
Joined: 3月 2017
Offline
I am scattering objects for instancing with redshift (trees) and need random Y rotation. I am doing this without a copy node, by merging the grid object inside the instance node. I want to use a simple attribute wrangle after the scatter to do this.

If anyone can point me to the right tutorial/example or vex code I would greatly appreciate it.
Edited by decksounds - 2017年4月21日 15:34:55
User Avatar
Member
2543 posts
Joined: 6月 2008
Offline
I am trying to do the same thing. I have come up with this code that works if you are scattering on a grid, (i.e. Y axis is up.)

// Randomize rotation.
vector axis = {0,1,0};
vector nvec = normalize(axis);
float rand = fit01(random(@ptnum+311),0,360);
vector4 quat = quaternion(radians(rand), nvec);
@orient = qmultiply({0,0,0,1}, quat);

But it does not work on a curved surface such as a sphere.
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
2543 posts
Joined: 6月 2008
Offline
There is a reply on OdForum for scattering along curved surfaces. Check out here. [forums.odforce.net]
Edited by Enivob - 2017年4月22日 13:09:32
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
7802 posts
Joined: 9月 2011
Online
Just replace the axis with the normal, and instead of qmultiply identity, use dihedral of up to N.
User Avatar
Member
109 posts
Joined: 3月 2017
Offline
Thanks guys, I will check out the odforce link and try to play with that vex. For now, I used the vops method in the Halloween instancing tutorial and it is working fine with redshift.

Now I would like to find a way to randomly blend between the Y axis world space normals and the point normals from the scatter so the trees look more natural.

Any ideas? I would prefer to do it in vops unless there is an easier way. Thanks again.
User Avatar
Member
7802 posts
Joined: 9月 2011
Online
If you compute the dihedral between the y-axis vector, and the normal vector, you can slerp between the resulting orientation and an identity orientation. You can use the align VOP to get the dihedral as a quaternion (its in the signature dropdown as angle axis), and the slerp vop will blend between orientations. Use qmultiply to transform the random y orientation by the local tilt.

Example point sop expressions:

random yaxis orientation:
name: orient, value (0, 1, 0, 2*$PI), type v4
quaternion(float(rand(@elemnum*32.3848374))*value.w,(vector)value)

align to normal:
name: tilt, value (0,1,0,0), type v4
dihedral((vector)value,@N)

random blend:
name: tilt, value (0,0,0,1), type v4
slerp(value,p@tilt,rand(@elemnum*1.03837373737))

multiply:
name: orient, value: (0,0,0,0), type v4
qmultiply(p@tilt,self)
Edited by jsmack - 2017年4月22日 19:13:23
  • Quick Links