Euphoria
mesh.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <optional>
4 
5 #include "io/vfs_path.h"
6 
7 #include "base/vec2.h"
8 #include "base/vec3.h"
9 #include "base/rgb.h"
10 #include "core/enum.h"
11 #include "base/aabb.h"
12 
13 
14 namespace eu::io
15 {
16  struct FileSystem;
17  struct FilePath;
18 }
19 
20 
21 namespace eu::core
22 {
23  enum class WrapMode
24  {
25  repeat,
28  };
29 
30 
31  struct MeshPoint
32  {
36 
37  MeshPoint
38  (
39  const vec3f& a_vertex,
40  const vec3f& a_normal,
41  const vec2f& a_uv
42  );
43  };
44 
45 
46  struct MeshFace
47  {
48  int a;
49  int b;
50  int c;
51 
52  MeshFace(int a_a, int a_b, int a_c);
53  };
54 
55 
56  struct MeshPart
57  {
58  unsigned int material;
59  std::vector<MeshPoint> points;
60  std::vector<MeshFace> faces;
61 
62  MeshPart();
63 
64  [[nodiscard]] Aabb calc_aabb() const;
65  };
66 
67 
69  {
72 
74  };
75 
76 
77  struct Material
78  {
79  std::string name;
80  std::optional<io::FilePath> shader;
84  float shininess;
85  float alpha;
86  std::vector<MaterialTexture> textures;
89 
90  Material();
91 
92  void set_texture
93  (
94  const std::string& texture_name,
95  const io::FilePath& texture_path
96  );
97  };
98 
99 
100  struct Mesh
101  {
102  std::vector<Material> materials;
103  std::vector<MeshPart> parts;
104 
105  [[nodiscard]] Aabb calc_aabb() const;
106  };
107 
108 
110  {
112  std::string error;
113  };
114 
115 
116  namespace meshes
117  {
119 
120  Mesh create_cube(float size);
121  Mesh create_sphere(float size, const std::string& texture);
122  Mesh create_box(float width, float height, float depth);
123  }
124 
125 }
Mesh create_box(float width, float height, float depth)
Definition: mesh.cc:716
LoadedMeshOrError load_mesh(io::FileSystem *fs, const io::FilePath &path)
Definition: mesh.cc:664
Mesh create_sphere(float size, const std::string &texture)
Definition: mesh.cc:703
Mesh create_cube(float size)
Definition: mesh.cc:696
WrapMode
Definition: mesh.h:24
Definition: enum.h:8
Definition: aabb.h:15
Definition: rgb.h:62
MaterialTexture(const io::FilePath &p, EnumValue t)
Definition: mesh.cc:66
io::FilePath path
Definition: mesh.h:70
std::vector< MaterialTexture > textures
Definition: mesh.h:86
float alpha
Definition: mesh.h:85
WrapMode wrap_s
Definition: mesh.h:87
void set_texture(const std::string &texture_name, const io::FilePath &texture_path)
Definition: mesh.cc:89
float shininess
Definition: mesh.h:84
std::string name
Definition: mesh.h:79
WrapMode wrap_t
Definition: mesh.h:88
std::optional< io::FilePath > shader
Definition: mesh.h:80
MeshFace(int a_a, int a_b, int a_c)
Definition: mesh.cc:38
std::vector< MeshPoint > points
Definition: mesh.h:59
std::vector< MeshFace > faces
Definition: mesh.h:60
Aabb calc_aabb() const
Definition: mesh.cc:53
unsigned int material
Definition: mesh.h:58
vec3f normal
Definition: mesh.h:34
vec3f vertex
Definition: mesh.h:33
MeshPoint(const vec3f &a_vertex, const vec3f &a_normal, const vec2f &a_uv)
Definition: mesh.cc:26
Aabb calc_aabb() const
Definition: mesh.cc:100
std::vector< MeshPart > parts
Definition: mesh.h:103
std::vector< Material > materials
Definition: mesh.h:102
Definition: vec2.h:33
Definition: vec3.h:48