1 #ifndef RAYLIB_CPP_INCLUDE_MESH_HPP_
2 #define RAYLIB_CPP_INCLUDE_MESH_HPP_
7 #include "./raylib.hpp"
8 #include "./raylib-cpp-utils.hpp"
9 #include "./BoundingBox.hpp"
10 #include "./Model.hpp"
18 Mesh(const ::Mesh& mesh) {
36 other.vertexCount = 0;
37 other.triangleCount = 0;
38 other.vertices =
nullptr;
39 other.texcoords =
nullptr;
40 other.texcoords2 =
nullptr;
41 other.normals =
nullptr;
42 other.tangents =
nullptr;
43 other.colors =
nullptr;
44 other.indices =
nullptr;
45 other.animVertices =
nullptr;
46 other.animNormals =
nullptr;
47 other.boneIds =
nullptr;
48 other.boneWeights =
nullptr;
50 other.vboId =
nullptr;
56 static ::Mesh
Poly(
int sides,
float radius) {
57 return ::GenMeshPoly(sides, radius);
63 static ::Mesh
Plane(
float width,
float length,
int resX,
int resZ) {
64 return ::GenMeshPlane(width, length, resX, resZ);
70 static ::Mesh
Cube(
float width,
float height,
float length) {
71 return ::GenMeshCube(width, height, length);
77 static ::Mesh
Sphere(
float radius,
int rings,
int slices) {
78 return ::GenMeshSphere(radius, rings, slices);
84 static ::Mesh
HemiSphere(
float radius,
int rings,
int slices) {
85 return ::GenMeshHemiSphere(radius, rings, slices);
91 static ::Mesh
Cylinder(
float radius,
float height,
int slices) {
92 return ::GenMeshCylinder(radius, height, slices);
98 static ::Mesh
Cone(
float radius,
float height,
int slices) {
99 return ::GenMeshCone(radius, height, slices);
105 static ::Mesh
Torus(
float radius,
float size,
int radSeg,
int sides) {
106 return ::GenMeshTorus(radius, size, radSeg, sides);
112 static ::Mesh
Knot(
float radius,
float size,
int radSeg,
int sides) {
113 return ::GenMeshKnot(radius, size, radSeg, sides);
120 return ::GenMeshHeightmap(heightmap, size);
127 return ::GenMeshCubicmap(cubicmap, cubeSize);
130 GETTERSETTER(
int, VertexCount, vertexCount)
131 GETTERSETTER(
int, TriangleCount, triangleCount)
132 GETTERSETTER(
float*, Vertices, vertices)
133 GETTERSETTER(
float *, TexCoords, texcoords)
134 GETTERSETTER(
float *, TexCoords2, texcoords2)
135 GETTERSETTER(
float *, Normals, normals)
136 GETTERSETTER(
float *, Tangents, tangents)
137 GETTERSETTER(
unsigned char *, Colors, colors)
138 GETTERSETTER(
unsigned short *, Indices, indices)
139 GETTERSETTER(
float *, AnimVertices, animVertices)
140 GETTERSETTER(
float *, AnimNormals, animNormals)
141 GETTERSETTER(
unsigned char *, BoneIds, boneIds)
142 GETTERSETTER(
float *, BoneWeights, boneWeights)
143 GETTERSETTER(
unsigned int, VaoId, vaoId)
144 GETTERSETTER(
unsigned int *, VboId, vboId)
146 Mesh& operator=(const ::
Mesh& mesh) {
151 Mesh& operator=(
const Mesh&) =
delete;
153 Mesh& operator=(
Mesh&& other) noexcept {
154 if (
this == &other) {
161 other.vertexCount = 0;
162 other.triangleCount = 0;
163 other.vertices =
nullptr;
164 other.texcoords =
nullptr;
165 other.texcoords2 =
nullptr;
166 other.normals =
nullptr;
167 other.tangents =
nullptr;
168 other.colors =
nullptr;
169 other.indices =
nullptr;
170 other.animVertices =
nullptr;
171 other.animNormals =
nullptr;
172 other.boneIds =
nullptr;
173 other.boneWeights =
nullptr;
175 other.vboId =
nullptr;
187 inline void Upload(
bool dynamic =
false) {
188 ::UploadMesh(
this, dynamic);
194 inline void UpdateBuffer(
int index,
void *data,
int dataSize,
int offset = 0) {
195 ::UpdateMeshBuffer(*
this, index, data, dataSize, offset);
201 inline void Draw(const ::Material& material, const ::Matrix& transform)
const {
202 ::DrawMesh(*
this, material, transform);
208 inline void Draw(const ::Material& material, ::
Matrix* transforms,
int instances)
const {
209 ::DrawMeshInstanced(*
this, material, transforms, instances);
217 inline void Export(
const std::string& fileName) {
218 if (!::ExportMesh(*
this, fileName.c_str())) {
227 if (vboId !=
nullptr) {
237 return ::GetMeshBoundingBox(*
this);
251 ::GenMeshTangents(
this);
259 return ::LoadModelFromMesh(*
this);
266 return ::LoadModelFromMesh(*
this);
270 void set(const ::Mesh& mesh) {
271 vertexCount = mesh.vertexCount;
272 triangleCount = mesh.triangleCount;
273 vertices = mesh.vertices;
274 texcoords = mesh.texcoords;
275 texcoords2 = mesh.texcoords2;
276 normals = mesh.normals;
277 tangents = mesh.tangents;
278 colors = mesh.colors;
279 indices = mesh.indices;
280 animVertices = mesh.animVertices;
281 animNormals = mesh.animNormals;
282 boneIds = mesh.boneIds;
283 boneWeights = mesh.boneWeights;
Matrix type (OpenGL style 4x4 - right handed, column major)
Vertex data definning a mesh.
raylib::BoundingBox BoundingBox() const
Compute mesh bounding box limits.
Mesh(const Mesh &)=delete
Load meshes from model file.
void Draw(const ::Material &material, ::Matrix *transforms, int instances) const
Draw multiple mesh instances with material and different transforms.
raylib::Model LoadModelFrom() const
Load model from generated mesh.
::Mesh Sphere(float radius, int rings, int slices)
Generate sphere mesh (standard sphere)
::Mesh Knot(float radius, float size, int radSeg, int sides)
Generate trefoil knot mesh.
void Unload()
Unload mesh from memory (RAM and/or VRAM)
Mesh & GenTangents()
Compute mesh tangents.
void UpdateBuffer(int index, void *data, int dataSize, int offset=0)
Upload mesh vertex data to GPU (VRAM)
::Mesh Cube(float width, float height, float length)
Generate cuboid mesh.
::Mesh Cone(float radius, float height, int slices)
Generate cone/pyramid mesh.
::Mesh Plane(float width, float length, int resX, int resZ)
Generate plane mesh (with subdivisions)
::Mesh Poly(int sides, float radius)
Generate polygonal mesh.
::Mesh HemiSphere(float radius, int rings, int slices)
Generate half-sphere mesh (no bottom cap)
::Mesh Torus(float radius, float size, int radSeg, int sides)
Generate torus mesh.
void Upload(bool dynamic=false)
Upload mesh vertex data to GPU (VRAM)
::Mesh Heightmap(const ::Image &heightmap, ::Vector3 size)
Generate heightmap mesh from image data.
void Draw(const ::Material &material, const ::Matrix &transform) const
Draw a 3d mesh with material and transform.
::Mesh Cylinder(float radius, float height, int slices)
Generate cylinder mesh.
::Mesh Cubicmap(const ::Image &cubicmap, ::Vector3 cubeSize)
Generate cubes-based map mesh from image data.
void Export(const std::string &fileName)
Export mesh data to file.
Exception used for most raylib-related exceptions.
All raylib-cpp classes and functions appear in the raylib namespace.