I create a tree. Like most things in H, up is +Y.
Scatter points on a grid and instance the tree to them:
… and they all sit upright. Super (though it's worth noting that the points have no Normal attribute at this point). If I want to do something more practical, like scatter on something non-flat, like a sphere, the trees all end up pointing up, rather than out:
OK: but the Scatter SOP will happily transfer surface normals to the scattered points if they exist in the first place, so drop a Normal SOP in before the scatter:
… but now my trees are all lying down:
For the last couple of months that I've been learning Houdini, I've got round this by rotating my tree before copying it, but that's a hack. What I ought to do is rotate my scattered point normals instead, but I can't suss out how. In this “little planet” example, “up” should be pointing out from the sphere - same direction as the normals.
I keep seeing - and playing with - this snippet of VEX for randomly rotating instances around a particular up vector:
float angle = radians(rand(@ptnum) * 360); vector axis = {0,1,0}; matrix3 m = ident(); rotate(m, angle, axis); @orient = quaternion(m);
… but I'm getting nowhere.
So how do create an @orient attrib from my @N normals? I realise that without a meaningful @up vector, there are an infinite number of possible quaternions that will orient things the way I want - that's fine, I just need one of the solutions!
Or: how do I just get a vector perpendicular to @N? (ie any one of the infinite number of solutions)
The frustrating thing about this is that it's so easy to hackily fix (just rotate the damn tree so it's growing up the Z axis instead of Y) but it seems like it ought to be so basic that it's making me feel even more stupid than normal.