FORUMS: list search recent posts

snap cv of a nurbs surface to average..this script is not working properly!please help!!

COW Forums : Autodesk Maya

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
theodora
snap cv of a nurbs surface to average..this script is not working properly!please help!!
on Aug 26, 2006 at 7:07:44 pm

I have the following script that snaps the selected vertices to the average distance between them..

global proc snapVertexToAverage()
{
string $selVtx[] = `filterExpand -sm 31 -ex 1 -fp 1`;
if (size($selVtx)<2) error "Not enough vertices selected.";

float $bB[6] = `polyEvaluate -bc`;

float $averX = ($bB[1]+$bB[0])/2;
float $averY = ($bB[3]+$bB[2])/2;
float $averZ = ($bB[5]+$bB[4])/2;

move -a $averX $averY $averZ;
}

What I want to do is apply this script -with the necessary transformations- to the cvs of a nurbs object..So what I did is the following:

select -r nurbsConeShape2.cv[0][1];
select -tgl nurbsConeShape1.cv[0][5];

string $selCv[] = `filterExpand -sm 28 -ex 1 -fp 1`;
if (size($selCv)<2) error "Not enough cvs selected.";

//I guess the problem is in this line of the script:
float $bB[6] = `polyEvaluate -bc`;
//I don't know how to replace polyEvaluate..I mean this is for polygons whereas I have nurbs..

float $averX = ($bB[1]+$bB[0])/2;
float $averY = ($bB[3]+$bB[2])/2;
float $averZ = ($bB[5]+$bB[4])/2;

move -a $averX $averY $averZ;

Could you please help me sort this out?????

Thanks in advance..Theodora




Return to posts index

Steve Sayer
Re: snap cv of a nurbs surface to average..this script is not working properly!please help!!
on Aug 27, 2006 at 1:14:30 am

Hmmm, I can't find a NURBS equivalent for polyEvaluate, either.

You can probably use pointPosition instead, with slightly different math. From the pointPosition docs: "This command returns the world or local space position for any type of point object. Valid selection items are: - curve and surface CVs..."

You'll have to execute it once per each CV selected, and average out all their world positions. Shouldn't be too difficult, though. Post again if you have questions as to how to go about doing it.

Good luck,

-Steve


Return to posts index

theodora
Re: snap cv of a nurbs surface to average..this script is not working properly!please help!!
on Aug 27, 2006 at 3:48:50 pm

thanks a lot for the suggestion about pointPosition..
but I don't know if I should use the bounding box in order to do the calculations for the average of the world positions..could you help me with this calculation please??

select -r frontdp0.cv[3][3];
select -tgl leftzp1.cv[0][6];

string $selCv[] = `filterExpand -sm 28 -ex 1 -fp 1`;
if (size($selCv)<2) error "Not enough vertices selected.";

float $bB[6] = `pointPosition frontdp0.cv[3][3]`;
float $bB[7] = `pointPosition leftzp1.cv[0][6]`;

float $averX = ($bB[1]+$bB[0])/2;
float $averY = ($bB[3]+$bB[2])/2;
float $averZ = ($bB[5]+$bB[4])/2;

move -a $averX $averY $averZ;

best regards,
theodora



Return to posts index


Steve Sayer
Re: snap cv of a nurbs surface to average..this script is not working properly!please help!!
on Aug 27, 2006 at 4:24:52 pm

Hi, theodora.

No, I'm not sure how we can get bounding box information about a NURBS CV selection. I'm sure there's a way, but I haven't turned it up yet.

Failing that, you can just add up all the point vectors and then average them out:

select -r frontdp0.cv[3][3];
select -tgl leftzp1.cv[0][6];

string $selCv[] = `filterExpand -sm 28 -ex 1 -fp 1`;
if (size($selCv)<2) error "Not enough vertices selected.";

vector $cvPos1 = `pointPosition frontdp0.cv[3][3]`;
vector $cvPos2 = `pointPosition leftzp1.cv[0][6]`;

vector $aver = (($cvPos1 + $cvPos2) / 2);
float $averX = $aver.x;
float $averY = $aver.y;
float $averZ = $aver.z;

move -a $averX $averY $averZ;
That should do it for those two points in particular. If you're looking for a general solution for any number of points, that'll take a few more lines of code... I'll get back to you on that a little later.

-Steve


Return to posts index

theodora
Re: snap cv of a nurbs surface to average..this script is not working properly!please help!!
on Aug 27, 2006 at 4:45:04 pm

you are amazing!!!thank you so much for your help!I will work on how I can apply it on any number of points too..

thank you!!



Return to posts index

Steve Sayer
Re: snap cv of a nurbs surface to average..this script is not working properly!please help!!
on Aug 27, 2006 at 5:22:27 pm

Don't thank me yet--I've noticed a problem with this method.

The kind of 'average' position that this method finds is probably not the 'average' that you want. It will be weighted more in one direction than another based on how many points lie in that direction. If you want all your points snapped to the centre of their bounding box, I'm going to have to try a different approach. Unfortunately I may not have a chance to do so today--maybe someone else will chime in.

It would really be helpful to have that bounding box info available for CVs as well as poly points! I'm surprised that the command, if it exists, is not more obvious...

Sorry I can't be of more help right now.

-Steve


Return to posts index


Steve Sayer
Re: snap cv of a nurbs surface to average..this script is not working properly!please help!!
on Aug 27, 2006 at 5:44:53 pm

...sheesh, I feel dumb.

Of course, just after posting that, I find the command we're looking for: exactWorldBoundingBox.

Here, try this:

string $selCv[] = `filterExpand -sm 28 -ex 1 -fp 1`;
if (size($selCv)<2) error "Not enough vertices selected.";

float $bB[] = `exactWorldBoundingBox`;
float $averX = ($bB[3] + $bB[0])/2;
float $averY = ($bB[4] + $bB[1])/2;
float $averZ = ($bB[5] + $bB[2])/2;

move -a $averX $averY $averZ;


That should do the trick!

-Steve


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]