learning - Academic Conferences Limited

learning - Academic Conferences Limited learning - Academic Conferences Limited

academic.conferences.org
from academic.conferences.org More from this publisher
27.06.2013 Views

Robert Lucas Note the need to create two triangles where there isn’t a shared vertex between the pair of cuts. The algorithm needs to be extended to remember all the created vertices as these will be needed to fill the hole created by the cut. 4.2 Filling the hole created by the cut This is a well-established problem with several solutions. It is commonly referred to as triangulating a polygon. The added vertices form a 2-D polygon. In the example of the cube, this polygon is simply defined by the set of 3-vectors given by the points A through H. For a solution see (Chazelle 1991) or (de Berg 2000) or perform a Google search on ‘triangulating a polygon’ for algorithms, comments and related problems and diversions, such as the Art Gallery Problem proposed by Victor Klee in 1973 when he was a young mathematician at Montreal University. One thing to note is that, unless we want to create a lot of unwanted and useless triangles (i.e. they are not really triangles at all) we need to be careful about vertices being collinear, that is we don’t want to create a triangle from three vertices that are in a straight line. We can easily test for two vectors being collinear using the vector dot product, but just how we implement this in terms of how accurate we want this test to be can be a source of problems. Where the test is too stringent we won’t catch all the collinear vertices, where it is too lax, we will be leaving visible gaps in our filled face. 4.3 Creating the cut data structure In order to create all the cut points we need to take every edge of the mesh and calculate the intersection of this edge with the plane that represents the blade performing the cut. Given two points represented by the vectors V1 and V2 and a plane represented by the normal N and a point on the plane given by the vector P. The point of the intersection is given by the vector (Bourke 1991): I = V1 + lambda (V2-V1) Where lambda is the scalar given by: lambda = N dot (P – V1) / N dot (V2 – V1) where dot is the vector dot product. Where lambda is between zero and one, then the intersection is actually on the line between the two points. This is exactly what we want to test for. So the algorithm for determining the cut points needs to take each edge of the original mesh and calculate the value of lambda and where this is between zero and one we have a cut point formed from the two vertices and the value for lambda. The cut points then need to be topologically sorted so that we deal with each adjacent edge containing a cut in succession to ensure that the triangles are created correctly. 4.4 Texture mapping Textures are applied to a surface using what are commonly known as uv coordinates. These are defined for every vertex of every triangle. The uv coordinates are two dimensional and in Unity are represented by a 2-vector. These uv vectors dictate how the texture is to be mapped onto the triangle. They range from zero to one, where one would dictate the rightmost position on the texture (for u) or highest position on the texture (for v). Thus a particular patch of a texture can be mapped onto each triangle by manipulating the uv coordinates for each vertex. Being able to map a texture onto a surface is very important. This is what gives our model realism. We can also use photographs for our textures and as shown in [Lucas 2010] this can be of huge advantage in scientific simulations by giving extra authenticity to the model. With a cut surface the situation is complicated by the fact that this surface has been programmatically created to fill the hole left by the cut using some number of different shaped triangles. The texture must be mapped such that there is continuity of the texture over the edges of one triangle to the next. This is not as complicated as it may first appear. Consider the vertex marked A Figure 4 that is common to many triangles. We want there to be continuity in the textures appearance as it is mapped over all the triangles meeting at Vertex A. 438

Robert Lucas Figure 4: A set of triangles filling a planar hole If we calculate the uv values for A based on the coordinates in space of A then clearly this will map identically for all the triangles that contain A (A has the same coordinates regardless of which triangle you pick!). This is true of any other vertex and as the mapping from one vertex to another is linear, will quite automatically get continuity at the edges as long as we calculate the uvs from the coordinates. To map the texture uniformly onto the surface we need to find the horizontal and vertical coordinate axes on the cut face. You can consider this to be like placing a sheet of graph paper onto the face. We already have the normal to the cut face as this is the same as the normal to the cutting plane. If we take the cross product of the normal and the ‘up’ vector we get the horizontal coordinate, and the cross product of the normal and the ‘right’ vector we get the vertical coordinate. The up and right vectors are defined for you in Unity. The algorithm is then (in pseudo code): Begin N = Cut plane normal H = N cross Right V = N cross Up For every triangle T do uv[1st Vertex] = Vector2(Vertex1 dot H, Vertex1 dot V) uv[2nd Vertex] = Vector2(Vertex2 dot H, Vetex2 dot V) uv[3 rd Vertex] = Vector2(Vertex3 dot H, Vertex3 dot V) Next End We can scale the texture in both directions by putting a multiplying factor in front of the Vector2 constructor. We can choose to treat textures differently for different objects by separating the texture for the original surface from that intended for the cut surface. For example we can have one texture for the surface of an egg, the shell, and another for the interior white. This effectively makes the shell infinitely thin, but saves on the number of meshes and triangles needed and can be a reasonable compromise where memory is tight. The materials associated with the textures are being stored within the code as this makes it unnecessary for external references to be made at run-time. Figure 5 shows a cross section of a Malteaser. This is constructed from two polygon models of a sphere with twelve vertical and horizontal divisions. The outer sphere has a brown chocolate texture and the middle sphere is given a cut-face texture made from a photograph of the centre of an actual Malteaser. 439

Robert Lucas<br />

Figure 4: A set of triangles filling a planar hole<br />

If we calculate the uv values for A based on the coordinates in space of A then clearly this will map<br />

identically for all the triangles that contain A (A has the same coordinates regardless of which triangle<br />

you pick!). This is true of any other vertex and as the mapping from one vertex to another is linear, will<br />

quite automatically get continuity at the edges as long as we calculate the uvs from the coordinates.<br />

To map the texture uniformly onto the surface we need to find the horizontal and vertical coordinate<br />

axes on the cut face. You can consider this to be like placing a sheet of graph paper onto the face.<br />

We already have the normal to the cut face as this is the same as the normal to the cutting plane. If<br />

we take the cross product of the normal and the ‘up’ vector we get the horizontal coordinate, and the<br />

cross product of the normal and the ‘right’ vector we get the vertical coordinate. The up and right<br />

vectors are defined for you in Unity. The algorithm is then (in pseudo code):<br />

Begin<br />

N = Cut plane normal<br />

H = N cross Right<br />

V = N cross Up<br />

For every triangle T do<br />

uv[1st Vertex] = Vector2(Vertex1 dot H, Vertex1 dot V)<br />

uv[2nd Vertex] = Vector2(Vertex2 dot H, Vetex2 dot V)<br />

uv[3 rd Vertex] = Vector2(Vertex3 dot H, Vertex3 dot V)<br />

Next<br />

End<br />

We can scale the texture in both directions by putting a multiplying factor in front of the Vector2<br />

constructor.<br />

We can choose to treat textures differently for different objects by separating the texture for the<br />

original surface from that intended for the cut surface. For example we can have one texture for the<br />

surface of an egg, the shell, and another for the interior white. This effectively makes the shell<br />

infinitely thin, but saves on the number of meshes and triangles needed and can be a reasonable<br />

compromise where memory is tight. The materials associated with the textures are being stored within<br />

the code as this makes it unnecessary for external references to be made at run-time. Figure 5 shows<br />

a cross section of a Malteaser. This is constructed from two polygon models of a sphere with twelve<br />

vertical and horizontal divisions. The outer sphere has a brown chocolate texture and the middle<br />

sphere is given a cut-face texture made from a photograph of the centre of an actual Malteaser.<br />

439

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!