Exemplo n.º 1
0
	bool Geometry::TextWriter::operator()( Geometry const & geometry, TextFile & file )
	{
		bool result{ true };

		if ( geometry.getMesh() )
		{
			Logger::logInfo( m_tabs + cuT( "Writing Geometry " ) + geometry.getName() );
			result = file.writeText( cuT( "\n" ) + m_tabs + cuT( "object \"" ) + geometry.getName() + cuT( "\"\n" ) ) > 0
					   && file.writeText( m_tabs + cuT( "{\n" ) ) > 0;
			castor::TextWriter< Geometry >::checkError( result, "Geometry name" );

			if ( result )
			{
				result = MovableObject::TextWriter{ m_tabs + cuT( "\t" ) }( geometry, file );
			}

			if ( result )
			{
				result = RenderedObject::TextWriter{ m_tabs + cuT( "\t" ) }( geometry, file );
			}

			if ( result )
			{
				result = file.writeText( m_tabs + cuT( "\tmesh \"" ) + geometry.getMesh()->getName() + cuT( "\"\n" ) ) > 0;
				castor::TextWriter< Geometry >::checkError( result, "Geometry mesh" );
			}

			if ( result )
			{
				result = file.writeText( m_tabs + cuT( "\tmaterials\n" ) ) > 0
						   && file.writeText( m_tabs + cuT( "\t{\n" ) ) > 0;
				castor::TextWriter< Geometry >::checkError( result, "Geometry materials" );

				if ( result )
				{
					uint16_t index{ 0u };

					for ( auto submesh : *geometry.getMesh() )
					{
						result &= file.writeText( m_tabs + cuT( "\t\tmaterial " ) + string::toString( index++ ) + cuT( " \"" ) + geometry.getMaterial( *submesh )->getName() + cuT( "\"\n" ) ) > 0;
						castor::TextWriter< Geometry >::checkError( result, "Geometry material" );
					}

					if ( result )
					{
						result = file.writeText( m_tabs + cuT( "\t}\n" ) ) > 0;
					}
				}
			}

			if ( result )
			{
				result = file.writeText( m_tabs + cuT( "}\n" ) ) > 0;
			}
		}

		return result;
	}
Exemplo n.º 2
0
	bool UniformBuffer::TextWriter::operator()( UniformBuffer const & object, TextFile & file )
	{
		bool result = file.writeText( m_tabs + cuT( "constants_buffer \"" ) + object.getName() + cuT( "\"\n" ) ) > 0
						&& file.writeText( m_tabs + cuT( "{\n" ) ) > 0;
		checkError( result, "Frame variable buffer" );
		auto tabs = m_tabs + cuT( "\t" );

		if ( result )
		{
			for ( auto & variable : object )
			{
				if ( result )
				{
					result = file.writeText( tabs + cuT( "variable \"" ) + variable->getName() + cuT( "\"\n" ) ) > 0
						&& file.writeText( tabs + cuT( "{\n" ) ) > 0;
					checkError( result, "Frame variable buffer variable name" );
				}

				if ( result )
				{
					result = file.writeText( tabs + cuT( "\tcount " ) + string::toString( variable->getOccCount() ) + cuT( "\n" ) ) > 0;
					checkError( result, "Frame variable buffer variable occurences" );
				}

				if ( result )
				{
					result = file.writeText( tabs + cuT( "\ttype " ) + variable->getFullTypeName() + cuT( "\n" ) ) > 0;
					checkError( result, "Frame variable buffer variable type name" );
				}

				if ( result )
				{
					result = file.writeText( tabs + cuT( "\tvalue " ) + variable->getStrValue() + cuT( "\n" ) ) > 0;
					checkError( result, "Frame variable buffer variable value" );
				}

				if ( result )
				{
					result = file.writeText( tabs + cuT( "}\n" ) ) > 0;
					checkError( result, "Frame variable buffer variable end" );
				}
			}
		}

		if ( result )
		{
			result = file.writeText( m_tabs + cuT( "}\n" ) ) > 0;
			checkError( result, "Frame variable buffer end" );
		}

		return result;
	}
