Please help me stand my trees up on my sphere [@N / @up / @orient problems]

   13495   9   3
User Avatar
Member
146 posts
Joined: Sept. 2011
Offline
This should be simple but I'm getting my knickers in a twist over it. I'm trying to align instances of an object over a surface, but they always end up lying down.

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.
User Avatar
Member
2528 posts
Joined: June 2008
Offline
You may find some information here to help.
http://forums.odforce.net/topic/27316-rotateorientalignmentquaternionsetc/?tab=comments#comment-156983 [forums.odforce.net]
Using Houdini Indie 20.0
Ubuntu 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
146 posts
Joined: Sept. 2011
Offline
Thanks Enivob!

In a nutshell, it seems that to orient the instances' Y axis to the point normals, you use a dihedral to create the orientation quaternion like this:

@orient = dihedral({0,1,0},@N);
User Avatar
Member
8514 posts
Joined: July 2007
Online
you always need up vector to get stable orient
I'd suggest you to just rotate your tree as that will make your life much easier:
vector up = {0,1,0};
vector nN = normalize(v@N);
p@orient = quaternion(maketransform(nN, up));
but if you really need N to represent Y axis you can do for example this:
vector up = {0,1,0};
vector nN = normalize(v@N);
matrix3 localrot = matrix3(maketransform(0, 0, {0,0,0}, {90, 0, 0}, {1,1,1}));
matrix3 rot = maketransform(nN, up);
p@orient = quaternion(localrot*rot);

but of course if your geo is translating or deforming, make sure your upvector is stable, so make it from polyframe for example
Edited by tamte - Oct. 9, 2017 11:49:34
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
146 posts
Joined: Sept. 2011
Offline
Thanks Tomas, lots to experiment with and get my head around.

Rotating the instanced geometry before caching it is what I've been doing up until now, but it felt a bit strange - it's all trees and bushes and nature. Feels wrong to create it growing along the ground, even if you know it'll look right when it's instanced into place. But I think for simplicity's sake I'll just cache them all out pre-rotated, as you suggest.

Ta!
User Avatar
Member
8514 posts
Joined: July 2007
Online
you can cache them out Y up
just have Transform SOP before copy to points, that's all
or make custom Copy HDA that has transform inside
or of course feel free to do that extra work and generate y-up orient, no wrong answers
Edited by tamte - Oct. 9, 2017 19:24:34
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
146 posts
Joined: Sept. 2011
Offline
Yep - I'm just thinking ahead - the Copy to points SOP is great for quick tests but I'm anticipating having lots of copies, lots of variants, so I'll be ditching the copy and using instancing, where I don't get the opportunity to do a transform of the geometry first. Should have been more clear in my question.

> feel free to do that extra work and generate y-up orient, no wrong answers

Yep, but I've gotta learn to pick my battles. If it looks right, it is right, in this particular game. Still getting my head round that

User Avatar
Member
8514 posts
Joined: July 2007
Online
you can always use copy for instancing packed disk objects and they can be processed through transform before, up to you
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
91 posts
Joined: Oct. 2015
Offline
@tamte thank you so much that one sweet vex snippet

“vector up = {0,1,0};
vector nN = normalize(v@N);
matrix3 localrot = matrix3(maketransform(0, 0, {0,0,0}, {90, 0, 0}, {1,1,1}));
matrix3 rot = maketransform(nN, up);
p@orient = quaternion(localrot*rot);”


i can do so much with that

for people who new you can just add box then “add pointwrangle add code in the pointwrangle” then drop down a copy stamp “add a ”line“ to right node of the copy stamp ” add the pointwrangle wire"
Edited by gfxfx - Oct. 11, 2017 13:21:34

Attachments:
a1.jpg (301.5 KB)
a2.jpg (344.9 KB)
b.jpg (482.2 KB)

User Avatar
Staff
1182 posts
Joined: July 2005
Online
When you copy to points, the tree should be oriented along the Z axis. You then make sure that the normal node “Adds Normals to” POINTS rather than vertices and you should be good to go.

I know you want to avoid rotating the tree but the copy to points is looking for things oriented along the Z axis so that is the UP vector for the copied objects.
Edited by rmagee - Oct. 11, 2017 18:03:35

Attachments:
copy_scatter_sphere.jpg (108.3 KB)
copy_scatter_sphere.hip (64.1 KB)

Robert Magee
Senior Product Marketing Manager
SideFX
  • Quick Links