Jump to content

How To Rotate The Point Normal?


hoknamahn

Recommended Posts

I need to rotate the point normals on arbitrary angles. There is a vector type angle parameter (each component of that vector is intend for it's own rotation axis). First of all I need to change the space from object to "normal", right? How to do it? Can I use obj2world->world2texture space change functions?

Any suggestions?

Link to comment
Share on other sites

OK. For SOPs, the bare-bones basic approach would go something like this:

// Basic N rotation (Euler) in SOPs
// --------------------------------

   // Build local coordinate system
   vector basis_z = normalize(N);
   vector up = {0,1,0};
   if(abs(dot(basis_z,up))>.98) up = {0,0,1};
   vector basis_x = normalize(cross(basis_z,up));
   vector basis_y = normalize(cross(basis_x,basis_z));

   // Rotate -- assumes "rot" is your vector of rotation values in degrees
   vector Kr = radians(rot);
   matrix mr = rotate(ident(),Kr.x,basis_x);
   mr = rotate(mr,Kr.y,basis_y);
   mr = rotate(mr,Kr.z,basis_z);

   // Modify N
   N = normalize(N*(matrix3)mr);

That's with a fixed "XYZ" order, but you can extend it to parameterize the order as per the transform SOP of course.

Many times you'll need to align the frame to some attribute (like texture UVs for example), in which case you'd need to get a gradient of the attribute to build your frame against. But the above is the basic approach (with a hard-coded "up").

Link to comment
Share on other sites

dunno if this fits here, if not i'll open a new thread...

btw...

Last night i was trying to get a Particle SOP in "Modify geometry" mode to ... break my object.. so each polygon were emitting a particle which then was "grabbing" it (facet with unique points first) and make each polygon falls down ... the problem was that the orientation of the polygon was wrong.. I menaged to have the best result by aliging the normal but then the "plane" of each polygon was rotated.. so the object looked already "broken" right at frame one.. sadly i didnt took any screeshot but if you have any advices to reach such effect they are really welcomed...or if this is not clear enought I'll take screeshots of a new scene.

cheers.

Link to comment
Share on other sites

hey

try adding a point sop and say ADD normal (default) just before u send it into the facetSOP

then under ur source in pops make sure that the number of points matches the number of nprims in ur sop going into ur pop network, and make the emission type - prim center (ordered)

hope this helps

Link to comment
Share on other sites

Hey!

I was just playing around with this code, and it occurred to me that there *is* one approach to building the local basis (in the absence of a reference direction like an "up" or a dPdu or the like) that is guaranteed to vary smoothly across all orientations of N -- it still suffers from the two singularities that cause the infamous "flip", but at least has the (possibly useful) characteristic that the "flip" is spread over the whole angular range instead of happening all at once at the limits...

I really don't know how useful this might be (if at all), but I thought I'd put it out there for discussion... here's the same code as above, except that instead of deriving the binormal from an arbitrary "up" reference, it derives it from the normal itself (and is therefore different for each N, but changes smoothly)

// Euler Rotation *without* an "up"
// -----------------------------------

   // Build local coordinate system
   vector basis_z = normalize(N);
   vector basis_x = normalize(set( basis_z.z-basis_z.y,
                                   basis_z.x-basis_z.z,
                                   basis_z.y-basis_z.x ) );
   vector basis_y = normalize(cross(basis_x,basis_z));

   // Rotate -- assumes "rot" is your vector of rotation values in degrees
   vector Kr = radians(rot+{0,0,-45});
   matrix3 mr = rotate(matrix3(ident()),Kr.x,basis_x);
           mr = rotate(mr,Kr.y,basis_y);
           mr = rotate(mr,Kr.z,basis_z);

   // Modify N
   N = normalize(N*mr);

Link to comment
Share on other sites

Huh!

It turns out that the previous approach ("binormal-from-N") gives an almost identical result (save for an offset) to the dihedral method that I mentioned in the other thread about the extrude sop. Pretty surprising (to me at least)... and it's much cheaper to compute than building the matrix.

Here's the dihedral approach -- in this case the angles are relative to the canonical XYZ vectors instead of something built on the face of a poly, but the overall distribution of orientations would be the same in either case -- and they look like a match to the "binormal-from-N" approach.

// Euler Rotation using dihedral angles
// ------------------------------------

   // Dihedral from cononical "up"
   vector n = normalize(N), y = {0,1,0};
   matrix3 md = length2(abs(n)-y)<0.001 ? matrix3(ident()) : dihedral(y,n);

   // Build local coordinate system
   vector basis_x = {1,0,0}*md;
   vector basis_y = y*md;
   vector basis_z = {0,0,1}*md;

   // Rotate -- assumes "rot" is your vector of rotation values in degrees
   vector Kr = radians(rot);
   matrix3 mr = rotate(matrix3(ident()),Kr.x,basis_x);
           mr = rotate(mr,Kr.y,basis_y);
           mr = rotate(mr,Kr.z,basis_z);

   // Modify N
   N = normalize(N*mr);

Anyhooo.... I should go to bed...

Link to comment
Share on other sites

Huh, so much info!

Thanks, Mario :)

Atskiy Sotona is a phrase from some russian slang and mean in this case something like "Smart Guy" :)

24803[/snapback]

Sotona - sounds like Satan and in fact that's what it means =) As for Atskiy - it's a genetive from Ad, that means Hell. So it can be literaly translated as "Infernal Satan" or something :ph34r:

As for connotation - it is both ironical, elevative and strongly approving of someone's outstanding aptitude.

NB. Sorry, Hoknamahn - I didn't mean to correct you - just wanted Mario to get that feeling from this russian expression that you and I get when we use it :)

Link to comment
Share on other sites

Sotona - sounds like Satan and in fact that's what it means =)  As for Atskiy - it's a genetive from Ad, that means Hell.  So it can be literaly translated as "Infernal Satan" or something  :ph34r:

As for connotation - it is both ironical, elevative and strongly approving of someone's outstanding aptitude.

NB.  Sorry, Hoknamahn - I didn't mean to correct you - just wanted Mario to get that feeling from this russian expression that you and I get when we use it  :)

24804[/snapback]

You can explain that better than me :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...