Procedural Generation
The mouette.procedural
module implements various functions to generate surface meshes or various shapes directly from code
Procedural shapes
triangle(P0, P1, P2)
Generates a triangle from three vertices
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P0,P1,P2
|
Vec
|
three points |
required |
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
a triangle |
unit_triangle(nu, nv, generate_uvs=False)
Generate a subdivided unit right triangle (half of a unit grid)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nu
|
int
|
number of subdivisions on the horizontal axis |
required |
nv
|
int
|
number of subdivisions on the vertical axis |
required |
generate_uvs
|
bool
|
whether to generate uv-coordinates. Defaults to False. |
False
|
Returns SurfaceMesh: a subdivided unit triangle
quad(P0, P1, P2, triangulate=False)
Generates a quad from three vertices
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P0,P1,P2
|
Vec
|
coordinates of corners. The fourth point is deduced as P2 + P1 - 2*P0 |
required |
triangulate
|
bool
|
whether to output two triangles instead of a quad. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
a quad |
unit_grid(nu, nv, triangulate=False, generate_uvs=False)
Generates a subdivided regular unit grid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nu
|
int
|
number of subdivisions on the horizontal axis |
required |
nv
|
int
|
number of subdivisions on the vertical axis |
required |
triangulate
|
bool
|
whether to split quads into two triangles. Defaults to False. |
False
|
generate_uvs
|
bool
|
whether to generate uv-coordinates. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
a subdivided unit grid of size nu*nv |
ring(N, defect, open=False, n_cover=1)
Computes a ring of triangles with prescribed number of triangles and angle defect at the center.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
N
|
int
|
number of triangles in the ring |
required |
defect
|
float
|
target angle defect to achieve. Position of the central point is adjusted via dichotomy to match this value. |
required |
open
|
bool)
|
whether to connect the last vertex to the first. |
False
|
n_cover
|
int
|
Number of covering of the ring. Defaults to 1. |
1
|
Raises:
Type | Description |
---|---|
Exception
|
Fails if N<3 |
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
the ring |
flat_ring(N, defect, n_cover=1)
tetrahedron(P1, P2, P3, P4, volume=False)
Simple tetrahedron from four points
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P1
|
Vec
|
first point |
required |
P2
|
Vec
|
second point |
required |
P3
|
Vec
|
third point |
required |
P4
|
Vec
|
fourth point |
required |
volume
|
bool
|
whether to generate a cell or just a surface. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
description |
hexahedron(P1, P2, P3, P4, P5, P6, P7, P8, colored=False, triangulate=False, volume=False)
Generate an hexahedron in arbitrary configuration given 8 points. Order and connectivity of points is:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P1
|
to P8 (Vec
|
coordinates of eight vertices |
required |
colored
|
bool
|
if set to true, will add a color attribute on faces. Defaults to False. |
False
|
triangulate
|
bool
|
if set to true, will triangulate the faces. Defaults to False. |
False
|
volume
|
bool
|
if set to true, will also generate three tetrahedra to fill the volume. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
a cube |
hexahedron_4pts(P1, P2, P3, P4, colored=False, volume=False)
Generate an hexahedron given by an absolute position and three points building a basis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P1
|
to P4 (Vec
|
coordinates of vertices |
required |
colored
|
bool
|
if set to true, will add a color attribute on faces to determine. Defaults to False. |
False
|
volume
|
bool
|
if set to true, will also generate three tetrahedra to fill the volume. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
[description] |
axis_aligned_cube(colored=False, triangulate=False)
generated an axis aligned cube as 6 quad faces.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
colored
|
bool
|
if set to true, will add a colo rattribute on faces to determine. Defaults to False. |
False
|
triangulate
|
bool
|
if set to true, will triangulate the faces. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
a cube |
octahedron()
Generate a unit octahedron as the dual mesh of the unit hexahedron
Reference
https://danielsieger.com/blog/2021/01/03/generating-platonic-solids.html
icosahedron(center=Vec(0, 0, 0), radius=1.0, uv=False)
dodecahedron()
Generate a unit dodecahedron as the dual mesh of an icosahedron
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
a dodecahedron |
cylinder(P1, P2, radius=1.0, N=50, fill_caps=True)
Generates a cylinder around the segment defined by P1 and P2
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P1
|
Vec
|
start of the cylinder (center of bottom face) |
required |
P2
|
Vec
|
end of the cylinder (center of top face) |
required |
radius
|
float
|
radius. Defaults to 1.. |
1.0
|
N
|
int
|
number of segments. Defaults to 50. |
50
|
fill_caps
|
bool
|
whether to also generate faces at caps. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
a cylinder |
torus(major_segments=50, minor_segments=30, major_radius=1.0, minor_radius=0.3, triangulate=False)
Generates a torus Args: major_segments (int): number of major segments. Defaults to 50. minor_segments (int): number of minor segments. Defaults to 30. major_radius (float): global radius of the torus. Defaults to 1. minor_radius (float): thickness of the torus. Defaults to 0.3 triangulate (bool, optional): whether to output a triangular or quadmesh. Defaults to False.
References
https://danielsieger.com/blog/2021/05/03/generating-primitive-shapes.html
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
a torus |
sphere_uv(n_lat=30, n_long=50, center=Vec(0.0, 0.0, 0.0), radius=1.0)
Generates a sphere using classical spherical uv-coordinates
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_lat
|
int
|
number of different latitudes for points. Defaults to 30. |
30
|
n_long
|
int
|
number of different longitudes for points. Defaults to 50. |
50
|
center
|
Vec
|
Center position of the sphere. Defaults to Vec(0.,0.,0.). |
Vec(0.0, 0.0, 0.0)
|
radius
|
float
|
Radius of the sphere. Defaults to 1. |
1.0
|
References
https://danielsieger.com/blog/2021/03/27/generating-spheres.html
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
the sphere |
icosphere(n_refine=3, center=Vec(0.0, 0.0, 0.0), radius=1.0)
Generates an icosphere, that is a subdivision of the icosahedron
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_refine
|
int
|
number of subdivisions. Defaults to 3. |
3
|
center
|
Vec
|
center of the sphere. Defaults to Vec(0.,0.,0.). |
Vec(0.0, 0.0, 0.0)
|
radius
|
float
|
radius of the sphere. Defaults to 1.. |
1.0
|
Returns:
Name | Type | Description |
---|---|---|
SurfaceMesh |
SurfaceMesh
|
the sphere |
sphere_fibonacci(n_pts, radius=1.0, build_surface=True)
Generates a point cloud or a surface mesh using fibonacci sampling of a sphere.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_pts
|
int
|
total number of vertices |
required |
radius
|
float
|
Radius of the sphere. Defaults to 1. |
1.0
|
build_surface
|
bool
|
If specified to True, the function will also compute a triangulation of the vertices. This is obtained through a convex hull algorithm (since points lay on a convex shape, the convex hull and the Delaunay triangulation are equivalent). Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
SurfaceMesh
|
[SurfaceMesh | PointCloud]: the generated mesh |
Polyline generation
chain_of_vertices(vertices, loop=False)
Creates a polyline that links the provided vertices in order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vertices
|
ndarray
|
vertex positions. |
required |
loop
|
bool
|
whether to link the last vertex with the first, creating a closed loop. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
PolyLine |
PolyLine
|
description |
vector_field(origins, vectors, length_mult=1.0)
Creates the representation of a vector field from an array of origin points and an array of vectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
origins
|
ndarray
|
size (N,K) with N the number of points and K<=3 the dimension. Origin of the vectors |
required |
vectors
|
ndarray
|
size (N,K) with N the number of points and K<=3 the dimension. Coordinates of each vector. |
required |
length_mult
|
float
|
factor multiplied to each vector to modulate their length for vizualisation purposes. Defaults to 1. |
1.0
|
Raises:
Type | Description |
---|---|
Exception
|
fails if the two arrays (origins and vectors) have a different shape |
Exception
|
fails if one of the two arrays have dimension > 3 |
Returns:
Name | Type | Description |
---|---|---|
PolyLine |
PolyLine
|
the vector field represented as a polyline. |
Transformations
spherify_vertices(points, radius=0.01, n_subdiv=1)
Transforms vertices of a point cloud as icospheres
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
PointCloud
|
the input point cloud |
required |
radius
|
float
|
radius of each sphere. Defaults to 1e-2. |
0.01
|
n_subdiv
|
int
|
number of subdivisions of the icospheres. Defaults to 1. |
1
|
Returns:
Type | Description |
---|---|
SurfaceMesh
|
SurfaceMesh |
cylindrify_edges(mesh, radius=0.05, N=50)
Transforms edges of a polyline as cylinder surface
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mesh
|
PolyLine
|
the input mesh |
required |
radius
|
float
|
Radius of the output cylinders. Defaults to 5e-2. |
0.05
|
N
|
int
|
Number of points inside each circle of the cylinders. Defaults to 50. |
50
|
Returns:
Type | Description |
---|---|
SurfaceMesh
|
SurfaceMesh |
dual_mesh(mesh)
Computes the dual mesh of a mesh
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mesh
|
SurfaceMesh
|
input surface |
required |
Returns:
Type | Description |
---|---|
SurfaceMesh
|
SurfaceMesh |