Untitled
Loading...
Searching...
No Matches
mesh.c File Reference

Mesh functions that modify and initialize Mesh data. More...

#include <math.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "utilities/types.h"
#include "utilities/utilities.h"
#include "utilities/mathf.h"
#include "core/mesh.h"
#include "uthash/uthash.h"

Go to the source code of this file.

Data Structures

struct  WeldedVertexKey
struct  WeldedEntry
struct  EdgePairKey
struct  EdgePairEntry

Functions

WeldedVertexKey get_welded_key (vec3 pos, float epsilon)
 Quantizes a position to its voxel boundary to be used as a WeldedVertexKey.
void clean_up_hull (Vector *in_vertices, Vector *in_faces)
 Removes extraneous points from a ConvexHull that aren't referenced by its HullFaces after running incremental_hull().
void check_face_visibility (vec3 p, Vector vertices, Vector hull_faces, Vector hull_indices, Vector *visible_faces_indices)
 Checks what faces are visible (facing) the given point.
void check_horizon_edges (MeshFace *face, Vector vertices, Vector *edges, Vector *counts)
void add_horizon_face_to_hull_faces (size_t p_idx, HorizonEdge e, Vector vertices, vec3 center, Vector *hull_faces, Vector *hull_indices, bool epa)
int pick_lowest_point (ConvexHull *hull)
bool setup_initial_hull_points (ConvexHull *hull)
void build_adjacency_map (Mesh *mesh)
 Builds a map of TriangleAdjacency over adjacent MeshFaces on the Mesh.
int find_mn_by_name (char name[256])
 Finds a Mesh inside of Globals.meshes via string.
void deduplicate (Vector *in_verts, Vector *faces)
 Deduplicates vertices.
void expand_hull (vec3 p, int index, Vector *vertices, Vector *hull_faces, Vector *hull_indices, Vector *horizon_edges, Vector *horizon_counts, Vector *visible_faces_indices, vec3 centroid)
void incremental_hull (ConvexHull *hull)
 Deduplicates vertices.
void compute_mesh_hulls (ConvexHull *hull)
 Combines contiguous triangles with same normals into one face.

Variables

EdgePairEntry * edge_pair_table = NULL
WeldedEntry * welded_table = NULL

Detailed Description

Mesh functions that modify and initialize Mesh data.

Definition in file mesh.c.


Data Structure Documentation

◆ WeldedVertexKey

struct WeldedVertexKey

Definition at line 16 of file mesh.c.

Data Fields
int32_t x
int32_t y
int32_t z

◆ WeldedEntry

struct WeldedEntry

Definition at line 23 of file mesh.c.

Data Fields
WeldedVertexKey key
size_t index
UT_hash_handle hh

◆ EdgePairKey

struct EdgePairKey

Definition at line 31 of file mesh.c.

Data Fields
int32_t a
int32_t b

◆ EdgePairEntry

struct EdgePairEntry

Definition at line 38 of file mesh.c.

Data Fields
EdgePairKey key
Vector tris
UT_hash_handle hh

Function Documentation

◆ get_welded_key()

WeldedVertexKey get_welded_key ( vec3 pos,
float epsilon )

Quantizes a position to its voxel boundary to be used as a WeldedVertexKey.

Note
The point of this is to avoid points that are slightly offset from one another breaking the adjacency map.
Parameters
posThe position.
epsilonThe epsilon that controls how quantized the positions become.
Returns
The resulting key.

Definition at line 82 of file mesh.c.

References get_welded_key(), vec3::x, WeldedVertexKey::x, vec3::y, WeldedVertexKey::y, vec3::z, and WeldedVertexKey::z.

Referenced by build_adjacency_map(), and get_welded_key().

◆ clean_up_hull()

void clean_up_hull ( Vector * in_vertices,
Vector * in_faces )

Removes extraneous points from a ConvexHull that aren't referenced by its HullFaces after running incremental_hull().

Parameters
in_verticesThe vertices to test.
in_facesThe faces to test against.

Definition at line 297 of file mesh.c.

References Vector::buffer, CAST_VEC, clean_up_hull(), Vector::count, deduplicate(), MeshFace::indices, init_vector(), vec3_equal(), and vector_expand().

Referenced by clean_up_hull(), and incremental_hull().

◆ check_face_visibility()

void check_face_visibility ( vec3 p,
Vector vertices,
Vector hull_faces,
Vector hull_indices,
Vector * visible_faces_indices )

Checks what faces are visible (facing) the given point.

Parameters
pThe new point to check against.
verticesThe current vec3 vertices on the ConvexHull.
hull_facesThe current MeshFaces on the ConvexHull.
hull_indicesThe indices that are indirections into hull_faces that provide all valid faces.
visible_faces_indicesThe expanding list of visible faces.

\(\text{ADD TO LIST, if } ((p - f_A) \cdot \vec{f_N}) \gt 0\)

Definition at line 349 of file mesh.c.

References CAST_VEC, check_face_visibility(), Vector::count, MeshFace::indices, MeshFace::normal, vec3_dot(), vec3_sub(), and vector_expand().

Referenced by check_face_visibility(), and expand_hull().

◆ check_horizon_edges()

void check_horizon_edges ( MeshFace * face,
Vector vertices,
Vector * edges,
Vector * counts )

◆ add_horizon_face_to_hull_faces()

void add_horizon_face_to_hull_faces ( size_t p_idx,
HorizonEdge e,
Vector vertices,
vec3 center,
Vector * hull_faces,
Vector * hull_indices,
bool epa )

◆ pick_lowest_point()

int pick_lowest_point ( ConvexHull * hull)

◆ setup_initial_hull_points()

◆ build_adjacency_map()

◆ find_mn_by_name()

int find_mn_by_name ( char name[256])

Finds a Mesh inside of Globals.meshes via string.

Parameters
nameThe name to compare.
Returns
The index of the mesh.
Warning
Returns -1 on failure.

Definition at line 229 of file mesh.c.

References CAST_VEC, Vector::count, find_mn_by_name(), MeshNode::free, GLOBALS, Globals::mesh_nodes, and MeshNode::name.

Referenced by find_mn_by_name(), and load_lightmap_from_binary().

◆ deduplicate()

void deduplicate ( Vector * in_verts,
Vector * faces )

Deduplicates vertices.

Parameters
in_vertsThe vec3s of the ConvexHull.
facesThe MeshFaces of the ConvexHull.

Definition at line 248 of file mesh.c.

References Vector::buffer, CAST_VEC, Vector::count, deduplicate(), MeshFace::indices, init_vector(), vec3_equal(), and vector_expand().

Referenced by clean_up_hull(), and deduplicate().

◆ expand_hull()

void expand_hull ( vec3 p,
int index,
Vector * vertices,
Vector * hull_faces,
Vector * hull_indices,
Vector * horizon_edges,
Vector * horizon_counts,
Vector * visible_faces_indices,
vec3 centroid )

◆ incremental_hull()

◆ compute_mesh_hulls()

void compute_mesh_hulls ( ConvexHull * hull)

Variable Documentation

◆ edge_pair_table

EdgePairEntry* edge_pair_table = NULL

Definition at line 92 of file mesh.c.

Referenced by build_adjacency_map().

◆ welded_table

WeldedEntry* welded_table = NULL

Definition at line 93 of file mesh.c.

Referenced by build_adjacency_map().