Browsing"User Controls"

HitchHiker – A dynamic thumbnail UI control for 3dsMax

Oct 24, 2008 by     2 Comments    Posted under: 3dsMax, DotNet, User Controls

HitchHiker is a custom UI control written in VB.net. It could be happily used in a windows forms project, but specifically I am writing all my stuff with the intention of integrating them into my animation workflow in 3dsMax.

Hitchhiker is a dynamic rollout creator – it has one method – populate(path) and it searches the location for a particular filetype. Depending on the display method, it will then dynamically cache thumbnails of many image filetypes and 3dsmax thumbnails and display them as a button within the control. The button has a custom event attached to it, and passes the file location so that you can do with it as you wish. However, you can also drag and drop from it into max should you wish.

Image Limitations in Windows

If you’ve ever done any windows programming, you will be aware of the native image filetypes that windows recognizes. The most notable omission is TARGA, a much used format in the 3d industry. Hitchhiker employs a custom image library to bridge the gap and provide access to many image filetypes.

these include BMP,TIF,PNG,ICO,PSD,JPG, and TGA. however, it is not just limited to image files. it will also search for .max, .wav, .avi and .xml. This makes it extremely flexible and could be used in just about any situation.

Why is this useful?

I hate building UI’s. Funny i guess considering i’m mostly programming UI controls but that’s the point. If i can put something on a maxscript rollout that handles all of the code generation of file handling, it means I can build a script quickly. Hitchhiker has multiple properties to control how the buttons appear in the control. Here’s a few examples. – click the image to see it full size.

Flatbot is a utility that allow me to take a folder of images and generate plane geometry, opacity mapped for a recent production. It’s a simple idea but it really saves time on setup.

Hitchhiker is on the left in ImageText display mode. You can also see that it rescales the thumbnail and keeps the aspect ratio correct. There is another custom class in this utility. The transparent picturebox control is an inherited user control, it simply paints the photoshop-esque checkerboard background for viewing images.

I wanted to be able to easily display the alpha channel of a Targa, but was frustrated on how to do it. I was able to build a method into HitchHiker that converts the targa into a temporary PNG and passes this to the custom picturebox control. This way, it displays the alpha correctly. This conversion is swift, and displays almost immediately.

You can probably see with this control you could build a CG asset browser in about 10 minutes.

other uses are : a sound loading utility –

Above, HitchHiker is in IconText display mode. All formats have a custom icon that will display if you don’t want image thumbnails.

When specifying avi as a search type, it will extract the first frame and do a GDI+ overlay of the icon type in the corner so you know it is a video file. –

HitchHiker also has a tooltip that displays after a moment on the selected button. (This can be disabled) Depending on the filetype, it will extract information pertaining to that format.

Future Plans

i’m most excited about integrating HitchHiker into a character pose system. Storing the poses in XML format for a character, it allows you to dynamically retrieve facial expressions, lipsync, rig poses, anything!

In the XML search function i have a routine that checks for a custom image. if you store a snapshot image titled the same name as the XML file, it will use this as an image on the button.

I’m hoping to release a free version of this control with reduced functionality soon.

thanks for reading!

Joystick Control – A custom user control project

Aug 28, 2008 by     1 Comment     Posted under: 3dsMax, DotNet, User Controls

Integrating a VB.net custom UI control into 3dsMax

A while ago I decided to research making your own UI controls in Visual Studio. Why? Well, as a character animator by day I am always looking for better ways of providing input for an animator to set various character attributes. I always liked the old joystick manipulator by Borislav Petrov but wanted a way of integrating this into the UI rather than in the viewport. Until Dot net was integrated with max, this would have been impossible without writing one yourself in C++.

This page details the results so far. As a project it was very much in the deep end, and the creation of the control was limited to my research into programming VB at the time. I have been coding maxscript in some shape or form since R3 but this was my first foray into this type of coding.

A brief Recap – Why arguments are not always bad…

Before I talk in more depth about the control itself, i thought i’d mention the basics of how events are handled within Visual Basic so that you can understand how to set these up and use them correctly within the MaxScript/DotNet bridge. I’m sure the procedure is similar in C# but I will use examples in VB as this is what i use. (My programmer friend Chris said to me once that VB and C# are identical, except C# is spoken with an American accent)

There are many handlers aside from the standard mouse input handlers, but for a custom control, these (along with GDI+ paint handlers) are the important ones. In VB, when you specify a mousedown handler it passes two arguments to the handling subroutine.

Private Sub Button1_MouseDown (ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
  Handles Button1.MouseDown
  )
  )

