How to get The up-vector of a primitive?

   20031   23   2
User Avatar
Member
23 posts
Joined: July 2005
Offline
Is it possible to get the Up-vector of a primitive with the “prim” expression function in SOP. for example;

prim(“../PrimA”,ch(“../GeoA/pattern”),“N”,0) gives me the x value of the normal of a (~selected) primitive.
What is the expressions to use to get the up-vector values.

(does a primitive has a up-vector by default just like a normal? or do you have to assign one first?)
User Avatar
Member
2199 posts
Joined: July 2005
Online
I think you answered your own question. There is no up vector by default, although normally you might consider the Normal to be the up-vector.
The trick is finding just the right hammer for every screw
User Avatar
Member
23 posts
Joined: July 2005
Offline
I'm asking that question because im trying to “glue” or align a piece geometry on another piece of geometry at SOP level using the normals of a pair of expression selected primitives on both pieces (1 each) as reference for orientation.

Think of it as procedural glueing candle stick holders on to a piano front or side.

(i tried alignSOP but it was a bit over my head).

I succeeded in getting the primitives in the same plane but they still need to a rotation in the plane itself to adjust its position when i change the primitive selection.

As a prototype i use two different sphere's rotated and translated to mimic a modeling position. I choose a primitive on both and use expressions to translate and rotate, to position the primitives on top of each other. if i vary the selection of the primitives. the aligned primitive keeps rotating around the surface normal.

This is only the expression i used in the rotate around the X-axis of a transformSOP.

if(dot(normalize(vector3(prim(“../TransA”,ch(“../PrimA/pattern”),“N”,0),prim(“../TransA”,ch(“../PrimA/pattern”),“N”,1),prim(“../TransA”,ch(“../PrimA/pattern”),“N”,2))),normalize(vector3(prim(“../PrimB”,ch(“../PrimB/pattern”),“N”,0),prim(“../PrimB”,ch(“../PrimB/pattern”),“N”,1),prim(“../PrimB”,ch(“../PrimB/pattern”),“N”,2)))) != ( -1),explodematrix(dihedral(normalize(vector3(prim(“../TransA”,ch(“../PrimA/pattern”),“N”,0),prim(“../TransA”,ch(“../PrimA/pattern”),“N”,1),prim(“../TransA”,ch(“../PrimA/pattern”),“N”,2))),normalize(vector3(prim(“../PrimB”,ch(“../PrimB/pattern”),“N”,0),prim(“../PrimB”,ch(“../PrimB/pattern”),“N”,1),prim(“../PrimB”,ch(“../PrimB/pattern”),“N”,2)))), “SRT”, “XYZ”, “RX”),180)
User Avatar
Member
2199 posts
Joined: July 2005
Online
Try this

http://www.sidefx.com/exchange/info.php?fileid=99&versionid=99 [sidefx.com]
The trick is finding just the right hammer for every screw
User Avatar
Member
23 posts
Joined: July 2005
Offline
Thanx. I tried that one but i cant get into the vex to see how it was done…

and if you vary the rotation of the SOP geo pieces before inputting them into the vex then the orientation of the qube in regard of the world axis doesn't stay the same.