Exemplo n.º 3
0
	bool OverlayCategory::TextWriter::operator()( OverlayCategory const & p_overlay, TextFile & p_file )
	{
		bool result = p_file.writeText( m_tabs + cuT( "\tposition " ) ) > 0
						&& Point2d::TextWriter{ String{} }( p_overlay.getPosition(), p_file )
						&& p_file.writeText( cuT( "\n" ) ) > 0;
		castor::TextWriter< OverlayCategory >::checkError( result, "OverlayCategory position" );

		if ( result )
		{
			result = p_file.writeText( m_tabs + cuT( "\tsize " ) ) > 0
					   && Point2d::TextWriter{ String{} }( p_overlay.getSize(), p_file )
					   && p_file.writeText( cuT( "\n" ) ) > 0;
			castor::TextWriter< OverlayCategory >::checkError( result, "OverlayCategory size" );
		}

		if ( result && p_overlay.getMaterial() )
		{
			result = p_file.writeText( m_tabs + cuT( "\tmaterial \"" ) + p_overlay.getMaterial()->getName() + cuT( "\"\n" ) ) > 0;
			castor::TextWriter< OverlayCategory >::checkError( result, "OverlayCategory material" );
		}

		for ( auto overlay : p_overlay.getOverlay() )
		{
			switch ( overlay->getType() )
			{
			case OverlayType::ePanel:
				result &= PanelOverlay::TextWriter( m_tabs + cuT( "\t" ) )( *overlay->getPanelOverlay(), p_file );
				break;

			case OverlayType::eBorderPanel:
				result &= BorderPanelOverlay::TextWriter( m_tabs + cuT( "\t" ) )( *overlay->getBorderPanelOverlay(), p_file );
				break;

			case OverlayType::eText:
				result &= TextOverlay::TextWriter( m_tabs + cuT( "\t" ) )( *overlay->getTextOverlay(), p_file );
				break;

			default:
				result = false;
			}
		}

		return result;
	}
Exemplo n.º 4
0
	bool ShaderObject::TextWriter::operator()( ShaderObject const & p_shaderObject, TextFile & p_file )
	{
		bool result = p_file.writeText( m_tabs + p_shaderObject.getStrType() + cuT( "\n" ) ) > 0
						&& p_file.writeText( m_tabs + cuT( "{\n" ) ) > 0;

		Path pathFile = p_file.getFilePath() / cuT( "Shaders" );

		if ( !File::directoryExists( pathFile ) )
		{
			File::directoryCreate( pathFile );
		}

		bool hasFile = false;

		if ( result )
		{
			Path file = p_shaderObject.getFile();

			if ( !file.empty() )
			{
				File::copyFile( file, pathFile );
				String fileName = Path{ cuT( "Shaders" ) } / file.getFileName() + cuT( "." ) + file.getExtension();
				string::replace( fileName, cuT( "\\" ), cuT( "/" ) );
				result = p_file.writeText( m_tabs + cuT( "\tfile \"" ) + fileName + cuT( "\"\n" ) ) > 0;
				castor::TextWriter< ShaderObject >::checkError( result, "ShaderObject file" );
			}
		}

		if ( hasFile )
		{
			for ( auto it : p_shaderObject.getUniforms() )
			{
				result = Uniform::TextWriter( m_tabs + cuT( "\t" ) )( it->getBaseUniform(), p_file );
			}
		}

		if ( result )
		{
			result = p_file.writeText( m_tabs + cuT( "}\n" ) ) > 0;
		}

		return result;
	}
