/
redgpu
/
raygpu
Обзор
Документация
Войти
/
redgpu
/
raygpu
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/models_glb.cpp
87 строк
2 KB
manuel
Reintroduce examples, fix gltf bug
27 сен 2025, 19:08
27 сен 2025, 19:08
91b81e9
Код
Авторство
О чём код?
#include "mathutils.h" #include <raygpu.h> #include <string> #include <iostream> #ifdef __EMSCRIPTEN__ #include <emscripten.h> #endif Model mod; float angle = 0; Mesh carmesh ; Texture checker ; Texture card ; Model carmodel; Camera3D cam; DescribedPipeline* pl; Material carMaterial{}; void mainloop(){ BeginDrawing(); ClearBackground(Color{35,0,0,255}); //DrawCircle(GetMouseX(), GetMouseY(), 100.0f, WHITE); BeginMode3D(cam); //UseNoTexture(); //BeginPipelineMode(pl); //if(angle > -0.1) Matrix stacc[10]; for(int i = 0;i < 10;i++){ stacc[i] = MatrixTranslate(0, 5 * (i - 5),0) * MatrixRotate(Vector3{0, 1, 0}, angle * i); } DrawMeshInstanced(carmesh, carMaterial, stacc, 10); //EndPipelineMode(); EndMode3D(); Matrix mat = ScreenMatrix(GetScreenWidth(), GetScreenHeight()); EndRenderpass(); BeginRenderpass(); DrawCircle(GetMouseX(), GetMouseY(), 50.0f, WHITE); DrawFPS(5, 5); if(IsKeyPressed(KEY_U)){ ToggleFullscreen(); } angle -= GetFrameTime() * 10.0f; EndDrawing(); } int main(){ SetConfigFlags(FLAG_VSYNC_HINT); InitWindow(1024, 800, "glTF Model Loading"); #ifndef __EMSCRIPTEN__ const char* ptr = FindDirectory("resources", 3); std::string resourceDirectoryPath = ptr ? ptr : ""; TRACELOG(LOG_INFO, "Directory path: %s", resourceDirectoryPath.c_str()); #else std::string resourceDirectoryPath = "/resources"; #endif //SetTargetFPS(60); //return 0; carmodel = LoadModel((resourceDirectoryPath + "/old_car_new.glb").c_str()); checker = LoadTextureFromImage(GenImageChecker(WHITE, BLACK, 100, 100, 10)); cam = CLITERAL(Camera3D){ .position = CLITERAL(Vector3){20,5,45}, .target = CLITERAL(Vector3){0,0,0}, .up = CLITERAL(Vector3){0,1,0}, .fovy = 45.0f }; UploadMesh(&carmodel.meshes[0], false); UploadMesh(&carmodel.meshes[1], false); carmesh = carmodel.meshes[0]; card = LoadTextureFromImage(LoadImage((resourceDirectoryPath + "/old_car_d.png").c_str())); carMaterial = LoadMaterialDefault(); carMaterial.maps[MATERIAL_MAP_DIFFUSE].texture = card; //pl = Relayout(DefaultPipeline(), carmesh.vao); //SetPipelineTexture(pl, 1, card); #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(mainloop, 0, 0); #else while(!WindowShouldClose()){ mainloop(); } #endif }