# Read and parse source and return all materials organized by their names
fun parse: Map[String, MtlDef]
do
var mat_lib = new Map[String, MtlDef]
var material: nullable MtlDef = null
while not eof do
var token = read_token
if token == "newmtl" then
var name = read_until_eol_or_comment
material = new MtlDef(name)
mat_lib[name] = material
else if material != null then
if token == "Ka" then
material.ambient = read_vec3
else if token == "Kd" then
material.diffuse = read_vec3
else if token == "Ks" then
material.specular = read_vec3
else if token == "d" then
material.dissolved = read_number
else if token == "Tr" then
material.dissolved = 1.0 - read_number
else if token == "illum" then
material.illumination_model = read_number.to_i
else if token == "map_Ka" then
material.map_ambient = read_until_eol_or_comment
else if token == "map_Kd" then
material.map_diffuse = read_until_eol_or_comment
else if token == "map_Bump" then
material.map_bump = read_until_eol_or_comment
else if token == "map_Ks" then
material.map_specular = read_until_eol_or_comment
else if token == "map_Ns" then
material.map_exponent = read_until_eol_or_comment
# TODO other line type headers
else if token == "Ns" then
else if token == "Ni" then
else if token == "sharpness" then
else if token == "bump" then
end
end
skip_eol
end
return mat_lib
end
lib/gamnit/model_parsers/mtl.nit:42,2--89,4