replacing vertices to connect meshes - openmesh

I am trying to connect two meshes by replacing boundary vertices of one mesh with the vertices of the other mesh. I currently do this by circulating over the in-halfedges and letting them point to the other vertex. Since I iteratively add edges along the way I am not able to insert faces. Is there an openmesh way to replace vertices and make sure all references (in/out halfedge, face etc.) stay correct?

If I understand you correctly you would like to "sew" / "weld" a boundary between two meshes together.
As you pointed out, it's not a good solution to directly manipulate the halfedge / face / ... pointers used by OpenMesh. Instead, this should be possible by inserting temporary triangles and then doing a collapse between pairs of opposing boundary vertices (removing the temporary triangles again). This way, OpenMesh will make sure all the pointers are setup correctly.

Related

Order of vertices in Geometry

In my program I have created a Geometry from the vertices of an intersection between a plane and a mesh. I use this Geometry to create a LineSegments object and it works perfectly. I would like to use the vertices in a couple of other ways as well, but the array of vertices in the Geometry is not in the correct order (the order that LineSegments draws them). I am unable to find where the information is stored that allows LineSegments to draw lines between the vertices in the correct order. The link below shows the problem:
https://gamedev.stackexchange.com/questions/99353/vertex-ordering-with-threejss-exporter
There is only one answer that suggests that you check the faces for more information, but from what I can see there is no information about the faces in my Geometry, it only contains the vertices that I put in there.
Any help would be much appreciated!
In a watertight and topologically correct mesh, every edge is shared by exactly two faces. When you cut by a plane, the two faces generate two edges that meet at a vertex, where the common edge pierces the plane.
So if you have a model such that you can reliably pair the edges of the faces (or if the edges are listed uniquely), you can obtain a list of section edges where the vertices are shared by two edges, and describe a closed polygon (unless the surface itself is open).
You can reconstruct this polygon by going from edge to edge, through the common vertices.
For instance, consider the cube below and assume that its faces are labeled left, right, front, back, top, bottom.
The section is made of five edges that can be labeled lt-rt, rt-rf, rf-bf, bf-lb, lb-lt.

UV-mapping a BufferGeometrys indices in Three.js

I'm having trouble UV mapping each side of a cube. The cube was made as a BufferGeometry where each side is a rotated copy of one side (sort of a working template) and rotated accordingly by applying a quarternion. UVs are copied as well. I'll skip any vertex coordinate I've seen before and rely on indices.
This leaves me with a total of 8 vertices and 12 faces. But I think I'm running short on vertices when I have to set all of my UVs. As obvious on the screenshot I've "correctly" mapped each side of the cube. But the top and bottom is lacking. I don't know how to set the vertex UV top and bottom faces.
Can I in some way apply several UVs on the same vertex depending on which face it is used in or have I completely lost the plot?
I could solve the problem by applying 6 PlaneBufferGeometry but that would leave me with 4*6=24 vertices. That is a whole lot more than 8.
I haven't been able to figure this one out. Either I've complete misunderstood how it works or what I'm trying to accomplish is impossible given my constraints.
With BufferGeometry, vertices can only be reused if all the attributes for that vertex match. Since each corner of the cube has 3 perpendicular normals, there must be 3 copies of that vertex.
If you have uvs, it is the same issue -- vertices must be duplicated if the uvs are different.
Study BoxBufferGeometry, which is implemented as "indexed-BufferGeometry".
three.js r.90

how to find all triangles for surface knowing vertices

I need to find all vertices that makes my surface, but I only know vertices (keep them as array) and edges. I'm doing it in XY coordinate system. I need it for Unity3D project (so pseudocode or C# code will be very helpful), but any mathematic ideas are appreciated, too.
I made some pictures for example.
If I don't have convex angle in my example it's really easy - I choose any vertex (e.g. 0) and take two next vertex in the loop. It gaves me triangles 0-1-2, 0-2-3 and 0-3-4.
It's quite easy, too, if I have one convex angle. I don't know how to find which vertex is convex (any ideas?) but it doesn't seem very complicated. Then I take him and make the same algorithm as above.
Unfortunatelly my idea stopped work for more complicated shapes, e.g (I always have one shape in my project, I just draw more of them to show more complex examples):
If I have shapes like this and try to use method described above, always any triangle is out of my shape.
I think that I can use for that any mathematic. My vertices are on XY coordinates, so I can count something. I can make more vertices if I need, too, so I could have:
I was trying to describe my problem as exactly how I can. I hope my english is understable.
Please, if you have any ideas - math ideas or pseudocode ideas how to make a surface for my vertices - write. If you have any single suggestion, not concrete idea - write, too. I am looking for inspiration, ideas, anything.
I'll make two assumptions:
You don't have any particular standards of one triangulation being better than another.
You want something conceptually easy.
Pick any vertex. Connect to any other vertex such that the formed line is entirely within the polygon. This means
The other vertex is not adjacent to the original
the connecting segment doesn't cross a side of the polygon.
It's possible that there is no such vertex. If so, then move to the next vertex, iterating until you find a pair you can connect. There will be at least one such pair.
When you draw that new segment, you've also divided the polygon into two polygons, each of which has fewer vertices than the original.
Recur on each of these polygons. Your stopping case (base case) on each thread is that you don't divide a triangle.

