Turn Moho curves into Bezier

Discuss ideas for new features with other users. To submit feature requests to Smith Micro, please visit support.smithmicro.com

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Turn Moho curves into Bezier

Post by Fazek »

I have an idea about how to put full cubic Bezier curve support into Moho, keeping the Curvature conception and all existing algorythms. Usage of Bezier has many advantages over the Moho curves, for example the perfect implementation of the fonts, .ai and .eps files. But it is good if you can keep the curvature and the easy handling of points.

Bezier uses 2 control points for all of the internal points on the curve. In 2D, it means 4 independent numerical parameters at all internal points (2 at the open ends of the curve). Moho is using cubic Bezier curves, but calculated from only one parameter, the "Curvature" (see my topic at Scripting: http://www.lostmarble.com/forum/viewtopic.php?t=4462).

What if you add 3 new parameters to this system at each points, keeping the Curvature, to fully match with cubic Bezier curves? The control points are calculated in Moho on a line, parallel with the line between the two neighbouring points of the actual point. Currently the distance of the control point (from the actual point, P1) is the distance of the neighbouring point (P0 or P2), multiplied by the Curvature:

(I mark the vector values with a beginning _underscore)

_M1= _P1 + Mag(_P1 - _P0) * _Norm(_P1 - _P2) * Curvature
_M2= _P1 - Mag(_P2 - _P0) * _Norm(_P1 - _P2) * Curvature

You can modify this with an independent Weight value:

_c1= _P1 + Mag(_P1 - _P0) * _Norm(_P1 - _P2) * Curvature * Weight
_c2= _P1 - Mag(_P2 - _P0) * _Norm(_P1 - _P2) * Curvature * (2.0 - Weight)

Default value for Weight is 1.0.
If the Weight is 1.0, this calculation is exactly the same as what Moho is using now.

To put the control points outside of the line, anywhere on the 2D space, you need two additional, perpendicular parameters. These could be, for example PCurvature and PWeight, working in the same way as Curvature and Weight:

_T1= perpendicular vector (y, -x) of Mag(_P1 - _P0) * Norm(_P1 - _P2)
_T2= perpendicular vector (y, -x) of Mag(_P2 - _P0) * Norm(_P1 - _P2)

_C1= _c1 + _T1 * PCurvature * PWeight
_C2= _c2 + _T2 * PCurvature * (2.0 - PWeight)

Default value for PCurvature is 0.0, for PWeight is 1.0.
In this case the calculation is exactly the same as what Moho is using now.

So if Weight= 1.0, and PCurvature= 0.0, you can use the old algorythms (even users' Lua files), file formats etc. But if you use these things correctly, you will get FULL CUBIC BEZIER SUPPORT. This solution is not redundant and fully compatible with the old system.

The only problem if any two of P0, P1, P2 are equal, this must be tested and processed (translating a point with a very-very small vector).

Now I'm making a Lua toy to try this, how these things are behaving when the points are moving.
Image
- - - Fazek
User avatar
cribble
Posts: 899
Joined: Wed Aug 04, 2004 12:42 pm
Location: London, UK
Contact:

Post by cribble »

http://www.lostmarble.com/forum/viewtopic.php?t=4112

Try adding to the suggestion list here.
--Scott
cribble.net
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post by Fazek »

No, I think this is a different request and I don't want to hide it inside of another one.

Now I wrote a Lua language script toy to try this conception. It seems you edit Bezier curves, but really it works with the Curvature, Weight, PCurvature, PWeight values. Now it seems working, but the PCurvature and PWeight are not quite stable if the points are moving. That's a problem so I am thinking on a different, but also easily computable solution. LM's original Curvature is genial because it is quite stable during the usual transformations like scaling or shearing, and not easy to extend it to full Bezier support while keeping its stability.

Download, copy to the scripts/tool folder and try it:
http://www.firkafilm.com/moho/fa_moho_to_bezier.lua
- - - Fazek
Toontoonz
Posts: 763
Joined: Fri Mar 25, 2005 9:28 pm

Post by Toontoonz »

I tried it out. Works good from what there is to work with.
Now if it could only be implemented into Moho..er.....Anime Studio :D

I wonder if Anime Studio will allow scripting...?
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post by Fazek »

Since this is a new way to calculate the curves, only Lost Marble or others who are working on the core program can implement it. Script programming is useless in this case.
- - - Fazek
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 5:22 pm
Location: sweden
Contact:

Post by rylleman »

The toy was great, this is the kind of control I would like in Moho.
Can you translate your curves to Moho kind?, Maybe working with your controls and have the tool script translate them to Moho curves automaticly?
Could it be used for better interpretation of external vector files?
Sorry if my questions may be stupid, I'm not very good at complex math like this.
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post by Fazek »

I am working on something to convert curves (typically defined by a sequence of linear segments) into Moho curves. You can see my another 'toy' at the Scripts section about this. But in this topic I try to show how LM could expand the existing curves to be compatible with the cubic Bezier curves. For cubic Bezier curves, there are many freely available algorythms and even shared libraries so Moho could have brighter future if they do this step (I hope only the name will change).

I'm happy if you like this toy but now I'm thinking on a modified version. Now there are two curvature values, one as the original and another for the perpendicular components. The other problem is that the existing Moho curves are working perfectly if you, for example streching the shape. So now I find a solution for these:

- to use only one "Curvature" value,
- to be as friendly to usual transformations as possible,
- keep the compatibility with cubic Bezier as much as possible.

To solve the Curvature problem, it is easy if I add the actual two vectors together before normalizing and multiplying with the Curvature. In my solution, there is a vector between the two neighbouring points, P0 and P2. Additonally, I am using the same vector, rotated by 90 degrees for the "perpendicular" components. Instead of this, I could use a second vector between the actual (P1) point and the bisecting (P0 + P2)/2 point of the two neighbours. It is behaving well in the transformations, but in some special cases it is not compatible with the cubic Bezier curves, so now I'm still searching the solution.
Last edited by Fazek on Mon Aug 07, 2006 5:12 pm, edited 6 times in total.
- - - Fazek
User avatar
DK
Posts: 2854
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Wow. Well done Fazek :) Amazing work.

D.K
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post by Fazek »

My new idea, mathematically:

_T1= Norm( _P1 - _P2 + (_P0 - (_P1 + _P2) / 2.0) * PLift )
_T2= Norm( _P1 - _P2 + (_P0 - (_P1 + _P2) / 2.0) * NLift )

This is the addition of Moho's original vector and a weighted "bisecting" vector. The weights, both PLift and NLift are 0 by default.

_C1= _T1 * Curvature * Weight (+_P1)
_C2= _T2 * Curvature * (2.0 - Weight) (+_P1)

The Curvature is the original Moho Curvature and Weight is similar to my first version's Weight (default to 1.0).

I made a toy for this new calculation style, similar to the first one, it is working very good - I think -, except for the endpoints of an open curve, since the "bisecting" vector is a null vector there. That's why I used the "perpendicular" vector of the first version at these points.

ADDED: A correction: the "bisecting" vector is not (0,0), only parallel to the Moho's original, so it is not possible to create a vector outside of Moho's original line. - Fazek

If you want to try it, download from:
http://www.firkafilm.com/moho/fa_moho_to_bezier2.lua
[/code]
Last edited by Fazek on Sat Aug 12, 2006 6:44 am, edited 1 time in total.
- - - Fazek
User avatar
Haki
Posts: 23
Joined: Mon Jul 10, 2006 10:57 am
Location: Germany/ Hanover
Contact:

Post by Haki »

Wow! Looks really promising!! :shock: I'm curious about your further developments! :!:
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Good grief!

Can you call Adobe and make them change their drawing tools to work like this???

That is the kind of bezier handle "movement" I desperately need with Illustrator...


... oh yeah... this would be great for Moho as well of course. ;)

