Anime Studio Forum Forum Index Anime Studio Forum

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

vector optimizing math/logic?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Anime Studio Forum Forum Index -> Scripting
View previous topic :: View next topic  
Author Message
spasmodic_cheese



Joined: 04 Aug 2004
Posts: 330

PostPosted: Sat Oct 02, 2004 12:23 pm    Post subject: vector optimizing math/logic? Reply with quote

Hey, I was wondering if anyone had any ideas on the best way to go about creating script that optimizes vector curves.

I think many people(including myself) would benefit from something like this whom import vectors and want to minimize the amount of points moho creates during the conversion.

But I can't really think of how to go about it...

at the moment im looking at
http://potrace.sourceforge.net/potrace.pdf

--- EDIT

Okay i read that.... and Shocked im drowning in symbols!
im reading this now
http://www.jarno.demon.nl/polygon.htm
and getting a better idea of what needs to be done.

I think i'll just tackle polygon simplification...then if i compelte that someone else can do curve approximation...
or help me understand it =P
Back to top
View user's profile Send private message
7feet



Joined: 04 Aug 2004
Posts: 840
Location: L.I., New Yawk.

PostPosted: Sun Oct 03, 2004 6:35 am    Post subject: Reply with quote

My basic idea was to use a hack of the Freehand tool script, using the angleTolerance bit's to filter out the points that aren't making much of a difference to the vector. I'd rather make the pixelTolerance variable translate to something that wasn't so screen resution specific, but I don't program much and I'm having a hard time getting my head around the flexibility of the Lua data/function structure. I think if someone would set up a script based on that concept to eliminate points that were under a certrain angle threshhold that would simplify imported vectors enourmously
Back to top
View user's profile Send private message Send e-mail Visit poster's website
myles



Joined: 21 Aug 2004
Posts: 823
Location: Australia, Victoria, Morwell

PostPosted: Mon Oct 04, 2004 7:40 am    Post subject: Reply with quote

I've put up an extremely naive and simple first draft of a point-reduction script at http://www-personal.monash.edu.au/~myless/catnap/mohofiles/index.html

How it works: if a point is "close enough" to the previous point on a curve, and not part of another curve, and "not particularly pointy", it will get deleted. Rolling Eyes

Well, actually, at the moment the points only get selected, and you can hit the Delete key if you like the look of the points selected - you can uncomment out the point deletion code if you really want to.

The definition of "close enough" and "not particularly pointy" are up to you to set numerically. "Pointy" is generally in the range 0.1 or less, normal smoothness is around 0.3, and "close enough" can be anything from 0.001 to 0.1 or more. Confused

Brian (7feet), is that close enough for starters ?

The script has a tendency to wipe out fine detail and leave a deformed but simplified version of the initial shapes, which is probably not what you wanted. Surprised

Because I want to keep some very small ellipses in a test file, I've also added a "keep every second point" checkbox - otherwise every single point on the ellipse was both close enough and not particularly pointy, so the whole (very small, 8-point) ellipse was getting deleted.

Well, I've put it up for laughs - don't expect anything sophisticated out of it - but maybe some of the Moho-related code will be useful for people who have a decent point-reduction algorithm to replace this silly one.

Result of running it on Lost Marble's Lenny character, using default settings:


Better than I expected but, as you can see, the pupils have been completely deleted and the eyebrows are reduced to almost uselessness.

Regards, Myles.


Last edited by myles on Mon Oct 04, 2004 8:21 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
spasmodic_cheese



Joined: 04 Aug 2004
Posts: 330

PostPosted: Mon Oct 04, 2004 8:18 am    Post subject: Reply with quote

yah thanks for the code!

this is what i was going to do in the first place, i thought hypothetically what you've jsut demonstrated.

its a start tho! im sure we can develop something worthwhile!
Back to top
View user's profile Send private message
maxic



Joined: 22 Sep 2004
Posts: 64
Location: Moscow, Russian Federation

