Heyvern's... Modified Universal Point Tool -- beta

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Heyvern's... Modified Universal Point Tool -- beta

Post by heyvern »

Be careful with this one! I wouldn't use it quite yet on anything important!
(Actually I have been using it for everything now and it works fine. I have had no problems with it. YMMV)

It works pretty well from my testing but there are some small problems with it and modifications and changes needed.

http://www.lowrestv.com/moho_stuff/hv_u ... t_tool.zip

To 7feet:
I called it hv_universal_point_tool and created a new/different icon for it. I hope this is okay. If you look at the code (or if anyone else does) keep in mind I am very new with Lua and Moho scripting and probably didn't code this very well. It works just as I want it to... but there is probably a better way to do it.

My feelings won't be hurt if you laugh at it... or shake your head in disgust.
;)
-----------------

Description:
Keep in mind I modified this tool for my own preferences. Not everyone will like the way this works if they are use to the "old" way. I LOVE IT! But that's just me.

Everything in the tool is based on a user definable selection radius around each point in relation to the mouse click.

The range is 0.01 - 0.5.

0.5 behaves just like the regular old translate tool and always selects the nearest point (you can't lasso at this setting). The default is 0.45 which is a comfortable radius for a "non-zoomed" screen.

So when you click on one point within this range... it selects that one point. If you click and drag... it lassos the points. Then click on any selected point and drag or scale... whatever.

Clicking anywhere outside of the selection radius deselects all points.

All of the modifier keys from the original are the same. Of course the one for the lasso isn't needed.

Known issues... there may be more...

1 Shift select doesn't work. Shift still adds new points... it will probably stay like this since the lasso works so well... I just wanted to mention it. (I will be "switching" the add point so I can use the shift for constraining.)

2 For some reason the layer modified point motion keys don't update correctly later in the timeline.

This happens also in 7feet's original tool. It is not a huge problem and the keys show up when you save or click on the channel... or do something that updates the screen. It should be fixed and probably has to do with one of the combinations of update frame thingy code in there somewhere.

3 The rotate point center modification thingy... when you use this it deselects all the points. I know what needs to be fixed. For now when you use it works normally as long as you click on or near a selected point within the radius. If you don't it still works but deselects the points.

4 The add point has a bit of trouble. Sometimes it adds the point in the "wrong" spot...

Update on this issue. The add point is also based on the selection radius. So... don't click "exactly" on a point when extending a line or adding a point and it works fine. This is kind of cool too. You don't have to be right on the point when extending a line since it uses that selection radius.


5 Not really a problem but...
... the curvature change (shift-cntrl-alt) must be clicked on or near a point or... any point that is selected... otherwise it just deselects.

I have decided This is NOT how I want it to work. I will be adding in a the find center of selection dohicky to make this work properly just like the scale and rotate currently.

Planned updates

1 A user definable selection radius. Done!. The range is 0.01-0.5. Setting this to 0.05 behaves exactly like the default Moho translate tool.

Currently the radius selection is based on "world" coordinates. This means that the radius gets tiny when zoomed out and huge when zoomed in. I will change this so it is based on screen pixel coordinates. I need some advice on how to do this though.

2 Adding the shift/constrain for translation. Currently you still can't use the shift to constrain translation. The shift key is for adding points. I will be switching the add point to the key that was for lasso in the original so I can use the shift for constrain.

3 Change rotation center point based on all the selected points instead of just "one".

Remember to use this for now on copies of important files so I don't feel terrible if something bad happens.

Update: So far... I have not found any problems using this tool. I am happily using it all the time now and have removed all the other redundant tools... I now have a few extra "spots" for new tools! Woohoo!

-Vern
Last edited by heyvern on Tue Feb 28, 2006 10:19 pm, edited 4 times in total.
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I added a selection radius... thingy changer doodad... link above is updated.

The default value is 0.45.

The max can be set to 0.50. If you set it to 0.50 the selection tool works just like the other one... sort of. It just selects the nearest point to the click.

Still based on "world space" not "screen space". I am having trouble figuring out how to do that.

-Vern
teotoon
Posts: 135
Joined: Wed Aug 04, 2004 7:19 am
Location: Turkey

Post by teotoon »

This tool is getting better and better. Thank you very much both 7Feet and Heyvern.

These functions were the ones I always wanted to have in Moho.
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I have updated some info on the original post regarding the "add point" issue.

Also no problems using it extensively from my end. I think it is safe to use now.

-Vern
User avatar
ulrik
Posts: 1087
Joined: Thu Aug 11, 2005 10:32 pm
Location: Stockholm Sweden
Contact:

Post by ulrik »

Thanks heyvern for sharing your ideas and scripting skills with us! :D
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Thanks for the comments so far. I hope Moho users find this as useful as I do.

This is the first "artistic" program that gave me the ability to change how it works. As a "non-programmer" I don't have the skills or tools to create "plug-ins". I've never had the ability to change the behavior of tools for an application to this extent before.

I wish all programs had this ability.

-Vern
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I found a weird bug!

This applies to the original Universal Point Tool from 7feet as well

This is a really weird one! Might need advice from Moho on this.

If you launch Moho and create a mesh using any tool. Then select 2 or more points or the whole thing and use the "change rotation center" with the following key modifier combo:

<shift><alt><cntrl> and drag...

You will get an error about trying to index the 'centervec' and it being a nil value.
Then Moho crashes.

I can't figure out why this happens and when it happens

Sometimes it doesn't happen.... sometimes it does.

This happens too quickly for me to copy the error from the Lua... message thingy window.

I will look at the code and probably just initialize the centervec value right at the start. This should take care of it I hope.

-Vern
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Post by 7feet »

Glad your hackin' at the thing.

Just tried it, and I sure don't remember seeing that before. Checking into it.

EDIT- Okay, the usual "uh, I fergetted" kinda thing. If you use the rotation first, it defines the variable centerVec as equal to the origin, whick is a Vector2 object, and all is well. Afew of the other functions in the OnMouseDown function will do the trick as well. But there's nothing in the OnMouseDown to take account of going right to the rotation origin changing bit (as there really should be, so you see the crosshairs as soon as you click the mouse).

So when you get to the OnMouseMoved function, you get the error because you are trying to assign a value to an index (in this case centerVec.x and centerVec.y) of a variable that hasn't been defined yet, and Lua gags. My quick fix - in the "Recurring Values" section at the top, I threw in a line "SF_UniversalPointTool.centerVec = LM.Vector2:new_local()" and it does the trick.

Actually, I don't know why I dragged it out

Code: Select all

			self.origin.x = mouseEvent.vec.x 
			self.origin.y = mouseEvent.vec.y 
			self.centerVec.x = self.origin.x. 
			self.centerVec.y = self.origin.y
and assigned the x and y separately there in the first place,

Code: Select all

self.origin = mouseEvent.vec
self.centerVec = self.origin
should be fine, and it's less typing. Who knows, it was a while ago.

And I must say, I do wish the Lua-Moho interaction was a little more robust when it comes to errors. Some bit of stupidity that makes Lua hiccup shouldn't be causing Moho to go down in flames.

Anyway, that should take care of that bug. I'm a little surprised that it never came up, but really you would only normally see it if that was the first thing you'd done on installing the script (most people), or the first thing you did with it after hitting <CTRL><F5> (since that seems to clear all global variables). Oh well, simple 'nuff fix.
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Hee hee...

7feet,

I think I know why you used the "longer" version of the code...

For some reason...

Code: Select all

self.origin = mouseEvent.vec 
self.centerVec = self.origin
Doesn't work properly. It works the first time you rotate.
But if you change the origin then rotate... it gets funky.

while your original code...

Code: Select all

self.origin.x = mouseEvent.vec.x 
self.origin.y = mouseEvent.vec.y 
self.centerVec.x = self.origin.x. 
self.centerVec.y = self.origin.y
Works fine. This doesn't make sense to me either. You are either getting the individual X and Y or both in one... It looks like either should work the same... can't figure it out. There must be something weird going on in there.

If it was a while ago you could easily have forgotten why you did it that way.

-vern
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Post by 7feet »

Most likely for just that reason. There's all kinds of stuff that should work, but you have to deal with what does. I do seem to remember that being one of those bits o' wierdness. But I'll have to look at it some more, might just be another stoopid thing I did somewhere else.

--Yeah, looking at it something seems a bit off. Can't quite place my finger on it, but I have a feeling there's something...
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Ha ha!

The fun part for me was I used that shorter bit of code without testing it first... two lines are better than four right? Yeehaa.

... then I started making changes to the modifier keys so I could add constrain translation and other improvements/fixes...

... so there I was... trying to figure out how I had broken the code...

Hee hee... I was relieved it wasn't me. For a moment there I thought I had gone completely insane...

plus on the Mac... those dang modifier keys are... slightly different... I have a cheat sheet stuck to my monitor now... alt is... option... no wait... alt is command... option is control... no wait... left foot on green... right hand on yellow... <sigh>


;)

