This reference page is linked to from the following overview topics: Autodesk Maya 2014, 3.9 UI draw manager, 4.5 Handling custom renderables for object overrides.
Main interface for drawing simple geometry in Viewport 2.0 and Maya Hardware Renderer 2.0.
Simple geometry includes things like lines and text.
All drawing operations, including setting state like color and font size, must occur between calls to beginDrawable() and endDrawable(). For example, to draw a pair of red lines you would do the following:
MColor red(1.0f, 0.0f, 0.0f); painter.beginDrawable(); painter.setColor( red ); painter.line( MPoint(0, 0, 0), MPoint(1, 1, 1) ); painter.line( MPoint(0, 0, 0), MPoint(-1, -1, 5) ); painter.endDrawable();
The call to endDrawable() resets the draw state, so if you wanted to continue drawing in red later on you would have to repeat the call to setColor(). E.g:
painter.beginDrawable();
painter.setColor( red );
painter.text( MPoint(0, 0, 4), "Hello, world!" );
painter.endDrawable();
Note that draw operations may not take place immediately but instead be queued up for later execution.
footPrintManip.cpp, footPrintNode.cpp, lineManip.cpp, lineManip.h, marqueeTool.cpp, and swissArmyManip.cpp.
#include <MUIDrawManager.h>
Public Types | |
| enum | FontSize { kDefaultFontSize, kSmallFontSize } |
Font size for drawing the text. More... | |
| enum | TextAlignment { kLeft, kCenter, kRight } |
Text alignment. More... | |
| enum | LineStyle { kSolid, kShortDotted, kShortDashed, kDashed, kDotted } |
Line style. More... | |
| enum | PaintStyle { kFlat, kStippled } |
Paint style. More... | |
| enum | Primitive { kPoints, kLines, kLineStrip, kClosedLine, kTriangles, kTriStrip } |
Primitive. More... | |
Public Member Functions | |
| void | beginDrawable () |
| Resets all draw state, such as color and line style, to defaults and indicates the start of a sequence of drawing operations. | |
| void | endDrawable () |
| Indicates the end of a sequence of drawing operations. | |
| void | setColor (const MColor &color) |
| Set the draw color. | |
| void | setColorIndex (const short index) |
| Set the color index for the later primitive and text drawing. | |
| void | setPointSize (float value) |
| Set the point size for the point drawing. | |
| void | setLineWidth (float value) |
| Set the line width for the primitive drawing (line, rect, box...) | |
| void | setLineStyle (LineStyle style) |
| Set the line style for the primitive drawing (line, rect, box...) | |
| void | setLineStyle (unsigned int factor, unsigned short pattern) |
| Set the dashed line pattern for the primitive drawing (line, rect, box...) | |
| void | setPaintStyle (PaintStyle style) |
| Set the paint style for filled primitive drawing. | |
| void | line (const MPoint &startPoint, const MPoint &endPoint) |
| Draw a straight line between two points. | |
| void | line2d (const MPoint &startPoint, const MPoint &endPoint) |
| Draw a straight line between two points. | |
| void | point (const MPoint &point) |
| Draw a point. | |
| void | point2d (const MPoint &point) |
| Draw a point. | |
| void | rect (const MPoint ¢er, const MVector &up, const MVector &normal, double scaleX, double scaleY, bool filled=false) |
| Draw a rectangle. | |
| void | rect2d (const MPoint ¢er, const MVector &up, double scaleX, double scaleY, bool filled=false) |
| Draw a 2D rectangle on the screen. | |
| void | sphere (const MPoint ¢er, double radius, bool filled=false) |
| Draw a sphere. | |
| void | circle (const MPoint ¢er, const MVector &normal, double radius, bool filled=false) |
| Draw a circle. | |
| void | circle2d (const MPoint ¢er, double radius, bool filled=false) |
| Draw a 2D circle on the screen. | |
| void | arc (const MPoint ¢er, const MVector &start, const MVector &end, const MVector &normal, double radius, bool filled=false) |
| Draw an arc. | |
| void | arc2d (const MPoint ¢er, const MVector &start, const MVector &end, double radius, bool filled=false) |
| Draw a 2D arc on the screen. | |
| void | mesh (Primitive mode, const MPointArray &position, const MVectorArray *normal=NULL, const MColorArray *color=NULL, const MUintArray *index=NULL) |
| Draw custom geometric shapes from an array of vertices. | |
| void | mesh2d (Primitive mode, const MPointArray &position, const MColorArray *color=NULL, const MUintArray *index=NULL) |
| Draw custom 2d geometric shapes from an array of vertices. | |
| void | cone (const MPoint &base, const MVector &direction, double radius, double height, bool filled=false) |
| Draw a cone. | |
| void | box (const MPoint ¢er, const MVector &up, const MVector &right, double scaleX=1.0, double scaleY=1.0, double scaleZ=1.0, bool filled=false) |
| Draw a box. | |
| void | setFontSize (FontSize fontSize) |
| Set the size of font to be used when drawing text. | |
| void | text (const MPoint &position, const MString &text, TextAlignment alignment=kLeft, const int *backgroundSize=NULL, const MColor *backgroundColor=NULL, bool dynamic=false) |
| Draw a screen facing and horizontal aligned text in viewport 2.0. | |
| void | text2d (const MPoint &position, const MString &text, TextAlignment alignment=kLeft, const int *backgroundSize=NULL, const MColor *backgroundColor=NULL, bool dynamic=false) |
| Draw a text on the screen. | |
| enum FontSize |
Font size for drawing the text.
| enum TextAlignment |
Text alignment.
| enum LineStyle |
Line style.
| enum PaintStyle |
Paint style.
| enum Primitive |
Primitive.
| void beginDrawable | ( | ) |
Resets all draw state, such as color and line style, to defaults and indicates the start of a sequence of drawing operations.
All drawing operations must take place between calls to beginDrawable() and endDrawable().
painter.beginDrawable();
painter.line( MPoint(0,0,0), MPoint(1,1,1) );
painter.line( MPoint(0,0,0), MPoint( -1, -1, 11) );
painter.endDrawable();
| void endDrawable | ( | ) |
Indicates the end of a sequence of drawing operations.
All internal drawing state, such as color and line style, are reset to defaults.
| void setColor | ( | const MColor & | color | ) |
Set the draw color.
This will remain in effect until the next call to setColor(), setColorIndex() or endDrawable().
For text this color will be used as the foreground color. Background color can be specified directly in the call to text().
Default: (0.7, 0.7, 0.7, 1)
| [in] | color | The color which will affect the later drawing |
| void setColorIndex | ( | const short | index | ) |
Set the color index for the later primitive and text drawing.
For default, it will use (0.7, 0.7, 0.7, 1) as default color.
| [in] | index | Color index |
| void setPointSize | ( | float | value | ) |
Set the point size for the point drawing.
| [in] | value | Point size in pixels. |
| void setLineWidth | ( | float | value | ) |
Set the line width for the primitive drawing (line, rect, box...)
| [in] | value | Line width in pixels. |
| void setLineStyle | ( | LineStyle | style | ) |
Set the line style for the primitive drawing (line, rect, box...)
| [in] | style | Line style type. |
| void setLineStyle | ( | unsigned int | factor, |
| unsigned short | pattern | ||
| ) |
Set the dashed line pattern for the primitive drawing (line, rect, box...)
| [in] | factor | a multiplier for each bit in the line stipple pattern. |
| [in] | pattern | a pattern determines which fragments of a line will be drawn |
| void setPaintStyle | ( | PaintStyle | style | ) |
Set the paint style for filled primitive drawing.
| [in] | style | Paint style type. |
Draw a straight line between two points.
| [in] | startPoint | The start point of the line. |
| [in] | endPoint | The end point of the line. |
Draw a straight line between two points.
| [in] | startPoint | The start point of the line, only x-y components(in pixels) are used. |
| [in] | endPoint | The end point of the line, only x-y components(in pixels) are used. |
| void point | ( | const MPoint & | point | ) |
| void point2d | ( | const MPoint & | point | ) |
Draw a point.
| [in] | point | Position of the point, only x-y components(in pixels) are used. |
| void rect | ( | const MPoint & | center, |
| const MVector & | up, | ||
| const MVector & | normal, | ||
| double | scaleX, | ||
| double | scaleY, | ||
| bool | filled = false |
||
| ) |
Draw a rectangle.
The rectangle is within the plane determined by a normal vector, and a up vector is given to determine the X-Y direction.
| [in] | center | Center of the rectangle |
| [in] | up | Up vector of the rectangle |
| [in] | normal | Normal vector of the rectangle plane |
| [in] | scaleX | Scale factor in X-direction |
| [in] | scaleY | Scale factor in Y-direction |
| [in] | filled | If true the rectangle will be filled otherwise it will just be drawn as an outline. |
| void rect2d | ( | const MPoint & | center, |
| const MVector & | up, | ||
| double | scaleX, | ||
| double | scaleY, | ||
| bool | filled = false |
||
| ) |
Draw a 2D rectangle on the screen.
The rectangle is always facing the camera, and a up vector is given to determine the X-Y direction.
| [in] | center | Center of the rectangle, only x-y components(in pixels) are used. |
| [in] | up | Up vector of the rectangle, only x-y components are used. |
| [in] | scaleX | Scale factor in X-direction |
| [in] | scaleY | Scale factor in Y-direction |
| [in] | filled | If true the rectangle will be filled otherwise it will just be drawn as an outline. |
| void sphere | ( | const MPoint & | center, |
| double | radius, | ||
| bool | filled = false |
||
| ) |
Draw a sphere.
| [in] | center | Center of the sphere. |
| [in] | radius | Radius of the sphere. |
| [in] | filled | If true the sphere will be filled otherwise it will just be drawn as a wireframe. |
Draw a circle.
The circle is drawn within the plane determined by a normal vector.
| [in] | center | Center of the circle |
| [in] | normal | Normal vector of the circle plane |
| [in] | radius | Radius of the circle |
| [in] | filled | If true the circle will be filled otherwise it will just be drawn as an outline. |
| void circle2d | ( | const MPoint & | center, |
| double | radius, | ||
| bool | filled = false |
||
| ) |
Draw a 2D circle on the screen.
The circle is always facing the camera.
| [in] | center | Center of the circle, only x-y components(in pixels) are used. |
| [in] | radius | Radius(in pixels) of the circle |
| [in] | filled | If true the circle will be filled otherwise it will just be drawn as an outline. |
| void arc | ( | const MPoint & | center, |
| const MVector & | start, | ||
| const MVector & | end, | ||
| const MVector & | normal, | ||
| double | radius, | ||
| bool | filled = false |
||
| ) |
Draw an arc.
The arc is within the plane determined by a normal vector. The arc sweeps in CCW from the vector that is the projection of the given start vector onto the arc plane, and ends at the vector that is the projection of the given end vector onto the arc plane.
| [in] | center | Center of the arc |
| [in] | start | Start vector, its projection onto the arc plane is the start of the arc. |
| [in] | end | End vector, its projection onto the arc plane is the end of the arc. |
| [in] | normal | Normal vector of the arc plane. |
| [in] | radius | Radius of the arc. |
| [in] | filled | If true the arc will be filled otherwise it will just be drawn as an outline. |
| void arc2d | ( | const MPoint & | center, |
| const MVector & | start, | ||
| const MVector & | end, | ||
| double | radius, | ||
| bool | filled = false |
||
| ) |
Draw a 2D arc on the screen.
The arc is always facing the camera. The arc sweeps in CCW from the start vector and ends at the end vector.
| [in] | center | Center of the arc, only x-y components(in pixels) are used |
| [in] | start | Start vector, only x-y components are used. |
| [in] | end | End vector, only x-y components are used. |
| [in] | radius | Radius(in pixels) of the arc. |
| [in] | filled | If true the arc will be filled otherwise it will just be drawn as an outline. |
| void mesh | ( | Primitive | mode, |
| const MPointArray & | position, | ||
| const MVectorArray * | normal = NULL, |
||
| const MColorArray * | color = NULL, |
||
| const MUintArray * | index = NULL |
||
| ) |
Draw custom geometric shapes from an array of vertices.
If the optional normal or color arrays are provided they must contain a single value per element of the positions array (i.e. all three arrays must be the same length).
The optional index array specifies the order in which the vertex positions (and their corresponding normals and colors) should be drawn. Vertices can be reused by having their indices appear multiple times, so the index array may be longer (or shorter) than the other three arrays.
If the index array is not provided then the vertices will be drawn in the order in which they appear in the positions array.
| [in] | mode | Primitive mode, e.g., point list, line list, etc. |
| [in] | position | List of the vertex positions. |
| [in] | normal | List of the vertex normals. |
| [in] | color | List of the vertex colors. |
| [in] | index | List of the vertex indices. |
| void mesh2d | ( | Primitive | mode, |
| const MPointArray & | position, | ||
| const MColorArray * | color = NULL, |
||
| const MUintArray * | index = NULL |
||
| ) |
Draw custom 2d geometric shapes from an array of vertices.
If the optional color arrays are provided they must contain a single value per element of the positions array (i.e. both arrays must be the same length).
The optional index array specifies the order in which the vertex positions (and their corresponding colors) should be drawn. Vertices can be reused by having their indices appear multiple times, so the index array may be longer (or shorter) than the other two arrays.
If the index array is not provided then the vertices will be drawn in the order in which they appear in the positions array.
| [in] | mode | Primitive mode, e.g., point list, line list, etc. |
| [in] | position | List of the vertex positions, only x-y components of the point are used. |
| [in] | color | List of the vertex colors. |
| [in] | index | List of the vertex indices. |
| void cone | ( | const MPoint & | base, |
| const MVector & | direction, | ||
| double | radius, | ||
| double | height, | ||
| bool | filled = false |
||
| ) |
Draw a cone.
| [in] | base | Base position for the cone |
| [in] | direction | The cone's tip will point in this direction. |
| [in] | radius | Radius of the cone |
| [in] | height | Height of the cone |
| [in] | filled | If true the cone will be filled otherwise it will just be drawn as an outline. |
| void box | ( | const MPoint & | center, |
| const MVector & | up, | ||
| const MVector & | right, | ||
| double | scaleX = 1.0, |
||
| double | scaleY = 1.0, |
||
| double | scaleZ = 1.0, |
||
| bool | filled = false |
||
| ) |
Draw a box.
| [in] | center | Center position for the box |
| [in] | up | The top of the box will be facing this direction. |
| [in] | right | The side of the box will be facing this direction. |
| [in] | scaleX | X size of the box |
| [in] | scaleY | Y size of the box |
| [in] | scaleZ | Z size of the box |
| [in] | filled | If true the box will be filled otherwise it will just be drawn as an outline. |
| void setFontSize | ( | FontSize | fontSize | ) |
Set the size of font to be used when drawing text.
Default: kDefaultFontSize
| [in] | fontSize | The font size to use. |
| void text | ( | const MPoint & | position, |
| const MString & | text, | ||
| TextAlignment | alignment = kLeft, |
||
| const int * | backgroundSize = NULL, |
||
| const MColor * | backgroundColor = NULL, |
||
| bool | dynamic = false |
||
| ) |
Draw a screen facing and horizontal aligned text in viewport 2.0.
It has a fixed size in screen space.
| [in] | position | Position of the text to be drawn, it is 3d object space. |
| [in] | text | Content of the text string. |
| [in] | alignment | Alignment of the text. "kLeft", background box's left bottom will be located at "position". In width direction, text area will be aligned to the left side of background. In height direction, text are will be aligned in the middle of background. |
"kCenter", background box' center bottom will be located at "position". text area's center and background box's center will be the same point.
"kRight", background box's right bottom will be located at "position". In width direction, text area will be aligned to the right side of background. In height direction, text are will be aligned in the middle of background.
| [in] | backgroundSize | The background box size of the text. Default is NULL, in this case there will be no background, just shows the text. If it is specified with smaller size than text, the text will be clipped. It is a int array with size 2, like "int backgroundSize[] = { width, height } " Size unit is the screen pixel. |
| [in] | backgroundColor | The color of the background, it can be transparent. If NULL is passed, background will be fully transparent. |
| [in] | dynamic | This is mostly used for performance. If the text draw is not changed frequently, we can leave it as default value false. If the text draw is changing very often like it is showing some dynamic numbers, in this case making dynamic true will give better performance. |
| void text2d | ( | const MPoint & | position, |
| const MString & | text, | ||
| TextAlignment | alignment = kLeft, |
||
| const int * | backgroundSize = NULL, |
||
| const MColor * | backgroundColor = NULL, |
||
| bool | dynamic = false |
||
| ) |
Draw a text on the screen.
| [in] | position | Position of the text to be drawn, it is in screen space, only x-y components are used. |
| [in] | text | Content of the text string. |
| [in] | alignment | Alignment of the text. "kLeft", background box's left bottom will be located at "position". In width direction, text area will be aligned to the left side of background. In height direction, text are will be aligned in the middle of background. |
"kCenter", background box' center bottom will be located at "position". text area's center and background box's center will be the same point.
"kRight", background box's right bottom will be located at "position". In width direction, text area will be aligned to the right side of background. In height direction, text are will be aligned in the middle of background.
| [in] | backgroundSize | The background box size(in pixels) of the text. Default is NULL, in this case there will be no background, just shows the text. If it is specified with smaller size than text, the text will be clipped. It is a int array with size 2, like "int backgroundSize[] = { width, height } " Size unit is the screen pixel. |
| [in] | backgroundColor | The color of the background, it can be transparent. If NULL is passed, background will be fully transparent. |
| [in] | dynamic | This is mostly used for performance. If the text draw is not changed frequently, we can leave it as default value false. If the text draw is changing very often like it is showing some dynamic numbers, in this case making dynamic true will give better performance. |