コード例 #1
0
	void Helper::RiBeginRef(const std::string& ribFile)
	{
		CM_TRACE_FUNC("Helper::RiBeginRef("<<ribFile<<")");

		m_ribFile = ribFile;

		//if m_ribFileFullPath is "", write the data into the current rib file.
		if( m_ribFile != "" ){
			//log
			RiArchiveRecord( RI_COMMENT, "output: %s", m_ribFile.c_str() );
			//write the data into another rib file.
			m_contex = RiGetContext();//push context
			liquidMessage("output rib: "+ std::string(m_ribFile.c_str()) , messageInfo);
			RiBegin_liq( const_cast< RtToken >( m_ribFile.c_str() ) );
		}
	}
コード例 #2
0
	static void _write(liqRibMeshData* pData, const structJob &currentJob)
	{
		CM_TRACE_FUNC("rm_writeMeshData.cpp::_write("<<pData->getFullPathName().asChar()<<","<<currentJob.name.asChar()<<")");

		if( pData->isEmpty() )
		{
			liquidMessage( "Could not export degenerate mesh", messageError );
			return;
		}
		//
		//RiArchiveRecord( RI_COMMENT, "Sometimes the polygon cant be rendered correctly, so I try to reverse the normal. //- yaoyansi" );
		//RiReverseOrientation();

		if(pData->isAreaLight())
		{
			RtLightHandle handle = INVALID_LIGHT_INDEX;

			{ // What happens if we're inside a motion block????? This whole approach of Liquid is flawed...
				LIQDEBUGPRINTF( "-> mesh is area light\n" );
				//	RiAttributeBegin();
				RtString ribname = const_cast< char* >( pData->getFullPathName().asChar() );
				RiAttribute( "identifier", "name", &ribname, RI_NULL );
				RtMatrix tmp;
				memcpy( tmp, pData->getTransformationMatrixPtr(), sizeof( RtMatrix ) );
				RiTransform( tmp );
				float areaIntensity = pData->getAreaIntensity();
				handle = RiAreaLightSource( "arealight", "intensity", &areaIntensity, RI_NULL );
			}
			//
			//mesh data begin
			//
			// Each loop has one polygon, so we just want an array of 1's of
			// the correct size. Stack version.
			//vector< RtInt > nloops( numFaces, 1 );
			// Alternatively (heap version):
			boost::scoped_array< RtInt > nloops( new RtInt[ pData->getNumFaces() ] );
			std::fill( nloops.get(), nloops.get() + pData->getNumFaces(), ( RtInt )1 );

			unsigned numTokens( pData->tokenPointerArray.size() );
			boost::scoped_array< RtToken > tokenArray( new RtToken[ numTokens ] );
			boost::scoped_array< RtPointer > pointerArray( new RtPointer[ numTokens ] );
			assignTokenArraysV( pData->tokenPointerArray, tokenArray.get(), pointerArray.get() );

			RiPointsGeneralPolygonsV( pData->getNumFaces(),
				&nloops[ 0 ],
				pData->getNverts().get(),
				pData->getVerts().get(),
				numTokens,
				tokenArray.get(),
				pointerArray.get() );
			//mesh data end

			{
				// RiAttributeEnd();
				RiIlluminate( handle, 1 );
			}
		}else{
			//mesh data begin
			//
			// Each loop has one polygon, so we just want an array of 1's of
			// the correct size. Stack version.
			//vector< RtInt > nloops( numFaces, 1 );
			// Alternatively (heap version):
			boost::scoped_array< RtInt > nloops( new RtInt[ pData->getNumFaces() ] );
			std::fill( nloops.get(), nloops.get() + pData->getNumFaces(), ( RtInt )1 );

			unsigned numTokens( pData->tokenPointerArray.size() );
			boost::scoped_array< RtToken > tokenArray( new RtToken[ numTokens ] );
			boost::scoped_array< RtPointer > pointerArray( new RtPointer[ numTokens ] );
			assignTokenArraysV( pData->tokenPointerArray, tokenArray.get(), pointerArray.get() );

			RiPointsGeneralPolygonsV( pData->getNumFaces(),
				&nloops[ 0 ],
				pData->getNverts().get(),
				pData->getVerts().get(),
				numTokens,
				tokenArray.get(),
				pointerArray.get() );
			//mesh data end//	
		}
	}