-vern
peter.h
Posts: 9
Joined: Mon Mar 13, 2006 7:41 am
Location: Wellington, New Zealand

New feature: Double click = SelectConnected ?

Post by peter.h »

Firstly, thanks guys for such a useful tool! I'm new to Moho, and love the ability to add improved tools like yours.

I do have a much-wanted feature request: I'd love to be able to easily "Select Connected". Doing this when double-clicking a curve/point while using your tool would be a VERY useful addition for me. Wha'da ya reckon? :)

Pete.
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Select any point or points and press the tab key.

I wanted to add this "back in" till I found the tab key to select connected.

------------------------------

I have been experimenting with a "fake" double click based on the system clock... but since a double click isn't in the "code" for Moho scripting... it isn't ready for prime time.

So far... my results have proven more annoying than a broken mouse button. Sometimes it works.... sometimes I sit there double clicking and screaming "Work damn you work!"

p.s. I have found from experience that yelling at any type of programming code has no positive effect whatsoever on functionality. Profanities seem to just make it worse.

-Vern
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

You know what?

I changed my mind.

I have been using the tab key to select connected and thought it was a "solution"... but I actually don't like it much.

I really like not selecting a whole mesh when you click inside it... but I miss being able to select the whole thing with one click.

I think I will put in the "select connected" with this tool when clicking right on the spline of a mesh (not hitting a point). This would use the same selection radius but if you click on any part of the "line" it selects the whole thing... (I hate a ton of modifier keys. Took 5 minutes to remember the combo to move the rotation center point... I'm old... my brain is thick and crusted over from years of use and MASH reruns).

I really need to get that selection radius thing worked out. I just can't figure out how to convert the coordinates to screen space... very annoying. Maybe if I stopped screaming at my computer.

-Vern
Post Reply