indexing description: "Factory that loads all kind of mtl files" author: "" date: "$Date$" revision: "$Revision$" class EM3D_MATERIAL_MTL_FACTORY inherit EM3D_MATERIAL_FACTORY create make feature {NONE} -- Implementation read_vertex( split_line: LIST[ STRING ] ): EM_VECTOR3D is -- Read a vector local i: INTEGER do from i:=1 until i>3 loop result[ i ] := read_double( split_line ) i := i + 1 end end read_double( split_line: LIST[ STRING ] ): DOUBLE is -- Read a double do from until split_line.after or else split_line.item.is_double loop split_line.forth end if split_line.after then result := 0 else result := split_line.item.to_double split_line.forth end end read_string( split_line: LIST[ STRING ] ): STRING is -- Read a String do from until split_line.after or else not split_line.is_empty loop split_line.forth end if not split_line.after then result := split_line.item end end feature -- Object creation load_material_internal( a_filename: STRING ) is -- Load a material from a file local file: PLAIN_TEXT_FILE command, line: STRING split_line: LIST[ STRING ] mat_name, tex_name: STRING material: EM3D_MATERIAL trans: DOUBLE do create file.make_open_read ( a_filename ) create material trans := 1 from until file.end_of_file loop file.read_line line := file.last_string line.prune_all_trailing ( '%R' ) split_line := line.split ( ' ' ) split_line.start command := split_line.item split_line.forth if command.is_equal( "#" ) then -- We have a comment elseif command.is_equal ( "newmtl" ) then if mat_name /= void then add_material ( material, mat_name ) end mat_name := read_string( split_line ) create material trans := 1 elseif command.is_equal ( "Ka" ) then material.set_ambient ( read_vertex( split_line ) ) elseif command.is_equal ( "Kd" ) then material.set_diffuse ( read_vertex( split_line ) ) elseif command.is_equal ( "Ks" ) then material.set_specular ( read_vertex( split_line ) ) elseif command.is_equal ( "d" ) or command.is_equal ( "Tr" ) then trans := read_double( split_line ) elseif command.is_equal ( "Ns" ) then material.set_shininess ( read_double( split_line ) ) elseif command.is_equal ( "map_Ka" ) then tex_name := read_string( split_line ) if file_system.file_exists ( tex_name ) then scene_manager.texture_factory.load_texture ( tex_name ) material.set_texture ( scene_manager.texture_factory.new_texture ( tex_name ) ) else tex_name := file_system.pathname ( file_system.dirname ( a_filename ), tex_name ) if file_system.file_exists ( tex_name ) then scene_manager.texture_factory.load_texture ( tex_name ) material.set_texture ( scene_manager.texture_factory.new_texture ( tex_name ) ) end end end end if mat_name /= void then add_material ( material, mat_name ) end end end