Bugfix for Freehand Tool

General Moho topics.

Moderators: Víctor Paredes, Belgarath, slowtiger

oik976
Posts: 10
Joined: Fri Apr 09, 2021 7:29 pm

Bugfix for Freehand Tool

Post by oik976 »

Hi all-

I've been frustrated with the freehand tool in Moho 13 for a while now, particularly having problems with the tapering. I know the Moho team is in active development, but I've actually gone through the lua and figured out a fix for how to re-enable tapering on freehand strokes (both via a mouse and a tablet). I'd love to share my fix with the community, but am not sure how I can publish it or submit it. I don't want to infringe on MohoAnimation's rights as the owner of the source code by re-distributing the code.

Is there a mechanism for making these kind of things available? I'm also toying with adding a few more modifications of my own. Would anyone else be interested? Particularly I'm looking at having a configurable length to the tapering effect on the start and ends, an adjustable flare (or taper) at intersections when auto welded...things like that to make it look a little more organic.
User avatar
synthsin75
Posts: 10254
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Bugfix for Freehand Tool

Post by synthsin75 »

You can freely distribute modded Moho tools. I even double-checked when LM bought Moho.
oik976
Posts: 10
Joined: Fri Apr 09, 2021 7:29 pm

Re: Bugfix for Freehand Tool

Post by oik976 »

Awesome! Thanks, Wes. I'll put some polish on what I have and then put it up here since it probably will get better visibility than in the scripting forum.
User avatar
DK
Posts: 2891
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Re: Bugfix for Freehand Tool

Post by DK »

Sounds very interesting! Would love to see it.
Cheers
D.K
User avatar
Greenlaw
Posts: 10387
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Bugfix for Freehand Tool

Post by Greenlaw »

This sounds pretty cool! Looking forward to trying your mods.
oik976
Posts: 10
Joined: Fri Apr 09, 2021 7:29 pm

Re: Bugfix for Freehand Tool

Post by oik976 »

Here is my most basic version....I've not really altered anything aside from fixing the stroke tapering (it was more of a function of removing some of the code SM added that was disabling tapering too aggressively). You may get some extra tapering in places where you don't quite want it. Anyway, to install just drop this lua in C:\Program Files\Smith Micro\Moho 13\Resources\Support\scripts\tool (sorry, I'm a Windows guy, so I'm not sure where to install it on other OSes). Please make sure to back up your un-edited one...I'd hate to break someone else's freehand tool.

The freehandtool with fixed tapering is here:

https://www.oddvisitors.com/resources/lm_freehand.lua

I also made a quick tool for auto formatting strokes. It tapers ends of strokes, and flares at the junctions similar to how I probably will implement in the freehand tool. You just select the points you would like to format, and it will auto format the stroke widths. Feel free to muck about with it as well:

https://www.oddvisitors.com/resources/o ... tCurve.lua

Like I said, these are very early scripts...considering them the earliest of alphas. Bugs may happen, and they're not very user friendly, but we all have to start somewhere. Hope they'll be helpful to someone.
User avatar
synthsin75
Posts: 10254
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Bugfix for Freehand Tool

Post by synthsin75 »

Could you upload those to mediafire or another file host?
Firefox is flagging your site as dangerous, and well, I just met you.


You should also be installing custom tools to your Custom Content Folder, rather than the install folder.
User avatar
Lukas
Posts: 1336
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Bugfix for Freehand Tool

Post by Lukas »

I recommend using the Custom Content Folder instead of replacing the original lua files.

Just rename everything in your script from "LM_Freehand" to "OI_Freehand" (or something) and add this code to disable the original tool:

Code: Select all

-- **************************************************
-- Prevent LM_Freehand from showing up in the Tools window because it is replaced by OI_Freehand
-- **************************************************
function LM_Freehand:IsRelevant(moho)
	return false
end
I'm pretty sure you'll even still be able to call LM_Freehand's functions. So there's less chance of breaking things overall. (Certain tools reference other tools)

