Is this script idea possible?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

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

Is this script idea possible?

Post by DK »

Could a script be written that reduces points in an object? I know LightWave modeler has a plugin that does this for 3D objects. I find it frustrating having to crop hundreds of needless points by hand when inserting text in AS. Is there another way maybe to do this already i don't know of?

Cheers
D.K
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I suppose something could be created to do this. It wouldn't be very "intelligent". Possibly something that deletes every other point or every 3rd point... something like that.

Also it wouldn't take into account "curve" integrity. If a bunch of points define a curve and you delete them the curve would be lost or changed. AS doesn't handle curves the way other drawing apps do.

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

Post by DK »

Sounds the same as the point reduction tool in Lightwave, you still have to go in and adjust curvatures etc afterwards but it's a lot easier to use than point by point deleting. I think I spent at least 30 minutes getting rid of unwanted points tonight :(

Cheers
D.K
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

I think the point count in letters are already pretty well optimized. There are two curvature values used for converting characters into vectors for AS (you can check those yourself with Fazek's tools), 0.0010 for straight lines, and 0.0300 for curves. Reducing the point count any further would probably distort the original vector shape of the characters too much (it is already a bit distorted). It is really a limitation of the method LM has chosen to implement vectors in AS (for details, see this thread started by Fazek).

Now about point count reduction in general. There is no substitute for manual point removal. A script would only go so far. A skilled human can take far more intelligent decisions about how to do it then a script ever could. Having claimed that, here is a strategy I can see that can help you remove points, and which could be incorporated into a script:
  • look for a sequence of points that have the same curvature value, and merge some of the neighboring points between the end points
The animator should be able to specify when using such a script how close together the curvature values may be to call them "the same", and what percentage of neighboring points to merge. Any script should also allow you to optimize only the selected points, so you can optimize only parts of a vector drawing that you think need optimizing.
Last edited by Rasheed on Mon Jan 22, 2007 11:55 am, edited 1 time in total.
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Heyvern, I just had a thought that a point reduction tool would also be really handy when importing illustrator files. Sometimes the amount of points that are imported are massive. Most times the workload in reducing the points has been so dauntimg to me i've just opted to simply import a jpg and trace it in AS.

Just my thoughts.

D.K
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Hi Rasheed, I was just playing with a few fonts and I think it's where the points bunch up that is the greatest problem. It's generally around the curved areas of the text obviously. Sometimes there are huge amounts of points grouped together depending on what font you use.

D.K
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

DK, I feel your pain. I guess the import filter used by LM doesn't really optimize the curves, because that would take far too much time. I see two solutions:
  1. write an import filter in LUA, as a script, which does an optimized (read: slow) import
  2. optimize the drawing after AS has imported the file
Both methods should be investigated, and probably be implemented.

There are some problems in converting Adobe Illustrator files. One problem seems to be that, current versions of Adobe Illustrator export in PDF format, instead of the former EPS format. Another problem seems to be that AI uses several types of Bézier curves, while AS uses one type, which hasn't have its handles exposed to the user or scripting interface, while AI has. This makes the .ai and .anme formats rather incompatible, and drives up the point count, even for an optimized import filter.

And even if you trace a bitmap of the original AI artwork, you can only go so far to approximate the original curve. The less points you use, the more the AS artwork is going to deviate from the AI artwork. For accurate representation, you still would need a lot of points.

I wonder, isn't there a way to optimize the artwork in AI, like there is a AS export filter for Photoshop?
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

I think you nailed it there Rasheed. If some sort of point reduction script was made available, it would be a great tool to help reduce that time spent on such a tedious task and allow more time for the creative energy. I felt my so drained from doing this repetetive task tonight it actually sapped away part of my enthusiasm for the project so I thought I should bring it up on the forum.

We're, (the not do tech minded), are so lucky to have guys like Heyverne and Rasheed here to winge to :)

D.K
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

DK wrote:Hi Rasheed, I was just playing with a few fonts and I think it's where the points bunch up that is the greatest problem. It's generally around the curved areas of the text obviously. Sometimes there are huge amounts of points grouped together depending on what font you use.
Well, it all depends on what algorithm is used to convert the TrueType fonts into Moho vectors. If a corner isn't sharp enough, 0.03 curvature values are used to pad the corner, instead of a single point with a 0.001 curvature value.

Mind you, the 0.03 value is the value you'll get if you use Smooth, and the 0.001 value is the value for Peak.

If you want to look at this example. This is the enlarged view of the letter p in Comic Sans MS

Image

After deleting some points and Peaking the corner point, you'll get this:

Image

I've looked at this in more detail, and it seems that there is a feature called font hinting, which obviously isn't used by AS, because it is a vector drawing program, and not an image editor. However, if you use font hinting in The Gimp (and I assume Photoshop as well), the legibility becomes better, and probably the point count as well in vector drawing programs. Because font hinting is supplied with the font (if I understood that part correctly), it should be possible to use this to improve the font's legibility and decrease the point count at the same time.

I think that LM hasn't included font hinting, because some fonts have their font hinting patented, and you'll probably need to pay a hefty fee to be able to use it in your own programs. Those patents probably also explain in part why Adobe Illustrator is so expensive. However, I'm just guessing here.

So, for the moment, it is much better to use an image editor like The Gimp or Photoshop to create exact representations of fonts. Play around with anti-aliasing and font hinting to create the most optimal results.
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

I really wanted to create a script that optimized curves, but at the moment I'm still a bit to wet behind the ears to pull that off, I'm afraid.

Perhaps something for the more experienced script writers?
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

Rasheed wrote:
  • look for a sequence of points that have the same curvature value, and merge some of the neighboring points between the end points
:oops: Sorry, that isn't right. What I should have written is:
  • look for a sequence of points, in which the formula describing how to go from one point to the next is the same, merge some of the neighboring points between the end points, and adjust the curvature of the remaining points so, that the new curve fits the old curve
For this formula, you really need to know how points are connected, therefore, the work Fazek has done is so important to create this optimization script.

Well, after the bone copying tool, it will be next on my list. I guess a tool script is best, because you can then select the points you want to optimize directly, instead of first select them, and next run a menu script.

Now I come to think of it, it might just become the opposite of the Split Curve menu script, in which you add points to a curve. Studying that script could give the aspiring script writer some clues how to write an Optimize Curve tool.
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Re: Is this script idea possible?

Post by Rasheed »

DK wrote:Could a script be written that reduces points in an object?
I was so caught up in the details, that I forgot to answer your question. Yes, in principle, such a script can be written.

No one has done it already, AFAIK, so whoever comes up with a solution first, can win a lot of appreciation from the many Adobe Illustrator fans out there. It would speed up production time enormously, and help to continue the flow of creativity for animators. I guess there is a real need.

So, go script this, please :)

