Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tried the panorama example #1

Open
dariocavada opened this issue Jan 7, 2025 · 3 comments
Open

Tried the panorama example #1

dariocavada opened this issue Jan 7, 2025 · 3 comments

Comments

@dariocavada
Copy link

I tried the panorama example, and both on Android and the web, I see a strange line, probably where the panorama should connect (I think the right and left edges).

Screenshot-2025-01-07-alle-18 09 57

@GeranBronn
Copy link

I also tried this package and drew some wires on the mesh and found that it is not the seem
When you offset the texture the seems are perfect
What I think is happening is with the triangles at the supposed join point it bunches up the total texture into this line of triangles
I am trying to figure out a way to redo the texture mapping on this line of triangles
Here is an image of what I found

Image

@GeranBronn
Copy link

Here is a better image of what is happening

This can be replicated by reducing the number of segments

The pano is squashed into this line of triangles

Image

@GeranBronn
Copy link

Ok solved:

Add these changes to this script: panorama_painter.dart

When drawing the mesh add these adjustments:

        // First triangle
        final triangleVertices1 = [
          vertices[i0],
          vertices[i1],
          vertices[i2],
        ];
        final textureCoordinates1 = _adjustTexCoords([ // Add the adjustment here:
          texCoords[i0],
          texCoords[i1],
          texCoords[i2],
        ], image.width.toDouble());

And here:

        // Second triangle
        final triangleVertices2 = [
          vertices[i1],
          vertices[i3],
          vertices[i2],
        ];
        final textureCoordinates2 = _adjustTexCoords([ // Add the adjustment here:
          texCoords[i1],
          texCoords[i3],
          texCoords[i2],
        ], image.width.toDouble());

Add this helper function in the class:

  static List<Offset> _adjustTexCoords(List<Offset> coords, double imgWidth) {
    // Determine the minimum U value (horizontal coordinate) among the texture coordinates.
    final double minU = coords.map((c) => c.dx).reduce(math.min);

    // Determine the maximum U value (horizontal coordinate) among the texture coordinates.
    final double maxU = coords.map((c) => c.dx).reduce(math.max);

    // Check if the triangle spans the texture seam.
    // If the difference between max and min U values exceeds half the image width,
    // it suggests that the triangle is crossing the seam.
    if (maxU - minU > imgWidth / 2) {
      // Adjust texture coordinates for triangles spanning the seam.
      // For coordinates with a U value less than half the image width, add the full image width
      // to effectively 'unwrap' the texture, preventing the texture from being squashed.
      return coords
          .map((c) => c.dx < imgWidth / 2 ? Offset(c.dx + imgWidth, c.dy) : c)
          .toList();
    }

    // If the triangle does not span the seam, return the original texture coordinates.
    return coords;
  }

Example:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants