REVIEWED: models_yaw_pitch_roll

This commit is contained in:
raysan5 2021-10-19 14:58:04 +02:00
parent fec0ce34c5
commit 2e151408bb
10 changed files with 10939 additions and 443 deletions

View file

@ -881,8 +881,8 @@ models/models_skybox: models/models_skybox.c
models/models_yaw_pitch_roll: models/models_yaw_pitch_roll.c models/models_yaw_pitch_roll: models/models_yaw_pitch_roll.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -s TOTAL_MEMORY=67108864 \ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -s TOTAL_MEMORY=67108864 \
--preload-file models/resources/models/gltf/plane/plane.gltf@resources/models/gltf/plane/plane.gltf \ --preload-file models/resources/models/obj/plane.gltf@resources/modelsobj/plane.gltf \
--preload-file models/resources/models/gltf/plane/plane_diffuse.png@resources/models/gltf/plane/plane_diffuse.png --preload-file models/resources/models/obj/plane_diffuse.png@resources/models/obj/plane_diffuse.png
models/models_heightmap: models/models_heightmap.c models/models_heightmap: models/models_heightmap.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \

View file

@ -19,10 +19,10 @@
int main(void) int main(void)
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
const int screenWidth = 800; const int screenWidth = 800;
const int screenHeight = 450; const int screenHeight = 450;
const char *voxFileNames[] = { const char *voxFileNames[] = {
"resources/models/vox/chr_knight.vox", "resources/models/vox/chr_knight.vox",
@ -30,7 +30,7 @@ int main(void)
"resources/models/vox/monu9.vox" "resources/models/vox/monu9.vox"
}; };
InitWindow(screenWidth, screenHeight, "raylib [models] example - magicavoxel loading"); InitWindow(screenWidth, screenHeight, "raylib [models] example - magicavoxel loading");
// Define the camera to look into our 3d world // Define the camera to look into our 3d world
Camera camera = { 0 }; Camera camera = { 0 };
@ -40,61 +40,61 @@ int main(void)
camera.fovy = 45.0f; // Camera field-of-view Y camera.fovy = 45.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
// Load MagicaVoxel files // Load MagicaVoxel files
Model models[MAX_VOX_FILES] = { 0 }; Model models[MAX_VOX_FILES] = { 0 };
for (int i = 0; i < MAX_VOX_FILES; i++) for (int i = 0; i < MAX_VOX_FILES; i++)
{ {
// Load VOX file and measure time // Load VOX file and measure time
double t0 = GetTime()*1000.0; double t0 = GetTime()*1000.0;
models[i] = LoadModel(voxFileNames[i]); models[i] = LoadModel(voxFileNames[i]);
double t1 = GetTime()*1000.0; double t1 = GetTime()*1000.0;
TraceLog(LOG_WARNING, TextFormat("[%s] File loaded in %.3f ms", voxFileNames[i], t1 - t0)); TraceLog(LOG_WARNING, TextFormat("[%s] File loaded in %.3f ms", voxFileNames[i], t1 - t0));
// Compute model translation matrix to center model on draw position (0, 0 , 0) // Compute model translation matrix to center model on draw position (0, 0 , 0)
BoundingBox bb = GetModelBoundingBox(models[i]); BoundingBox bb = GetModelBoundingBox(models[i]);
Vector3 center = { 0 }; Vector3 center = { 0 };
center.x = bb.min.x + (((bb.max.x - bb.min.x)/2)); center.x = bb.min.x + (((bb.max.x - bb.min.x)/2));
center.z = bb.min.z + (((bb.max.z - bb.min.z)/2)); center.z = bb.min.z + (((bb.max.z - bb.min.z)/2));
Matrix matTranslate = MatrixTranslate(-center.x, 0, -center.z); Matrix matTranslate = MatrixTranslate(-center.x, 0, -center.z);
models[i].transform = matTranslate; models[i].transform = matTranslate;
} }
int currentModel = 0; int currentModel = 0;
SetCameraMode(camera, CAMERA_ORBITAL); // Set a orbital camera mode SetCameraMode(camera, CAMERA_ORBITAL); // Set a orbital camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCamera(&camera); // Update our camera to orbit UpdateCamera(&camera); // Update our camera to orbit
// Cycle between models on mouse click // Cycle between models on mouse click
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) currentModel = (currentModel + 1)%MAX_VOX_FILES; if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) currentModel = (currentModel + 1)%MAX_VOX_FILES;
// Cycle between models on key pressed // Cycle between models on key pressed
if (IsKeyPressed(KEY_RIGHT)) if (IsKeyPressed(KEY_RIGHT))
{ {
currentModel++; currentModel++;
if (currentModel >= MAX_VOX_FILES) currentModel = 0; if (currentModel >= MAX_VOX_FILES) currentModel = 0;
} }
else if (IsKeyPressed(KEY_LEFT)) else if (IsKeyPressed(KEY_LEFT))
{ {
currentModel--; currentModel--;
if (currentModel < 0) currentModel = MAX_VOX_FILES - 1; if (currentModel < 0) currentModel = MAX_VOX_FILES - 1;
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
@ -112,19 +112,19 @@ int main(void)
DrawText("MOUSE LEFT BUTTON to CYCLE VOX MODELS", 40, 410, 10, BLUE); DrawText("MOUSE LEFT BUTTON to CYCLE VOX MODELS", 40, 410, 10, BLUE);
DrawText(TextFormat("File: %s", GetFileName(voxFileNames[currentModel])), 10, 10, 20, GRAY); DrawText(TextFormat("File: %s", GetFileName(voxFileNames[currentModel])), 10, 10, 20, GRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Unload models data (GPU VRAM) // Unload models data (GPU VRAM)
for (int i = 0; i < MAX_VOX_FILES; i++) UnloadModel(models[i]); for (int i = 0; i < MAX_VOX_FILES; i++) UnloadModel(models[i]);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }

View file

@ -32,9 +32,9 @@ int main(void)
camera.fovy = 30.0f; // Camera field-of-view Y camera.fovy = 30.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera type camera.projection = CAMERA_PERSPECTIVE; // Camera type
// Model loading Model model = LoadModel("resources/models/obj/plane.obj"); // Load model
// NOTE: Diffuse map loaded automatically Texture2D texture = LoadTexture("resources/models/obj/plane_diffuse.png"); // Load model texture
Model model = LoadModel("resources/models/gltf/plane/plane.gltf"); model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
float pitch = 0.0f; float pitch = 0.0f;
float roll = 0.0f; float roll = 0.0f;
@ -88,7 +88,7 @@ int main(void)
// Draw 3D model (recomended to draw 3D always before 2D) // Draw 3D model (recomended to draw 3D always before 2D)
BeginMode3D(camera); BeginMode3D(camera);
DrawModel(model, (Vector3){ 0.0f, 0.0f, 15.0f }, 0.25f, WHITE); // Draw 3d model with texture DrawModel(model, (Vector3){ 0.0f, -8.0f, 0.0f }, 1.0f, WHITE); // Draw 3d model with texture
DrawGrid(10, 10.0f); DrawGrid(10, 10.0f);
EndMode3D(); EndMode3D();

View file

@ -7,17 +7,17 @@
| models/obj/turret.obj,<br>models/turret_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - | | models/obj/turret.obj,<br>models/turret_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
| models/obj/well.obj,<br>models/well_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - | | models/obj/well.obj,<br>models/well_diffuse.png | [Alberto Cano](https://www.artstation.com/albertocano) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - |
| models/obj/cube.obj,<br>models/cube_diffuse.png | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - | | models/obj/cube.obj,<br>models/cube_diffuse.png | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - |
| models/obj/plane.gltf,<br>models/gltf/plane/plane.bin,<br>models/gltf/plane/plane_diffuse.png | [GiaHanLam](https://sketchfab.com/GiaHanLam) | [CC-BY](https://creativecommons.org/licenses/by/4.0/) | Used by: [`models_yaw_pitch_roll.c`](https://github.com/raysan5/raylib/blob/master/examples/models/models_yaw_pitch_roll.c)
| models/iqm/guy.iqm,<br>models/iqm/guyanim.iqm,<br>models/iqm/guytex.png,<br>models/iqm/guy.blend | [@culacant](https://github.com/culacant) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - | | models/iqm/guy.iqm,<br>models/iqm/guyanim.iqm,<br>models/iqm/guytex.png,<br>models/iqm/guy.blend | [@culacant](https://github.com/culacant) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - |
| models/iqm/vertex_colored_object.iqm | ❔ | ❔ | - | | models/iqm/vertex_colored_object.iqm | ❔ | ❔ | - |
| models/gltf/plane/plane.gltf,<br>models/gltf/plane/plane.bin,<br>models/gltf/plane/plane_diffuse.png | [GiaHanLam](https://sketchfab.com/GiaHanLam) | [CC-BY](https://creativecommons.org/licenses/by/4.0/) | Used by: [`models_yaw_pitch_roll.c`](https://github.com/raysan5/raylib/blob/master/examples/models/models_yaw_pitch_roll.c) | models/gltf/... | _various_ | Check [LICENSE](https://github.com/raysan5/raylib/blob/master/examples/models/resources/models/gltf/LICENSE) | - |
| models/gltf/... | _various_ | Check [LICENSE](https://github.com/raysan5/raylib/blob/master/examples/models/resources/models/gltf/LICENSE) | - |
| models/vox/chr_knight.vox | ❔ | ❔ | - | | models/vox/chr_knight.vox | ❔ | ❔ | - |
| models/vox/chr_sword.vox | ❔ | ❔ | - | | models/vox/chr_sword.vox | ❔ | ❔ | - |
| models/vox/monu9.vox | ❔ | ❔ | - | | models/vox/monu9.vox | ❔ | ❔ | - |
| billboard.png | [@emegeme](https://github.com/emegeme) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - | | billboard.png | [@emegeme](https://github.com/emegeme) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - |
| cubicmap.png | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - | | cubicmap.png | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - |
| cubicmap_atlas.png | [@emegeme](https://github.com/emegeme) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - | | cubicmap_atlas.png | [@emegeme](https://github.com/emegeme) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - |
| heightmap.png | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - | | heightmap.png | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | - |
| dresden_square_1k.hdr | [HDRIHaven](https://hdrihaven.com/hdri/?h=dresden_square) | [CC0](https://hdrihaven.com/p/license.php) | - | | dresden_square_1k.hdr | [HDRIHaven](https://hdrihaven.com/hdri/?h=dresden_square) | [CC0](https://hdrihaven.com/p/license.php) | - |
| dresden_square_2k.hdr | [HDRIHaven](https://hdrihaven.com/hdri/?h=dresden_square) | [CC0](https://hdrihaven.com/p/license.php) | - | | dresden_square_2k.hdr | [HDRIHaven](https://hdrihaven.com/hdri/?h=dresden_square) | [CC0](https://hdrihaven.com/p/license.php) | - |
| skybox.png | | ❔ | - | | skybox.png | | ❔ | - |

View file

@ -1,9 +0,0 @@
WWI Plane Model created by GiaHanLam (https://sketchfab.com/GiaHanLam)
This model is free to use, licensed as Creative Commons Attribution (CC-BY 4.0)
License details: https://creativecommons.org/licenses/by/4.0/
As per the license, author must be credited and commercial use is allowed.
This model was donwload from author Sketchfab account: https://sketchfab.com/3d-models/wwi-plane-model-f0d39a6daacd4925a8922db193886715

View file

@ -1,327 +0,0 @@
{
"accessors": [
{
"bufferView": 2,
"componentType": 5126,
"count": 3446,
"max": [
143.99604797363281,
168.74668884277344,
75.31597900390625
],
"min": [
-143.99604797363281,
-43.94732666015625,
-49.556678771972656
],
"type": "VEC3"
},
{
"bufferView": 2,
"byteOffset": 41352,
"componentType": 5126,
"count": 3446,
"max": [
1,
0.99916732311248779,
0.99978786706924438
],
"min": [
-1,
-0.99928808212280273,
-0.99977350234985352
],
"type": "VEC3"
},
{
"bufferView": 3,
"componentType": 5126,
"count": 3446,
"max": [
1,
1,
1,
1
],
"min": [
0,
0,
0,
0
],
"type": "VEC4"
},
{
"bufferView": 1,
"componentType": 5126,
"count": 3446,
"max": [
4.8965663909912109,
0.99786919355392456
],
"min": [
0.0036561768501996994,
0.0083234198391437531
],
"type": "VEC2"
},
{
"bufferView": 0,
"componentType": 5125,
"count": 7692,
"max": [
3445
],
"min": [
0
],
"type": "SCALAR"
}
],
"asset": {
"extras": {
"author": "GiaHanLam (https://sketchfab.com/GiaHanLam)",
"license": "CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)",
"source": "https://sketchfab.com/3d-models/wwi-plane-model-f0d39a6daacd4925a8922db193886715",
"title": "WWI Plane Model"
},
"generator": "Sketchfab-8.25.0",
"version": "2.0"
},
"bufferViews": [
{
"buffer": 0,
"byteLength": 30768,
"byteOffset": 0,
"name": "floatBufferViews",
"target": 34963
},
{
"buffer": 0,
"byteLength": 27568,
"byteOffset": 30768,
"byteStride": 8,
"name": "floatBufferViews",
"target": 34962
},
{
"buffer": 0,
"byteLength": 82704,
"byteOffset": 58336,
"byteStride": 12,
"name": "floatBufferViews",
"target": 34962
},
{
"buffer": 0,
"byteLength": 55136,
"byteOffset": 141040,
"byteStride": 16,
"name": "floatBufferViews",
"target": 34962
}
],
"buffers": [
{
"byteLength": 196176,
"uri": "plane.bin"
}
],
"images": [
{
"uri": "plane_diffuse.png"
}
],
"materials": [
{
"doubleSided": true,
"name": "Material_24",
"pbrMetallicRoughness": {
"baseColorFactor": [
1,
1,
1,
1
],
"baseColorTexture": {
"index": 0,
"texCoord": 0
},
"metallicFactor": 0,
"roughnessFactor": 0.59999999999999998
}
}
],
"meshes": [
{
"name": "BODY_Material #24_0",
"primitives": [
{
"attributes": {
"COLOR_0": 2,
"NORMAL": 1,
"POSITION": 0,
"TEXCOORD_0": 3
},
"indices": 4,
"material": 0,
"mode": 4
}
]
}
],
"nodes": [
{
"children": [
1
],
"name": "RootNode (gltf orientation matrix)",
"rotation": [
-0.70710678118654746,
-0,
-0,
0.70710678118654757
]
},
{
"children": [
2
],
"name": "RootNode (model correction matrix)"
},
{
"children": [
3
],
"matrix": [
1,
0,
0,
0,
0,
0,
1,
0,
0,
-1,
0,
0,
0,
0,
0,
1
],
"name": "base"
},
{
"children": [
4,
6
],
"name": "RootNode"
},
{
"children": [
5
],
"matrix": [
1,
0,
0,
0,
0,
2.2204460492503131e-16,
-1,
0,
0,
1,
2.2204460492503131e-16,
0,
0,
0,
0,
1
],
"name": "BODY"
},
{
"mesh": 0,
"name": "BODY_Material #24_0"
},
{
"children": [
7
],
"matrix": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
-680,
0,
90,
1
],
"name": "Sky001"
},
{
"children": [
8
],
"matrix": [
1,
0,
0,
0,
0,
2.2204460492503131e-16,
1,
0,
0,
-1,
2.2204460492503131e-16,
0,
0,
0,
0,
1
],
"name": ""
},
{
"name": ""
}
],
"samplers": [
{
"magFilter": 9729,
"minFilter": 9987,
"wrapS": 10497,
"wrapT": 10497
}
],
"scene": 0,
"scenes": [
{
"name": "OSG_Scene",
"nodes": [
0
]
}
],
"textures": [
{
"sampler": 0,
"source": 0
}
]
}

File diff suppressed because it is too large Load diff

View file

Before

Width:  |  Height:  |  Size: 804 KiB

After

Width:  |  Height:  |  Size: 804 KiB

Before After
Before After

View file

@ -6,10 +6,11 @@ attribute vec2 vertexTexCoord;
attribute vec3 vertexNormal; attribute vec3 vertexNormal;
attribute vec4 vertexColor; attribute vec4 vertexColor;
attribute mat4 instance; attribute mat4 instanceTransform;
// Input uniform values // Input uniform values
uniform mat4 mvp; uniform mat4 mvp;
uniform mat4 matNormal;
// Output vertex attributes (to fragment shader) // Output vertex attributes (to fragment shader)
varying vec3 fragPosition; varying vec3 fragPosition;
@ -19,43 +20,16 @@ varying vec3 fragNormal;
// NOTE: Add here your custom variables // NOTE: Add here your custom variables
// https://github.com/glslify/glsl-inverse
mat3 inverse(mat3 m)
{
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
float b01 = a22*a11 - a12*a21;
float b11 = -a22*a10 + a12*a20;
float b21 = a21*a10 - a11*a20;
float det = a00*b01 + a01*b11 + a02*b21;
return mat3(b01, (-a22*a01 + a02*a21), (a12*a01 - a02*a11),
b11, (a22*a00 - a02*a20), (-a12*a00 + a02*a10),
b21, (-a21*a00 + a01*a20), (a11*a00 - a01*a10))/det;
}
// https://github.com/glslify/glsl-transpose
mat3 transpose(mat3 m)
{
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
void main() void main()
{ {
// Compute MVP for current instance
mat4 mvpi = mvp*instanceTransform;
// Send vertex attributes to fragment shader // Send vertex attributes to fragment shader
fragPosition = vec3(instance*vec4(vertexPosition, 1.0)); fragPosition = vec3(mvpi*vec4(vertexPosition, 1.0));
fragTexCoord = vertexTexCoord; fragTexCoord = vertexTexCoord;
fragColor = vertexColor; fragColor = vertexColor;
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
mat3 normalMatrix = transpose(inverse(mat3(instance)));
fragNormal = normalize(normalMatrix*vertexNormal);
mat4 mvpi = mvp*instance;
// Calculate final vertex position // Calculate final vertex position
gl_Position = mvpi*vec4(vertexPosition, 1.0); gl_Position = mvpi*vec4(vertexPosition, 1.0);