Extrude Polygon and Generate 3D Corner Table
|CS 6491 Computer Graphics (Graduate)||Jarek Rossignac||Fall 2014||Java/Processing||No||Code N/A|
Another project from Jarek Rossignac's Graduate Graphics class. For this assignment we were to take the 2-D polygon editing code from our last assignment and extrude it to 3-D using a Minkowski sum of the 2D polygon with a cylinder. We were to accomplish this by taking the sidewalks we calculated in assignment 4, convert all their corners to vertices, and then extrude that sidewalk in the z direction to build a 3-D mesh. We needed to maintain connectivity (so instead of contained polygons, we have a single polygon. We needed to represent this structure using the same GVNS structure we used in assignment 4. For my assignment, I enabled simultaneous 2D and 3D construction within the same program – pressing 1 toggles between the 2D version and the 3D extrusion. All the editing functionality from assignment 4 is maintained in the 2D version, while the 3D version can be modified by selecting multiple vertices and moving them in either X-Y or Z directions.
For selecting, I enabled both single click and a “Selection Plane”. The selected vertexes are yellow. The Selection Plane is a transparent plane that will select any vertexes in the 3D construct that are between the viewer and the plane. The plane is described by the viewing normal, so as the camera is moved, the plane's geometry stays perpendicular to the viewer, and will select or unselect vertexes as appropriate. To move the plane further or closer, press k and move the mouse up or down – the plane will move further or closer to the eye.
The mouse pointer actually shoots a ray toward the mesh, and selects the verts in the z==0 plane closest to where the ray hits the plane. This also uses the view normal, along with the FOV of the rendering. The moving green sphere represents where on the z==0 plane the mouse is currently selecting, with the three rgb axes moving with the sphere to provide some perspective and sense of placement within the scene. For 3D the intention is to use the Selection Plane to select vertexes (since often multiple verts are required to have a useful effect) so I restricted the ray-cast to the z==0 plane for the location visualization, but it could be easily extended to apply to any z location.
To accomplish the extrusion I take the polygon that has been edited, and then convert its sidewalks to arrays of points (maintaining rounded corners). I find the sidewalk that is contained by no other sidewalk and I then find the points closest to this sidewalk and the the points making up the sidewalks it contains. I duplicate this pair of points in both lists (they parent poly and the contained poly) for every contained poly. I reorder the contained poly so that this duplicated point is at the beginning and end of its list of points, and then I insert this list in the parent list, at the appropriate location, between the duplicated points that were correspond to the closest point in the parent poly.
Doing this for every sidewalk yields a single list of points, which I treat as the floor of the 3D extrusion. I duplicate this list, in reverse order, with some initial Z displacement, for the roof of the 3D extrusion, and then iterate through every point, building vertexes (a structure I use to hold a pt and some other relevant info for a vertex ) and the corner table for the new 3D extrusion. By constructing the corner table carefully, I can hardcode the V,N and S entries for every vertex pair.
Below are videos of the mesh-building and editing process, with links if they don't play :
|Edit and Extrude Original Mesh|
|Multiple Selection Editing|
|Move Top Vertices 1, 2|
|Navigate Connected 3-D Mesh|