#include #include #include static Camera3D camera = {0}; static Model model = {0}; static bool model_loaded = false; void setup() { Serial.begin(115200); Serial.println("raylib-esp32 model_loading example"); raylib_esp32_display_config_t disp = { .driver = RAYLIB_DRIVER_GC9A01, .spi_host = SPI2_HOST, .pin_sclk = 12, .pin_mosi = 11, .pin_cs = 10, .pin_dc = 9, .pin_rst = 8, .pin_bl = 7, .width = 240, .height = 240, .spi_freq_hz = 40000000, }; ESP_ERROR_CHECK(raylib_esp32_init(&disp)); /* * Mount LittleFS. Put your .glb / .obj files in the data/ folder * and upload with: pio run -t uploadfs */ esp_err_t fs_ret = raylib_esp32_mount_fs("/data", "spiffs"); if (fs_ret != ESP_OK) { Serial.printf("FS mount failed: %d\n", fs_ret); } InitWindow(240, 240, "model_loading"); camera.position = (Vector3){5.0f, 5.0f, 5.0f}; camera.target = (Vector3){0.0f, 0.0f, 0.0f}; camera.up = (Vector3){0.0f, 1.0f, 0.0f}; camera.fovy = 45.0f; camera.projection = CAMERA_PERSPECTIVE; model = LoadModel("/data/model.glb"); model_loaded = (model.meshCount > 0); if (!model_loaded) { Serial.println("Model not found — showing fallback cube. " "Upload a model.glb to the data/ folder."); } } void loop() { BeginDrawing(); ClearBackground(RAYWHITE); BeginMode3D(camera); if (model_loaded) { DrawModel(model, (Vector3){0}, 1.0f, WHITE); } else { DrawCube((Vector3){0}, 2.0f, 2.0f, 2.0f, SKYBLUE); DrawCubeWires((Vector3){0}, 2.0f, 2.0f, 2.0f, DARKBLUE); } DrawGrid(10, 1.0f); EndMode3D(); DrawFPS(4, 4); if (!model_loaded) { DrawText("No model.glb found", 10, 220, 10, RED); } EndDrawing(); }