Beispiel #1
0
MStatus MayaToThea::doIt( const MArgList& args)
{
	MStatus stat = MStatus::kSuccess;
	MGlobal::displayInfo("Executing mayaToThea...");
	logger.setLogLevel(Logging::Debug);
	
	MArgDatabase argData(syntax(), args);
	
	int width = -1;
	int height = -1;

	MayaScene *mayaScene = MayaTo::MayaSceneFactory().getMayaScene();

	if( !mayaScene->good )
	{
		logger.error("Problems have occurred during creation of mayaScene(). Sorry cannot proceed.\n\n");
		MayaTo::MayaSceneFactory().deleteMaysScene();
		return MS::kFailure;
	}

	if ( argData.isFlagSet("-width", &stat))
	{
		argData.getFlagArgument("-width", 0, width);
		logger.debug(MString("width: ") + width);
		if( width > 0 )
			mayaScene->renderGlobals->imgWidth = width;
	}

	if ( argData.isFlagSet("-height", &stat))
	{
		argData.getFlagArgument("-height", 0, height);
		logger.debug(MString("height: ") + height);
		if( height > 0 )
			mayaScene->renderGlobals->imgHeight = height;
	}

	if ( argData.isFlagSet("-stopIpr", &stat))
	{
		logger.debug(MString("-stopIpr"));
		EventQueue::Event e;
		e.type = EventQueue::Event::IPRSTOP;
		theRenderEventQueue()->push(e);
		return MS::kSuccess;
	}

	if ( argData.isFlagSet("-pauseIpr", &stat))
	{
		logger.debug(MString("-pauseIpr"));
		logger.debug(MString("-stopIpr"));
		EventQueue::Event e;
		e.type = EventQueue::Event::IPRPAUSE;
		theRenderEventQueue()->push(e);
		return MS::kSuccess;
	}

	if ( argData.isFlagSet("-startIpr", &stat))
	{
		logger.debug(MString("-startIpr"));
		mayaScene->setRenderType(MayaScene::IPR);
	}
	
	if ( argData.isFlagSet("-camera", &stat))
	{
	    MDagPath camera;
        MSelectionList selectionList;
		argData.getFlagArgument("-camera", 0, selectionList);
        stat = selectionList.getDagPath(0, camera);
		camera.extendToShape();
		logger.debug(MString("camera: ") + camera.fullPathName());
		mayaScene->setCurrentCamera(camera);
	}			

	EventQueue::Event e;
	e.type = EventQueue::Event::INITRENDER;
	theRenderEventQueue()->push(e);
	
	RenderQueueWorker::startRenderQueueWorker();
	
	return MStatus::kSuccess;
}
Beispiel #2
0
MStatus MayaToCorona::doIt( const MArgList& args)
{
    MStatus stat = MStatus::kSuccess;
    std::unique_ptr<MayaTo::CmdArgs> cmdArgs(new MayaTo::CmdArgs);

    MArgDatabase argData(syntax(), args);

    if (argData.isFlagSet("-version", &stat))
    {
        MStringArray res;
        for (auto v : getFullVersionString())
            res.append(v.c_str());
        setResult(res);

        return MS::kSuccess;
    }

    MayaTo::MayaToWorld::WorldRenderState rstate = MayaTo::getWorldPtr()->renderState;
    if (argData.isFlagSet("-state", &stat))
    {
        if (rstate == MayaTo::MayaToWorld::RSTATETRANSLATING)
            setResult("rstatetranslating");
        if (rstate == MayaTo::MayaToWorld::RSTATERENDERING)
            setResult("rstaterendering");
        if (rstate == MayaTo::MayaToWorld::RSTATEDONE)
            setResult("rstatedone");
        if (rstate == MayaTo::MayaToWorld::RSTATENONE)
            setResult("rstatenone");
        if (rstate == MayaTo::MayaToWorld::RSTATESTOPPED)
            setResult("rstatestopped");
        return MS::kSuccess;
    }

    MGlobal::displayInfo("Executing mayaToCorona...");
    setLogLevel();

    if (argData.isFlagSet("-canDoIPR", &stat))
    {
        if(MayaTo::getWorldPtr()->canDoIPR())
            setResult("yes");
        else
            setResult("no");
        return MS::kSuccess;
    }

    if ( argData.isFlagSet("-stopIpr", &stat))
    {
        Logging::debug(MString("-stopIpr"));
        EventQueue::Event e;
        e.type = EventQueue::Event::IPRSTOP;
        theRenderEventQueue()->push(e);
        return MS::kSuccess;
    }

    if ( argData.isFlagSet("-pauseIpr", &stat))
    {
        Logging::debug(MString("-pauseIpr"));
        Logging::debug(MString("-stopIpr"));
        EventQueue::Event e;
        e.type = EventQueue::Event::IPRPAUSE;
        theRenderEventQueue()->push(e);
        return MS::kSuccess;
    }

    if (argData.isFlagSet("-usrDataString", &stat))
    {
        Logging::debug(MString("-usrDataString"));
        argData.getFlagArgument("-usrDataString", 0, cmdArgs->userDataString);
    }

    if (argData.isFlagSet("-usrDataInt", &stat))
    {
        Logging::debug(MString("-usrDataInt"));
        argData.getFlagArgument("-usrDataInt", 0, cmdArgs->userDataInt);
    }

    if (argData.isFlagSet("-usrDataFloat", &stat))
    {
        Logging::debug(MString("-usrDataFloat"));
        argData.getFlagArgument("-usrDataFloat", 0, cmdArgs->userDataFloat);
    }

    if (argData.isFlagSet("-usrEvent", &stat))
    {
        Logging::debug(MString("-usrEvent"));
        argData.getFlagArgument("-usrEvent", 0, cmdArgs->userEvent);

        EventQueue::Event e;
        e.cmdArgsData = std::move(cmdArgs);
        e.type = EventQueue::Event::USER;
        theRenderEventQueue()->push(e);
        return MS::kSuccess;
    }

    // I have to request useRenderRegion here because as soon the command is finished, what happens immediatly after the command is
    // put into the queue, the value is set back to false.
    MObject drg = objectFromName("defaultRenderGlobals");
    MFnDependencyNode drgfn(drg);
    cmdArgs->useRenderRegion = drgfn.findPlug("useRenderRegion").asBool();

    cmdArgs->renderType = MayaTo::MayaToWorld::WorldRenderType::UIRENDER;
    if (MGlobal::mayaState() == MGlobal::kBatch)
        cmdArgs->renderType = MayaTo::MayaToWorld::WorldRenderType::BATCHRENDER;

    if ( argData.isFlagSet("-startIpr", &stat))
    {
        Logging::debug(MString("-startIpr"));
        cmdArgs->renderType = MayaTo::MayaToWorld::WorldRenderType::IPRRENDER;
    }

    if (argData.isFlagSet("-width", &stat))
    {
        argData.getFlagArgument("-width", 0, cmdArgs->width);
        Logging::debug(MString("width: ") + cmdArgs->width);
    }

    if (argData.isFlagSet("-height", &stat))
    {
        argData.getFlagArgument("-height", 0, cmdArgs->height);
        Logging::debug(MString("height: ") + cmdArgs->height);
    }

    if ( argData.isFlagSet("-camera", &stat))
    {
        MDagPath camera;
        MSelectionList selectionList;
        argData.getFlagArgument("-camera", 0, selectionList);
        stat = selectionList.getDagPath(0, camera);
        camera.extendToShape();
        Logging::debug(MString("camera: ") + camera.fullPathName());
        cmdArgs->cameraDagPath = camera;
    }

    EventQueue::Event e;
    e.cmdArgsData = std::move(cmdArgs);
    e.type = EventQueue::Event::INITRENDER;
    theRenderEventQueue()->push(e);

    //
    if (MGlobal::mayaState() == MGlobal::kBatch)
    {
        RenderQueueWorker::startRenderQueueWorker();
    }
    return MStatus::kSuccess;
}
Beispiel #3
0
MStatus MayaToFuji::doIt( const MArgList& args)
{
    MStatus stat = MStatus::kSuccess;
    MGlobal::displayInfo("Executing mayatoFuji...");
    logger.setLogLevel(Logging::Debug);

    MArgDatabase argData(syntax(), args);

    int width = -1;
    int height = -1;

    if ( argData.isFlagSet("-width", &stat))
    {
        argData.getFlagArgument("-width", 0, width);
        logger.debug(MString("width: ") + width);
    }

    if ( argData.isFlagSet("-height", &stat))
    {
        argData.getFlagArgument("-height", 0, height);
        logger.debug(MString("height: ") + height);
    }

    if ( argData.isFlagSet("-stopIpr", &stat))
    {
        logger.debug(MString("-stopIpr"));
        EventQueue::Event e;
        e.type = EventQueue::Event::IPRSTOP;
        theRenderEventQueue()->push(e);
        return MS::kSuccess;
    }

    if ( argData.isFlagSet("-pauseIpr", &stat))
    {
        logger.debug(MString("-pauseIpr"));
        return MS::kSuccess;
    }

    MayaScene::RenderType rtype = MayaScene::NORMAL;
    if ( argData.isFlagSet("-startIpr", &stat))
    {
        logger.debug(MString("-startIpr"));
        rtype = MayaScene::IPR;
    } else {
        logger.debug(MString("normal render"));
    }

    // if we are here, we want a normal or an startIPR rendering, so initialize the scene
    mtfu_MayaScene *mayaScene = new mtfu_MayaScene(rtype);

    if( !mayaScene->good )
    {
        logger.error("Problems have occurred during creation of mayaScene(). Sorry cannot proceed.\n\n");
        return MS::kFailure;
    }

    if( !mayaScene->parseScene(MayaScene::HIERARCHYPARSE) )
    {
        logger.error("Problems have occurred during parsing of the scene. Sorry cannot proceed.\n\n");
        return MS::kFailure;
    }

    if ( argData.isFlagSet("-camera", &stat))
    {
        MDagPath camera;
        MSelectionList selectionList;
        argData.getFlagArgument("-camera", 0, selectionList);
        stat = selectionList.getDagPath(0, camera);
        camera.extendToShape();
        logger.debug(MString("camera: ") + camera.fullPathName());
        mayaScene->setCurrentCamera(camera);
    }

    if( height > 0)
        mayaScene->renderGlobals->imgHeight = height;

    if( width > 0)
        mayaScene->renderGlobals->imgWidth = width;

    if(!mayaScene->renderScene())
    {
        logger.error("Problems have occurred during rendering of the scene. Sorry cannot proceed.\n\n");
        return MS::kFailure;
    }

    MGlobal::displayInfo("mayatoFuji rendering done.\n");
    return MStatus::kSuccess;
}
Beispiel #4
0
void TheaRenderer::render()
{
	clearMaterialLists();

	MString fileName = this->mtth_scene->getFileName();
	this->mtth_renderGlobals->exportSceneFile = true; // trigger use of XML commands
	if( this->mtth_renderGlobals->exportSceneFile )
		this->sceneXML = TheaSDK::XML::Scene(fileName.asChar());
	else
		this->scene = TheaSDK::Scene::New(fileName.asChar());

	MString moduleDir = getRendererHome();
	MString gpuDriver = moduleDir + "bin/Plugins/Presto/presto-x64.dll";
	MString cpuDriver = moduleDir + "bin/Plugins/Presto/presto-x86-x64.dll";

	bool gpuSuccess = TheaSDK::Kernel::Root().initPrestoGPUDriver(gpuDriver.asChar());
	bool cpuSuccess = TheaSDK::Kernel::Root().initPrestoCPUDriver(cpuDriver.asChar());
	if( !gpuSuccess )
		Logging::error("Unable to load presto gpu driver.");
	if( !cpuSuccess )
		Logging::error("Unable to load presto cpu driver.");
	
	if(!isGood )
	{
		EventQueue::Event e;
		e.data = NULL;
		e.type = EventQueue::Event::FRAMEDONE;
		theRenderEventQueue()->push(e);
		return;
	}

	this->defineSettings();
	this->defineCamera();
	this->defineGeometry();
	this->defineLights();
	this->defineEnvironment();
	
	if( this->mtth_renderGlobals->exportSceneFile )
	{
		std::string currentFile = MFileIO::currentFile().asChar();
		std::vector<std::string> parts;
		pystring::split(currentFile, parts, "/");
		currentFile = pystring::replace(parts.back(), ".ma", "");
		currentFile = pystring::replace(currentFile, ".mb", "");
		MString scenePath = MString("C:/daten/3dprojects/mayaToThea/data/Thea/") + currentFile.c_str() + ".xml";
		//MString scenePath = this->mtth_renderGlobals->basePath + "/Thea/" + currentFile.c_str() + ".xml";
		TheaSDK::XML::Importer::Write(this->sceneXML);
		Logging::debug(MString("Exporting scene to: ") + scenePath);
		TheaSDK::SaveScene(scenePath.asChar());
	}


	volatile bool isrendering=true;

	// don't start asynchronus because we are in a seperate task anyway
	bool ok = TheaSDK::StartRendering(renderEndCallback, (void *)this, false, false);

	this->mtth_renderGlobals->getImageName();
	MString filename = this->mtth_renderGlobals->imageOutputFile.asChar();
	std::string imgFormatExt = this->mtth_renderGlobals->imageOutputFile.toLowerCase().asChar();
	std::vector<std::string> fileParts;
	pystring::split(imgFormatExt, fileParts, ".");
	std::string ext = fileParts.back();
	
	Logging::debug(MString("Saving image as ") +  filename);
	TheaSDK::SaveImage(filename.asChar());

	EventQueue::Event e;
	e.data = NULL;
	e.type = EventQueue::Event::FRAMEDONE;
	theRenderEventQueue()->push(e);
}
Beispiel #5
0
void TheaRenderer::render()
{
	clearMaterialLists();

	MFnDependencyNode depFn(getRenderGlobalsNode());
	std::shared_ptr<MayaScene> scene = MayaTo::getWorldPtr()->worldScenePtr;
	std::shared_ptr<RenderGlobals> renderGlobals = MayaTo::getWorldPtr()->worldRenderGlobalsPtr;
	std::shared_ptr<TheaRenderer> renderer = std::static_pointer_cast<TheaRenderer>(MayaTo::getWorldPtr()->worldRendererPtr);

	MString fileName = scene->getFileName();
	renderGlobals->exportSceneFile = true; // trigger use of XML commands
	if (renderGlobals->exportSceneFile)
		this->sceneXML = TheaSDK::XML::Scene(fileName.asChar());
	else
		this->scene = TheaSDK::Scene::New(fileName.asChar());

	MString moduleDir = getRendererHome();
	MString gpuDriver = moduleDir + "bin/Plugins/Presto/presto-x64.cuda.dll";
	MString cpuDriver = moduleDir + "bin/Plugins/Presto/presto-x64.cpu.dll";

	bool gpuSuccess = TheaSDK::Kernel::Root().initPrestoCUDADriver(gpuDriver.asChar());
	bool cpuSuccess = TheaSDK::Kernel::Root().initPrestoCPUDriver(cpuDriver.asChar());
	if( !gpuSuccess )
		Logging::error("Unable to load presto gpu driver.");
	if( !cpuSuccess )
		Logging::error("Unable to load presto cpu driver.");
	
	if(!isGood )
	{
		EventQueue::Event e;
		e.type = EventQueue::Event::FRAMEDONE;
		theRenderEventQueue()->push(e);
		return;
	}

	this->defineSettings();
	this->defineCamera();
	this->defineGeometry();
	this->defineLights();
	this->defineEnvironment();
	
	if (renderGlobals->exportSceneFile)
	{
		std::string currentFile = MFileIO::currentFile().asChar();
		std::vector<std::string> parts;
		pystring::split(currentFile, parts, "/");
		currentFile = pystring::replace(parts.back(), ".ma", "");
		currentFile = pystring::replace(currentFile, ".mb", "");
		MString scenePath = MString("C:/daten/3dprojects/mayaToThea/data/Thea/") + currentFile.c_str() + ".xml";
		//MString scenePath = this->mtth_renderGlobals->basePath + "/Thea/" + currentFile.c_str() + ".xml";
		TheaSDK::XML::Importer::Write(this->sceneXML);
		Logging::debug(MString("Exporting scene to: ") + scenePath);
		TheaSDK::SaveScene(scenePath.asChar());
	}


	volatile bool isrendering=true;

	MayaTo::getWorldPtr()->setRenderState(MayaTo::MayaToWorld::WorldRenderState::RSTATERENDERING);
	size_t framebufferCallbackId = RenderQueueWorker::registerCallback(&framebufferCallback);

	// don't start asynchronus because we are in a seperate task anyway
	bool ok = TheaSDK::StartRendering(renderEndCallback, (void *)this, false, false);
	framebufferCallback();

	RenderQueueWorker::unregisterCallback(framebufferCallbackId);

	renderGlobals->getImageName();
	MString filename = renderGlobals->imageOutputFile.asChar();
	std::string imgFormatExt = renderGlobals->imageOutputFile.toLowerCase().asChar();
	std::vector<std::string> fileParts;
	pystring::split(imgFormatExt, fileParts, ".");
	std::string ext = fileParts.back();
	
	Logging::debug(MString("Saving image as ") +  filename);
	TheaSDK::SaveImage(filename.asChar());

	EventQueue::Event e;
	e.type = EventQueue::Event::FRAMEDONE;
	theRenderEventQueue()->push(e);
}