| TGX 1.1.0 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 structure. 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 cached version of a Mesh3D object by copying selected data arrays into one or two user-supplied RAM buffers. More...
template<typename color_t >
const Mesh3D< color_t > * | tgx::cacheMesh (const Mesh3D< color_t > *mesh, void *ram_buffer, size_t ram_size, const char *copy_order="VNTIF", size_t *ram_used=nullptr)
| Convenience overload of cacheMesh() with a single RAM buffer.
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 Mesh3D object where selected PROGMEM arrays 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 cached version of a Mesh3D object by copying selected data arrays into one or two user-supplied RAM buffers.

This is useful on MCUs where meshes are stored in slow flash/PROGMEM but some RAM is available for faster rendering. The method first copies the linked Mesh3D structures themselves, then tries to copy the requested arrays in the order specified by copy_order. Each allocation first tries the first buffer; if it does not fit there, it tries the second buffer when supplied. If an array does not fit in either buffer, its original pointer is kept.

Copy-order letters:

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

For example, "VIT" means: copy vertex arrays first, then texture images, then texture-coordinate arrays if there is still room.

Remarks
  1. The memory buffers supplied do not need to be aligned; the method aligns allocations internally.
  2. The method also caches the sub-meshes linked after this one.
  3. The returned mesh points either to cached arrays or to the original arrays for data that did not fit in the supplied buffers.

Parameters

  mesh | Pointer to the Mesh3D object to cache.
  ram1_buffer | Pointer to the first memory buffer, usually the fastest RAM.
  ram1_size | Size in bytes of the first RAM buffer.
  ram2_buffer | Optional pointer to a second memory buffer, may be nullptr.
  ram2_size | Optional size in bytes of the second RAM buffer, or 0 if not supplied.
  copy_order | Optional C string describing which data should be copied and in which order. Default is "VNTIF".
  ram1_used | If non-null, receives the number of bytes consumed in ram1_buffer.
  ram2_used | If non-null, receives the number of bytes consumed in ram2_buffer.

Returns
  The cached mesh object, or the original mesh if even the Mesh3D structures themselves could not be copied.

## ◆ 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 Mesh3D object where selected PROGMEM arrays 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 usually provide smaller improvements.

Returns
  A pointer to the new mesh, or nullptr on error. On error, all allocations performed by the method are freed. The method 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

Also deletes linked sub-meshes, if any.