From 44e127689d99e3effb3e9cbd79829498a56a373b Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Fri, 23 Apr 2021 21:00:49 +0200 Subject: [PATCH] rogueviz::objmodel:: load faces with more than 3 vertices --- rogueviz/objmodels.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/rogueviz/objmodels.cpp b/rogueviz/objmodels.cpp index 2e3ef552..d1cea4e6 100644 --- a/rogueviz/objmodels.cpp +++ b/rogueviz/objmodels.cpp @@ -159,24 +159,34 @@ void model::load_obj(model_data& md) { else if(s == "f") { struct vertexinfo { int f, t, n; }; array vis; - vector hys; - vector tot; char bar; - for(int i=0; i<3; i++) { - vis[i].f = vis[i].t = vis[i].n = 1; - scan(fs, vis[i].f); + + auto get_vi = [&] (vertexinfo& vi) { + vi.f = vi.t = vi.n = 1; + scan(fs, vi.f); if(peek(fs) == '/') { scan(fs, bar); - if(peek(fs) != '/') scan(fs, vis[i].t); + if(peek(fs) != '/') scan(fs, vi.t); } if(peek(fs) == '/') { scan(fs, bar); - scan(fs, vis[i].n); + scan(fs, vi.n); } - vis[i].f--; vis[i].t--; vis[i].n--; - if(vis[i].f < 0 || vis[i].f >= isize(vertices)) + vi.f--; vi.t--; vi.n--; + if(vi.f < 0 || vi.f >= isize(vertices)) throw hr_exception("illegal ID"); + }; + + get_vi(vis[0]); + get_vi(vis[1]); + next_triangle: + get_vi(vis[2]); + + vector hys; + vector tot; + + for(int i=0; i<3; i++) { hys.push_back(vertices[vis[i].f]); tot.push_back(textured ? tvertices[vis[i].t] : point3(0,0,0)); } @@ -219,6 +229,10 @@ void model::load_obj(model_data& md) { tri(a+1, b+1); } } + + while(among(peek(fs), ' ', '\r', '\n')) scan(fs, bar); + if(isdigit(peek(fs))) { vis[1] = vis[2]; println(hlog, "next triangle"); goto next_triangle; } + println(hlog, "last triangle"); } else if(s == "l") { int a, b;