| TGX 1.0.8 A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.

Loading...
Searching...
No Matches
Mesh3D.h
Go to the documentation of this file.
1
5//
6// Copyright 2020 Arvind Singh
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11//version 2.1 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
16// Lesser General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public
19// License along with this library; If not, see <http://www.gnu.org/licenses/>.
20
21
22#ifndef _TGX_MESH3D_H_
23#define _TGX_MESH3D_H_
24
25// only C++, no plain C
26#ifdef __cplusplus
27
28
29#include "Misc.h"
30#include "Vec2.h"
31#include "Vec3.h"
32#include "Box3.h"
33#include "Color.h"
34#include "Image.h"
35
36#include <stdint.h>
37
38
39 namespace tgx
40{
41
42
153 template<typename color_t>
154 struct Mesh3D
155 {
156 // make sure right away that the template parameter is admissible to prevent cryptic error message later.
157 static_assert(is_color<color_t>::value, "color_t must be one of the color types defined in color.h");
158
159 int32_t id;
160
161 uint16_t nb_vertices;
162 uint16_t nb_texcoords;
163 uint16_t nb_normals;
164 uint16_t nb_faces;
165 uint16_t len_face;
166
167 const fVec3* vertice;
168 const fVec2* texcoord;
169 const fVec3* normal;
170 const uint16_t* face;
171
172 const Image<color_t>* texture;
173
174 RGBf color;
175
176 float ambiant_strength;
177 float diffuse_strength;
178 float specular_strength;
179 int specular_exponent;
180
181 const Mesh3D * next;
182
183 fBox3 bounding_box;
184
185 const char* name;
186 };
187
188
189
190
227 template<typename color_t> const Mesh3D<color_t> * cacheMesh(const Mesh3D<color_t> * mesh,
228 void * ram1_buffer, size_t ram1_size,
229 void * ram2_buffer, size_t ram2_size,
230 const char * copy_order = "VNTIF",
231 size_t * ram1_used = nullptr,
232 size_t * ram2_used = nullptr);
233
234
235
236
237
238
239
240#if defined(ARDUINO_TEENSY41)
241
242//******************************************************************************************
243//
244// TEENSY 4 SPECIFIC METHODS
245//
246//******************************************************************************************
247
248
264 template<typename color_t> Mesh3D<color_t>* copyMeshEXTMEM(const Mesh3D<color_t>* mesh,
265 bool copy_vertices = false,
266 bool copy_normals = false,
267 bool copy_texcoords = false,
268 bool copy_textures = true,
269 bool copy_faces = false);
270
271
279 template<typename color_t> void freeMeshEXTMEM(Mesh3D<color_t>* mesh);
280
281
282
283
284//***************************************************************
285// NOT YET IMPLEMENTED : TODO...
286//***************************************************************
287
288
293 //template<typename color_t> Mesh3D<color_t>* copyMeshFromSDToEXTMEM(const char * filename);
294
295
296#endif
297
298
299}
300
301
302
303#include "Mesh3D.inl"
304
305
306#endif
307
308#endif
309
Box3.h
3D box class
Color.h
Color classes [RGB565, RGB24, RGB32, RGB64, RGBf, HSV].
Image.h
Main image class.
tgx::freeMeshEXTMEM
void freeMeshEXTMEM(Mesh3D< color_t > *mesh)
Delete a mesh allocated with copyMeshEXTMEM().
tgx::cacheMesh
const Mesh3D< color_t > * cacheMesh(const Mesh3D< color_t > *mesh, void *ram1_buffer, size_t ram1_size, void *ram2_buffer, size_t ram2_size, const char *copy_order="VNTIF", size_t *ram1_used=nullptr, size_t *ram2_used=nullptr)
Creates a "cache version" of a mesh by copying part of its data into fast memory buffers.
tgx::copyMeshEXTMEM
Mesh3D< color_t > * copyMeshEXTMEM(const Mesh3D< color_t > *mesh, bool copy_vertices=false, bool copy_normals=false, bool copy_texcoords=false, bool copy_textures=true, bool copy_faces=false)
Create a copy of a mesh where specified arrays in PROGMEM are copied to EXTMEM.
Misc.h
Utility/miscellaneous functions used throughout the library.
Vec2.h
2D vector.
Vec3.h
3D vector.
tgx::Image
Image class [MAIN CLASS FOR THE 2D API].
Definition: Image.h:143
tgx::Box3< float >
tgx::Mesh3D
3D mesh data stucture.
Definition: Mesh3D.h:155
tgx::Mesh3D::vertice
const fVec3 * vertice
Vertex array.
Definition: Mesh3D.h:167
tgx::Mesh3D::ambiant_strength
float ambiant_strength
Object ambiant coefficient (how much it reflects the ambiant light component). Typical value: 0....
Definition: Mesh3D.h:176
tgx::Mesh3D::name
const char * name
Mesh name, or nullptr.
Definition: Mesh3D.h:185
tgx::Mesh3D::nb_vertices
uint16_t nb_vertices
Number of vertices in the vertex array.
Definition: Mesh3D.h:161
tgx::Mesh3D::next
const Mesh3D * next
Next object to draw when chaining is enabled. nullptr at end of chain.
Definition: Mesh3D.h:181
tgx::Mesh3D::bounding_box
fBox3 bounding_box
Object bounding box.
Definition: Mesh3D.h:183
tgx::Mesh3D::nb_texcoords
uint16_t nb_texcoords
Number of texture coordinates in the texcoord array.
Definition: Mesh3D.h:162
tgx::Mesh3D::specular_strength
float specular_strength
Object ambiant coefficient (how much it reflects the specular light component). Typical value: 0....
Definition: Mesh3D.h:178
tgx::Mesh3D::texcoord
const fVec2 * texcoord
Texture coord array (nullptr if none).
Definition: Mesh3D.h:168
tgx::Mesh3D::texture
const Image< color_t > * texture
Texture image (or nullptr if none).
Definition: Mesh3D.h:172
tgx::Mesh3D::specular_exponent
int specular_exponent
Specular exponent. 0 to disable specular lightning. Typical value between 4 and 64.
Definition: Mesh3D.h:179
tgx::Mesh3D::diffuse_strength
float diffuse_strength
Object diffuse coefficient (how much it reflects the diffuse light component). Typical value: 0....
Definition: Mesh3D.h:177
tgx::Mesh3D::color
RGBf color
Default color to use when texturing is disabled.
Definition: Mesh3D.h:174
tgx::Mesh3D::nb_normals
uint16_t nb_normals
Number of normal vectors in the normal array.
Definition: Mesh3D.h:163
tgx::Mesh3D::nb_faces
uint16_t nb_faces
Number of triangular faces in the mesh.
Definition: Mesh3D.h:164
tgx::Mesh3D::face
const uint16_t * face
Array of triangles (format described above).
Definition: Mesh3D.h:170
tgx::Mesh3D::normal
const fVec3 * normal
Normal vector array (nullptr if none). all vectors must have unit norm.
Definition: Mesh3D.h:169
tgx::Mesh3D::len_face
uint16_t len_face
Number of elements (uint16_t) in the face array.
Definition: Mesh3D.h:165
tgx::Mesh3D::id
int32_t id
Set to 1 (may change in future version).
Definition: Mesh3D.h:159
tgx::RGBf
Color in R,G,B float format.
Definition: Color.h:2407
tgx::Vec2< float >
tgx::Vec3< float >