Beispiel #1
0
World::World()
  : mRenderType(RTYPENONE)
  , mRenderState(RSTATENONE)
{
    // in batch mode we do not need any renderView callbacks, and timer callbacks do not work anyway in batch
    if (MGlobal::mayaState() != MGlobal::kBatch)
        timerCallbackId = MTimerMessage::addTimerCallback(0.1f, renderQueueWorkerCallback);

    std::string oslShaderPath = (getRendererHome() + "shaders").asChar();

    MStringArray oslDirs;
    MGlobal::executePythonCommand("import appleseed_maya.osltools as osl; osl.getOSODirs();", oslDirs, false, false);

    for (uint i = 0; i < oslDirs.length(); i++)
        shaderSearchPath.append(oslDirs[i].asChar());

    mSwatchRenderer.reset(new AppleseedSwatchRenderer());
}
Beispiel #2
0
void ShaderDefinitions::readShaderDefinitions()
{

	ShadingNode sn;
	std::vector<ShadingNode> snodes;
	snodes.push_back(sn);
	this->shadingNodes.push_back(sn);

	logger.feature(MString("home dir: ") + getRendererHome());
	logger.feature(MString("shader defs file: ") + getRendererHome() + "ressources/shaderDefinitions.txt");
	
	std::string shaderDefFile = (getRendererHome() + "ressources/shaderDefinitions.txt").asChar();

	std::ifstream shaderFile(shaderDefFile.c_str());
	if( !shaderFile.good())
	{
		logger.error(MString("Unable to open shaderInfoFile ") + MString(shaderDefFile.c_str()));
		shaderFile.close();
		return;
	}
	std::string line;

	ShadingNode node;

	do{
		std::getline(shaderFile, line);
		//logger.debug(line.c_str());
		if(validString(line))
		{
			std::vector<std::string> stringArray;
			pystring::split(line, stringArray, ":");

			if(pystring::startswith(line, "shader_end"))
			{
				// these nodes are automatically valid because they are supported
				node.nodeState = ShadingNode::VALID;

				this->shadingNodes.push_back(node);
				// clean up old node
				node = ShadingNode();
			}

			if(pystring::startswith(line, "shader_start"))
			{
				node.typeName = stringArray[1].c_str();
			}
			//inatt:blender:float
			if(pystring::startswith(line, "inatt"))
			{
				if( stringArray.size() > 2 )
				{
					ShaderAttribute att;
					att.name = stringArray[1];
					att.type = stringArray[2];
					node.inputAttributes.push_back(att);
				}
			}
			if(pystring::startswith(line, "outatt"))
			{
				if( stringArray.size() > 2 )
				{
					ShaderAttribute att;
					att.name = stringArray[1];
					att.type = stringArray[2];
					node.outputAttributes.push_back(att);
				}
			}
		}

	}while(!shaderFile.eof());

	//logger.debug("Reading of shader def file done.");
	shaderFile.close();
	readDone = true;
}
Beispiel #3
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 #4
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);
}