TGX 1.0.3
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
39namespace 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;
169 const fVec3* normal;
170 const uint16_t* face;
171
173
175
180
181 const Mesh3D * next;
182
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
3D box class
Color classes [RGB565, RGB24, RGB32, RGB64, RGBf, HSV].
Main image class.
void freeMeshEXTMEM(Mesh3D< color_t > *mesh)
Delete a mesh allocated with copyMeshEXTMEM().
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.
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.
Utility/miscellaneous functions used throughout the library.
2D vector.
3D vector.
Image class [MAIN CLASS FOR THE 2D API].
Definition: Image.h:143
3D mesh data stucture.
Definition: Mesh3D.h:155
const fVec3 * vertice
Vertex array.
Definition: Mesh3D.h:167
float ambiant_strength
Object ambiant coefficient (how much it reflects the ambiant light component). Typical value: 0....
Definition: Mesh3D.h:176
const char * name
Mesh name, or nullptr.
Definition: Mesh3D.h:185
uint16_t nb_vertices
Number of vertices in the vertex array.
Definition: Mesh3D.h:161
const Mesh3D * next
Next object to draw when chaining is enabled. nullptr at end of chain.
Definition: Mesh3D.h:181
fBox3 bounding_box
Object bounding box.
Definition: Mesh3D.h:183
uint16_t nb_texcoords
Number of texture coordinates in the texcoord array.
Definition: Mesh3D.h:162
float specular_strength
Object ambiant coefficient (how much it reflects the specular light component). Typical value: 0....
Definition: Mesh3D.h:178
const fVec2 * texcoord
Texture coord array (nullptr if none).
Definition: Mesh3D.h:168
const Image< color_t > * texture
Texture image (or nullptr if none).
Definition: Mesh3D.h:172
int specular_exponent
Specular exponent. 0 to disable specular lightning. Typical value between 4 and 64.
Definition: Mesh3D.h:179
float diffuse_strength
Object diffuse coefficient (how much it reflects the diffuse light component). Typical value: 0....
Definition: Mesh3D.h:177
RGBf color
Default color to use when texturing is disabled.
Definition: Mesh3D.h:174
uint16_t nb_normals
Number of normal vectors in the normal array.
Definition: Mesh3D.h:163
uint16_t nb_faces
Number of triangular faces in the mesh.
Definition: Mesh3D.h:164
const uint16_t * face
Array of triangles (format described above).
Definition: Mesh3D.h:170
const fVec3 * normal
Normal vector array (nullptr if none). all vectors must have unit norm.
Definition: Mesh3D.h:169
uint16_t len_face
Number of elements (uint16_t) in the face array.
Definition: Mesh3D.h:165
int32_t id
Set to 1 (may change in future version).
Definition: Mesh3D.h:159
Color in R,G,B float format.
Definition: Color.h:2407