public void Read( BinaryReader R ) { m_rawTextureLine = R.ReadString(); m_name = R.ReadString(); string fileName = R.ReadString(); m_fileName = fileName != string.Empty ? new FileInfo( fileName ) : null; string errorText = R.ReadString(); m_error = errorText != string.Empty ? new Exception( errorText ) : null; m_constantColorType = (CONSTANT_COLOR_TYPE) R.ReadInt32(); m_customConstantColor.x = R.ReadSingle(); m_customConstantColor.y = R.ReadSingle(); m_customConstantColor.z = R.ReadSingle(); m_customConstantColor.w = R.ReadSingle(); }
public Texture( string _textureLine ) { m_rawTextureLine = _textureLine; // Parse texture name Parser P = new Parser( _textureLine ); m_name = P.ReadString( true, false ); try { // Check if it's a constant color m_name = m_name.ToLower(); if ( m_name.StartsWith( "_" ) ) { // Procedural texture switch ( m_name ) { case "_default": m_constantColorType = CONSTANT_COLOR_TYPE.DEFAULT; break; case "_black": m_constantColorType = CONSTANT_COLOR_TYPE.BLACK; break; case "_blackalphawhite": m_constantColorType = CONSTANT_COLOR_TYPE.BLACK_ALPHA_WHITE; break; case "_white": m_constantColorType = CONSTANT_COLOR_TYPE.WHITE; break; case "_invalid": m_constantColorType = CONSTANT_COLOR_TYPE.INVALID; break; default: throw new Exception( "Unsupported procedural texture type \"" + m_name + "\"!" ); } } else if ( m_name.StartsWith( "ipr_constantcolor" ) ) { m_constantColorType = CONSTANT_COLOR_TYPE.CUSTOM; P = new Parser( _textureLine ); P.ConsumeString( "ipr_constantColor", false ); string strColor = P.ReadBlock( '(', ')' ); m_customConstantColor = P.ReadFloat4( strColor ); // Compare known colors to revert to basic types if ( CompareFloat4( m_customConstantColor, float4.Zero ) ) { m_constantColorType = CONSTANT_COLOR_TYPE.BLACK; } else if ( CompareFloat4( m_customConstantColor, float4.UnitW ) ) { m_constantColorType = CONSTANT_COLOR_TYPE.BLACK_ALPHA_WHITE; } else if ( CompareFloat4( m_customConstantColor, float4.One ) ) { m_constantColorType = CONSTANT_COLOR_TYPE.WHITE; } } if ( m_constantColorType == CONSTANT_COLOR_TYPE.TEXTURE ) { // Build file name string fullPath = Path.Combine( ms_TexturesBasePath.FullName, m_name ); if ( Path.GetExtension( fullPath.ToLower() ) == "" ) fullPath += ".tga"; // Assume tga files if unspecified m_fileName = new FileInfo( fullPath ); } } catch ( Exception _e ) { m_error = _e; } }