This is useful since even when using a dotnetcontrol, you can pass the sender and event arguments and use them in a similar way. These arguments are important in regard to a control that uses the mouseposition to set positions of UI elements.

Writing a custom event class

With a custom control, you might not want to just return the mouse position in the event handler. Due to the nature of the control you might need another property that you can do something with. This is where writing your own event class comes in. You can specify what the handler uses as its ‘e’ argument. This is the basics of the new event class. It inherits the eventargs class so that it can use all of the properties of this class but augment them with others.

Public Class JoystickEventArgs

Inherits EventArgs

Private _location As Size
Private _X As Integer
Private _Y As Integer
Private _MorphValue As MorphValue

Public Property Location() As Size
Get
Return _location
End Get
Set(ByVal value As Size)
_location = value
End Set
End Property

Public Property X() As Integer
Get
Return _X
End Get
Set(ByVal value As Integer)
_X = value
End Set
End Property
Public Property Y() As Integer
Get
Return _Y
End Get
Set(ByVal value As Integer)
_Y = value
End Set
End Property

Public Property MorphValue() As MorphValue
Get
Return _MorphValue
End Get
Set(ByVal value As MorphValue)
_MorphValue = value
End Set
End Property

Public Sub New(ByVal Joystick As Joystick)
Location = Joystick.MovableLabel.Location
X = Me.Location.Width
Y = Me.Location.Height
MorphValue = GetMorphValuesLinear(Me.Location) End Sub
End Class


However, this class is not complete without another class. I created one called morphvalue, which is simply a container object to store four integer values for up,down,left and right. I also created an enumeration that you can retrieve in the handler to show which quadrant of the control you are in. This means you can use a case expression to control different objects on a per quadrant basis. The joystickeventarg creates an instance of this class each time it is called (within the new sub) and calls the getmorphvalueslinear() function. this is not listed but returns a value related to the mouse position.

Public Class MorphValue

Enum Quad
TopLeft
TopRight
TopCenter
BottomLeft
BottomRight
BottomCenter
CenterLeft
CenterRight
Reset
End Enum

Private _Left As Integer
Private _Right As Integer
Private _Up As Integer
Private _Down As Integer
Private _Area As Quad

Public Property Area() As Quad
Get
Return _Area
End Get
Set(ByVal value As Quad)
_Area = value
End Set
End Property

Public Property Left() As Integer
Get
Return _Left
End Get
Set(ByVal value As Integer)
_Left = value
End Set
End Property

Public Property Right() As Integer
Get
Return _Right
End Get
Set(ByVal value As Integer)
_Right = value
End Set
End Property

Public Property Up() As Integer
Get
Return _Up
End Get
Set(ByVal value As Integer)
_Up = value
End Set
End Property

Public Property Down() As Integer
Get
Return _Down
End Get
Set(ByVal value As Integer)
_Down = value
End Set
End Property

Public Sub New(ByVal Area As Quad, ByVal Value1 As Integer, ByVal Value2 As Integer, ByVal Value3 As Integer, ByVal Value4 As Integer)

Me.Up = Value1
Me.Down = Value2
Me.Left = Value3
Me.Right = Value4
Me.Area = Area
End Sub

End Class


so, within Visual studio and bound to the joystickmove handler on the joystick object, the new joystickeventargs class returns the following output –

Private Sub Joystick1_JoystickMove(ByVal sender As System.Object, ByVal e As LoneRobot.JoystickEventArgs) Handles Joystick1.JoystickMove

Dim Mretval As Size = Joystick1.MorphtoValue(e.MorphValue.Up, e.MorphValue.Down, e.MorphValue.Left, e.MorphValue.Right)

Label1.Text = e.X.ToString & "/" & e.Y.ToString & " || " & Mretval.Width.ToString & "/" & Mretval.Height.ToString
LabelUP.Text = e.MorphValue.Up.ToString
LabelDown.Text = e.MorphValue.Down.ToString
LabelLeft.Text = e.MorphValue.Left.ToString
LabelRight.Text = e.MorphValue.Right.ToString

LabelUP.Height = e.MorphValue.Up
LabelDown.Height = e.MorphValue.Down
LabelLeft.Height = e.MorphValue.Left
LabelRight.Height = e.MorphValue.Right
Label2.Text = e.MorphValue.Area
End Sub

you will see that the handler is now specifying "e As LoneRobot.JoystickEventArgs" meaning that it is returning this class.

If you are binding this into a max dotnetcontrol event, you just need to set the morph channels to the morphvalue.<direction> property of  the eventarg.

download