Start building mesh primitives.

This commit is contained in:
James Grogan 2022-11-18 15:11:54 +00:00
parent a20c0183df
commit fcd90b5db4
30 changed files with 856 additions and 97 deletions

View file

@ -2,6 +2,8 @@
#include "MeshBuilder.h"
#include <math.h>
#include <iostream>
std::unique_ptr<TriMesh> MeshPrimitives::buildRectangleAsTriMesh()
@ -29,6 +31,85 @@ std::unique_ptr<TriMesh> MeshPrimitives::buildRectangleAsTriMesh()
return MeshBuilder::buildTriMesh(locations, edge_ids, face_ids);
}
std::unique_ptr<TriMesh> MeshPrimitives::buildRoundedRectangleAsTriMesh(double radius, double aspect_ratio, unsigned num_segments)
{
unsigned num_fans = 4;
unsigned num_nodes_per_fan = num_segments + 2;
VecPoints locations(num_fans * num_nodes_per_fan);
double rect_start_x = radius;
double rect_end_x = 1.0 - radius;
double rect_end_y = 1.0 - radius;
double delta_theta = (M_PI/4.0) / double (num_segments);
double running_theta = 0;
locations[0] = {rect_end_x, radius};
unsigned offset = 1;
for (unsigned idx=0; idx<=num_segments; idx++)
{
locations[offset + idx] = {rect_end_x + radius*sin(running_theta), radius*(1.0 - cos(running_theta))};
running_theta += delta_theta;
}
offset += num_segments;
locations[offset] = {rect_end_x, rect_end_y};
offset++;
running_theta = 0;
for (unsigned idx=0; idx<=num_segments;idx++)
{
locations[offset + idx] = {rect_end_x + radius*cos(running_theta), rect_end_y + radius*sin(running_theta)};
running_theta += delta_theta;
}
offset += num_segments;
locations[offset] = {rect_start_x, rect_end_y};
offset ++;
running_theta = 0;
for (unsigned idx=0; idx<=num_segments;idx++)
{
locations[offset + idx] = {rect_start_x - radius*sin(running_theta), rect_end_y + radius*cos(running_theta)};
running_theta += delta_theta;
}
offset += num_segments;
locations[offset] = {rect_start_x, radius};
offset++;
running_theta = 0;
for (unsigned idx=0; idx<=num_segments;idx++)
{
locations[offset + idx] = {rect_start_x - radius*cos(running_theta), radius *(1 - sin(running_theta))};
running_theta += delta_theta;
}
unsigned num_edges_per_fan = 2*num_segments + 1;
unsigned num_inner_rect_edges = 3*num_fans;
EdgeIds edge_ids(num_edges_per_fan*num_fans + num_inner_rect_edges + 1);
// Fan edges
for (unsigned jdx=0; jdx< num_fans; jdx++)
{
unsigned node_offset = jdx*num_nodes_per_fan;
unsigned edge_offset = jdx*num_edges_per_fan;
// Inner edges
for(unsigned idx=0; idx<=num_segments; idx++)
{
edge_ids[edge_offset + idx] = {node_offset, node_offset + idx + 1};
}
// Outer edges
for(unsigned idx=0; idx<num_segments; idx++)
{
edge_ids[edge_offset + num_segments + 1 + idx] = {node_offset + idx + 1, node_offset + idx + 2};
}
}
// Inner rect edges
unsigned edge_offset = num_edges_per_fan*num_fans;
}
std::unique_ptr<LineMesh> MeshPrimitives::buildRectangleAsLineMesh()
{
VecPoints locations = {