Spring Layers...

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
Rai López
Posts: 2297
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Spring Layers...

Post by Rai López »

...HELLO! :D I've recover this old script from AFX that makes a layer follow another layer with spring effect, very interesting! (really :) ) If somebody could addapt it to a LUA language for it can be work in Moho like embedded script... Like the "guts" and calcules are still made, I was wondering if something like this could be easily translated for someone interested and I've put it here (just in case...) CIAO & THANKS!

Code: Select all

// One spring - version 1.2

// This script attaches a spring between the 2 layers shown in the popups.
// Layer 1 keeps its original motion, while layer 2 is attached by a spring to it.

//      LAYER                                               PROPERTY                     CHANNEL
//      ------                                              ----------                     --------
// 1: Layer that moves                               doesn't matter               doesn't matter
// 2: Layer attached to #1 by a spring        doesn't matter               doesn't matter


if (time() == start_time) {
   rest_length = 10;							// rest length of spring in pixels
   damp = 0.95;										// Damping (0 = infinite friction, 1 = none)

   p1 = value(pop_layer(1), position);
   p2 = value(pop_layer(2), position);

   last_p1 = tmap(time() - step_time, value(pop_layer(1), position));
   last_p2 = tmap(time() - step_time, value(pop_layer(2), position)); 

   v1 = (p1 - last_p1);
   v2 = (p2 - last_p2);
} else {
  p1 = value(pop_layer(1), position);

   delta = p2 - p1;
   n_delta = normalize(delta);

   a = 2 * n_delta * (length(delta) - rest_length) * step_time;

	v2 = (v2 - a) * damp;
  v1 = (v1 + a) * damp;

   p1 = p1 + v1;
   p2 = p2 + v2;
}
value(pop_layer(2), position) = p2;
User avatar
mr. blaaa
Posts: 622
Joined: Sat Jul 30, 2005 4:41 pm
Location: ---
Contact:

Post by mr. blaaa »

yes, this would be a gread addon, ihope some of the script-cracks r able to do this (pleasy, pleasy, please, please) :wink:
Image
User avatar
Rai López
Posts: 2297
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

...THANK YOU (again) for your support mr. blaaa!!! :D
User avatar
bupaje
Posts: 1175
Joined: Fri Nov 12, 2004 8:44 am
Location: California
Contact:

Post by bupaje »

I was just looking at one of my animations and was going to suggest something I think is similar -so I place me vote and request for something like this as well.

In my case I think it might be useful for liquid effects. Let's see if I can explain .... For example I did that fish animation and if you look you will see that the light layer and another 'relection' layer I put on top don't move with the water movement or fish. I could animate each layer and try to sync them but attaching say this light and reflections layer to the water layer with a spring or bone dynamics type connection so that the waves move them back and forth to create a sort of caustics type effect. Might also be useful for effect of liquid sloshing around in a bucket or other enclosed area.

Hope I've explained it right. :)
[url=http://burtabreu.animationblogspot.com:2gityfdw]My AnimationBlogSpot[/url:2gityfdw]
User avatar
Rai López
Posts: 2297
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

...THANKS FOR SUPPORT IT!!! :D ...You know? In the past I had doing some experiments in the bone Dinamics line, you can examine it here if you are interested... it works, yes... but I think that the Embedded Script way it'd be a more interesting, realistic, simple and quickly way to get this effect... (I still hope someone cheer up!) :) CIAO!
User avatar
bupaje
Posts: 1175
Joined: Fri Nov 12, 2004 8:44 am
Location: California
Contact:

Post by bupaje »

Thanks for that sample -looks very interesting. Will explore it some more tonight.
[url=http://burtabreu.animationblogspot.com:2gityfdw]My AnimationBlogSpot[/url:2gityfdw]
User avatar
mr. blaaa
Posts: 622
Joined: Sat Jul 30, 2005 4:41 pm
Location: ---
Contact:

Post by mr. blaaa »

Jaiiks. Yeah. Some more to play around with. Cool Ramón! :D
Image
User avatar
7feet
Posts: 840
Joined: Tue Aug 03, 2004 9:45 pm
Location: L.I., New Yawk.
Contact:

Post by 7feet »

I thought this might be kind of cool, too, so that code is sitting there in a TextEdit window waiting for me to mess with it. If it worked like the targeting script (it looks for a layer named "Target") it should be pretty quick 'n easy to whip out. Of course, I've been wrong about that before. Hope not. I have a problem lettting things go once I started working on them, and it's smacked me in the head more than once.
User avatar
bupaje
Posts: 1175
Joined: Fri Nov 12, 2004 8:44 am
Location: California
Contact:

Post by bupaje »

7feet wrote:...I have a problem lettting things go once I started working on them, ....
We're counting on that. ;) Actually I have a bit of the same personality but age and diminsihed capacity seem to be taking the edge of my obsessive nature. ;)
[url=http://burtabreu.animationblogspot.com:2gityfdw]My AnimationBlogSpot[/url:2gityfdw]
User avatar
Rai López
Posts: 2297
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

...ARGHHH!!! :x I CAN'T UNDERSTAND YOU GUYS! ( :( sorry...) Not very well, at least... 7feet, are you saying that you are working on it or I'm understanding only that I want to listen? :roll: (jaja...) Well, THANK YOU anyway... By the way, when I made the proyect that I puted about Spring Layers (by bones) we could not work over several bones at a time and make any change was tedious, now that I've been playing with it again, I've enjoined because we can select now all the bones of the spring layer and make changes about dinamics in real time! Much more intuitive, confortable, and funny, you (mr. blaaa & others) must try it! :D
Post Reply