foggyball

11-16-2010, 05:47 PM

Can anyone help me?

Firstly I'm really rubbish with mel, I've dabbled on and off over the years but never enough to get a good handle on it.

So with my excuses out of the way.....

I have a scene with a nurbsSphere1 a locator and a distanceBetween node connect to them both.

If I added the expression (shown at the end of the post) to the nurbsSphere1 scale X,Y and Z I get the exact result I'm after.

The problem is I need to apply this to 50 or more spheres. I can get the first part done with this:

//How many spheres do you want?

float $numberSphere = 60;

//How big a gap between the spheres

float $sphereGap = 1.3;

//How large a sphere do you want?

float $sphereRadius = .5;

$i=0;

while($i++ < $numberSphere)

{

sphere -r .5 -ax 0 1 0;

move ($i*$sphereGap) 0 0;

}

spaceLocator -p 0 2 0;

//Create distanceBetween node and connect to sphere1 and locator

shadingNode -asUtility distanceBetween;

connectAttr -f locator1.translate distanceBetween1.point1;

connectAttr -f nurbsSphere1.translate distanceBetween1.point2;

But I can't figure out how to get the expression to be put on each sphere via a for loop. Can anyone help me?

This is the expression for the spheres.

$dummy = distanceBetween1.distance;

// get locators position in X

float $locPos = `getAttr locator1.translateX`;

// Get the spheres world position

float $spherePos = `getAttr nurbsSphere1.translateX`;

// Check the distance in comparison to the sphere.

$distX = $locPos - $spherePos;

float $scaleUp = 0;

float $scaleDown = 0;

float $scaleUpRate = -2;

float $scaleDownRate = 10;

if ($distX < $scaleUp)

{

nurbsSphere1.scaleX = 1.0 + ((`smoothstep ($scaleUpRate) ($scaleUp) ($distX)`) * 1);

nurbsSphere1.scaleY = 1.0 + ((`smoothstep ($scaleUpRate) ($scaleUp) ($distX)`) * 1);

nurbsSphere1.scaleZ = 1.0 + ((`smoothstep ($scaleUpRate) ($scaleUp) ($distX)`) * 1);

}

else if ($distX > $scaleDown)

{

nurbsSphere1.scaleX = 1 + ((1.0 - `smoothstep ($scaleDown) ($scaleDownRate) ($distX)`) * 1);

nurbsSphere1.scaleY = 1 + ((1.0 - `smoothstep ($scaleDown) ($scaleDownRate) ($distX)`) * 1);

nurbsSphere1.scaleZ = 1 + ((1.0 - `smoothstep ($scaleDown) ($scaleDownRate) ($distX)`) * 1);

}

print (" scale Sphere 1 :"+nurbsSphere1.scaleX+" distX to sphere 1 :"+$distX+"\n");

What this should give me is a locator which when dragged along the x direction, scales the spheres up and down based on distance. This gives a similar look to the Dock in Mac OS X.

If anyone can shed some light on how I can 'glue' these two bits of code together, I'd be very grateful.

Dave

Firstly I'm really rubbish with mel, I've dabbled on and off over the years but never enough to get a good handle on it.

So with my excuses out of the way.....

I have a scene with a nurbsSphere1 a locator and a distanceBetween node connect to them both.

If I added the expression (shown at the end of the post) to the nurbsSphere1 scale X,Y and Z I get the exact result I'm after.

The problem is I need to apply this to 50 or more spheres. I can get the first part done with this:

//How many spheres do you want?

float $numberSphere = 60;

//How big a gap between the spheres

float $sphereGap = 1.3;

//How large a sphere do you want?

float $sphereRadius = .5;

$i=0;

while($i++ < $numberSphere)

{

sphere -r .5 -ax 0 1 0;

move ($i*$sphereGap) 0 0;

}

spaceLocator -p 0 2 0;

//Create distanceBetween node and connect to sphere1 and locator

shadingNode -asUtility distanceBetween;

connectAttr -f locator1.translate distanceBetween1.point1;

connectAttr -f nurbsSphere1.translate distanceBetween1.point2;

But I can't figure out how to get the expression to be put on each sphere via a for loop. Can anyone help me?

This is the expression for the spheres.

$dummy = distanceBetween1.distance;

// get locators position in X

float $locPos = `getAttr locator1.translateX`;

// Get the spheres world position

float $spherePos = `getAttr nurbsSphere1.translateX`;

// Check the distance in comparison to the sphere.

$distX = $locPos - $spherePos;

float $scaleUp = 0;

float $scaleDown = 0;

float $scaleUpRate = -2;

float $scaleDownRate = 10;

if ($distX < $scaleUp)

{

nurbsSphere1.scaleX = 1.0 + ((`smoothstep ($scaleUpRate) ($scaleUp) ($distX)`) * 1);

nurbsSphere1.scaleY = 1.0 + ((`smoothstep ($scaleUpRate) ($scaleUp) ($distX)`) * 1);

nurbsSphere1.scaleZ = 1.0 + ((`smoothstep ($scaleUpRate) ($scaleUp) ($distX)`) * 1);

}

else if ($distX > $scaleDown)

{

nurbsSphere1.scaleX = 1 + ((1.0 - `smoothstep ($scaleDown) ($scaleDownRate) ($distX)`) * 1);

nurbsSphere1.scaleY = 1 + ((1.0 - `smoothstep ($scaleDown) ($scaleDownRate) ($distX)`) * 1);

nurbsSphere1.scaleZ = 1 + ((1.0 - `smoothstep ($scaleDown) ($scaleDownRate) ($distX)`) * 1);

}

print (" scale Sphere 1 :"+nurbsSphere1.scaleX+" distX to sphere 1 :"+$distX+"\n");

What this should give me is a locator which when dragged along the x direction, scales the spheres up and down based on distance. This gives a similar look to the Dock in Mac OS X.

If anyone can shed some light on how I can 'glue' these two bits of code together, I'd be very grateful.

Dave