Simple Guide To AS Scripting Dream?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
GCharb
Posts: 2274
Joined: Mon Oct 10, 2005 2:31 am
Location: Montreal, Quebec, Canada
Contact:

Post by GCharb »

The good thing about this script is that you decide where the shape breaks apart!

Not an expert script guru, but the one you want may give unexpected results.
User avatar
hayasidist
Posts: 3849
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Post by hayasidist »

Hi DK... does it have to be separate layers? you can make a good "fly-apart" with shapes on one layer. The hard part, as I see it, is to get those new shapes...
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Hi hayasidist.
Woud'nt have to be on seperate layers I guess. The hard part would be point placement I think. You would have to create two points from each split section so the shapes, when rejoined, would maintain the original shape, probably with a little peak curvature thrown in to maintain a straight edge where each object edge finished and the new object edge started???

Cheers
D.K
User avatar
hayasidist
Posts: 3849
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Post by hayasidist »

yeah - like I said -- the hard part is geting the fragments! frankly, I'd be seriously tempted to leave that as the artist's decision. For example - you have a lovely 2d image of a cup ... but (as I do - and maybe as you do?) the visible part of the inside back is "just an oval" at the top of the (bent top and bottom) rectangle that is the front ... now if you want the cup to fly apart in a recognisable fashion you may need to sculpt the whole of the rear... and you've used gradient fill on the big shape (so it's not just a simple case of the same fill for each sub-shape) ... plus think about how the "edges" might need to twist as they fly off ... er ... my brain is already hurting.
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Yes..... your right....it goes way beyond just simple shapes..... :(

D.K
User avatar
GCharb
Posts: 2274
Joined: Mon Oct 10, 2005 2:31 am
Location: Montreal, Quebec, Canada
Contact:

Post by GCharb »

The script I was referring to can put the shapes on separate layers or on the same layer, and as hayasidist said, it leave the placement to the artist.

You select the parts that will be broken by assigning different shapes, and when it is broken then you animate, maybe with physics.

I am learning Lua scripting for a new tutorial at the moment, and even though it is a capable scripting language, it lacks a few things to make such an advanced script.
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

Hi DK,
what you're asking is to add a meshing algorithm to divide a 2D surface into small parts using some rules. There are many algorithms to do that and each one has one kind of restriction:
dividing shape, threshold, etc.
http://en.wikipedia.org/wiki/Ruppert%27s_algorithm
http://en.wikipedia.org/wiki/Delaunay_triangulation
-G
User avatar
hayasidist
Posts: 3849
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Post by hayasidist »

thanks Genete. now I have another scientific explanation for why my brain hurt, just to add to the previous lingering agony caused by trying to understand the maths behind Catmull and Mandelbrot! :) sadly, it hurts even more now I've read the links you provided! :shock:

anyhoo....

if the artist designs the fragments as individual shapes (no shared sides or points), then getting them to fly apart is pretty straightforward I think. I've had a poke at this (not in a script - just playing with translate / rotate points). So ... broadly (without going into the maths or AS features such as motion paths / particles):

the fragments accelerate away from the centre for a short time (force / duration of the explosion) then change velocity (speed and direction) under the influence of gravity / friction. Could get cute by applying spin and by varying the initial acceleration so that it's smaller for shapes starting furthest from the blast centre. The "action" is over when the fragments have either stopped moving or are out of visible (rendered) frame or the animation duration is reached.

DK - is that the sort of thing you wanted?? (Don't get too excited - I have other things higher on the list right now!)
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Hi hayasidist.
Actually simply breaking the object mesh up was all I meant but WOW your idea is really interesting!!!!! If not, the animation can always be done by hand quite quickly, it's just the time factor involved in breaking an object down into smaller peices can be quite time consuming.

Being a Lua novice one other reason I made this post was to try andto help me ge a hold of how one could go about concepting a Lua script.

1. Come up with idea.
2. Work out what types of commands you need to use
3. Search the commands and implement them in the Lua script as per GCharbs blog.

Would that be a close aproximation of the process?

Cheers
D.K
User avatar
hayasidist
Posts: 3849
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Post by hayasidist »

yes - more or less - and without worrying about the "textbook" on such as RAD, Waterfall, V-models - the way I work with any programming task is:

- understand the basic need (e.g. I need to make a shape explode)
- look in more detail at the requirements / constraints of the "need" and of the "environment" in which the need has to be provided (e.g. fills / 2d / ... / gravity / friction / ...)
- analyse the problem into steps (e.g. break into fragments, preserve fills, handle edge strokes, what governs fragment flight path, how do you know when to stop? ...)
- design the solution with the development environment in mind - see below about "libraries" - (e.g. select the shape, overlay with triangular grid, ... )
- write and test the code in outline (i.e. ignore detail -- such as actually changing edge fill) (sometimes not even in the final environment - e.g. if it's a mostly algorithmic problem then I'll do the try out in a spreadsheet; if it's the "explode" problem then animate a fragment path by hand to see what looks right)
- this usually shows up analysis and design problems (e.g. the idea behind breaking the shape is good but it takes the program an unacceptably long run time; should the initial explosion duration be fixed or user-selectable, ...)
-iterate...

Obviously, the more of the "design-code-test-iterate process" that you can do by way of "thought experiment" the faster the total process - so, again for example, if you know that the software library doesn't have a set of routines to do -whatever- then you know you'll need to write them from scratch or do something different (e.g. as AS provides template particles in the library you can decide to use them or not; but if it didn't and you had to build everything from scratch you'd have to design and build a "particles" system or think up another way to skin the proverbial cat). So it helps if you have a list of "what the system willl give you" to hand (or in your head)...

Scripting in AS uses: the base LUA language; the LUA function library (e.g. maths / trig functions); the AS function library.
The AS library comes in three main parts:
> functions and values are available for a layer, a bone, etc.
> important data structures and types such as Vectors, 2D points, colours, etc.
> things needed to build the user interface and for translating mouse clicks into "drawn lines" etc ..

(see viewtopic.php?t=13513 and viewtopic.php?t=1031)

whew -- sorry that's turned into a long post...

... but scripting is really not that hard. Imagine you had to explain how to draw and animate a walk cycle to someone who was just starting out ..
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Wow hayasidist !!!
Thanks for that thorough post :)
Right now I'm trying to come to grips with the basics so rewriting a particle system is a little out of my goalset just now...hehehehe :)

I do remember Vern playing around with Action Script exmples to use in a Lua collisions AS script some time ago. I imagine this explosion script would incorporate some of the math etc needed to pull this off. I am sure his examples are still floating around the forum somewhere.

If you do have a crack at this explosion system it would be quite an amazing and extremely used script I imagine.

Cheers
D.K
User avatar
hayasidist
Posts: 3849
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Post by hayasidist »

Right now I'm trying to come to grips with the basics...
like I said - if you want to learn to write code that's one challenge; if you want to learn to write LUA in an AS environment that's another. IMHO, the AS environment is a pretty tough place to learn the basics of programming - a bit like trying to learn to swim in a surfer's paradise - better to start out in the calm of the training pool. But once you're ready for the thrill of the ride ....
Post Reply