diff --git a/src/nxsbuild/nexusbuilder.cpp b/src/nxsbuild/nexusbuilder.cpp index aff3057..c088502 100644 --- a/src/nxsbuild/nexusbuilder.cpp +++ b/src/nxsbuild/nexusbuilder.cpp @@ -207,6 +207,8 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float std::vector vertex_to_box; + //find connected pieces of triangles belonging to the same texture + //iterate over the triangles and connect the vertices. UnionFind components; components.init(mesh.vert.size()); @@ -214,8 +216,8 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float int v[3]; for(int i = 0; i < 3; i++) { v[i] = face.V(i) - &*mesh.vert.begin(); - - + + int &t = vertex_to_tex[v[i]]; if(t != -1 && t != face.tex) qDebug() << "Missing vertex replication across seams\n"; @@ -227,17 +229,15 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float } int n_boxes = components.compact(vertex_to_box); + //assign a texture to each vertex (we already split) for(auto &face: mesh.face) { int v[3]; for(int i = 0; i < 3; i++) { int v = face.V(i) - &*mesh.vert.begin(); vertex_to_tex[v] = face.tex; } - /* assert(vertex_to_box[v[0]] == vertex_to_box[v[1]]); - assert(vertex_to_box[v[0]] == vertex_to_box[v[2]]); - assert(components.root(v[0]) == components.root(v[2])); - assert(components.root(v[0]) == components.root(v[1])); */ } + //assign all boxes to a tex (and remove boxes where the tex is -1 //compute boxes @@ -251,13 +251,15 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float vcg::Box2f &box = boxes[b]; box_texture[b] = tex; auto &t = mesh.vert[i].T().P(); - t[0] = fmod(t[0], 1.0); - t[1] = fmod(t[1], 1.0); - // if(isnan(t[0]) || isnan(t[1]) || t[0] < 0 || t[1] < 0 || t[0] > 1 || t[1] > 1) - // cout << "T: " << t[0] << " " << t[1] << endl; + if(t[0] != 1.0) + t[0] = fmod(t[0], 1.0); + if(t[1] != 1.0) + t[1] = fmod(t[1], 1.0); + if(t[0] != 0.0f || t[1] != 0.0f) box.Add(t); } + //erase boxes assigned to no texture, and remap vertex_to_box int count = 0; std::vector remap(mesh.vert.size(), -1); @@ -277,6 +279,18 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float std::vector origins(boxes.size()); for(size_t b = 0; b < boxes.size(); b++) { auto &box = boxes[b]; + cout << "Box: " << box.DimX() << endl; + if(box.DimX() > 0.9) { + for(auto &face: mesh.face) { + int v[3]; + for(int i = 0; i < 3; i++) { + auto v = face.V(i); + int j = (i+1)%3; + if(fabs(v->T().u() - face.V(j)->T().u()) > 0.1) + cout << v->T().u() << " " << face.V(j)->T().u() << endl; + } + } + } int tex = box_texture[b]; //enlarge 1 pixel @@ -414,7 +428,6 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float auto V1 = face.V(1)->T().P(); auto V2 = face.V(2)->T().P(); areausage += (V2 - V0)^(V2 - V1)/2; - } { diff --git a/src/nxsbuild/nxsbuild.pro b/src/nxsbuild/nxsbuild.pro index 7e14ca3..491ef5e 100644 --- a/src/nxsbuild/nxsbuild.pro +++ b/src/nxsbuild/nxsbuild.pro @@ -9,7 +9,7 @@ QMAKE_CXXFLAGS += -std=c++11 -g -fpermissive INCLUDEPATH += \ ../../../vcglib \ - ../../../vcglib/eigenlib + ../../../vcglib/eigenlib DEFINES += _FILE_OFFSET_BITS=64 DEFINES += _USE_MATH_DEFINES diff --git a/src/nxsbuild/plyloader.cpp b/src/nxsbuild/plyloader.cpp index 26ff528..0497167 100644 --- a/src/nxsbuild/plyloader.cpp +++ b/src/nxsbuild/plyloader.cpp @@ -312,8 +312,10 @@ quint32 PlyLoader::getTriangles(quint32 size, Triangle *buffer) { if (has_textures) { float n; - vertex.t[0] = modf(vertex.t[0], &n); - vertex.t[1] = modf(vertex.t[1], &n); + if(vertex.t[0] != 1.0) + vertex.t[0] = modf(vertex.t[0], &n); + if(vertex.t[1] != 1.0) + vertex.t[1] = modf(vertex.t[1], &n); } current.vertices[k] = vertex; diff --git a/src/nxsedit/nxsedit.pro b/src/nxsedit/nxsedit.pro index 037582b..1e272c5 100644 --- a/src/nxsedit/nxsedit.pro +++ b/src/nxsedit/nxsedit.pro @@ -13,13 +13,15 @@ DEFINES += NDEBUG INCLUDEPATH += \ ../../../vcglib \ - ../../../vcglib/eigenlib + ../../../vcglib/eigenlib \ + ../corto/include win32:INCLUDEPATH += ../../../glew/include ../../../corto/include win32:LIBS += opengl32.lib GLU32.lib ../../../glew/lib/glew32.lib ../../../corto/lib/corto.lib -unix:INCLUDEPATH += /usr/local/lib -unix:LIBS += -L /usr/local/lib -lcorto +#unix:INCLUDEPATH += /usr/local/lib +#unix:LIBS += -L /usr/local/lib -lcorto +unix:LIBS += ../corto/libcorto.a SOURCES += \ ../../../vcglib/wrap/system/qgetopt.cpp \ diff --git a/src/nxsview/nxsview.pro b/src/nxsview/nxsview.pro index c267b1b..2513fe7 100644 --- a/src/nxsview/nxsview.pro +++ b/src/nxsview/nxsview.pro @@ -18,9 +18,8 @@ INCLUDEPATH += \ win32:INCLUDEPATH += ../../../glew/include ../../../corto/include win32:LIBS += opengl32.lib GLU32.lib ../../../glew/lib/glew32.lib ../../../corto/lib/corto.lib -unix:INCLUDEPATH += /usr/local/lib -unix:LIBS += -lGLEW -lGLU -lcorto -#-lcurl +unix:INCLUDEPATH += /usr/local/lib ../../../corto/include +unix:LIBS += -lGLEW -lGLU ../../../corto/libcorto.a SOURCES += \ ../../../vcglib/wrap/gui/trackmode.cpp \