PDA

View Full Version : Scaling based on distance to other object?

svdelle
04-05-2004, 04:23 AM
I'm trying to get this ball to scale based on the distance to another object.

Imagine thousands of balls (sized 1m in diameter for easy math) placed in colums and rows (like a grid).

Now I want these balls to scale from 0 (or very close to) to 1 based on the position of a Null. I want each ball to be 1m in diameter if the Null is placed directly at the same position as the ball (that is on the groundplane x,z plane - Y should not be concidered) and slowly decrease in size as the Null moves away from the ball (making other balls scale up as it gets closer to them).

I guess I'll have to calculate the distance (radius in some way) from each balls center to the Null, and based on that distance, set the scale of the ball.

I don't know whether this is a job for LScript or Expressions. I've tried to use Expression in a very simple way, just for testing. [ball.Scale.X] = [manip.Position.X], but this seems to make the ball follow the Null (called manip) instead of scaling it.

Any hints for pointing me in the right direction?

Thanks

wingwalker
04-05-2004, 11:11 AM
you could try level of detail object replacement.

create 8 balls in incrimental sizes.

Im not sure if it will definatley work, as i dont know how LOD works with multiple cameras.

worth a try though!!

Rob T

svdelle
04-06-2004, 01:46 AM
I just thought that it would be a good idea to use LW's ability to scale through expressions ... now that it's there.

My problem is basically to choose between expressions or LScript (and in the end how to apply it), 'cause in 'descriptive programming' it could look something like this:

-----
If the distance (the radius) from the center of me to the center of the Null is greater than (let's say) 1 m.

Then scale me to 0

Else Scale me to the negative distance (the radius) from the center of me to the center of the Null
-----

(The object should be at full scale when the distance is 0)

I don't know if this is possible programmatically ... I would guess though.

moubctez
04-06-2004, 06:19 AM
Try this expression:

selector(1, vmag([ball.Position] - [Null.Position]), 1, vmag([ball.Position] - [Null.Position]))

apply it to all scale channels (ball.Scale.X, ball.Scale.Y, ball.ScaleZ)

svdelle
04-06-2004, 08:12 AM
Well, it does scale the ball when I move the Null up and down on the Y-axis (I need it to work on both x and z, but not on the Y).

But then again, I can't have more than 1 ball using the Null-name-reference. The 'compiler' gives and error "Too few results generated"? And then crashes.

But thank you very much for trying.

moubctez
04-07-2004, 04:24 AM
What LightWave version? What platform? :)

svdelle
04-07-2004, 04:26 AM
I'm testing on Windows (laptop), version 7.5(no letter) but whould transfer to Mac when I'm ready for final modeling and rendering.

moubctez
04-07-2004, 12:53 PM
Here is the plug-in for you (both Mac and Win):

When applied in Motion Options, the object will be scaled from Min.Scale to Max.Scale as the reference object is between Min.Distance and Max.Distance.

Send me an e-mail if you find it useful.
Cheers :)

svdelle
04-09-2004, 03:02 AM
Well, it does something like it ... But it does it in reverse.

I wan't the object to be scaled to full size when the Null is in the same position as the ball, and scaling down as the Null moves away. I've tried to play with switching the values, but it won't let me do that.

Besides, I need all balls to act as independent objects to the same one Null.

I think my only option is to learn LScript ... but thanks for trying!

Any good pointers to learning LScrip for an LScript beginner with ambitions like this?

moubctez
04-09-2004, 03:21 AM
I am going to fix that. Wait for the web-page update later today. :)