Showing posts with label orient. Show all posts
Showing posts with label orient. Show all posts

Tuesday, 27 August 2024

creating orient and rotating points around vector

I think Toadstorm posted this somewhere on odforce... but it's a useful little vex snippet


 vector fwd = v@N;

vector up = {0,1,0};
// if you don't have a defined up vector but want to compute one the way houdini does it natively,
// compute the rotation that rotates +Z to N and apply this to +Y...
// matrix3 d = dihedral({0,0,1}, fwd);
// up = normalize(d * up);matrix3 m = maketransform(fwd, up);
// now you can rotate this around whatever axis you want.
vector axis = normalize(chv("axis")); // or use an existing vector attribute!
float angle = @noiseVal*radians(ch("angle")); // or use a random float attribute!
rotate(m, angle, axis);// now convert this rotated matrix to a quaternion and bind to p@orient. copy to points and/or DOPs will understand this.
@orient = quaternion(m);

Thursday, 9 March 2023

Monday, 9 March 2020

orient point attribute


I always seem to forget/ignore the orient attribute, and it always bites me in the ass.. (think instancing objects onto points with random rotations etc) Usually I randomise/mess up the target points' normals, but if you forget to give your source object clean normals, this can lead to some messy point normals..
If instead, you mess up the target points' orient, you avoid this nonsense. It's worth creating a custom vector attribute display to visualise the orients!

Another snippet stolen from Rich Lord's notes/tools page - https://www.richlord.com/tools/

I suspect that there's a shortcut for building the matrix at the end, but from my understanding this setup should be quite clean..

// create an axis and an up vector.
// The axis will represent the Z direction of the final matrix
vector axis = chv("axis");
vector up   = chv("up");
// normalise these two vectors
axis = normalize(axis);
up = normalize(up);
// build a vector for each axis, then build a matrix out of it.
// I may be normalizing a bit much here, but it cant hurt.
vector zaxis = axis;
vector xaxis = normalize(cross(up, axis));
vector yaxis = normalize(cross(axis, xaxis));
matrix3 default = set(xaxis, yaxis, zaxis);
// create the orient quaternion as a point attribute
p@orient = quaternion(default);

Wednesday, 19 June 2019

rotate packed primitives/ WALTER ROTATE

how to rotate a/bunch of packed primitive/s -
Use a WALTER ROTATE.

in a primitive wrangle:


float randomFactor=rand(@primnum+2323)*chf("randomMult");
matrix3 rot = primintrinsic(0, "transform", @primnum);
vector4 orient = quaternion(rot);
vector x = normalize(qrotate(orient, {1,0,0}));
vector y = normalize(qrotate(orient, {0,1,0}));
rotate(rot, radians(chf("angle") * randomFactor), x);
rotate(rot, radians(chf("angley")), y);
setprimintrinsic(0, "transform", @primnum, rot);

//////////////////
what we are doing is:
  • making a random factor to multiply the rotations, using primnum as a seed
  • creating a matrix called "rot", and initialising it to the transform of the primitive
  • create a vector called "orient", using the quarternion of the rot matrix
  • create vectors x and y
  • rotate the rot matrix using input angles for x and y
  • then finally set the primitive intrinsic using the rot matrix