Weird lines on texture


On the right side is an object in Windows’ 3D Viewer app. This same object I’ve imported into my engine however when I try to render it the texture is quite messed up (Image on the left side).
These weird line type things are causing an issue. It is not an issue with the texture coordinates as you can see there is a portion of the color that matches up but there are these artifacts all over the model. Can anyone help?

My first guess is that texture seams aren’t being handled correctly. I.e. where two vertices have the same positional coordinates but different texture coordinates and they’re being forcibly merged, with one set of texture coordinates simply being discarded. This is not an uncommon issue with OBJ loaders where the author hasn’t thought about texture seams then just tries to “paper over” the problem when they encounter it.

1 Like

yesyes, I understood what the issue is, however I could use some help in trying to fix it

// Loop through all the faces
for (Face face : faces) {
	// Add the index of the first vertex to the list
	indicesOrganized.add(face.vertex1);
	// Add the index of the second vertex to the list
	indicesOrganized.add(face.vertex2);
	// Add the index of the third vertex to the list
	indicesOrganized.add(face.vertex3);

	// If the object file does have texture coordinates
	if (face.textureCoordinate1 != -1) {
		// Get the texture coordinate for the first vertex
		Vector2f textureCoordinate1 = textureCoordinatesIn.get(face.textureCoordinate1);
		// Get the texture coordinate for the second vertex
		Vector2f textureCoordinate2 = textureCoordinatesIn.get(face.textureCoordinate2);
		// Get the texture coordinate for the third vertex
		Vector2f textureCoordinate3 = textureCoordinatesIn.get(face.textureCoordinate3);

		// Store the X of the texture coordinate of the first vertex
		textureCoordinates[2 * face.vertex1] = textureCoordinate1.x;
		// Store the Y of the texture coordinate of the first vertex
		textureCoordinates[2 * face.vertex1 + 1] = textureCoordinate1.y;

		// Store the X of the texture coordinate of the second vertex
		textureCoordinates[2 * face.vertex2] = textureCoordinate2.x;
		// Store the Y of the texture coordinate of the second vertex
		textureCoordinates[2 * face.vertex2 + 1] = textureCoordinate2.y;

		// Store the X of the texture coordinate of the third vertex
		textureCoordinates[2 * face.vertex3] = textureCoordinate3.x;
		// Store the Y of the texture coordinate of the third vertex
        textureCoordinates[2 * face.vertex3 + 1] = textureCoordinate3.y;
	}
   // ... Rest of the organization
}

Here’s how I am currently importing the texture coordinates (It’s from the book “3D Game Development with LWJGL”)

If you’re reading an OBJ file, you need to create an OpenGL vertex for each distinct combination of indices. Typically this involves using an associative array (e.g. java.util.HashMap) which maps position/texcoord/normal triples to OpenGL indices and an array (e.g. java.util.ArrayList) which holds the reverse mapping. You need the reverse mapping to create the attribute arrays.

Alternatively you can just make all vertices distinct, so you have three distinct vertices for each triangle.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.