From c21baf0d92c9a3ad44d46b698fb87d739dd64dc6 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 2 Apr 2021 15:56:35 +0200 Subject: [PATCH] ADDED: GenMeshDefault() #1556 --- src/models.c | 23 +++++++++++++++++++++-- src/raylib.h | 13 +------------ src/rlgl.h | 3 +-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/models.c b/src/models.c index ec7e5f869..3d667944c 100644 --- a/src/models.c +++ b/src/models.c @@ -1501,6 +1501,25 @@ bool IsModelAnimationValid(Model model, ModelAnimation anim) } #if defined(SUPPORT_MESH_GENERATION) +Mesh GenMeshDefault(int vertexCount) +{ + Mesh mesh = { 0 }; + + mesh.vertexCount = vertexCount; + mesh.triangleCount = vertexCount/3; + + mesh.vertices = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float)); + mesh.texcoords = (float *)RL_CALLOC(mesh.vertexCount*2, sizeof(float)); + mesh.normals = (float *)RL_CALLOC(mesh.vertexCount*3, sizeof(float)); + mesh.colors = (unsigned char *)RL_CALLOC(mesh.vertexCount*4, sizeof(unsigned char)); + + // Upload vertex data to GPU (static mesh) + // NOTE: mesh.vboId array is allocated inside UploadMesh() + UploadMesh(&mesh, false); + + return mesh; +} + // Generate polygonal mesh Mesh GenMeshPoly(int sides, float radius) { @@ -1869,7 +1888,7 @@ par_shapes_mesh* par_shapes_create_icosahedron(); // 20 sides polyhedron } // Generate sphere mesh (standard sphere) -RLAPI Mesh GenMeshSphere(float radius, int rings, int slices) +Mesh GenMeshSphere(float radius, int rings, int slices) { Mesh mesh = { 0 }; @@ -1911,7 +1930,7 @@ RLAPI Mesh GenMeshSphere(float radius, int rings, int slices) } // Generate hemi-sphere mesh (half sphere, no bottom cap) -RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices) +Mesh GenMeshHemiSphere(float radius, int rings, int slices) { Mesh mesh = { 0 }; diff --git a/src/raylib.h b/src/raylib.h index c6adb2ec8..3ad0bd82f 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -701,17 +701,6 @@ typedef enum { GAMEPAD_AXIS_RIGHT_TRIGGER = 5 // [1..-1] (pressure-level) } GamepadAxis; -// Mesh vertex attributes -typedef enum { - MESH_VERTEX_POSITION = 1, - MESH_VERTEX_TEXCOORD1 = 2, - MESH_VERTEX_TEXCOORD2 = 4, - MESH_VERTEX_NORMAL = 8, - MESH_VERTEX_TANGENT = 16, - MESH_VERTEX_COLOR = 32, - MESH_VERTEX_INDEX = 64 -} MeshVertexAttributes; - // Material map index typedef enum { MATERIAL_MAP_ALBEDO = 0, // MATERIAL_MAP_DIFFUSE @@ -1398,7 +1387,7 @@ RLAPI void UnloadModelAnimations(ModelAnimation* animations, unsigned int count) RLAPI bool IsModelAnimationValid(Model model, ModelAnimation anim); // Check model animation skeleton match // Mesh generation functions -RLAPI Mesh GenMeshCustom(int vertexCount, int flags); // Generate custom empty mesh (data initialized to 0) +RLAPI Mesh GenMeshDefault(int vertexCount); // Generate an empty mesh with vertex: position, texcoords, normals, colors RLAPI Mesh GenMeshPoly(int sides, float radius); // Generate polygonal mesh RLAPI Mesh GenMeshPlane(float width, float length, int resX, int resZ); // Generate plane mesh (with subdivisions) RLAPI Mesh GenMeshCube(float width, float height, float length); // Generate cuboid mesh diff --git a/src/rlgl.h b/src/rlgl.h index f6de9ec2e..571ebeb96 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -92,7 +92,7 @@ #define RL_FREE(p) free(p) #endif #else - #include "raylib.h" // Required for: Model, Mesh, Material, Shader, Texture2D + #include "raylib.h" // Required for: Shader, Texture2D #endif #include "raymath.h" // Required for: Vector3, Matrix @@ -2772,7 +2772,6 @@ void rlUnloadTexture(unsigned int id) glDeleteTextures(1, &id); } - // Generate mipmap data for selected texture void rlGenerateMipmaps(Texture2D *texture) {