PostPosted: Mon Oct 04, 2004 10:59 am    Post subject: Reply with quote

potrace.pdf Has data which will help to transform in due course MoHo into the small monster of animation. As you think, it is possible on Lua. Or how to make that the data of other program came back in MoHo?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
spasmodic_cheese



Joined: 04 Aug 2004
Posts: 330

PostPosted: Mon Oct 04, 2004 12:27 pm    Post subject: Reply with quote

potrace is a bitmap to vector convertor, the part of it that we can take and transform into lua is the way it creates a polygon and then optimizes it.
Back to top
View user's profile Send private message
Benvindo



Joined: 03 Aug 2004
Posts: 38

PostPosted: Mon Oct 04, 2004 4:25 pm    Post subject: point-reduction script Reply with quote

[quote="myles"]I've put up an extremely naive and simple first draft of a point-reduction script at http://www-personal.monash.edu.au/~myless/catnap/mohofiles/index.html


Thanks Myles

it worked reeeeaaaal nice Very Happy


Cheers

Benvindo
Back to top
View user's profile Send private message
myles



Joined: 21 Aug 2004
Posts: 823
Location: Australia, Victoria, Morwell

PostPosted: Tue Oct 05, 2004 1:06 am    Post subject: Re: point-reduction script Reply with quote

Benvindo wrote:
Thanks Myles

it worked reeeeaaaal nice Very Happy


You're welcome Benvindo - I'm glad to hear it is of some use. Very Happy

Regards, Myles.
Back to top
View user's profile Send private message Visit poster's website
AcouSvnt



Joined: 04 Aug 2004
Posts: 190
Location: Rochester, NY

PostPosted: Tue Oct 05, 2004 2:00 am    Post subject: Reply with quote

Seems the pupil removal could be averted if you add additional conditions to avoid deleting any curve in its entirety (if all points on a curve have been selected, maybe have it "rethink" those points).
_________________
-Keith
Back to top
View user's profile Send private message Visit poster's website AIM Address
7feet



Joined: 04 Aug 2004
Posts: 840
Location: L.I., New Yawk.

PostPosted: Tue Oct 05, 2004 9:23 am    Post subject: Reply with quote

Ack! Scripting! My brain hurts!

Thanks for putting that script up, Myles. It inspired my to whack my head against it for a while. I added some code (that I hacked out of the Freehand script) that detects the angle that a point forms relative to it's 2 adjacent points with a user specified angle threshold. It even seems to be working. I tweaked the every second point bit so it's a little more like "never pick consecutive points". Per suggestions, I also slapped in a checkbox to never select an entire curve, as well as allowing you to set the minimum number of points a curve must have before it'll be affected. The latter was because initially I was seeing short , 3-4 point open curves going right to straight lines and it was annoying me. I also made it so it will never select the existing endpoints of an open curve.

One of the main reasons that I put in the point angle analysis is that it also allows you use the simplifications on drawings done inside of Moho. With it you can unload a lot of points (especially from Freehand drawings) without killing sharp corners, even though the vertex's pointiness might be set above the scripts curvature threshhold.

That was kinda fun, in a long, somewhat exasperating sort of way. Its been a Loooong time since I've tried any coding.
Oh, yeah, before I forget, here's my version. Not so elegant, but it seems to be doin' the trick. Anybody finds anything dopey with the logic or has any suggestions for improvement, let me know.

Now if I can just get the Auto-weld script to work the way I want...

--Brian
Back to top
View user's profile Send private message Send e-mail Visit poster's website
myles



Joined: 21 Aug 2004
Posts: 823
Location: Australia, Victoria, Morwell

PostPosted: Wed Oct 06, 2004 1:21 am    Post subject: Reply with quote

Woohoo! Thanks, Brian, for the cool modifications - I'll give it a try tonight.
Sounds like it's much improved.

I must admit I haven't really played with Auto-weld yet - what does or doesn't it do that doesn't work the way you want it ?

