Avara3D 0.2.0
C++ API reference
MeshElement.h
1//
2// MeshElement.h
3// avara3d
4//
5// Created by Morgan Davis on 12/23/16.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_MESH_MESHELEMENT_H
10#define AVARA3D_MESH_MESHELEMENT_H
11
12#include <climits>
13#include <cstddef>
14#include <memory>
15#include <span>
16#include <vector>
17
18#include "a3d/Assert.h"
19#include "a3d/Math.h"
20#include "a3d/mesh/AABB.h"
21#include "a3d/mesh/IndexFormats.h"
22#include "a3d/mesh/PrimitiveTopology.h"
23#include "a3d/mesh/VertexLayout.h"
24#include "a3d/util/Bitmask.h"
25
26namespace a3d {
27
28 class Line;
29 class Material;
30 class Node;
31 class GLSLProgram;
32 class Renderer;
33 class RenderContext;
34 class RenderItem;
35
44
45 public:
46 // [Public Lifecycle Functions]
47
65 MeshElement(VertexLayout layout,
66 std::span<const std::byte> vertexBytes,
67 uint32_t vertexCount,
68 uint16_t vertexStride,
69 PrimitiveTopology topology,
70 IndexFormat indexFormat,
71 std::span<const std::byte> indexBytes,
72 uint32_t indexCount);
73 virtual ~MeshElement();
74
75 // [Internal Types]
76
77 enum class DirtyMask : uint32_t {
78 None = 0,
79 VertexData = 1 << 0,
80 IndexData = 1 << 1,
81 // AABB?
82 All = UINT_MAX
83 };
84
85 // [Internal Member Functions]
86
87 PrimitiveTopology topology() const;
88
89 VertexLayout vertexLayout() const;
90 uint32_t vertexCount() const;
91 std::span<const std::byte> vertexBytes() const;
92 uint16_t vertexStride() const;
93
94 IndexFormat indexFormat() const;
95 uint32_t indexCount() const;
96 std::span<const std::byte> indexBytes() const;
97
98 const AABB& localAABB() const;
99 AABB worldAABB(const math::mat4& worldMat, bool vertfit) const;
100 math::vec3 localExtent() const;
101 math::vec3 worldExtent(const math::mat4& worldTransform) const;
102
103 void beginBuild(VertexLayout layout,
104 uint16_t vertexStride,
105 PrimitiveTopology topology,
106 IndexFormat indexFormat,
107 uint32_t reserveVerts = 0,
108 uint32_t reserveIndices = 0);
109 void appendVertexBytes(const void* vertexBytes);
110 void appendIndex(uint32_t idx);
111 void appendTriangle(uint32_t a, uint32_t b, uint32_t c);
112 void endBuild(bool recomputeAABB = true);
113
114 void burnTransform(const math::mat4& transform, bool normals);
115
116 DirtyMask dirtyMask() const;
117 void dirtyMask(DirtyMask mask);
118
119 protected:
120 // [Protected Member Functions]
121
122 void genLocalAABB();
123
124 // [Protected Lifecycle]
125
126 MeshElement();
127
128 // [Protected Member Variables]
129
130 PrimitiveTopology _topology;
131 VertexLayout _vertexLayout;
132 std::vector<std::byte> _vertexData;
133 uint32_t _vertexCount;
134 uint16_t _vertexStride;
135 IndexFormat _indexFormat;
136 std::vector<std::byte> _indexData;
137 uint32_t _indexCount;
138 AABB _localAABB;
139 DirtyMask _dirtyMask;
140 };
141
142 namespace util::bitmask {
143
144 template<>
145 struct enable_ops<MeshElement::DirtyMask> : std::true_type {};
146
147 }
148}
149
150#endif // AVARA3D_MESH_MESHELEMENT_H
Owns the vertex and optional index data for one mesh primitive.
Definition: MeshElement.h:43
MeshElement(VertexLayout layout, std::span< const std::byte > vertexBytes, uint32_t vertexCount, uint16_t vertexStride, PrimitiveTopology topology, IndexFormat indexFormat, std::span< const std::byte > indexBytes, uint32_t indexCount)
Creates a MeshElement by copying the supplied vertex and index data.
Axis-aligned bounding box defined by minimum and maximum corners.
Definition: AABB.h:17