gamnit :: ObjFileParser :: parse
src
to extract an ObjDef
# Execute parsing of `src` to extract an `ObjDef`
fun parse: nullable ObjDef
do
var obj_obj = null
while not eof do
var token = read_token
if token.is_empty or token == "#" then
# Ignore empty lines and comments
else if token == "v" then # Vertex points
var vec = read_vec4
geometry.vertex_points.add vec
else if token == "vt" then # Texture coords
var vec = read_vec3
geometry.texture_coords.add vec
else if token == "vn" then # Normals
var vec = read_vec3 # This one should not accept `w` values
geometry.normals.add vec
else if token == "vp" then # Parameter space vertices
var vec = read_vec3
geometry.params.add vec
else if token == "f" then # Faces
var face = read_face
if obj_obj == null then
obj_obj = new ObjObj("")
geometry.objects.add obj_obj
end
obj_obj.faces.add face
else if token == "mtllib" then
current_material_lib = read_until_eol_or_comment
else if token == "usemtl" then
current_material_name = read_until_eol_or_comment
# TODO other line type headers
else if token == "s" then
else if token == "o" then
obj_obj = new ObjObj(read_until_eol_or_comment)
geometry.objects.add obj_obj
else if token == "g" then
end
skip_eol
end
return geometry
end
lib/gamnit/model_parsers/obj.nit:61,2--103,4