Regards, Myles.
Back to top
View user's profile Send private message Visit poster's website
7feet



Joined: 04 Aug 2004
Posts: 840
Location: L.I., New Yawk.

PostPosted: Wed Oct 06, 2004 3:34 am    Post subject: Reply with quote

Well, on the Autoweld. I had a few .AI's I'd exported from Wings3D. They were pretty complex mechanical images, and the Illistrator files had an awful lot of points. Many of these points were so close together (on the order of 7 or 8 vertexes) that you had to zoom in a lot to see that they were distinguishable. I've tried playing a bit with the parameter (it's 100 in the script) that determines if a point is close enough to another to weld them. On simpler images I seem to remember it working okay. But if there a a lot of points in a very small area for some reason it doesn't weld them together. Perhaps it's because they are on separate curves.

On that note, the section of the script which is supposed to weld dead-end points into the nearest point of the nearest curve has been commented out since the first beta. Really, besides the simplification of points welding clusters together would give, it's the fact that points that seem to be welded to a curve yet aren't really bolloxes up creating filled shapes out of imported vectors. I've looked at it a little, but haven't really had a chance to figure out the logic..

I don't want to clutter up the basic interface, but I can already see that I'm going to be adding a lot more parameters to a lot of the tools for my own use ( or anyone else who wants them.). Good defaults are cool, but given the opportunity to set it up I'm gonna arrange things so I can twaek like crazy.

On use, because the curvature on a point in my version is basically a check to verify if you should even look at the angle between adjacent points, you could still end up with a sharp point, with point's very nearby under the distance threshold, that don't really contribute much to the image. Haveta make it smarter, but I'm just getting the structure of Lua down in my head, didn't want to bust out something too kludgy I'd need to fix later. For real usefulness, I think that I made the default angle tolerance too low. I'm also not sure if my translation of the algorithm from the freehand script is quite right, but at least it seems to avoing the angular, defining curves like I wanted. Also, I just now thought that in addition to having a minimum distance between points, a maximum to keep broad curves that cover a lot of angular distance from being mucked up would be a good thing as well.

'Kay, now I have to put the adjustable Origin for the Rotate Points thingy I said I would do earlier into effect. Anyone has some other script modification ideas, throw 'em out. Knowing myself, I won't be happy 'til I can think in Lua. Hope it doesn't keep me from animating...

--Brian
SevenFeetDesign
Back to top
View user's profile Send private message Send e-mail Visit poster's website
AcouSvnt



Joined: 04 Aug 2004
Posts: 190
Location: Rochester, NY

PostPosted: Thu Oct 07, 2004 2:02 am    Post subject: Reply with quote

"Think in Lua", eh? I don't know ... it's not that it's a hard language, obviously it goes to great lengths to make things easy ... but somehow that makes it hard. I'm used to declaring and defining everything, and knowing exactly how many bytes there are in an array at all times. Using something like Lua will be counterintuitive for me because there's so much trusting involved. Confused
_________________
-Keith
Back to top
View user's profile Send private message Visit poster's website AIM Address
spasmodic_cheese



Joined: 04 Aug 2004
Posts: 330

PostPosted: Thu Oct 07, 2004 2:23 am    Post subject: Reply with quote

lol keith, maybe you should write a lua script that calls your c =P
Back to top
View user's profile Send private message
7feet



Joined: 04 Aug 2004
Posts: 840
Location: L.I., New Yawk.

PostPosted: Thu Oct 07, 2004 3:03 am    Post subject: Reply with quote

Yeah, well, that comment was a little facetious, but it was the first programming (as little as it is) I'd done in almost 17 years. I was kinda amazed it did about what I wanted. In some ways I'd rather it were a little more explicitly typed, since you can put just about anything inside a variable and quite possibly get all turned around if you're a neo-novice like me. Think I have ti sit down and read Programming in Lua another time or 2.

--Brian
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Anime Studio Forum Forum Index -> Scripting All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group