コード例 #3
0
	void Renderer::shader_UserDefinedShader(const liqShader* liqshader)
	{
		CM_TRACE_FUNC("shader_UserDefinedShader("<<liqshader->getName()<<")");

		// write co-shaders before
		unsigned int i; 
		for(i=0; i<liqshader->m_coShaderArray.size(); i++)
		{
			liqShader &coShader = liqShaderFactory::instance().getShader(liqshader->m_coShaderArray[i]);
			if( coShader.hasErrors )
			{
				char errorMsg[512];
				sprintf(errorMsg, "[liqShader::write] While initializing coShader for '%s', node couldn't be exported", coShader.getName().c_str());
				liquidMessage( errorMsg, messageError );
			}
			else
			{
				assert(0&&"er has not coShader.");
				//coShader.writeAsCoShader(/*shortShaderNames, indentLevel*/);
			}
		}

		// write shader
		char* shaderFileName = const_cast<char*>(liqshader->getShaderFileName().c_str());
		if( liqshader->shaderSpace != "" )
		{
			this->shader_transformBegin((const liqString)liqshader->shaderSpace.asChar());
		}
		// output shader
		// its one less as the tokenPointerArray has a preset size of 1 not 0

		if( liqshader->shader_type_ex == "light" )
		{
			//outputIndentation(indentLevel);
			RtLightHandle ret = this->shader_light( *liqshader,  liqshader->tokenPointerArray );
#ifdef RIBLIB_AQSIS
			(const_cast<liqShader*>(liqshader))->shaderHandler.set( reinterpret_cast<ptrdiff_t>(static_cast<RtLightHandle>(ret)) );
#else
			liqshader->shaderHandler.set( ret );
#endif
		}else if(liqshader->shader_type_ex == "surface"){
			//outputIndentation(indentLevel);
			this->shader_surface( *liqshader,  liqshader->tokenPointerArray );
		}else if(liqshader->shader_type_ex == "displace"){
			//outputIndentation(indentLevel);
			this->shader_displacement( *liqshader,  liqshader->tokenPointerArray );
		}else if(liqshader->shader_type_ex == "volume"){
			//outputIndentation(indentLevel);
			this->shader_volume( *liqshader,   liqshader->tokenPointerArray );
		}else if(liqshader->shader_type_ex == "shadow"){
			//outputIndentation(indentLevel);
			this->shader_shadow( *liqshader,   liqshader->tokenPointerArray );
		}else if(liqshader->shader_type_ex == "environment"){
			//outputIndentation(indentLevel);
			this->shader_environment( *liqshader,   liqshader->tokenPointerArray );
		}else if(liqshader->shader_type_ex == "lens"){
			//outputIndentation(indentLevel);
			this->shader_lens( *liqshader,   liqshader->tokenPointerArray );
		}
		else{
			char errorMsg[512];
			sprintf(errorMsg, "[liqShader::write] Unknown shader type for %s shader_type=%s", liqshader->getName().c_str(), liqshader->shader_type_ex.asChar());
			liquidMessage( errorMsg, messageError );
		}

		if( liqshader->shaderSpace != "" )
		{
			this->shader_transformEnd((const liqString)liqshader->shaderSpace.asChar());
		}
	}
