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);

No comments:

Post a Comment