diff --git a/src/raylib.h b/src/raylib.h index 641bd10e0..b1c178570 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1552,8 +1552,10 @@ RLAPI void DrawGrid(int slices, float spacing); // Model management functions RLAPI Model LoadModel(const char *fileName); // Load model from files (meshes and materials) +RLAPI Model LoadModelEx(const char *fileName, bool upload); // Load model from files (meshes and materials) with option to auto uploading meshes to GPU or not RLAPI Model LoadModelFromMesh(Mesh mesh); // Load model from generated mesh (default material) RLAPI bool IsModelValid(Model model); // Check if a model is valid (loaded in GPU, VAO/VBOs) +RLAPI void UploadModel(const Model *model, bool dynamic); // Upload model data to GPU (VRAM) RLAPI void UnloadModel(Model model); // Unload model (including meshes) from memory (RAM and/or VRAM) RLAPI BoundingBox GetModelBoundingBox(Model model); // Compute model bounding box limits (considers all meshes) diff --git a/src/rmodels.c b/src/rmodels.c index 24f4a4fc9..d8f3ecada 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -1088,6 +1088,12 @@ void DrawGrid(int slices, float spacing) // Load model from files (mesh and material) Model LoadModel(const char *fileName) +{ + return LoadModelEx(fileName, true); +} + +// Load model from files (mesh and material) without Uploading Vertex data to GPU +Model LoadModelEx(const char *fileName, bool upload) { Model model = { 0 }; @@ -1110,12 +1116,15 @@ Model LoadModel(const char *fileName) // Make sure model transform is set to identity matrix! model.transform = MatrixIdentity(); - if ((model.meshCount != 0) && (model.meshes != NULL)) + if(upload) { - // Upload vertex data to GPU (static meshes) - for (int i = 0; i < model.meshCount; i++) UploadMesh(&model.meshes[i], false); + if ((model.meshCount != 0) && (model.meshes != NULL)) + { + // Upload vertex data to GPU (static meshes) + for (int i = 0; i < model.meshCount; i++) UploadMesh(&model.meshes[i], false); + } + else TRACELOG(LOG_WARNING, "MESH: [%s] Failed to load model mesh(es) data", fileName); } - else TRACELOG(LOG_WARNING, "MESH: [%s] Failed to load model mesh(es) data", fileName); if (model.materialCount == 0) { @@ -1187,6 +1196,17 @@ bool IsModelValid(Model model) return result; } +// Upload model data to GPU (RAM and/or VRAM) +void UploadModel(const Model *model, bool dynamic) +{ + if ((model->meshCount != 0) && (model->meshes != NULL)) + { + // Upload vertex data to GPU (static meshes) + for (int i = 0; i < model->meshCount; i++) UploadMesh(&model->meshes[i], false); + } + else TRACELOG(LOG_WARNING, "Model: [%s] Failed to load model mesh(es) data"); +} + // Unload model (meshes/materials) from memory (RAM and/or VRAM) // NOTE: This function takes care of all model elements, for a detailed control // over them, use UnloadMesh() and UnloadMaterial() @@ -4407,7 +4427,7 @@ static Model LoadOBJ(const char *fileName) tinyobj_shapes_free(objShapes, objShapeCount); tinyobj_materials_free(objMaterials, objMaterialCount); - for (int i = 0; i < model.meshCount; i++) UploadMesh(model.meshes + i, true); + // Restore current working directory if (CHDIR(currentDir) != 0)