| TGX 1.1.4 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
155 template<typename color_t>
156 struct Mesh3D
157 {
158 // make sure right away that the template parameter is admissible to prevent cryptic error message later.
159 static_assert(is_color<color_t>::value, "color_t must be one of the color types defined in color.h");
160
161 int32_t id;
162
163 uint16_t nb_vertices;
164 uint16_t nb_texcoords;
165 uint16_t nb_normals;
166 uint16_t nb_faces;
167 uint16_t len_face;
168
169 const fVec3* vertice;
170 const fVec2* texcoord;
171 const fVec3* normal;
172 const uint16_t* face;
173
174 const Image<color_t>* texture;
175
176 RGBf color;
177
178 float ambiant_strength;
179 float diffuse_strength;
180 float specular_strength;
181 int specular_exponent;
182
183 const Mesh3D * next;
184
185 fBox3 bounding_box;
186
187 const char* name;
188 };
189
190
191
192
235 template<typename color_t> const Mesh3D<color_t> * cacheMesh(const Mesh3D<color_t> * mesh,
236 void * ram1_buffer, size_t ram1_size,
237 void * ram2_buffer, size_t ram2_size,
238 const char * copy_order = "VNTIF",
239 size_t * ram1_used = nullptr,
240 size_t * ram2_used = nullptr);
241
242
246 template<typename color_t> const Mesh3D<color_t> * cacheMesh(const Mesh3D<color_t> * mesh,
247 void * ram_buffer, size_t ram_size,
248 const char * copy_order = "VNTIF",
249 size_t * ram_used = nullptr);
250
251
252
253
254
255
256
257#if defined(ARDUINO_TEENSY41)
258
259//******************************************************************************************
260//
261// TEENSY 4 SPECIFIC METHODS
262//
263//******************************************************************************************
264
265
282 template<typename color_t> Mesh3D<color_t>* copyMeshEXTMEM(const Mesh3D<color_t>* mesh,
283 bool copy_vertices = false,
284 bool copy_normals = false,
285 bool copy_texcoords = false,
286 bool copy_textures = true,
287 bool copy_faces = false);
288
289
297 template<typename color_t> void freeMeshEXTMEM(Mesh3D<color_t>* mesh);
298
299
300
301
302//***************************************************************
303// NOT YET IMPLEMENTED : TODO...
304//***************************************************************
305
306
311 //template<typename color_t> Mesh3D<color_t>* copyMeshFromSDToEXTMEM(const char * filename);
312
313
314#endif
315
316
317}
318
319
320
321#include "Mesh3D.inl"
322
323
324#endif
325
326#endif
327
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 cached version of a Mesh3D object by copying selected data arrays into one or two user-supp...
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 Mesh3D object where selected PROGMEM arrays 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:145
tgx::Box3< float >
tgx::Mesh3D
3D mesh data structure.
Definition: Mesh3D.h:157
tgx::Mesh3D::vertice
const fVec3 * vertice
Vertex array.
Definition: Mesh3D.h:169
tgx::Mesh3D::ambiant_strength
float ambiant_strength
Object ambient coefficient (how much it reflects the ambient light component). Typical value: 0....
Definition: Mesh3D.h:178
tgx::Mesh3D::name
const char * name
Mesh name, or nullptr.
Definition: Mesh3D.h:187
tgx::Mesh3D::nb_vertices
uint16_t nb_vertices
Number of vertices in the vertex array.
Definition: Mesh3D.h:163
tgx::Mesh3D::next
const Mesh3D * next
Next object to draw when chaining is enabled. nullptr at end of chain.
Definition: Mesh3D.h:183
tgx::Mesh3D::bounding_box
fBox3 bounding_box
Object bounding box.
Definition: Mesh3D.h:185
tgx::Mesh3D::nb_texcoords
uint16_t nb_texcoords
Number of texture coordinates in the texcoord array.
Definition: Mesh3D.h:164
tgx::Mesh3D::specular_strength
float specular_strength
Object specular coefficient (how much it reflects the specular light component). Typical value: 0....
Definition: Mesh3D.h:180
tgx::Mesh3D::texcoord
const fVec2 * texcoord
Texture coord array (nullptr if none).
Definition: Mesh3D.h:170
tgx::Mesh3D::texture
const Image< color_t > * texture
Texture image (or nullptr if none).
Definition: Mesh3D.h:174
tgx::Mesh3D::specular_exponent
int specular_exponent
Specular exponent. 0 to disable specular lighting. Typical value between 4 and 64.
Definition: Mesh3D.h:181
tgx::Mesh3D::diffuse_strength
float diffuse_strength
Object diffuse coefficient (how much it reflects the diffuse light component). Typical value: 0....
Definition: Mesh3D.h:179
tgx::Mesh3D::color
RGBf color
Default color to use when texturing is disabled.
Definition: Mesh3D.h:176
tgx::Mesh3D::nb_normals
uint16_t nb_normals
Number of normal vectors in the normal array.
Definition: Mesh3D.h:165
tgx::Mesh3D::nb_faces
uint16_t nb_faces
Number of triangular faces in the mesh.
Definition: Mesh3D.h:166
tgx::Mesh3D::face
const uint16_t * face
Array of triangles (format described above).
Definition: Mesh3D.h:172
tgx::Mesh3D::normal
const fVec3 * normal
Normal vector array (nullptr if none). all vectors must have unit norm.
Definition: Mesh3D.h:171
tgx::Mesh3D::len_face
uint16_t len_face
Number of elements (uint16_t) in the face array.
Definition: Mesh3D.h:167
tgx::Mesh3D::id
int32_t id
Set to 1 (may change in future version).
Definition: Mesh3D.h:161
tgx::RGBf
Color in R,G,B float format.
Definition: Color.h:2405
tgx::Vec2< float >
tgx::Vec3< float >