View Full Version : rotation from pointOnSurface ?
CrustedInk 07-29-2008, 01:36 PM hey.
is there a possibiliity to get the rotation from a pointonsurface-command ? i want a mel script, that dublicates a single object and place these 'new' objects on the ground. (e.g. stones on the floor or trees) the translation in x,y,z works with `pointOnSurface -u $u -v $v -position $ground`, but all objects have the rotation of 0. It would be nice, if the objects get the orientation of the normal from this point, so that they 'look' not only straight up but in the right direction
|
|
NaughtyNathan
07-29-2008, 02:27 PM
as long as PointOnSurface can return the surface normal at the given point (I'm guessing it does) you can do this. You just need a function to convert a single normal vector into a x,y,z rotation. Such a calculation is not trivial, but should be quite easy to find on the net.. however you're luck is in as I've already written such a proc! ;)
give it an object (transform) name and a vector and it will rotate the object so it's Y axis points along the vector (it's position doesn't change)
e.g:
rotateObjectToVector pCube1 <<-0.57735,0.57735,0.57735>>;
global proc rotateObjectToVector(string $object,vector $V)
{
float $m[16] = `getAttr ($object+".worldMatrix")`; // the original matrix
float $xLen = `mag <<$m[00],$m[01],$m[02]>>`;
float $yLen = `mag <<$m[04],$m[05],$m[06]>>`;
float $zLen = `mag <<$m[08],$m[09],$m[10]>>`;
vector $A = unit(cross($V,<<rand(1),rand(1),rand(1)>>)); // dummy cross 1
vector $B = unit(cross($V,$A)); // dummy cross 2
vector $X = ($A * $xLen);
vector $Y = ($V * $yLen);
vector $Z = ($B * $zLen);
xform -matrix
($X.x) ($X.y) ($X.z) 0
($Y.x) ($Y.y) ($Y.z) 0
($Z.x) ($Z.y) ($Z.z) 0
$m[12] $m[13] $m[14] 1
$object;
}
bear in mind that you cannot assume any kind of "sensible" rotation from a single vector, so while your object will be correctly pointed in the normal direction it may be at any arbitrary Y rotation!
hope this helps!
:nathaN
CrustedInk
07-29-2008, 04:20 PM
oh damn. nathan, you are my hero :) the second solution you posted for my problem. great, it works fine. some little tweaks and the script is more or less perfect... ^^ i mean.. it works. i'll post it here, when it's done
trancor
07-29-2008, 04:35 PM
Maybe I got here a little too late; but there is a command called rot, you put in a vector in space, you put in an axis vector, and then a radian (either that or an angle) for how much you want the object to rotate. And it rotates. You can find the face normal with polyInfo -faceNormals
But what ever, you seem like you got an answer
CGTalk Moderation
07-29-2008, 04:35 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.