Skip to content

Commit

Permalink
fixed texture boundary issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
ponchio committed Oct 4, 2024
1 parent a0558ea commit 26c4f68
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
35 changes: 24 additions & 11 deletions src/nxsbuild/nexusbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,17 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float
std::vector<int> 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());

for(auto &face: mesh.face) {
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";
Expand All @@ -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
Expand All @@ -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<int> remap(mesh.vert.size(), -1);
Expand All @@ -277,6 +279,18 @@ QImage NexusBuilder::extractNodeTex(TMesh &mesh, int level, float &error, float
std::vector<vcg::Point2i> 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
Expand Down Expand Up @@ -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;

}

{
Expand Down
2 changes: 1 addition & 1 deletion src/nxsbuild/nxsbuild.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/nxsbuild/plyloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/nxsedit/nxsedit.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
5 changes: 2 additions & 3 deletions src/nxsview/nxsview.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 26c4f68

Please sign in to comment.