(On the other hand it is a good example how to get 2 data streams into 1 vex. that is something else i have'nt succeded in yet).
User Avatar
Member
2199 posts
Joined: July 2005
Online
Sorry don't quite follow what you mean by
if you vary the rotation of the SOP geo pieces before inputting them into the vex then the orientation of the qube in regard of the world axis doesn't stay the same

Could you explain further?

I think the vex code for that sop was set up in vops which makes it a bit difficult to read, when I get home I can post up the vop network that made it if I can find it.

By the way you can get to the vex code by RMB and going to type properties and then the VEX tab.

To access other data streams in a vex sop use the import function.


Hope that helps a little
The trick is finding just the right hammer for every screw
User Avatar
Member
23 posts
Joined: July 2005
Offline
Thanx, Simon, If you still can find it, i would really appreciate that to see the inner workings of that VEX.

Also thanks for the info on getting more than one point data stream into a vex. I did wonder how to use the global variables for more than one data stream.
for now i want to try to get it working on sop level. (My matrix and vector knowledge isn't that good yet).

to eleborate;

To test modeling circumstances i put a transformSOP between both the alignment source, the alignment target geometry and the Vex “orient”.

If you change the initial orientation of the box or the sphere with the transformSOP before they get plugged into the Vex, the box start to “spin” on the primitive surface if you vary the rotation of the target or source geometry along one of the axis.

I like to be able to assign an up( or down) to a piece of geometry that i'm going to allign, so that when it gets aligned to the source geometry it will keep its “upright” position.( The candle stick holders on the piano metafor or the up and down in level-geometry)

So after the translation and rotation to align a piece of geometry on a primitive surface i wanted to apply a transformAxisSOP with the Normal of the primitive as rotation axis so i could compensate for the spin.

For that i wanted to calculate the angle between the up-vectors of the primitives of the source and target that are used for the initial alignment

The user participation in this all is to be able to assign wat up or down is for the geometry that gets aligned.

I yet have come up with a solution how to get or assign those up-vectors for those two planes.
User Avatar
Member
23 posts
Joined: July 2005
Offline
eh,Something else i forgot to ask, something that i stumbled apon with custom OTL's.

How do you get something like a value “total number of primitives” for a subnet SOP into the OTL parameters to use as a range max in a primitve selection slider parameter?
User Avatar
Member
2199 posts
Joined: July 2005
Online
Now I see what you mean, yes it will spin, because as you say there is no defined up vector. Orient was designed as a modelling solution so that you set it up once and then leave it be. The problem is that it simply computes the dihedral matrix that aligns the two normals but nothing else, dihedrals are unstable and the rotation around the normal changes when the orientation changes. The way round this is to add another vector at 90 degrees so using the center of the prim “c” and the first point “p0”

vector up = p0-c

we can then do the cross product twice to build a complete coordinate axis

so
zaxis = N
yaxis = cross(N, up)
xaxis = cross(N,yaxis)

do the cross product twice ensures all vectors are at right angles

you then have to do this again for the prim you want to align to.
Once you have both sets of axes you can do a stable alignment.
To do this you build a matrix out of the axis vectors, invert one and multiple the two together.
This final matrix can be used to reposition all your points.

(there may be other better ways to do all this, but that's how I do it)

Anyway, thats a lot to do in an expression, hence the need for vex.

The alternative is to do it at object level using the rivet object.


To get the total number of primitives use nprims(“path to sop”)
But you can't use it to change the range of a slider, AFAIK.

I'll try and update orient to add the functions you need.
The trick is finding just the right hammer for every screw
User Avatar
Member
23 posts
Joined: July 2005
Offline
Thanks Simon, That explains a lot.

I'm used to 3dsmax, zo i never had the need before to open the curtain and find the actual Wizard of Oz; the real inner workings of 3d space.

I appricate the update very much. (Still would like a peek into the Vex if that's ok with you. How those matrixes are build. i tried my hand on a spot of normalmap rendering but got a bit atangled in Vex).

Sometimes the help files of Houdini are a bit sketchy when you really have to start typing those expressions or stringing up those operators.

( largly through my unfamiliarity with what is possible with vectors & matrix )
User Avatar
Member
2199 posts
Joined: July 2005
Online
Typing help and exhelp in the textport will give you a list of all commands.
For help on a particular one type exhelp followed by the name. It's much quicker than going through the html help.
The trick is finding just the right hammer for every screw
User Avatar
Member
23 posts
Joined: July 2005
Offline
Ah, Thanks again for the file.

I'm going to examine its in and out's CSI;Miami style.
User Avatar
Member
23 posts
Joined: July 2005
Offline
shock That last file should be called Superglue instead of Orient.

It opens a door to a lot of posibilities for “hinge” like constructions.

Thanks again. As i said before the inside will a good example too on how to use matrixes in VEX.
User Avatar
Member
2199 posts
Joined: July 2005
Online
Yeah I think it's a much better way of doing things, it probably explains why there is no dihedral vop, you can only access it through the inline vop.

I'll update the one on Exchange to match as it a far more stable way of doing things.

The reason its not called glue or such like is because I have another sop for doing that, you specify two points on each mesh an it “glues” the two together scaleing and rotating so that everything lines up.
The trick is finding just the right hammer for every screw
User Avatar
Member
23 posts
Joined: July 2005
Offline
There is some scaling effect of the geometry if you use the parameter slider Prim a or Prim B to change the alignment primitives.

They are not connected in the VEX with other subnet operaters.

Are they like local variables?
User Avatar
Member
2199 posts
Joined: July 2005
Online
Ah, that sounds like a bug, I'll take a look.
Unless, when you change the prim slider value do you also update the “prim A point 0” and the “prim B point 0” value. These have to be point numbers in the prim you what to align otherwise the sop doesn't build the correct up vector for the transform. It's a bit of a pain but at the moment it's the only way I can think to do it as vex can't get this info itself.

The Prim A and Prim B parameters are just dummy parameters that are used by the expressions in the Prim A and Prim B tabs to look up the prim normals and centers, since this is information you can't access directly in VEX, vex being a points only method.
The trick is finding just the right hammer for every screw
User Avatar
Member
23 posts
Joined: July 2005
Offline
Letting the user do some preparation stuff before alignment could be an option.

for example;

Input 1 would be the geometry that is going to be aligned/transformed.
Input 2 would be a reference primitive on the geometry isolated by a deleteSOP.
And Input 3 a isolated primitive also with a deleteSOP on the geometry to be aligned to.

And maybe for the CIU hide everything exept the spinner control,flip and offset/translation.
User Avatar
Member
2199 posts
Joined: July 2005
Online
You could easily do this now, just put the whole thing inside a new asset do your pre-deleting and then remap the expressions to point at the pre-deleted prim instead of the one specified on the main tab. That way the prim and point number could always be 0.
The trick is finding just the right hammer for every screw
User Avatar
Member
23 posts
Joined: July 2005
Offline
Yep, I did it, and it works like a Charm. Scaling is also gone. Thanks Again.
User Avatar
Member
23 posts
Joined: July 2005
Offline
Some final thoughts about the Up-vector of a primitive.

After searching this forum, odforce and reading Simons awnsers it finally dawned on me that it is a “point of perspective” question. “Up” in regard to Worldspace or the observer(camera).

So in both cases the Y-axis, If you want to know if a piece of geometry is ‘'up“ you compare it to the Y-axis (or in real life your sense of equibrilium).

On http//www.netcomuk.co.uk/~jenolive/vect18d.html there is a item about ”Finding the line where two planes meet“.

”If two planes are not parallel they intersect and have a line of intersection.
The cross product of the two normal vectors of these planes gives a vector which is perpendicular to both of them and which is therefore parallel to the line of intersection of the two planes.“

The primitive is the first plane. If we construct a second plane parallel to the y-axis and make sure the center of the first plane lies on this second plane then we can calculate a directional vector that is ’'up'' compared to the y-axis and lies on the primitive;the up-vector, except for those 2 instances that the cross product is -1 or 1and the primitive is perpendicular to the y-axis aka lying down and not up.

With a curveSOP we can construct a closed curve or plane that goes through the origin followed by the centerpoint translated a distanche along the y-axis (point 1 in a default LineSOP (0,1,0) with origin P) and the original centre of the primitive P. (or the crossproduct of the positional vector of the centerpoint and the translated center point gives us a ”normal“?)

From that plane we can get the normal with a Prim() expression and ”cross product" it with the the primitive's normal. the direction of the intersection line. we know that point P also lies on that line. So we got our normal and Upvector.

I have to test it yet, so fingers crossed. wink
  • Quick Links