| 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
40 namespace tgx
41{
42
43
52 template<typename color_t>
53 struct MeshMaterial3Dv2
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
58 const Image<color_t>* texture;
59
60 RGBf color;
61
62 float ambiant_strength;
63 float diffuse_strength;
64 float specular_strength;
65 int specular_exponent;
66 };
67
68
80 template<typename color_t>
81 struct MeshMaterialExtra3Dv2
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
86 RGBf emissive_color;
87 float emissive_strength;
88 const Image<color_t>* emissive_texture;
89 uint32_t flags;
90 };
91
92
120 struct Meshlet3Dv2
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
128 uint32_t payload_offset32;
129
130 uint8_t nb_vertices;
131 uint8_t nb_normals;
132 uint8_t nb_texcoords;
133 uint8_t material_index;
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
247 const MeshMaterial3Dv2<color_t>* materials;
248 const Meshlet3Dv2* meshlets;
249 const uint32_t* payload;
250
251 fBox3 bounding_box;
252
253 const char* name;
254
255 const MeshMaterialExtra3Dv2<color_t>* material_extras;
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
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.
Vec4.h
4D vector.
tgx::Image
Image class [MAIN CLASS FOR THE 2D API].
Definition: Image.h:145
tgx::Box3< float >
tgx::Mesh3Dv2
Compact meshlet-based 3D mesh data structure.
Definition: Mesh3Dv2.h:239
tgx::Mesh3Dv2::materials
const MeshMaterial3Dv2< color_t > * materials
Material array.
Definition: Mesh3Dv2.h:247
tgx::Mesh3Dv2::name
const char * name
Mesh name, or nullptr.
Definition: Mesh3Dv2.h:253
tgx::Mesh3Dv2::nb_meshlets
uint16_t nb_meshlets
Number of meshlets in the mesh.
Definition: Mesh3Dv2.h:244
tgx::Mesh3Dv2::bounding_box
fBox3 bounding_box
Global object bounding box.
Definition: Mesh3Dv2.h:251
tgx::Mesh3Dv2::nb_materials
uint16_t nb_materials
Number of materials. Must be <= 256 because meshlet material indices are uint8_t.
Definition: Mesh3Dv2.h:245
tgx::Mesh3Dv2::id
int32_t id
Version/id. Expected to be 2162 for Mesh3Dv2.
Definition: Mesh3Dv2.h:242
tgx::Mesh3Dv2::material_extras
const MeshMaterialExtra3Dv2< color_t > * material_extras
Optional material extension array, or nullptr.
Definition: Mesh3Dv2.h:255
tgx::Mesh3Dv2::payload
const uint32_t * payload
32-bit aligned meshlet payload blob.
Definition: Mesh3Dv2.h:249
tgx::Mesh3Dv2::meshlets
const Meshlet3Dv2 * meshlets
Meshlet header array.
Definition: Mesh3Dv2.h:248
tgx::MeshMaterial3Dv2
Material definition for a Mesh3Dv2 object.
Definition: Mesh3Dv2.h:54
tgx::MeshMaterial3Dv2::texture
const Image< color_t > * texture
Optional texture image, or nullptr if the material is not textured.
Definition: Mesh3Dv2.h:58
tgx::MeshMaterial3Dv2::color
RGBf color
Default color to use when texturing is disabled.
Definition: Mesh3Dv2.h:60
tgx::MeshMaterial3Dv2::ambiant_strength
float ambiant_strength
Object ambient coefficient (how much it reflects the ambient light component). Typical value: 0....
Definition: Mesh3Dv2.h:62
tgx::MeshMaterial3Dv2::diffuse_strength
float diffuse_strength
Object diffuse coefficient (how much it reflects the diffuse light component). Typical value: 0....
Definition: Mesh3Dv2.h:63
tgx::MeshMaterial3Dv2::specular_strength
float specular_strength
Object specular coefficient (how much it reflects the specular light component). Typical value: 0....
Definition: Mesh3Dv2.h:64
tgx::MeshMaterial3Dv2::specular_exponent
int specular_exponent
Specular exponent. 0 to disable specular lighting. Typical value between 4 and 64.
Definition: Mesh3Dv2.h:65
tgx::MeshMaterialExtra3Dv2
Optional material extension for a Mesh3Dv2 object.
Definition: Mesh3Dv2.h:82
tgx::MeshMaterialExtra3Dv2::emissive_strength
float emissive_strength
Emissive multiplier. 0.0f disables emission.
Definition: Mesh3Dv2.h:87
tgx::MeshMaterialExtra3Dv2::flags
uint32_t flags
Reserved per-material behavior flags. 0 means default behavior.
Definition: Mesh3Dv2.h:89
tgx::MeshMaterialExtra3Dv2::emissive_texture
const Image< color_t > * emissive_texture
Optional emissive texture image, or nullptr.
Definition: Mesh3Dv2.h:88
tgx::MeshMaterialExtra3Dv2::emissive_color
RGBf emissive_color
Emissive color. Black means no color emission.
Definition: Mesh3Dv2.h:86
tgx::Meshlet3Dv2
Header for a single meshlet inside a Mesh3Dv2 object.
Definition: Mesh3Dv2.h:121
tgx::Meshlet3Dv2::nb_normals
uint8_t nb_normals
Number of local normals.
Definition: Mesh3Dv2.h:131
tgx::Meshlet3Dv2::nb_vertices
uint8_t nb_vertices
Number of local vertices. With the uint8_t face stream format, this must be <= 128.
Definition: Mesh3Dv2.h:130
tgx::Meshlet3Dv2::payload_offset32
uint32_t payload_offset32
Offset of this meshlet payload in Mesh3Dv2::payload, in 32-bit words.
Definition: Mesh3Dv2.h:128
tgx::Meshlet3Dv2::material_index
uint8_t material_index
Index in Mesh3Dv2::materials.
Definition: Mesh3Dv2.h:133
tgx::Meshlet3Dv2::sphere_radius
uint16_t sphere_radius
Quantized bounding sphere radius.
Definition: Mesh3Dv2.h:125
tgx::Meshlet3Dv2::sphere_center
int16_t sphere_center[3]
Quantized bounding sphere center relative to the global bounding-box center.
Definition: Mesh3Dv2.h:122
tgx::Meshlet3Dv2::cone_cos
int16_t cone_cos
Signed-normalized cone cosine. Values <= -32767 disable meshlet cone culling.
Definition: Mesh3Dv2.h:126
tgx::Meshlet3Dv2::nb_texcoords
uint8_t nb_texcoords
Number of local texture coordinates.
Definition: Mesh3Dv2.h:132
tgx::Meshlet3Dv2::cone_dir
int16_t cone_dir[3]
Signed-normalized quantized visibility cone direction.
Definition: Mesh3Dv2.h:123
tgx::RGBf
Color in R,G,B float format.
Definition: Color.h:2407