Follow Curve - maintain joint volume - layer script WIP

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

Dear Vern, it is much more simple:

-Don't work on degrees. Otherwise you need to continuously change from deg to radians and vice versa.
-I didn't know that the mod fucntion existed. So I wrote my own version.

The right code should be this:

Given an angle of the child bone: Alpha (radians), you want to calculate the angle that fits in a [-pi,pi]. pi=180 deg

Code: Select all

   function mod_2pi(Alpha)
        if (Alpha > math.pi)
           Alpha = Alpha-math.ceil(Alpha/(math.pi))*math.pi
        if(Alpha < -1*math.pi)
           Alpha = Alpha-math.floor(Alpha/(math.pi))*math.pi
        return Alpha
    end

Examples:

Alpha = 190 deg
returns= 190-ceil(190/180)*180=190-2*180 = -170

Alpha = -190 deg
returns= -190-floor(-190/180)*180=-190+2*180 = 170

Alpha = 590 deg
returns= 590-ceil(590/180)*180=590-4*180 = -130

Alpha = -590 deg
returns= -590-floor(-590/180)*180=-590+4*180 = 130

Hope it works. I've not tested it :)
-G
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

There are a lot of calculations going on. Things can also get "whacked" while editing the file which causes the points to jump way off the screen. You have to reopen the file or restart AS. I have no idea what causes this yet.

I've run into similar script problems before. You try to do too much and it just can't handle it. That is why I need to try this out with a BUNCH of joints set up to see how bad it gets.

It could be this script will have limitations on what it can realistically handle, but maybe if Mike sees this he could use it as a guide for adding features into the application to do the same thing.

-vern
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Continuing to "refine" the script. One thing I noticed was an annoying "pop" at the crossover at the top of the rotation or my test "arm". The inner points of each side of the joint will "peak" and "smooth" depending on when the angle flips from one side to the other. What was happening is that AS was not updating the view when the key frame on frame 1 was changed.

What happens is that there is a point in the time line during a rotation where the "elbow" or outside point of the joint stays "peaked" for one frame. If you do anything like click in the screen or on the frame it immediately updates fixing this. However it doesn't render properly.

I mentioned before that the code:

Code: Select all

layer:UpdateCurFrame()
was causing the points being moved to not go to the correct spot. It was as if the script wasn't working at all. However I discovered the location of the "update" code is the critical factor. By putting it BEFORE the movement of the points it works fine and fixes the point "peaking" issue mentioned above.

Here are the results of the new code.

http://www.lowrestv.com/anime_studio/sc ... curve5.swf

I've included Genete's suggestions and advice to remove all the conversions from degrees to radians. I'm using all radians now Genete, you should be proud. ;). I still can't get the rotation to work going around more than one time in each direction. I know why I just can't figure out what to do about it. You see the rotation flips sides when the "base" bone rotation goes past 180 or below -180. If however the bone continues to rotate around again I can't figure out how to check for that.

I think the key is in the code that Genete provided above. I need to study that more closely and understand it better. It's in there. I can see it ;).

-vern
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

So annoying.

It isn't a "deal breaker" but it is annoying. The update frame code must be used on every frame all the time. Without this the changes are updated one frame "behind" (which causes the point peaking problem I mentioned previously).

Using this little bit of code slows down performance... at least it does on my slow Mac which is why it probably won't be an issue. However I've been testing this with a small number of joints set up. With more of them the performance hit might get worse. I just don't understand why using it is so slow and why AS does just update on the current frame after scripting point motion.

I also tried that "run once" per frame trick but this won't work while rotating the bone. If the script isn't updating while rotating the bone you don't see the results. It only helps when playing back or scrubbing the time line.

Another feature request I suppose... process layer scripts BEFORE updating the screen and only run the crazy script ONCE for each interaction. Or give us a "mousedown" check for layer scripts. I could just update once per frame and while the mouse is down.

This script will work but it is going to have a performance hit with a lot of joints. There is so much going on and it has to happen many many many times per frame even if it isn't needed.

-vern
User avatar
synthsin75
Posts: 10280
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

Great looking results, Vern. But yeah, I'd have to agree that performance may effect usefulness.

I'd assume that the 'ceiling' and 'floor' of that code Genete provided needs an 'else' to handle multiple rotations. But that's not a big deal as we could always do a step key to 'reset' the rotation.
User avatar
mkelley
Posts: 1647
Joined: Fri Nov 02, 2007 5:29 pm
Location: Sunny Florida
Contact:

Post by mkelley »

Maybe performance will be a good reason Mike should look at including this functionality into the core somehow.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I'm starting to agree with MKelly on this one.

This script would work great if those features I mentioned in my last post were added. It would fly like the wind. Without them, it will tend to "bog down" if there are a lot of joints. Keep in mind you could have, arm, legs, wrist, fingers, foot, toes etc.

I've tried to see where I can cut down on some of the work being done by the script. Eliminating the point curvature and point peaking might help but I really like that.

Also the frame 0 table creation issue. I've run into this before. To speed up the scripting performance I put the table creation on frame 0 only but then scrubbing the time line or rotating a bone really fast can "break" the script and lose the table reference.

Still, even if this could be used just for arms and legs and maybe other interesting effects it does have benefits.

-vern
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Well, I finally tested it out on my "faster" PC. Hmm... that performance issue doesn't seem to be a real problem there. I will have to add several more joints to really know for sure. I guess 5 year old Macs won't run this as well as 2 year old PC's. ;)

-vern
User avatar
madrobot
Posts: 670
Joined: Mon Apr 07, 2008 3:07 pm

Post by madrobot »

This sounds great
Is anyone else getting a "file not found" error on those links,
or is it just me?
User avatar
Víctor Paredes
Site Admin
Posts: 5818
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Post by Víctor Paredes »

madrobot wrote:This sounds great
Is anyone else getting a "file not found" error on those links,
or is it just me?
I'm having the same problem here. I missed this topic before. It sound great, can somebody put the current code and add some instructions to make it work, please?
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

selgin wrote:
madrobot wrote:This sounds great
Is anyone else getting a "file not found" error on those links,
or is it just me?
I'm having the same problem here. I missed this topic before. It sound great, can somebody put the current code and add some instructions to make it work, please?
Only Vern has the current (latest) code and the instructions are the one that are in the posts, there are nor more instructions.
There is a code pasted in one of the posts but it seems to be not completed (not the last one).

I don't see the animations either.
-G
User avatar
Víctor Paredes
Site Admin
Posts: 5818
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Post by Víctor Paredes »

can somebody upload a configured file? It's hard to me to conceive it without seeing the swf files.
thanks
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

My hosting provider mucked up my web site during a move to a new server. Some file extensions apparently aren't "visible" or don't "exist". Everything has to be html or zip... something odd is going on I'm trying to get resolved.

-vern
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Apparently any files I uploaded before or during the "switch" (that I wasn't aware of) didn't get transfered or were corrupted. I reloaded those files and those links should work now.

Pain in the arse. I check the ftp and the files were there but they just wouldn't show up when. Had to upload them again.

-vern
Post Reply