GlGraphics and OBJLoader, objloader's model texture not showing correctly
in
Contributed Library Questions
•
1 years ago
I have been able to import a 3Dmodel into Processing with OBJLoader and load the model as GLModel. With the help of this post:
http://forum.processing.org/topic/glgraphics-and-objloader
The model imports well and looks as it should. But.
The problem at hand is that the texture that is mapped in the 3Dmodel is not showing correctly.
My code currently looks like this:
model = new OBJModel(this, "objekti007.obj", "relative", TRIANGLES);
glmodel = new GLModel(this, model.getFaceCount()*3 , TRIANGLES, GLModel.DYNAMIC);
//********************GLGRAPHICS INITIALIZE OBJECT
//************************************************
//********************UPDATE VERTICES
//************************************************
glmodel.beginUpdateVertices();
int i = 0;
for (int f = 0; f < model.getFaceCount(); f++) {
PVector[] fverts = model.getFaceVertices(f);
for (int v = 0; v < fverts.length; v++) {
glmodel.updateVertex(i++, fverts[v].x, fverts[v].y, fverts[v].z);
}
}
glmodel.endUpdateVertices();
// Enabling colors.
glmodel.initColors();
glmodel.beginUpdateColors();
for (int c = 0; c < model.getVertexCount(); c++) {
glmodel.updateColor(c, 255, 255, 225, 255);
}
glmodel.endUpdateColors();
//********************UPDATE NORMALS
//************************************************
glmodel.initNormals();
glmodel.beginUpdateNormals();
int index = 0;
for (int s = 0; s < model.getSegmentCount(); s++) {
Segment segment = model.getSegment(s);
Face[] faces = segment.getFaces();
for (int nn = 0; nn < faces.length; nn++) {
PVector[] vs = faces[nn].getVertices();
PVector[] ns = faces[nn].getNormals();
for (int k = 0; k < vs.length; k++) {
glmodel.updateNormal(index++, ns[k].x, ns[k].y, ns[k].z);
}
}
}
glmodel.endUpdateNormals();
//********************UPDATE UV'S
//************************************************
// Enabling the use of texturing
glmodel.initTextures(1);
omatekstuuri = new GLTexture(this, "maapallotila_blur03.png");
glmodel.setTexture(0, omatekstuuri);
// glmodel.setTexture(0, glg1.getTexture());
glmodel.beginUpdateTexCoords(0);
int b = 0;
for (int f = 0; f < model.getUVCount(); f++) {
PVector uvs = model.getUV(f);
glmodel.updateTexCoord(b++, uvs.x, uvs.y);
}
glmodel.endUpdateTexCoords();
Is the problem with updating texture coordinates and they are not positioned how they should? I am quite puzzled.
http://forum.processing.org/topic/glgraphics-and-objloader
The model imports well and looks as it should. But.
The problem at hand is that the texture that is mapped in the 3Dmodel is not showing correctly.
My code currently looks like this:
model = new OBJModel(this, "objekti007.obj", "relative", TRIANGLES);
glmodel = new GLModel(this, model.getFaceCount()*3 , TRIANGLES, GLModel.DYNAMIC);
//********************GLGRAPHICS INITIALIZE OBJECT
//************************************************
//********************UPDATE VERTICES
//************************************************
glmodel.beginUpdateVertices();
int i = 0;
for (int f = 0; f < model.getFaceCount(); f++) {
PVector[] fverts = model.getFaceVertices(f);
for (int v = 0; v < fverts.length; v++) {
glmodel.updateVertex(i++, fverts[v].x, fverts[v].y, fverts[v].z);
}
}
glmodel.endUpdateVertices();
// Enabling colors.
glmodel.initColors();
glmodel.beginUpdateColors();
for (int c = 0; c < model.getVertexCount(); c++) {
glmodel.updateColor(c, 255, 255, 225, 255);
}
glmodel.endUpdateColors();
//********************UPDATE NORMALS
//************************************************
glmodel.initNormals();
glmodel.beginUpdateNormals();
int index = 0;
for (int s = 0; s < model.getSegmentCount(); s++) {
Segment segment = model.getSegment(s);
Face[] faces = segment.getFaces();
for (int nn = 0; nn < faces.length; nn++) {
PVector[] vs = faces[nn].getVertices();
PVector[] ns = faces[nn].getNormals();
for (int k = 0; k < vs.length; k++) {
glmodel.updateNormal(index++, ns[k].x, ns[k].y, ns[k].z);
}
}
}
glmodel.endUpdateNormals();
//********************UPDATE UV'S
//************************************************
// Enabling the use of texturing
glmodel.initTextures(1);
omatekstuuri = new GLTexture(this, "maapallotila_blur03.png");
glmodel.setTexture(0, omatekstuuri);
// glmodel.setTexture(0, glg1.getTexture());
glmodel.beginUpdateTexCoords(0);
int b = 0;
for (int f = 0; f < model.getUVCount(); f++) {
PVector uvs = model.getUV(f);
glmodel.updateTexCoord(b++, uvs.x, uvs.y);
}
glmodel.endUpdateTexCoords();
Is the problem with updating texture coordinates and they are not positioned how they should? I am quite puzzled.
1