indexing description: "This factory parses all the materials from a .x file" date: "$Date$" revision: "$Revision$" class EM3D_MATERIAL_X_FACTORY inherit EM3D_MATERIAL_FACTORY EM3D_X_PARSING_SUPPORT export {NONE} all end feature -- Object creation load_material_internal( a_filename: STRING ) is -- Load a material from a file local file: PLAIN_TEXT_FILE name: STRING do create file.make_open_read( a_filename ) -- Parse all the 'Mesh' tags from file.start until file.end_of_file loop file.read_word if file.last_string.is_equal ( "//" ) then elseif file.last_string.is_equal ( "Material" ) then name := file.position.out file.read_word -- Read the Mesh name if not file.last_string.is_equal( "{" ) then name := file.last_string.twin file.read_word end add_material( parse_material( file ), a_filename+"#"+name ) end file.read_line end file.close end feature {NONE} -- Implementation parse_material( a_file: PLAIN_TEXT_FILE ):EM3D_MATERIAL is -- Parse the mesh part local v4: EM_VECTOR4D texture: STRING do create result v4 := parse_vector4d( a_file ) -- TODO: What is the ambient or diffuse value? result.set_ambient ( v4 ) result.set_diffuse ( v4 ) result.set_shininess ( parse_double( a_file ) ) v4 := parse_vector3d( a_file ); v4.w := 1 result.set_specular ( v4 ) v4 := parse_vector3d( a_file ); v4.w := 1 result.set_emission( v4 ) -- Parse optional things from a_file.read_word until a_file.last_string.is_equal ( "}" ) or a_file.end_of_file loop if a_file.last_string.is_equal ( "TextureFilename" ) then skip ( a_file, '{' ) texture := parse_string( a_file ) if file_system.file_exists ( texture ) then scene_manager.texture_factory.load_texture ( texture ) result.set_texture ( scene_manager.texture_factory.new_texture ( texture ) ) else texture := file_system.pathname ( file_system.dirname ( a_file.name ), texture ) if file_system.file_exists ( texture ) then scene_manager.texture_factory.load_texture ( texture ) result.set_texture ( scene_manager.texture_factory.new_texture ( texture ) ) end end a_file.search( '}' ); a_file.forth else skip_block( a_file ) end a_file.read_word end end end