From 9cfc16923c42466d72b93f7c7e3edf96f4ae41dd Mon Sep 17 00:00:00 2001 From: Roddy McNeill Date: Mon, 6 Apr 2026 15:23:19 +1000 Subject: [PATCH] Add GenMeshPlaneData() for CPU-side mesh generation without GPU upload --- src/raylib.h | 3 ++- src/rmodels.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index 6849e7176..af4e9a3c0 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1617,7 +1617,8 @@ RLAPI bool ExportMeshAsCode(Mesh mesh, const char *fileName); // Mesh generation functions 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 GenMeshPlane(float width, float length, int resX, int resZ); // Generate plane mesh (with subdivisions) and upload to GPU +RLAPI Mesh GenMeshPlaneData(float width, float length, int resX, int resZ); // Generate plane mesh data (with subdivisions) RLAPI Mesh GenMeshCube(float width, float height, float length); // Generate cuboid mesh RLAPI Mesh GenMeshSphere(float radius, int rings, int slices); // Generate sphere mesh (standard sphere) RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices); // Generate half-sphere mesh (no bottom cap) diff --git a/src/rmodels.c b/src/rmodels.c index 3dd28c6c1..d53f067d8 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -2634,8 +2634,20 @@ Mesh GenMeshPoly(int sides, float radius) return mesh; } -// Generate plane mesh (with subdivisions) +// Generate plane mesh (with subdivisions) and upload to GPU Mesh GenMeshPlane(float width, float length, int resX, int resZ) +{ + Mesh mesh = GenMeshPlaneData(width, length, resX, resZ); + + // Upload vertex data to GPU (static mesh) + UploadMesh(&mesh, false); + + return mesh; +} + +// Generate plane mesh data (with subdivisions), no GPU upload +// Allows CPU-side mesh manipulation (e.g. vertex deformation) before manually calling UploadMesh() +Mesh GenMeshPlaneData(float width, float length, int resX, int resZ) { Mesh mesh = { 0 }; @@ -2761,9 +2773,6 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) par_shapes_free_mesh(plane); #endif - // Upload vertex data to GPU (static mesh) - UploadMesh(&mesh, false); - return mesh; }