Beispiel #1
0
void MannequinMoveManipulator::drawUI(MHWRender::MUIDrawManager &drawManager,
  const MHWRender::MFrameContext &frameContext) const {
  float size = _manipScale * MFnManip3D::globalSize();
  float handleSize = MFnManip3D::handleSize() / 100.0f; // Probably on [0, 100].
  float handleHeight = size * handleSize * 0.5f;
  float handleOfs = size - handleHeight;
  float handleRadius = handleHeight * 0.25f;

  beginDrawable(drawManager, _glPickableItem + 0, true);
  drawManager.setLineWidth(MFnManip3D::lineSize());
  drawManager.setColorIndex(_selected[0] ? _selColor : _xColor);
  drawManager.line(_origin, _origin + (_x * size));
  drawManager.cone(_origin + (_x * handleOfs), _x, handleRadius, handleHeight,
    true);
  drawManager.endDrawable();

  beginDrawable(drawManager, _glPickableItem + 1, true);
  drawManager.setLineWidth(MFnManip3D::lineSize());
  drawManager.setColorIndex(_selected[1] ? _selColor : _yColor);
  drawManager.line(_origin, _origin + (_y * size));
  drawManager.cone(_origin + (_y * handleOfs), _y, handleRadius, handleHeight,
    true);
  drawManager.endDrawable();

  beginDrawable(drawManager, _glPickableItem + 2, true);
  drawManager.setLineWidth(MFnManip3D::lineSize());
  drawManager.setColorIndex(_selected[2] ? _selColor : _zColor);
  drawManager.line(_origin, _origin + (_z * size));
  drawManager.cone(_origin + (_z * handleOfs), _z, handleRadius, handleHeight,
    true);
  drawManager.endDrawable();
};
Beispiel #2
0
MStatus grabUVContext::drawFeedback(MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context)
{
	// to draw the brush ring.
	drawMgr.beginDrawable();
	{
		drawMgr.setColor( MColor(1.f, 1.f, 1.f) ); 
		drawMgr.setLineWidth( 2.0f );
		drawMgr.circle2d(MPoint(fBrushCenterScreenPoint.x, fBrushCenterScreenPoint.y), fBrushConfig.size());
	}				
	drawMgr.endDrawable();

	return MS::kSuccess;
}
Beispiel #3
0
void uiDrawManagerDrawOverride::addUIDrawables(
    const MDagPath& objPath,
    MHWRender::MUIDrawManager& drawManager,
    const MHWRender::MFrameContext& frameContext,
    const MUserData* data)
{
    const uiDrawManagerData* thisdata = dynamic_cast<const uiDrawManagerData*>(data);
    if (!thisdata) {
        return;
    }

    switch (thisdata->fUIType) 
    {
    case uiDrawManager::kText: 
        {
            // Draw a text "uiDrawManager"
            // All drawing operations must take place between calls to beginDrawable()
            // and endDrawable().
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setFontSize(thisdata->fTextFontSize);
            drawManager.setFontIncline(thisdata->fTextIncline);
            drawManager.setFontWeight(thisdata->fTextWeight);
            drawManager.setFontStretch(thisdata->fTextStretch);
            drawManager.setFontLine(thisdata->fTextLine);

            MString faceName = uiDrawManagerData::fFontList[thisdata->fFontFaceIndex];
            drawManager.setFontName(faceName);
            int boxSize[] = { thisdata->fTextBoxWidth, thisdata->fTextBoxHeight };
            if (thisdata->fDraw2D) {
                // uiDrawManagerData::fPosition gives a screen space position 
                // where 2D UI item is located.                
                drawManager.text2d(thisdata->fPosition, thisdata->fText, thisdata->fTextAlignment, 
                    boxSize[0]+boxSize[1] == 0 ? NULL : boxSize, &thisdata->fTextBoxColor, false);
            }
            else {
                // for 3D items, place it at the origin of the world space.
                drawManager.text(thisdata->fPosition, thisdata->fText, thisdata->fTextAlignment, 
                    boxSize[0]+boxSize[1] == 0 ? NULL : boxSize, &thisdata->fTextBoxColor, false);
            }

            drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kLine:
	case uiDrawManager::kLineList:
	case uiDrawManager::kLineStrip:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setLineWidth(thisdata->fLineWidth);
            drawManager.setLineStyle(thisdata->fLineStyle);
			if (thisdata->fUIType == uiDrawManager::kLineStrip)
				drawManager.lineStrip(thisdata->fLines, thisdata->fDraw2D);
            else
				drawManager.lineList(thisdata->fLines, thisdata->fDraw2D);
			drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kPoint:
    case uiDrawManager::kPointList:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setPointSize(thisdata->fPointSize);
            drawManager.points(thisdata->fPoints, thisdata->fDraw2D);
            drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kRect:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setLineWidth(thisdata->fLineWidth);
            drawManager.setLineStyle(thisdata->fLineStyle);
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
            if (thisdata->fDraw2D) {
                // For 2d rectangle, an up vector in screen space is used to determine its X 
                // and Y directions. In addition, "fRectScaleX" and "fRectScaleY"(in pixels)
                // specify the half-lengths of the 2d rectangle.
                drawManager.rect2d(thisdata->fPosition, thisdata->fRectUp,
                    thisdata->fRectScaleX, thisdata->fRectScaleY, thisdata->fIsFilled);
            }
            else {
                // For 3d rectangle, the up vector should not be parallel with the normal vector.
				drawManager.rect(thisdata->fPosition, thisdata->fRectUp, thisdata->fRectNormal,
                    thisdata->fRectScaleX, thisdata->fRectScaleY, thisdata->fIsFilled);
            }

            drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kQuad:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setLineWidth(thisdata->fLineWidth);
            drawManager.setLineStyle(thisdata->fLineStyle);

            // prepare primitive type
            MUIDrawManager::Primitive mode = 
                thisdata->fIsFilled ? MUIDrawManager::kTriStrip : MUIDrawManager::kClosedLine;
            // prepare position list
            MPointArray position;
            for (int i = 0; i < 4; ++i) {
                position.append(thisdata->fQuadVertex[i]);
            }
            // prepare index
            MUintArray index;
            index.append(0);
            index.append(1);
            index.append(3);
            index.append(2);

            // draw mesh
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
            if (thisdata->fDraw2D) {
                drawManager.mesh2d(mode, position, NULL, thisdata->fIsFilled ? &index : NULL);
            }
            else {
                drawManager.mesh(mode, position, NULL, NULL, thisdata->fIsFilled ? &index : NULL);
            }

            drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kSphere:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setLineWidth(thisdata->fLineWidth);
            drawManager.setLineStyle(thisdata->fLineStyle);
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
			drawManager.sphere(thisdata->fPosition, thisdata->fRadius, thisdata->fIsFilled);

            drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kCircle:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setLineWidth(thisdata->fLineWidth);
            drawManager.setLineStyle(thisdata->fLineStyle);
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
            if (thisdata->fDraw2D) {
                // The radius in specified as pixel unit for 2d items.
				drawManager.circle2d(thisdata->fPosition, thisdata->fRadius, 
                    thisdata->fIsFilled);
            }
            else {
                drawManager.circle(thisdata->fPosition, thisdata->fCircleNormal, thisdata->fRadius, 
                    thisdata->fIsFilled);
            }

            drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kArc:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setLineWidth(thisdata->fLineWidth);
            drawManager.setLineStyle(thisdata->fLineStyle);
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
            if (thisdata->fDraw2D) {
                // If 2d, the range of the arc is defined by the start and end vectors 
                // specified in screen space.
                drawManager.arc2d(thisdata->fPosition, thisdata->fArcStart, thisdata->fArcEnd, 
                    thisdata->fRadius, thisdata->fIsFilled);
            }
            else {
                // For 3d arc, the projections of the start and end vectors onto the arc plane(
                // determined by the normal vector) determine the range of the arc.
                drawManager.arc(thisdata->fPosition, thisdata->fArcStart, thisdata->fArcEnd, 
                    thisdata->fArcNormal, thisdata->fRadius, thisdata->fIsFilled);
            }

            drawManager.endDrawable();
        }
        break;

	case uiDrawManager::kIcon:
		{	
            MString iconName = uiDrawManagerData::fIconList[thisdata->fIconIndex];
			drawManager.beginDrawable();
			drawManager.setColor(thisdata->fColor);
			drawManager.icon(thisdata->fPosition, iconName, thisdata->fIconScale);
			drawManager.endDrawable();
		}
		break;

	case uiDrawManager::kCone:
		{
			drawManager.beginDrawable();

			drawManager.setColor(thisdata->fColor);
			drawManager.setLineWidth(thisdata->fLineWidth);
			drawManager.setLineStyle(thisdata->fLineStyle);
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
			drawManager.cone(thisdata->fPosition,
							thisdata->fConeDirection,
							thisdata->fRadius, 
							thisdata->fConeHeight,
							thisdata->fIsFilled);

			drawManager.endDrawable();
		}
		break;

	case uiDrawManager::kBox:
		{
			drawManager.beginDrawable();

			drawManager.setColor(thisdata->fColor);
			drawManager.setLineWidth(thisdata->fLineWidth);
			drawManager.setLineStyle(thisdata->fLineStyle);
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
			drawManager.box(thisdata->fPosition, 
							thisdata->fBoxUp,
							thisdata->fBoxRight,
							thisdata->fBoxScale[0],
							thisdata->fBoxScale[1],
							thisdata->fBoxScale[2],
							thisdata->fIsFilled);

			drawManager.endDrawable();
		}
		break;
	
	default:
        perror("unhandled ui types.");
        break;
    }
    
}
void sphericalBlendShapeVisualizerDrawOverride::addUIDrawables(
								const MDagPath& objPath,
								MHWRender::MUIDrawManager& drawManager,
								const MHWRender::MFrameContext& frameContext,
								const MUserData* data)
{
	sphericalBlendShapeVisualizerData* pLocatorData = (sphericalBlendShapeVisualizerData*)data;
	if (!pLocatorData)
	{
		return;
	}

	MMatrix spaceMatrix    = pLocatorData->fSpaceMatrix;
	MMatrix spaceInvMatrix = spaceMatrix.inverse();

	short poleAxis      = pLocatorData->fPoleAxis;
	short seamAxis      = pLocatorData->fSeamAxis;

	drawManager.beginDrawable();

	MColor lineColor, vertexColor, poleAxisColor, seamAxisColor;
	lineColor		= MColor(0.7294f, .239216f, 0.2980f, 1.0f);
	vertexColor		= MColor(0.5843f, 0.78824f, .17255f, 1.0f);
	poleAxisColor   = MColor(1.0f, 0.0f, 0.f, 1.0f);
	seamAxisColor   = MColor(0.0f, 1.0f, 0.0f, 1.0f);

	MMatrix identity;
	identity.setToIdentity();

	double radius   = 1.0;
	int numRings    = 20;
	int numSections = 20;

	MPoint sphericalPoint, xyzPoint;
	MPoint startPoint, endPoint, firstPoint;
	MPointArray points;

	drawManager.setDepthPriority(5);

	drawManager.setColor(lineColor);

	bboxPoints.clear();
	bboxPoints.setLength(numRings*numSections);

	for(int ring=0; ring<=numRings; ring++) {
		double azimuth = (double)ring / numRings * M_PI * 2;

		for(int section=0; section<=numSections; section++) {
			double zenith = (double)section / (numSections) * M_PI;

			sphericalPoint.x = radius;
			sphericalPoint.y = zenith;
			sphericalPoint.z = azimuth;
			
			if (section==0) {
				sphericalToCartesian(sphericalPoint, poleAxis, seamAxis, startPoint);
				startPoint = startPoint * spaceMatrix;
				firstPoint = startPoint;
				bboxPoints.append(firstPoint);
				continue;
			} else {
				sphericalToCartesian(sphericalPoint, poleAxis, seamAxis, endPoint);
				endPoint = endPoint * spaceMatrix;
				drawManager.line(startPoint, endPoint);
				bboxPoints.append(endPoint);
				startPoint = endPoint;
			}
		}
	}

	for(int ring=0; ring<=numRings; ring++) {
		double azimuth = (double)ring / numRings * M_PI * 2;

		for(int section=0; section<=numSections; section++) {
			double zenith = (double)section / (numSections) * M_PI;

			sphericalPoint.x = radius;
			sphericalPoint.y = azimuth;
			sphericalPoint.z = zenith;
			
			if (section==0) {
				sphericalToCartesian(sphericalPoint, poleAxis, seamAxis, startPoint);
				startPoint = startPoint * spaceMatrix;
				firstPoint = startPoint;
				continue;
			} else {
				sphericalToCartesian(sphericalPoint, poleAxis, seamAxis, endPoint);
				endPoint = endPoint * spaceMatrix;
				drawManager.line(startPoint, endPoint);
				startPoint = endPoint;
			}
		}
	}

	drawManager.setLineWidth(3.0);
	drawManager.setLineStyle(MHWRender::MUIDrawManager::kDashed);
	
	startPoint = MPoint(0, 0, 0) * spaceMatrix;


	MVector endVector(0, 0, 0);
	setAxis(endVector, poleAxis, radius);
	endPoint = MPoint(endVector) * spaceMatrix;

	drawManager.setColor(poleAxisColor);
	drawManager.line(startPoint, endPoint);

	endVector = MVector(0, 0, 0);
	setAxis(endVector, seamAxis, radius);
	endPoint = MPoint(endVector) * spaceMatrix;

	drawManager.setColor(seamAxisColor);
	drawManager.line(startPoint, endPoint);
	drawManager.endDrawable();
}