public void SetMaterial( Material material ) { this.material = material; }
void Parse( string[] lineTokens ) { switch ( lineTokens[ 0 ].ToLower( ) ) { // Model. case "model": this.model_name = lineTokens[ 1 ]; this.model = new Model( this.model_name ); break; // Mesh. case "mesh": if ( this.current_mesh != null ) { this.CalculateNormals( ); this.current_mesh.SetVertexData( this.vertices ); this.vertices = null; this.current_mesh.SetIndexData( this.indices ); this.indices = null; this.current_mesh.CreateVertexBuffer( this.g_device ); this.meshes.Add( this.current_mesh ); this.current_mesh = null; } else { this.current_mesh = new Mesh( lineTokens[ 1 ] ); } break; // BeginMaterial. case "bmat": this.material = new Material( lineTokens[ 1 ] ); break; // DiffuseMap. case "dmap": if ( this.material != null ) { Texture2D tex = this.LoadTexture( Path.Combine( this.model_path, lineTokens[ 1 ] ) ); this.material.AddTexture( TextureType.DiffuseMap, tex ); tex = null; } break; // NormalMap. case "nmap": if ( this.material != null ) { Texture2D tex = this.LoadTexture( Path.Combine( this.model_path, lineTokens[ 1 ] ) ); this.material.AddTexture( TextureType.NormalMap, tex ); tex = null; } break; // SpecularMap. case "smap": if ( this.material != null ) { Texture2D tex = this.LoadTexture( Path.Combine( this.model_path, lineTokens[ 1 ] ) ); this.material.AddTexture( TextureType.SpecularMap, tex ); tex = null; } break; // EmissiveMap. case "emap": if ( this.material != null ) { Texture2D tex = this.LoadTexture( Path.Combine( this.model_path, lineTokens[ 1 ] ) ); this.material.AddTexture( TextureType.EmissiveMap, tex ); tex = null; } break; // EndMaterial. case "emat": this.model.SetMaterial( this.material ); this.material = null; break; // Position. case "v": this.positions.Add( this.ParseVector3( lineTokens ) ); break; // TextureCoordinate. case "vt": Vector2 vt = this.ParseVector2( lineTokens ); vt.Y = ( 1.0f - vt.Y ); this.texcoords.Add( vt ); break; // Face. case "f": for ( int vi = 1; vi <= 3; vi++ ) { string[] indices = lineTokens[ vi ].Split( '/' ); int pos_index = ( int.Parse( indices[ 0 ], CultureInfo.InvariantCulture ) - 1 ); int tc_index = 0; Vector2 tex_coord = Vector2.Zero; if ( int.TryParse( indices[ 1 ], out tc_index ) ) { tex_coord = this.texcoords[ tc_index - 1 ]; } this.vertex_data.Add( new Vertex( this.positions[ pos_index ], tex_coord, Vector3.Zero ) ); } break; // Unknown command. default: break; } }