Euphoria
geom.builder.h
Go to the documentation of this file.
1#pragma once
2
3// #include "eu/render/color.h"
4
5namespace eu::core
6{
7struct Geom;
8}
9
11{
12
19using Index = u64;
20
22enum class SideCount
23{
26};
27
29enum class NormalsFacing
30{
31 In,
32 Out
33};
34
46
50{
54
55 Triangle(const Vertex& a, const Vertex& b, const Vertex& c);
56};
57
58using Influence4 = std::array<std::size_t, 4>;
59
61struct Builder
62{
66 Index add_color(const Lin_rgb& color);
67 void add_weight(const v4& weight);
69
70 // find or add
74 Index foa_color(const Lin_rgb& color, float max_diff);
75
77 Builder& add_quad(bool ccw, const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3);
78 Builder& add_face(const std::vector<Vertex>&);
79
80 Builder& move(const v3& dir);
83
84 [[nodiscard]] Geom to_geom() const;
85
86 Builder& write_obj(const std::string& path);
87
88 std::vector<std::vector<Vertex>> faces; // each face needs to have 3 or more vertices
89 std::vector<v3> positions;
90 std::vector<n3> normals;
91 std::vector<v2> texcoords;
92 std::vector<v3> lin_colors;
93 std::vector<v4> weights;
94 std::vector<Influence4> influences;
95};
96
97
98
106Builder create_box(float x, float y, float z, NormalsFacing normals_facing, const Rgb& color = colors::white);
107
108
109
110Builder create_xz_plane(float x, float z, bool invert, const Rgb& color = colors::white);
111
112
113
114Builder create_xy_plane(float x, float y, SideCount two_sided, const Rgb& color = colors::white);
115
116
117
127);
128
133} // namespace eu::core::geom
Builder create_box(float x, float y, float z, NormalsFacing normals_facing, const Rgb &color=colors::white)
Creates a box/cube mesh.
u64 Index
A type alias for the index used in the Builder.
std::array< std::size_t, 4 > Influence4
Builder create_xy_plane(float x, float y, SideCount two_sided, const Rgb &color=colors::white)
SideCount
An enum describing if a face is one or two-sided.
NormalsFacing
The possible directions that normals can face.
Builder create_uv_sphere(float diameter, int longitude_count, int latitude_count, NormalsFacing normals_facing, const Rgb &color=colors::white)
Creates a UV sphere mesh.
Builder create_xz_plane(float x, float z, bool invert, const Rgb &color=colors::white)
constexpr auto white
Definition colors.h:156
std::uint64_t u64
Definition ints.h:15
Represents a linear sRGB color.
Definition colors.h:29
A (inclusive) range between two values.
Definition range.h:19
Represents color in gamma (non-linear) space (aka sRGB).
Definition colors.h:14
vertices and triangles
Definition geom.h:30
A helper utility to create a Geom.
Index foa_text_coord(const v2 &v, float max_diff)
Index add_position(const v3 &pos)
std::vector< v3 > lin_colors
in linear space
std::vector< v3 > positions
Builder & add_face(const std::vector< Vertex > &)
void add_weight(const v4 &weight)
void add_influence(const Influence4 &weight)
Index foa_normal(const n3 &norm, float max_diff)
Builder & write_obj(const std::string &path)
std::vector< Influence4 > influences
std::vector< n3 > normals
std::vector< v4 > weights
std::vector< std::vector< Vertex > > faces
Builder & scale(float scale)
Index foa_position(const v3 &pos, float max_diff)
Index add_normal(const n3 &norm)
Builder & move(const v3 &dir)
std::vector< v2 > texcoords
Builder & invert_normals()
Index add_color(const Lin_rgb &color)
Index foa_color(const Lin_rgb &color, float max_diff)
Index add_text_coord(const v2 &tc)
Builder & add_quad(bool ccw, const Vertex &v0, const Vertex &v1, const Vertex &v2, const Vertex &v3)
Builder & add_triangle(const Triangle &t)
A simple triangle face in a Builder.
Triangle(const Vertex &a, const Vertex &b, const Vertex &c)
A single vertex referencing the shared data in the Builder.
Vertex(Index pnt, Index clr)
Vertex(Index a_position, Index a_normal, Index a_texture, Index a_color)
a 3d unit (vector)
Definition vec3.h:94
a 2d vector
Definition vec2.h:17
a 3d vector
Definition vec3.h:27
A 4d vector.
Definition vec4.h:17