Exemplo n.º 1
0
MStatus PluginTestUserOperation::execute(const MHWRender::MDrawContext & drawContext)
{
	//return MStatus::kSuccess;
	M3dView view;
	if(M3dView::getM3dViewFromModelPanel(panelName, view) == MStatus::kSuccess)
	{
		// Get the current viewport and scale it relative to that
		//
		int targetW, targetH;
		drawContext.getRenderTargetSize(targetW, targetH);

		// Some user drawing of scene bounding boxes
		//
		MDagPath cameraPath;
		MFnCamera fnCamera;
		view.getCamera(cameraPath);
		MMatrix m3dViewProjection, m3dViewModelView;
		view.projectionMatrix(m3dViewProjection);
		view.modelViewMatrix(m3dViewModelView);
		MFloatMatrix m3dFloatViewProjection(m3dViewProjection.matrix);
		MFloatMatrix m3dFloatViewModelView(m3dViewModelView.matrix);
		MFloatMatrix viewProjection = m3dFloatViewModelView * m3dFloatViewProjection;
		SurfaceDrawTraversal traversal;
		traversal.enableFiltering(true);
		traversal.setFrustum(cameraPath, targetW, targetH);
		traversal.traverse();
		unsigned int numItems = traversal.numberOfItems();
		MFnMesh fnMesh;
		for (int i = 0; i < numItems; i++)
		{
			MDagPath path;
			traversal.itemPath(i, path);
			if (path.hasFn(MFn::kMesh))
			{
				fnMesh.setObject(path);
				MFloatMatrix modelWorld(path.inclusiveMatrix().matrix);
				MTransformationMatrix transformMatrix;
				MFloatMatrix modelViewProjection = modelWorld * viewProjection;
				modelViewProjection = modelViewProjection.transpose();
				MIntArray triangleCounts;
				MIntArray triangleVertices; // This is the index list for all the triangles in the mesh in one big list. Ie. first 3 are for tri 1 etc. Index into getPoints()
				fnMesh.getTriangles(triangleCounts, triangleVertices);
				//int indices[100];
				//triangleVertices.get(indices);
				MFloatPointArray vertexArray;
				//float points[1000][4];
				fnMesh.getPoints(vertexArray);
				//vertexArray.get(points);
				UserSceneRenderer::get()->render(triangleVertices, vertexArray, modelViewProjection);
			}
		}
	}
	return MStatus::kSuccess;
}
MStatus viewRenderUserOperation::execute( const MHWRender::MDrawContext & drawContext )
{
	// Sample code to debug pass information
	static const bool debugPassInformation = false;
	if (debugPassInformation)
	{
		const MHWRender::MPassContext & passCtx = drawContext.getPassContext();
		const MString & passId = passCtx.passIdentifier();
		const MStringArray & passSem = passCtx.passSemantics();
		printf("viewRenderUserOperation: drawing in pass[%s], semantic[", passId.asChar());
		for (unsigned int i=0; i<passSem.length(); i++)
			printf(" %s", passSem[i].asChar());
		printf("\n");
	}

	// Example code to find the active override.
	// This is not necessary if the operations just keep a reference
	// to the override, but this demonstrates how this
	// contextual information can be extracted.
	//
	MHWRender::MRenderer *theRenderer = MHWRender::MRenderer::theRenderer();
	const MHWRender::MRenderOverride *overridePtr = NULL;
	if (theRenderer)
	{
		const MString & overrideName = theRenderer->activeRenderOverride();
		overridePtr = theRenderer->findRenderOverride( overrideName );
	}

	// Some sample code to debug lighting information in the MDrawContext
	//
	if (fDebugLightingInfo)
	{
		viewRenderOverrideUtilities::printDrawContextLightInfo( drawContext );
	}

	// Some sample code to debug other MDrawContext information
	//
	if (fDebugDrawContext)
	{
		MStatus status;
		MMatrix matrix = drawContext.getMatrix(MHWRender::MFrameContext::kWorldMtx, &status);
		double dest[4][4];
		status = matrix.get(dest);
		printf("World matrix is:\n");
		printf("\t%f, %f, %f, %f\n", dest[0][0], dest[0][1], dest[0][2], dest[0][3]);
		printf("\t%f, %f, %f, %f\n", dest[1][0], dest[1][1], dest[1][2], dest[1][3]);
		printf("\t%f, %f, %f, %f\n", dest[2][0], dest[2][1], dest[2][2], dest[2][3]);
		printf("\t%f, %f, %f, %f\n", dest[3][0], dest[3][1], dest[3][2], dest[3][3]);

		MDoubleArray viewDirection = drawContext.getTuple(MHWRender::MFrameContext::kViewDirection, &status);
		printf("Viewdirection is: %f, %f, %f\n", viewDirection[0], viewDirection[1], viewDirection[2]);

		MBoundingBox box = drawContext.getSceneBox(&status);
		printf("Screen box is:\n");
		printf("\twidth=%f, height=%f, depth=%f\n", box.width(), box.height(), box.depth());
		float center[4];
		box.center().get(center);
		printf("\tcenter=(%f, %f, %f, %f)\n", center[0], center[1], center[2], center[3]);


		int originX, originY, width, height;
		status = drawContext.getViewportDimensions(originX, originY, width, height);
		printf("Viewport dimension: center(%d, %d), width=%d, heigh=%d\n", originX, originY, width, height);
	}

	//  Draw some addition things for scene draw
	//
	M3dView mView;
	if (mPanelName.length() &&
		(M3dView::getM3dViewFromModelPanel(mPanelName, mView) == MStatus::kSuccess))
	{
		// Get the current viewport and scale it relative to that
		//
		int targetW, targetH;
		drawContext.getRenderTargetSize( targetW, targetH );

		if (fDrawLabel)
		{
			MString testString("Drawing with override: ");
			testString += overridePtr->name();
			MPoint pos(0.0,0.0,0.0);
			glColor3f( 1.0f, 1.0f, 1.0f );
			mView.drawText( testString, pos);
		}

		// Some user drawing of scene bounding boxes
		//
		if (fDrawBoundingBoxes)
		{
			MDagPath cameraPath;
			mView.getCamera( cameraPath);
			MCustomSceneDraw userDraw;
			userDraw.draw( cameraPath, targetW, targetH );
		}
	}
	return MStatus::kSuccess;
}