How to discriminate between vertices 1,2, and 3 inside a GLES Vertex Shader that is drawing triangle(s)

Is there any way to tell, from within a gl es vertex shader (that is drawing triangles) which of the three vertices is being processed?
Using gl_VertexID doesn't work for me, because it gives the index of the vertex in the list of vertices, but I use indices to specify a different order to draw the vertices, and so the value I want cannot be determined from gl_VertexID alone.
You can add a vertex attribute to represent the indices 0, 1, 2, but as #matic-oblak noted you may have to replicate some vertices that are shared between triangles. If the mesh is "three-colorable" (in the graph theory sense) then you can assign indices without any replication.
A tetrahedron is not 3-colorable, whereas a cube is 2-colorable, and we can triangulate the faces of a cube and get a 3-colorable mesh. Ordinary vertices have degree 6 in a triangular mesh and are "locally" 3-colorable.
Therefore you can 3-color a mesh as much as possible -- where it fails you will have to replicate vertices. Unfortunately 3-coloring is an NP-complete problem , but with a some simple heuristics I think you can do a fairly reasonable job.
As I commented above, what I was looking for is deliberately not available for pipeline efficiency reasons. See the comment by Alfonse Reinheart at the following page:
https://www.opengl.org/discussion_boards/showthread.php/181822-gl_VertexId-gl_InstanceID-gl_PrimitiveID-but-where-is-gl_IndexID
The other answer, posted by wcochran is interesting, and could be a way to pass less information to the rendering pipeline, although as s/he points out, it comes at the cost of some substantial preprocessing.

2D geometry outline shader

I want to create a shader to outline 2D geometry. I'm using OpenGL ES2.0. I don't want to use a convolution filter, as the outline is not dependent on the texture, and it is too slow (I tried rendering the textured geometry to another texture, and then drawing that with the convolution shader). I've also tried doing 2 passes, the first being single colorded overscaled geometry to represent an oultine, and then normal drawing on top, but this results in different thicknesses or unaligned outlines. I've looking into how silhouette's in cel-shading are done but they are all calculated using normals and lights, which I don't use at all.
I'm using Box2D for physics, and have "destructable" objects with multiple fixtures. At any point an object can be broken down (fixtures deleted), and I want to the outline to follow the new outter counter.
I'm doing the drawing with a vertex buffer that matches the vertices of the fixtures, preset texture coordinates, and indices to draw triangles. When a fixture is removed, it's associated indices in the index buffer are set to 0, so no triangles are drawn there anymore.
The following image shows what this looks like for one object when it is fully intact.
The red points are the vertex positions (texturing isn't shown), the black lines are the fixtures, and the blue lines show the seperation of how the triangles are drawn. The gray outline is what I would like the outline to look like in any case.
This image shows the same object with a few fixtures removed.
Is this possible to do this in a vertex shader (or in combination with other simple methods)? Any help would be appreciated.
Thanks :)
Assuming you're able to do something about those awkward points that are slightly inset from the corners (eg, if you numbered the points in English-reading order, with the first being '1', point 6 would be one)...
If a point is interior then if you list all the polygon edges connected to it in clockwise order, each pair of edges in sequence will have a polygon in common. If any two edges don't have a polygon in common then it's an exterior point.
Starting from any exterior point you can then get the whole outline by first walking in any direction and subsequently along any edge that connects to an exterior point you haven't visited yet (or, alternatively, that isn't the edge you walked along just now).
Starting from an existing outline and removing some parts, you can obviously start from either exterior point that used to connect to another but no longer does and just walk from there until you get to the other.
You can't handle this stuff in a shader under ES because you don't get connectivity information.
I think the best you could do in a shader is to expand the geometry by pushing vertices outward along their surface normals. Supposing that your data structure is a list of rectangles, each described by, say, a centre, a width and a height, you could achieve the same thing by drawing each with the same centre but with a small amount added to the width and height.
To be completely general you'd need to store normals at vertices, but also to update them as geometry is removed. So there'd be some pushing of new information from the CPU but it'd be relatively limited.

Resources