| TGX 1.0.7 A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.

Loading...
Searching...
No Matches
Classes | Functions
Mesh3D.h File Reference

3D model mesh class. More...

`#include "Misc.h"`
`#include "Vec2.h"`
`#include "Vec3.h"`
`#include "Box3.h"`
`#include "Color.h"`
`#include "Image.h"`
`#include <stdint.h>`
`#include "Mesh3D.inl"`

Go to the source code of this file.

## Classes
struct | tgx::Mesh3D< color_t >
| 3D mesh data stucture. More...

## Functions
template<typename color_t >
const Mesh3D< color_t > * | tgx::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. More...
template<typename color_t >
Mesh3D< color_t > * | tgx::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. More...
template<typename color_t >
void | tgx::freeMeshEXTMEM (Mesh3D< color_t > *mesh)
| Delete a mesh allocated with copyMeshEXTMEM(). More...

## Detailed Description

3D model mesh class.

## Function Documentation

## ◆ cacheMesh()

template<typename color_t >

const Mesh3D< color_t > * tgx::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.

A typical scenario for using this method is when when using a MCU (Teesny, ESP32..) with limited RAM and slow FLASH memory.

The method copy as much as it can into the given RAM1/RAM2 buffers but will leave the arrays that are to big in their current place. The method never 'fails' but it may return the original mesh if caching is not possible.

A C-string describes which arrays should be copied and in which order:

- "V" = vertex array.
- "N" = normal array.
- "T" = texture array.
- "I" = texture image
- "F" = face arrays.

For example "VIT" means: "copy vertex arrays first, then image texture and finally texture coord (if there is still room)".

Remarks
  1. The memory buffers supplied do not need to be be aligned, the method takes care of it.
  2. The method also caches the sub-meshes linked after this one.

Parameters

  mesh | Pointer to the mesh to cache.
  ram1_buffer | pointer to the first memory buffer (should have the fastest access).
  ram1_size | size in bytes of the ram1 buffer.
  ram2_buffer | pointer to a second memory buffer, may be nullptr.
  ram2_size | size in bytes of the ram2 buffer or 0 if not supplied.
  copy_order | (Optional) c string that describe which array should be copied and in which order.
  ram1_used | If non-null, the number of bytes consumed in ram1_buffer is put here.
  ram2_used | If non-null, the number of bytes consumed in ram2_buffer is put here.

Returns
  The cached mesh (or the initial mesh if nothing was cached).

## ◆ copyMeshEXTMEM()

template<typename color_t >

Mesh3D< color_t > * tgx::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.

Attention
  This method is defined only for Teensy 4.1

Remarks
  1. Obviously, external RAM must be present...
  2. Only arrays in PROGMEM are copied to EXTMEM. Arrays located elsewhere are not copied.
  3. The source mesh must not have any part located in EXTMEM already or the method will fail.
  4. In practice, it is most efficient to copy textures to EXTMEM (the other arrays provide less improvments).

Returns
  a pointer to the new mesh or nullptr on error (nothing is allocated in that case). the methods also copies the sub-meshes linked to this one (via the ->next pointer).

## ◆ freeMeshEXTMEM()

template<typename color_t >

void tgx::freeMeshEXTMEM | ( | Mesh3D< color_t > * | mesh | ) |

Delete a mesh allocated with copyMeshEXTMEM().

Attention
  This method is defined only for Teensy 4.1

Deletes also the linked sub-meshes is any.