ViewItem3D: Package basics

From The Foundry MODO SDK wiki
Jump to: navigation, search

The ViewItem3D Interface allows an item package to draw in the 3D viewport.

Overview

Items presenting this interface are incorporated into the 3D view using stroke drawing, which is simple wireframe drawing style. Any item type or package can draw, not just locators.

Headers

Sample Methods

The package instance class derives from CLxImpl_ViewItem3D, and exports the ILxViewItem3D interface.

ViewItem3D::Draw()

The Draw() method is called to allow the item to draw in 3D. It's passed a ChannelRead Object and a StrokeDraw Object, and the typical process is much like the sample here. The item reads the values of its own channels and then draws primitives to represent them. In this case it draw three circles on the cardinal planes representing a sphere of a certain radius. The View Interface is not used, but is included to hint at some of the other types of drawing that can be done.

        LxResult
vitm_Draw (
        ILxUnknownID            chanRead,
        ILxUnknownID            strokeDraw,
        int                     selectionFlags,
        LXtVector               itemColor)              LXx_OVERRIDE
{
        CLxUser_ChannelRead     chan (chanRead);
        CLxUser_StrokeDraw      draw (strokeDraw);
        CLxUser_View            view (strokeDraw);
        LXtVector               center, axis;
        double                  radius, alpha;

        radius = chan.FValue (m_item, "myRadiusChannel");
        alpha  = chan.FValue (m_item, "myAlphaChannel");

        strokeDraw.Begin (LXiSTROKE_CIRCLES, itemColor, alpha);

        LXx_VCLR (center);
        LXx_VCLR (axis);
        for (int i = 0; i < 3; i++) {
                LXx_VCLR (axis);
                axis[i] = radius;
                strokeDraw.Vert (center);
                strokeDraw.Vert (axis, LXiSTROKE_RELATIVE);
        }
        return LXe_OK;
}
ViewItem3D::WorldSpace()

Normally drawing is done in the local coordinates of the item (at least for Locator-derived item types). This is why the center used for drawing in the sample code above is set to the origin -- that's the center of the item's coordinates, not the world origin. This can be changed by this method, which in combination with the code above will now draw the circle at the world origin.

        LxResult
vitm_WorldSpace (void)
{
        return LXe_TRUE;
}