MaterialsOptimizer.Parser.ReadFloat4 C# (CSharp) Method

ReadFloat4() public method

public ReadFloat4 ( string _block ) : float4
_block string
return float4
        public float4 ReadFloat4( string _block )
        {
            Parser	P = new Parser( _block );

            float4	Result = new float4();

            int		coordinateIndex = 0;
            while ( P.OK ) {
                float	value = P.ReadFloat();
                P.ReadString();	// Skip separator

                switch ( coordinateIndex ) {
                    case 0: Result.x = value; break;
                    case 1: Result.y = value; break;
                    case 2: Result.z = value; break;
                    case 3: Result.w = value; break;
                    default: Error( "Unexpected coordinate!" ); break;
                }

                coordinateIndex++;
            }
            return Result;
        }

Same methods

Parser::ReadFloat4 ( ) : float4

Usage Example

Ejemplo n.º 1
0
                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;
                    }
                }
All Usage Examples Of MaterialsOptimizer.Parser::ReadFloat4