The other solution could be to do the programming in AI, to create a Moho/AS file from within Adobe Illustrator. The AS script would still be necessary, because not all people use AI to create AI files.

This is a somewhat trickier road, because the cross-platform (Mac, Windows) JavaScripting doesn't seem powerful enough, so you might have to write a plug in for both Windows and Mac OS X (both Power PC and Intel processor) separately to do the conversion.

And, of course, Linux users would be left out in the cold, because Adobe doesn't have a Linux desktop version of Adobe Illustrator CS 2, while the Linux desktop is slowly gaining popularity.
myles
Posts: 821
Joined: Sat Aug 21, 2004 3:32 am
Location: Australia, Victoria, Morwell
Contact:

Post by myles »

Check out Brian Quinn (7feet)'s point reduction script.

Regards, Myles.
"Quote me as saying I was mis-quoted."
-- Groucho Marx
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Wow Myles.....it works great. I especially like the way the script just selects the points for you and you can choose to delete or not to delete. Very nice work Myles and Brian and thanks to Rasheed and Vern.

D.K
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

Perhaps I'm not too smart, but how does this menu script work?

I created a curve with a lot of points, using the Split Curve tool, then used 7Feet's script, and none of the points were deleted, nor selected. Nothing, ziltch.

The user interface is also very unclear.
  • Minimum separation
  • Pointiness to retain
  • Angle tolerance
  • Minimum points per curve
  • Minimum points per curve
  • Avoid selecting sequential points
  • Avoid selecting entire curves
If you don't know how the script works, you probably don't know how to use it. This means that I would have to understand the script before I can use it. That shouldn't be the case. We don't want all animators to become Lua script writers, do we?

A good script should be clear and easy to use, even for non-programmers. This scripts is not yet in that category of "good scripts".
Post Reply