---------

So the shifting and changing of the curve handles as you move points around is what would happen during animation correct? This was the big sticking point for LM when addressing this issue I suppose.

Potentially (if this could be implemented in Moho in some future version) you could even key frame the orientation of the curve handles?

p.s. This is almost identical to the point control in Animation:Master. As you move points the others... uh... do that... in response.. and you have control handles to tweak.

-vern
User avatar
DK
Posts: 2854
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Hi Fazek.
Have you seen the way Microsoft Expression Graphic Designer handles vector point plotting/drawing? (see img attachment).
As you plot your curve it leaves behind a guideline that really helps you visualize what your curve is doing. It is the most comfortable way of plotting a bezier curve with a mouse i've ever come across? Maybe it could be possible to implement something similar for moho?

Cheers
D.K

Image [/img]
User avatar
Lost Marble
Site Admin
Posts: 2347
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Post by Lost Marble »

Hi Fazek,

These are some very interesting ideas you're coming up with. I'm kind of swamped right now to write a long response, but I can definitely see the appeal of this kind of curve representation. It would handle accurate reproduction of Illustrator-style artwork, as well as respond well in animation conditions.

The animation issue is something that causes real problems with Illustrator curves, and I think a lot of people don't understand the problems. Your solution looks like an excellent approach. If something like this goes into Moho/Anime Studio, it will need quite a bit of testing to make sure it works well with bones and other kinds of animation, but this just may be the right way to approach it.

Thanks for sharing your experiments with all of us!
User avatar
Víctor Paredes
Site Admin
Posts: 5661
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Post by Víctor Paredes »

god has talked.

is there no invitation yet to fazek becomes part of the lostmarble/e-frontier team?
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post by Fazek »

In this version, it is a problem if the "bisecting" vector has no perpendicular component to the original LM's vector (linearly dependent). It is the case if the points are collinear and at the ends of open curves. In this case, it is not possible to move the C1,C2 points outside of the line. This is a hard problem and I don't know yet how to make a solution. And this feature is required if you scale the shape in one direction into a single line. So it is not possible to emulate all of the possible Bezier curves, only a subset of them.

I think a few experiments needed to find the perfect solution, and until that, I don't recommend LM to include this into Moho. Maybe there is no perfect solution and it is better to keep the existing system. But in that case, we can use these experiments to create a perfect emulation of Bezier curves. It is required to implement .ai and .eps files, and the fonts correctly. Perhaps we can use one or more virtual systems to manipulate the curves, with other kinds of handles, etc.

I think the best advantage of the cubic Bezier curves is that there are a lot of existing algorythms to manipulate these curves. So it MUST BE in Moho somehow!
- - - Fazek
Post Reply