I also tried to mod some stuff in the Freehand tool. I added <Shift> modifier to turn weld ends on. I also wanted it to auto-close on mouse up if you were not near an endpoint, but I broke some stuff...auto-close is no longer available... I'll share it if I can get it to work. It's super useful. All the checkboxes in the toolbar are confusing and take me out of the flow.
(But honestly, shift should probably allow you to draw straight lines like in any other software... So it should probably use Control instead and force you to use the Eraser tool)
User avatar
Greenlaw
Posts: 10387
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Bugfix for Freehand Tool

Post by Greenlaw »

Lukas wrote: Sat Apr 10, 2021 10:27 am Just rename everything in your script from "LM_Freehand" to "OI_Freehand" (or something) and add this code to disable the original tool...
When you place a Tool mod with the same filename in the Custom Content Folder, doesn't it automatically prevent the original Tool in Programs from loading?

It seems to work that way for me and that's the assumption I've always had. Just wondering if there are exceptions I'm not aware of? Or is the bit of code just for safety?

Thanks for any additional info.
Last edited by Greenlaw on Sat Apr 10, 2021 9:14 pm, edited 2 times in total.
oik976
Posts: 10
Joined: Fri Apr 09, 2021 7:29 pm

Re: Bugfix for Freehand Tool

Post by oik976 »

I totally get being cautious...a lot of people have been doing sketchy stuff lately. (Also, I have you at a disadvantage....I've been lurking since before the Anime Studio days, so of course I know who you are, but not vice versa.)

Is a google drive link okay? They do virus scanning if memory serves.

Here is the lm_freehand tool:
https://drive.google.com/file/d/1nnBLWA ... sp=sharing

And my format points script/tool:
https://drive.google.com/file/d/1yXoLMK ... sp=sharing

I need to get the namespace stuff fixed, possibly today while the kids are busy doing something (I hope). I'll post an update when I've got it.
oik976
Posts: 10
Joined: Fri Apr 09, 2021 7:29 pm

Re: Bugfix for Freehand Tool

Post by oik976 »

Also, thanks for the tips, Wes and Lukas. To be honest this is my first stab at lua scripting (C# is my lingua franca, with Javascript and Java in a close second and third). Its been kind of a humbling experiment going back to writing scripts without a debugger and the usual IDE tools.
User avatar
synthsin75
Posts: 10254
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Bugfix for Freehand Tool

Post by synthsin75 »

Thanks, Oik, just downloaded. And welcome from the shadows.
Greenlaw wrote: Sat Apr 10, 2021 3:26 pm
Lukas wrote: Sat Apr 10, 2021 10:27 am Just rename everything in your script from "LM_Freehand" to "OI_Freehand" (or something) and add this code to disable the original tool...
When you place a Tool mod with the same filename in the Custom Content Folder, doesn't it automatically prevent the original Tool in Programs from loading?

It seems to work that way for me and that's the assumption I've always had. Just wondering if there are exceptions I'm not aware of? Or is the bit of code just for safety?

Thanks for any additional info.
Yeah, a custom tool with the same name just replaces the LM tool. But if you want a tool with your own name and the factory tool suppressed (to free up toolbar space), you do what Lukas said.
User avatar
Greenlaw
Posts: 10387
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Bugfix for Freehand Tool

Post by Greenlaw »

Ah! Now that makes sense to me. Thanks for explaining, Wes!
User avatar
Lukas
Posts: 1336
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Bugfix for Freehand Tool

Post by Lukas »

Yeah, it's just nice and clean to keep the "LM_" files unmodified and you'll always be able to tell where new files came from. I recently found out it didn't work for the Set Origin tool though, because that tool is always relevant (LM_SetOrigin:IsRelevant is never called)... First tool I've seen that it doesn't work on though.
But the best part is is that the original functions will still be called by other tools. For example, I think, the translate points tool uses the code of the select points tool when you press control. But if you replace that tool, the translate points tool also is affected. Which is not always desired, especially when official Moho updates change some tools. I also made a button that disables all custom tools and shows the original tools, which is useful if stuff goes wrong and you don't know what custom tools might be buggy. I'll share it in the Scripting section sometime. 🙂
User avatar
Greenlaw
Posts: 10387
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Bugfix for Freehand Tool

Post by Greenlaw »

Thanks for the insight, Lukas! This is good to know.
Post Reply