Exemplo n.º 5
0
	bool LightCategory::TextWriter::operator()( LightCategory const & p_light, TextFile & p_file )
	{
		static std::map< LightType, String > type
		{
			{ LightType::eDirectional, cuT( "directional" ) },
			{ LightType::ePoint, cuT( "point" ) },
			{ LightType::eSpot, cuT( "spot" ) },
		};

		Logger::logInfo( m_tabs + cuT( "Writing Light " ) + p_light.getLight().getName() );
		bool result = p_file.writeText( cuT( "\n" ) + m_tabs + cuT( "light \"" ) + p_light.getLight().getName() + cuT( "\"\n" ) ) > 0
						&& p_file.writeText( m_tabs + cuT( "{\n" ) ) > 0;
		castor::TextWriter< LightCategory >::checkError( result, "LightCategory name" );

		if ( result )
		{
			result = MovableObject::TextWriter{ m_tabs + cuT( "\t" ) }( p_light.getLight(), p_file );
		}

		if ( result )
		{
			result = p_file.writeText( m_tabs + cuT( "\ttype " ) + type[p_light.getLightType()] + cuT( "\n" ) ) > 0;
			castor::TextWriter< LightCategory >::checkError( result, "LightCategory type" );
		}

		if ( result )
		{
			result = p_file.writeText( m_tabs + cuT( "\tcolour " ) ) > 0
					   && Point3f::TextWriter( String{} )( p_light.getColour(), p_file )
					   && p_file.writeText( cuT( "\n" ) ) > 0;
			castor::TextWriter< LightCategory >::checkError( result, "LightCategory colour" );
		}

		if ( result )
		{
			result = p_file.writeText( m_tabs + cuT( "\tintensity " ) ) > 0
					   && Point2f::TextWriter( String{} )( p_light.getIntensity(), p_file )
					   && p_file.writeText( cuT( "\n" ) ) > 0;
			castor::TextWriter< LightCategory >::checkError( result, "LightCategory intensity" );
		}

		if ( result && p_light.getLight().isShadowProducer() )
		{
			result = p_file.writeText( m_tabs + cuT( "\tshadow_producer true\n" ) ) > 0;
			castor::TextWriter< LightCategory >::checkError( result, "LightCategory shadow producer" );
		}

		return result;
	}
Exemplo n.º 6
0
	bool SceneNode::TextWriter::operator()( SceneNode const & node, TextFile & file )
	{
		bool result = node.getName() == cuT( "RootNode" )
			|| node.getName() == cuT( "ObjectRootNode" )
			|| node.getName() == cuT( "CameraRootNode" );

		if ( node.getName() != cuT( "RootNode" )
			 && node.getName() != cuT( "ObjectRootNode" )
			 && node.getName() != cuT( "CameraRootNode" ) )
		{
			Logger::logInfo( m_tabs + cuT( "Writing Node " ) + node.getName() );
			result = file.writeText( cuT( "\n" ) + m_tabs + cuT( "scene_node \"" ) + node.getName() + cuT( "\"\n" ) ) > 0
					   && file.writeText( m_tabs + cuT( "{\n" ) ) > 0;
			castor::TextWriter< SceneNode >::checkError( result, "Node name" );

			if ( result
				&& node.getParent()
				&& node.getParent()->getName() != cuT( "RootNode" )
				&& node.getParent()->getName() != cuT( "ObjectRootNode" )
				&& node.getParent()->getName() != cuT( "CameraRootNode" ) )
			{
				result = file.writeText( m_tabs + cuT( "\tparent \"" ) + node.getParent()->getName() + cuT( "\"\n" ) ) > 0;
				castor::TextWriter< SceneNode >::checkError( result, "Node parent name" );
			}

			if ( result )
			{
				result = file.print( 256, cuT( "%s\torientation " ), m_tabs.c_str() ) > 0
						   && Quaternion::TextWriter( String() )( node.getOrientation(), file )
						   && file.writeText( cuT( "\n" ) ) > 0;
				castor::TextWriter< SceneNode >::checkError( result, "Node orientation" );
			}

			if ( result )
			{
				result = file.print( 256, cuT( "%s\tposition " ), m_tabs.c_str() ) > 0
						   && Point3r::TextWriter( String() )( node.getPosition(), file )
						   && file.writeText( cuT( "\n" ) ) > 0;
				castor::TextWriter< SceneNode >::checkError( result, "Node position" );
			}

			if ( result )
			{
				result = file.print( 256, cuT( "%s\tscale " ), m_tabs.c_str() ) > 0
						   && Point3r::TextWriter( String() )( node.getScale(), file )
						   && file.writeText( cuT( "\n" ) ) > 0;
				castor::TextWriter< SceneNode >::checkError( result, "Node scale" );
			}

			if ( result )
			{
				result = file.writeText( m_tabs + cuT( "}\n" ) ) > 0;
				castor::TextWriter< SceneNode >::checkError( result, "Node end" );
			}
		}

		if ( result )
		{
			for ( auto const & it : node.m_children )
			{
				if ( result
					 && it.first.find( cuT( "_REye" ) ) == String::npos
					 && it.first.find( cuT( "_LEye" ) ) == String::npos )
				{
					SceneNodeSPtr node = it.second.lock();

					if ( node )
					{
						result = SceneNode::TextWriter{ m_tabs }( *node, file );
					}
				}
			}
		}

		return result;
	}