Rename examples for consistency
This commit is contained in:
parent
670eab8b17
commit
d92531b81d
4 changed files with 10 additions and 8 deletions
|
|
@ -4,17 +4,19 @@
|
||||||
*
|
*
|
||||||
* raylib supports multiple models file formats:
|
* raylib supports multiple models file formats:
|
||||||
*
|
*
|
||||||
* - OBJ > Text file, must include vertex position-texcoords-normals information,
|
* - OBJ > Text file format. Must include vertex position-texcoords-normals information,
|
||||||
* if files references some .mtl materials file, it will be loaded (or try to)
|
* if files references some .mtl materials file, it will be loaded (or try to).
|
||||||
* - GLTF > Modern text/binary file format, includes lot of information and it could
|
* - GLTF > Text/binary file format. Includes lot of information and it could
|
||||||
* also reference external files, raylib will try loading mesh and materials data
|
* also reference external files, raylib will try loading mesh and materials data.
|
||||||
* - IQM > Binary file format including mesh vertex data but also animation data,
|
* - IQM > Binary file format. Includes mesh vertex data but also animation data,
|
||||||
* raylib can load .iqm animations.
|
* raylib can load .iqm animations.
|
||||||
|
* - VOX > Binary file format. MagikaVoxel mesh format:
|
||||||
|
* https://github.com/ephtracy/voxel-model/blob/master/MagicaVoxel-file-format-vox.txt
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 2.6 (www.raylib.com)
|
* This example has been created using raylib 4.0 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
|
* Copyright (c) 2014-2021 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
|
||||||
108
examples/models/models_loading_gltf.c
Normal file
108
examples/models/models_loading_gltf.c
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [models] example - Load 3d gltf model
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 3.5 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Example contributed by Hristo Stamenov (@object71) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Hristo Stamenov (@object71) and Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************
|
||||||
|
*
|
||||||
|
* To export a model from blender, make sure it is not posed, the vertices need to be in the
|
||||||
|
* same position as they would be in edit mode.
|
||||||
|
* and that the scale of your models is set to 0. Scaling can be done from the export menu.
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define MAX_MODELS 8
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - model");
|
||||||
|
|
||||||
|
// Define the camera to look into our 3d world
|
||||||
|
Camera camera = { 0 };
|
||||||
|
camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position
|
||||||
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||||
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
|
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
||||||
|
|
||||||
|
Model model[MAX_MODELS] = { 0 };
|
||||||
|
|
||||||
|
model[0] = LoadModel("resources/gltf/raylib_32x32.glb");
|
||||||
|
model[1] = LoadModel("resources/gltf/rigged_figure.glb");
|
||||||
|
model[2] = LoadModel("resources/gltf/GearboxAssy.glb");
|
||||||
|
model[3] = LoadModel("resources/gltf/BoxAnimated.glb");
|
||||||
|
model[4] = LoadModel("resources/gltf/AnimatedTriangle.gltf");
|
||||||
|
model[5] = LoadModel("resources/gltf/AnimatedMorphCube.glb");
|
||||||
|
model[6] = LoadModel("resources/gltf/vertex_colored_object.glb");
|
||||||
|
model[7] = LoadModel("resources/gltf/girl.glb");
|
||||||
|
|
||||||
|
int currentModel = 0;
|
||||||
|
|
||||||
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
|
SetCameraMode(camera, CAMERA_FREE); // Set free camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
UpdateCamera(&camera);
|
||||||
|
|
||||||
|
if (IsKeyReleased(KEY_RIGHT))
|
||||||
|
{
|
||||||
|
currentModel++;
|
||||||
|
if (currentModel == MAX_MODELS) currentModel = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyReleased(KEY_LEFT))
|
||||||
|
{
|
||||||
|
currentModel--;
|
||||||
|
if (currentModel < 0) currentModel = MAX_MODELS - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(SKYBLUE);
|
||||||
|
|
||||||
|
BeginMode3D(camera);
|
||||||
|
|
||||||
|
DrawModelEx(model[currentModel], position, (Vector3){ 0.0f, 1.0f, 0.0f }, 180.0f, (Vector3){ 2.0f, 2.0f, 2.0f }, WHITE);
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
|
|
||||||
|
EndMode3D();
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
for (int i = 0; i < MAX_MODELS; i++) UnloadModel(model[i]); // Unload models
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
examples/models/models_loading_gltf.png
Normal file
BIN
examples/models/models_loading_gltf.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
151
examples/models/models_loading_vox.c
Normal file
151
examples/models/models_loading_vox.c
Normal file
|
|
@ -0,0 +1,151 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [models] example - magicavoxel loader and viewer
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 3.8 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Example contributed by Johann Nadalutti
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Johann Nadalutti
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
#include "raymath.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
// VOX Files to load and view
|
||||||
|
|
||||||
|
#define NUM_VOX_FILES 3
|
||||||
|
|
||||||
|
const char* szVoxFiles[] = {
|
||||||
|
"resources/vox/chr_knight.vox",
|
||||||
|
"resources/vox/chr_sword.vox",
|
||||||
|
"resources/vox/monu9.vox"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - magicavoxel loading");
|
||||||
|
|
||||||
|
// Load MagicaVoxel files
|
||||||
|
Model models[NUM_VOX_FILES] = { 0 };
|
||||||
|
|
||||||
|
for (int i = 0; i < NUM_VOX_FILES; i++)
|
||||||
|
{
|
||||||
|
// Load MagicaVoxel File and build model
|
||||||
|
double t0, t1;
|
||||||
|
t0 = GetTime() * 1000.0;
|
||||||
|
|
||||||
|
models[i] = LoadModel(szVoxFiles[i]);
|
||||||
|
|
||||||
|
t1 = GetTime() * 1000.0;
|
||||||
|
TraceLog(LOG_INFO, TextFormat("Vox <%s> loaded in %f ms", GetFileName(szVoxFiles[i]), t1 - t0));
|
||||||
|
|
||||||
|
//Compute model's center matrix
|
||||||
|
BoundingBox bb = GetModelBoundingBox(models[i]);
|
||||||
|
Vector3 center;
|
||||||
|
center.x = bb.min.x + (((bb.max.x - bb.min.x) / 2));
|
||||||
|
center.z = bb.min.z + (((bb.max.z - bb.min.z) / 2));
|
||||||
|
|
||||||
|
Matrix matP = MatrixTranslate(-center.x, 0, -center.z);
|
||||||
|
models[i].transform = matP;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Define the camera to look into our 3d world
|
||||||
|
Camera camera = { { 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
|
||||||
|
|
||||||
|
// Model drawing position
|
||||||
|
Vector3 position = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
|
int currentModel = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SetCameraMode(camera, CAMERA_ORBITAL); // Set a orbital camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// Main game loop
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
UpdateCamera(&camera); // Update internal camera and our camera
|
||||||
|
|
||||||
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
||||||
|
{
|
||||||
|
currentModel = (currentModel + 1) % NUM_VOX_FILES; // Cycle between models
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY_RIGHT))
|
||||||
|
{
|
||||||
|
currentModel++;
|
||||||
|
if (currentModel >= NUM_VOX_FILES) currentModel = 0;
|
||||||
|
}
|
||||||
|
else if (IsKeyPressed(KEY_LEFT))
|
||||||
|
{
|
||||||
|
currentModel--;
|
||||||
|
if (currentModel < 0) currentModel = NUM_VOX_FILES - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
//Display model
|
||||||
|
BeginMode3D(camera);
|
||||||
|
|
||||||
|
Vector3 rotAxis = { 1,0,0 };
|
||||||
|
Vector3 scale = { 1,1,1 };
|
||||||
|
|
||||||
|
|
||||||
|
DrawModelEx(models[currentModel], position, rotAxis, 0, scale, WHITE);
|
||||||
|
//DrawModelWiresEx(models[currentModel], position, rotAxis, -90.0f, scale, BLACK);
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0);
|
||||||
|
|
||||||
|
EndMode3D();
|
||||||
|
|
||||||
|
//Display debug infos
|
||||||
|
DrawRectangle(30, 400, 310, 30, Fade(SKYBLUE, 0.5f));
|
||||||
|
DrawRectangleLines(30, 400, 310, 30, Fade(DARKBLUE, 0.5f));
|
||||||
|
DrawText("MOUSE LEFT BUTTON to CYCLE VOX MODELS", 40, 410, 10, BLUE);
|
||||||
|
|
||||||
|
DrawText(GetFileName(szVoxFiles[currentModel]), 100, 10, 20, DARKBLUE);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Unload models data (GPU VRAM)
|
||||||
|
for (int i = 0; i < NUM_VOX_FILES; i++) UnloadModel(models[i]);
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in a new issue