TGX 1.1.1
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
80 template<typename color_t>
82 {
83 // make sure right away that the template parameter is admissible to prevent cryptic error message later.
84 static_assert(is_color<color_t>::value, "color_t must be one of the color types defined in Color.h");
85
89 uint32_t flags;
90 };
91
92
121 {
122 int16_t sphere_center[3];
123 int16_t cone_dir[3];
124
125 uint16_t sphere_radius;
126 int16_t cone_cos;
127
129
130 uint8_t nb_vertices;
131 uint8_t nb_normals;
132 uint8_t nb_texcoords;
134 };
135
136
237 template<typename color_t>
238 struct Mesh3Dv2
239 {
240 static_assert(is_color<color_t>::value, "color_t must be one of the color types defined in Color.h");
241
242 int32_t id;
243
244 uint16_t nb_meshlets;
245 uint16_t nb_materials;
246
249 const uint32_t* payload;
250
252
253 const char* name;
254
256 };
257
258
308 template<typename color_t> const Mesh3Dv2<color_t>* cacheMesh(const Mesh3Dv2<color_t>* mesh,
309 void* ram1_buffer, size_t ram1_size,
310 void* ram2_buffer, size_t ram2_size,
311 const char* copy_order = "PLMI",
312 size_t* ram1_used = nullptr,
313 size_t* ram2_used = nullptr);
314
315
319 template<typename color_t> const Mesh3Dv2<color_t>* cacheMesh(const Mesh3Dv2<color_t>* mesh,
320 void* ram_buffer, size_t ram_size,
321 const char* copy_order = "PLMI",
322 size_t* ram_used = nullptr);
323
324
325#if defined(ARDUINO_TEENSY41)
326
356 template<typename color_t> Mesh3Dv2<color_t>* copyMeshEXTMEM(const Mesh3Dv2<color_t>* mesh,
357 bool copy_payload = false,
358 bool copy_meshlets = false,
359 bool copy_materials = false,
360 bool copy_textures = true,
361 size_t* extmem_used = nullptr);
362
363
369 template<typename color_t> void freeMeshEXTMEM(Mesh3Dv2<color_t>* mesh);
370
371#endif
372
373
374}
375
376
377#include "Mesh3Dv2.inl"
378
379
380#endif
381
382#endif
383
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:239
const MeshMaterial3Dv2< color_t > * materials
Material array.
Definition: Mesh3Dv2.h:247
const char * name
Mesh name, or nullptr.
Definition: Mesh3Dv2.h:253
uint16_t nb_meshlets
Number of meshlets in the mesh.
Definition: Mesh3Dv2.h:244
fBox3 bounding_box
Global object bounding box.
Definition: Mesh3Dv2.h:251
uint16_t nb_materials
Number of materials. Must be <= 256 because meshlet material indices are uint8_t.
Definition: Mesh3Dv2.h:245
int32_t id
Version/id. Expected to be 2162 for Mesh3Dv2.
Definition: Mesh3Dv2.h:242
const MeshMaterialExtra3Dv2< color_t > * material_extras
Optional material extension array, or nullptr.
Definition: Mesh3Dv2.h:255
const uint32_t * payload
32-bit aligned meshlet payload blob.
Definition: Mesh3Dv2.h:249
const Meshlet3Dv2 * meshlets
Meshlet header array.
Definition: Mesh3Dv2.h:248
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
Optional material extension for a Mesh3Dv2 object.
Definition: Mesh3Dv2.h:82
float emissive_strength
Emissive multiplier. 0.0f disables emission.
Definition: Mesh3Dv2.h:87
uint32_t flags
Reserved per-material behavior flags. 0 means default behavior.
Definition: Mesh3Dv2.h:89
const Image< color_t > * emissive_texture
Optional emissive texture image, or nullptr.
Definition: Mesh3Dv2.h:88
RGBf emissive_color
Emissive color. Black means no color emission.
Definition: Mesh3Dv2.h:86
Header for a single meshlet inside a Mesh3Dv2 object.
Definition: Mesh3Dv2.h:121
uint8_t nb_normals
Number of local normals.
Definition: Mesh3Dv2.h:131
uint8_t nb_vertices
Number of local vertices. With the uint8_t face stream format, this must be <= 128.
Definition: Mesh3Dv2.h:130
uint32_t payload_offset32
Offset of this meshlet payload in Mesh3Dv2::payload, in 32-bit words.
Definition: Mesh3Dv2.h:128
uint8_t material_index
Index in Mesh3Dv2::materials.
Definition: Mesh3Dv2.h:133
uint16_t sphere_radius
Quantized bounding sphere radius.
Definition: Mesh3Dv2.h:125
int16_t sphere_center[3]
Quantized bounding sphere center relative to the global bounding-box center.
Definition: Mesh3Dv2.h:122
int16_t cone_cos
Signed-normalized cone cosine. Values <= -32767 disable meshlet cone culling.
Definition: Mesh3Dv2.h:126
uint8_t nb_texcoords
Number of local texture coordinates.
Definition: Mesh3Dv2.h:132
int16_t cone_dir[3]
Signed-normalized quantized visibility cone direction.
Definition: Mesh3Dv2.h:123
Color in R,G,B float format.
Definition: Color.h:2407