TGX 1.1.0
A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.
Loading...
Searching...
No Matches
Mesh3Dv2.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_MESH3DV2_H_
23#define _TGX_MESH3DV2_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 "Vec4.h"
33#include "Box3.h"
34#include "Color.h"
35#include "Image.h"
36
37#include <stdint.h>
38
39
40namespace tgx
41{
42
43
52 template<typename color_t>
54 {
55 // make sure right away that the template parameter is admissible to prevent cryptic error message later.
56 static_assert(is_color<color_t>::value, "color_t must be one of the color types defined in Color.h");
57
59
61
66 };
67
68
97 {
98 int16_t sphere_center[3];
99 int16_t cone_dir[3];
100
101 uint16_t sphere_radius;
102 int16_t cone_cos;
103
105
106 uint8_t nb_vertices;
107 uint8_t nb_normals;
108 uint8_t nb_texcoords;
110 };
111
112
205 template<typename color_t>
206 struct Mesh3Dv2
207 {
208 static_assert(is_color<color_t>::value, "color_t must be one of the color types defined in Color.h");
209
210 int32_t id;
211
212 uint16_t nb_meshlets;
213 uint16_t nb_materials;
214
217 const uint32_t* payload;
218
220
221 const char* name;
222 };
223
224
271 template<typename color_t> const Mesh3Dv2<color_t>* cacheMesh(const Mesh3Dv2<color_t>* mesh,
272 void* ram1_buffer, size_t ram1_size,
273 void* ram2_buffer, size_t ram2_size,
274 const char* copy_order = "PLMI",
275 size_t* ram1_used = nullptr,
276 size_t* ram2_used = nullptr);
277
278
282 template<typename color_t> const Mesh3Dv2<color_t>* cacheMesh(const Mesh3Dv2<color_t>* mesh,
283 void* ram_buffer, size_t ram_size,
284 const char* copy_order = "PLMI",
285 size_t* ram_used = nullptr);
286
287
288#if defined(ARDUINO_TEENSY41)
289
318 template<typename color_t> Mesh3Dv2<color_t>* copyMeshEXTMEM(const Mesh3Dv2<color_t>* mesh,
319 bool copy_payload = false,
320 bool copy_meshlets = false,
321 bool copy_materials = false,
322 bool copy_textures = true,
323 size_t* extmem_used = nullptr);
324
325
331 template<typename color_t> void freeMeshEXTMEM(Mesh3Dv2<color_t>* mesh);
332
333#endif
334
335
336}
337
338
339#include "Mesh3Dv2.inl"
340
341
342#endif
343
344#endif
345
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 cached version of a Mesh3D object by copying selected data arrays into one or two user-supp...
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.
Utility/miscellaneous functions used throughout the library.
2D vector.
3D vector.
4D vector.
Image class [MAIN CLASS FOR THE 2D API].
Definition: Image.h:145
Compact meshlet-based 3D mesh data structure.
Definition: Mesh3Dv2.h:207
const MeshMaterial3Dv2< color_t > * materials
Material array.
Definition: Mesh3Dv2.h:215
const char * name
Mesh name, or nullptr.
Definition: Mesh3Dv2.h:221
uint16_t nb_meshlets
Number of meshlets in the mesh.
Definition: Mesh3Dv2.h:212
fBox3 bounding_box
Global object bounding box.
Definition: Mesh3Dv2.h:219
uint16_t nb_materials
Number of materials. Must be <= 256 because meshlet material indices are uint8_t.
Definition: Mesh3Dv2.h:213
int32_t id
Version/id. Expected to be 2162 for Mesh3Dv2.
Definition: Mesh3Dv2.h:210
const uint32_t * payload
32-bit aligned meshlet payload blob.
Definition: Mesh3Dv2.h:217
const Meshlet3Dv2 * meshlets
Meshlet header array.
Definition: Mesh3Dv2.h:216
Material definition for a Mesh3Dv2 object.
Definition: Mesh3Dv2.h:54
const Image< color_t > * texture
Optional texture image, or nullptr if the material is not textured.
Definition: Mesh3Dv2.h:58
RGBf color
Default color to use when texturing is disabled.
Definition: Mesh3Dv2.h:60
float ambiant_strength
Object ambient coefficient (how much it reflects the ambient light component). Typical value: 0....
Definition: Mesh3Dv2.h:62
float diffuse_strength
Object diffuse coefficient (how much it reflects the diffuse light component). Typical value: 0....
Definition: Mesh3Dv2.h:63
float specular_strength
Object specular coefficient (how much it reflects the specular light component). Typical value: 0....
Definition: Mesh3Dv2.h:64
int specular_exponent
Specular exponent. 0 to disable specular lighting. Typical value between 4 and 64.
Definition: Mesh3Dv2.h:65
Header for a single meshlet inside a Mesh3Dv2 object.
Definition: Mesh3Dv2.h:97
uint8_t nb_normals
Number of local normals.
Definition: Mesh3Dv2.h:107
uint8_t nb_vertices
Number of local vertices. With the uint8_t face stream format, this must be <= 128.
Definition: Mesh3Dv2.h:106
uint32_t payload_offset32
Offset of this meshlet payload in Mesh3Dv2::payload, in 32-bit words.
Definition: Mesh3Dv2.h:104
uint8_t material_index
Index in Mesh3Dv2::materials.
Definition: Mesh3Dv2.h:109
uint16_t sphere_radius
Quantized bounding sphere radius.
Definition: Mesh3Dv2.h:101
int16_t sphere_center[3]
Quantized bounding sphere center relative to the global bounding-box center.
Definition: Mesh3Dv2.h:98
int16_t cone_cos
Signed-normalized cone cosine. Values <= -32767 disable meshlet cone culling.
Definition: Mesh3Dv2.h:102
uint8_t nb_texcoords
Number of local texture coordinates.
Definition: Mesh3Dv2.h:108
int16_t cone_dir[3]
Signed-normalized quantized visibility cone direction.
Definition: Mesh3Dv2.h:99
Color in R,G,B float format.
Definition: Color.h:2407