コード例 #4
0
	void Renderer::shader_UserDefinedShader(const liqShader* liqshader, std::vector<MString> &yetExportedShaders/*, SHADER_TYPE forceAs*/)
	{
		CM_TRACE_FUNC("Renderer::shader_UserDefinedShader("<<liqshader->getName()<<",...)");

		SHADER_TYPE forceAs = liqshader->forceAs;

		// check if shader was yet exported (we don't want to export co-shaders more than one time)
		for(unsigned int i=0; i<yetExportedShaders.size(); i++)
		{
			if( yetExportedShaders[i] == liqshader->shaderHandler )
			{
				return; // won't export another time
			}
		}

		// force type : permit to write a co-shader as a Surface/Displace/...
		// use forceAs directly, instead of shaderType. //- yaoyansi
		//SHADER_TYPE shaderType = liqshader->shader_type;
		//if( forceAs != SHADER_TYPE_UNKNOWN )
		//{
		//	shaderType = forceAs;
		//}

		// write co-shaders before
		for(unsigned int i=0; i<liqshader->m_coShaderArray.size(); i++)
		{
			liqShader &coShader = liqShaderFactory::instance().getShader(liqshader->m_coShaderArray[i]);
			if( coShader.hasErrors )
			{
				char errorMsg[512];
				sprintf(errorMsg, "[liqShader::write] While initializing coShader for '%s', node couldn't be exported", coShader.getName().c_str());
				liquidMessage( errorMsg, messageError );
			}
			else
			{
				//this->writeAsCoShader(&coShader/*shortShaderNames, indentLevel*/);
				coShader.forceAs = SHADER_TYPE_SHADER;
				this->shader_UserDefinedShader(&coShader, yetExportedShaders /*, SHADER_TYPE_SHADER*/);
			}
		}

		// write rib attributes (but not for coshaders)
		RiArchiveRecord( RI_COMMENT, "writeRibAttributes() is omitted." );
		//writeRibAttributes(liqshader/*, shaderType*/);

		// write shader
		char* shaderFileName = const_cast<char*>(liqshader->getShaderFileName().c_str());
		if( liqshader->shaderSpace != "" )
		{
			this->shader_transformBegin((const liqString)liqshader->shaderSpace.asChar());
		}
		// output shader
		// its one less as the tokenPointerArray has a preset size of 1 not 0
		if(forceAs == SHADER_TYPE_UNKNOWN)
		{
		if( liqshader->shader_type_ex == "light" )
		{
				//outputIndentation(indentLevel);
				RtLightHandle ret = this->shader_light( *liqshader,  liqshader->tokenPointerArray );
#ifdef RIBLIB_AQSIS
				(const_cast<liqShader*>(liqshader))->shaderHandler.set( reinterpret_cast<ptrdiff_t>(static_cast<RtLightHandle>(ret)) );
#else
				liqshader->shaderHandler.set( ret );
#endif
		}else if(liqshader->shader_type_ex == "surface"){
				//outputIndentation(indentLevel);
				this->shader_surface( *liqshader,  liqshader->tokenPointerArray );
		}else if(liqshader->shader_type_ex == "displacement"){
				//outputIndentation(indentLevel);
				this->shader_displacement( *liqshader,  liqshader->tokenPointerArray );
		}else if(liqshader->shader_type_ex == "volume"){
				//outputIndentation(indentLevel);
				this->shader_volume( *liqshader,   liqshader->tokenPointerArray );
		}else if(liqshader->shader_type_ex == "shader"){
				this->shader_shader( *liqshader,   liqshader->tokenPointerArray );
		}else{
			char errorMsg[512];
			sprintf(errorMsg, "[liqShader::write] Unknown shader type for %s shader_type=%s", liqshader->getName().c_str(), liqshader->shader_type_ex.asChar());
			liquidMessage( errorMsg, messageError );
		}
		}else{//forceAs != SHADER_TYPE_UNKNOWN
			switch( forceAs )// use forceAs directly, instead of shaderType. //- yaoyansi
			{
			case SHADER_TYPE_SURFACE :
				this->shader_surface( *liqshader,  liqshader->tokenPointerArray );
				break;
			case SHADER_TYPE_DISPLACEMENT :
				this->shader_displacement( *liqshader,  liqshader->tokenPointerArray );
				break;
			case SHADER_TYPE_VOLUME :
				this->shader_volume( *liqshader,   liqshader->tokenPointerArray );
				break;
			case SHADER_TYPE_SHADER :
				this->shader_shader( *liqshader,   liqshader->tokenPointerArray );
				break;
			case SHADER_TYPE_LIGHT :
			{
				RtLightHandle ret = this->shader_light( *liqshader,  liqshader->tokenPointerArray );
#ifdef RIBLIB_AQSIS
				(const_cast<liqShader*>(liqshader))->shaderHandler.set( reinterpret_cast<ptrdiff_t>(static_cast<RtLightHandle>(ret)) );
#else
				liqshader->shaderHandler.set( ret );
#endif
				break;
			}
			default :
				char errorMsg[512];
				sprintf(errorMsg, "[liqShader::write] Unknown shader type for %s shader_type=%d", liqshader->getName().c_str(), forceAs);
				liquidMessage( errorMsg, messageError );
				break;
			}
		}
		//
		if( liqshader->shaderSpace != "" )
		{
			this->shader_transformEnd((const liqString)liqshader->shaderSpace.asChar());
		}

		yetExportedShaders.push_back(liqshader->shaderHandler);
	}