[Closed] Drag-to-select interface possible?
Hi, I’m creating a rig selection interface for the animators that’s supposed to work a little like the one in Maya or MotionBuilder, and the animators have requested that they be able to drag a selection around a number of interface elements to select multiple of them in one go. I’m not sure if that’s possible though?
The idea (in case I didn’t explain properly) is illustrated here:
note: source image pulled off flickr, I claim no ownership
I’ve implemented this exact feature in c#, though technically it might also be possible in Maxscript+Dotnet.
Thanks lo,
MaxScript is my primary tool, with a bit of DotNet when needed (wish I knew more!), any idea where to start though?
Is this only a selection interface, or can the points be moved? Are there any other needed features?
Basically, in maxscript, You would need to create a dotnet control (or dotnetObject if this will be hosted in a dotnet form) typically of type “panel” or “usercontrol”.
You would then need to register the following events for this control:
[ul]
[li]Paint
[/li][li]MouseDown
[/li][li]MouseUp
[/li][li]MouseMove
[/li][li]SizeChanged (if you want it to be resizable)
[/li][/ul]
and possibly others I’ve forgotten.
You will create a System.Drawing.Rectangle representing the bounds of each selectable point and implement the selection logic in the mouse events. You will need to paint the control yourself in the Paint event.
If you go down this route you will probably have more questions, but it’s easier to give you directions once you’ve already started, because it’s not a very short code.
Okay, thanks. That sounds like the route I will go. I would like for it to be customizable per character, but it’s not a requirement. I will give it a go, and come back when I get stuck. Again, thanks.
Here is some very incomplete pseudocode to get you started:
struct ctrlPoint --a selectable control point
(
boundsF, -- a System.Drawing.RectangleF (float) which describes the point's normalized bounds in the range of 0.0-1.0 (where 1.0 is the size of the panel control)
--normalizing these coordinates allows easy resizing of the control
bounds, -- un-normalized point coords (this will need to be updated each time the panel is resized
animHandle, -- a handle to the node or maxobject the point selects
isSelected --boolean
fn updateBounds w h =
(
--update the bounds rect using the constant boundsF rect and the w/h variables (panel size).
)
)
rollout rigCtrlRol "Test"
(
local ctrlPoints = #()
local dragRectPoint -- a point where dragging started
local dragRect -- the selection rectangle
dotnetControl pnl "Panel" width:500 height:500
on pnl paint s e do
(
--e.graphics.drawimage.... the background image
for p in ctrlPoints
(
--e.graphics.fillEllipse ... --paint the point
)
if dragRect != undefined do
(
--paint the drag rectangle
)
)
on pnl mouseDown s e do
(
--check if clicked inside a point
--if not, start a drag rectangle
--(
--dragRectPoint = e.location....
--dragRect = ...
--reset all points .isSelected property...
--)
)
on pnl mouseUp s e do
(
dragRect = undefined --reset the dragRect
for p in ctrlPoints where p.isSelected do
(
--perform selection logic
)
)
on pnl mouseMove s e do
(
if dragRect != undefined do
(
--recalculate the dragRect. Be sure to support dragging in all directions!
for p in ctrlPoints do
(
p.isSelected = --do the point bounds intersect/are contained inside the drag rect?
)
)
)
on pnl sizeChanged s e do
(
--calculate all points updated bounds
)
)
this is a very loose structure, you should not take it literally, maybe just draw ideas.
Am I on the right track so far? Ignore the image, since it obviously isn’t important for testing.
try destroyDialog testDragSelect_Rollout catch()
rollout testDragSelect_Rollout "Character Studio with Dragging Functionality" width:512 height:512
(
local mouseIsDown
dotNetControl tds_dnc_usercontrol "System.Windows.Forms.Usercontrol" width:500 height:500 align:#center
on testDragSelect_Rollout open do
(
mouseIsDown = false
--tds_dnc_usercontrol.backgroundImage = (dotNetclass "System.Drawing.Image").fromfile @"X:\3dsmax\2013\MaxScript\images\characterStudioBackground.png"
)
on tds_dnc_usercontrol MouseDown do
(
print "Down!"
mouseIsDown = true
)
on tds_dnc_usercontrol MouseUp do
(
print "Up!"
mouseIsDown = false
)
on tds_dnc_usercontrol MouseMove do
(
if mouseIsDown then print "Moved with button down (ie drag!)"
)
)
createDialog testDragSelect_Rollout
edit: hadn’t seen the above post – looks like some very good ideas there!
Yup, it seems you are on the right track. Do keep posting your updates, I will be happy to track your progress.
This is something I’ve always wanted to learn how to do. I’d really apppreciate it if you could continue to post your progress and allow us to learn from it.
Thanks!
john
Certainly will, I’m re-starting from (almost) scratch again right now though, since I think I’ll be limiting myself too much unless I go the dotnet form route.
All good ideas, especially the save/load point data is something I want to do.
More features you might want to implement:
- Support for Alt/Ctrl.
- Different color for selected points.
- Different color for points under the mouse but not selected (preview selection).
- Save/load point data in external files.
These will require a little more complex logic.
What I eventually ended up doing was to add a design mode to the control, in which the points are movable, and a separate property editor allows you to set properties of the points (in your case, for example, determine which object they select), so the user is able to also create the interface he wants according to the character (just another option to consider).
Hey Mixx,
I’m not sure how much exp you have with dotNet stuff. A while back I started a thread which covered so examples of dotNet UI stuff which Lo himself helped out a lot on. It was a learning exp for me and a good resource for some basic examples.
I figured I would put the link on here in case there is something you may find useful on it.
http://forums.cgsociety.org/showthread.php?f=98&t=1015046&highlight=dotnet
Not a whole lot – though I somehow convinced my production manager that now is a good time to dedicate some extra resources (ie, hours!) to learn it.
Thanks, looks very useful. I also found PEN’s tutorial on MaxScript Dotnet forms – good stuff there.