mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 12:07:27 +00:00
Complete models_loading example.
This had a few things missing/commented, but after fixing the load paths and uncommenting code, it seems to work fine for me. I also ran `zig format` on the example, I can submit a PR without that if it isn't ideal.
This commit is contained in:
parent
1996635c5b
commit
51b327fa03
@ -7,8 +7,9 @@
|
||||
|
||||
usingnamespace @import("raylib");
|
||||
|
||||
pub fn main() anyerror!void
|
||||
{
|
||||
const resourceDir = "raylib/examples/models/resources/";
|
||||
|
||||
pub fn main() anyerror!void {
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const screenWidth = 800;
|
||||
@ -17,19 +18,19 @@ pub fn main() anyerror!void
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - models loading");
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
var camera = Camera {
|
||||
.position = Vector3 { .x = 50.0, .y = 50.0, .z = 50.0 }, // Camera position
|
||||
.target = Vector3 { .x = 0.0, .y = 10.0, .z = 0.0 }, // Camera looking at point
|
||||
.up = Vector3 { .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target)
|
||||
var camera = Camera{
|
||||
.position = Vector3{ .x = 50.0, .y = 50.0, .z = 50.0 }, // Camera position
|
||||
.target = Vector3{ .x = 0.0, .y = 10.0, .z = 0.0 }, // Camera looking at point
|
||||
.up = Vector3{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target)
|
||||
.fovy = 45.0, // Camera field-of-view Y
|
||||
.type = CameraType.CAMERA_PERSPECTIVE // Camera mode type
|
||||
.type = CameraType.CAMERA_PERSPECTIVE, // Camera mode type
|
||||
};
|
||||
|
||||
var model = LoadModel("resources/models/castle.obj"); // Load model
|
||||
var texture = LoadTexture("resources/models/castle_diffuse.png"); // Load model texture
|
||||
var model = LoadModel(resourceDir ++ "models/castle.obj"); // Load model
|
||||
var texture = LoadTexture(resourceDir ++ "models/castle_diffuse.png"); // Load model texture
|
||||
model.materials[0].maps[@enumToInt(MAP_DIFFUSE)].texture = texture; // Set map diffuse texture
|
||||
|
||||
//var position = Vector3 { .x = 0.0, .y = 0.0, .z = 0.0 }; // Set model position
|
||||
var position = Vector3{ .x = 0.0, .y = 0.0, .z = 0.0 }; // Set model position
|
||||
|
||||
var bounds = MeshBoundingBox(model.meshes[0]); // Set model bounds
|
||||
|
||||
@ -51,8 +52,7 @@ pub fn main() anyerror!void
|
||||
camera.Update();
|
||||
|
||||
// Load new models/textures on drag&drop
|
||||
if (IsFileDropped())
|
||||
{
|
||||
if (IsFileDropped()) {
|
||||
var count: c_int = 0;
|
||||
var droppedFiles = GetDroppedFiles(&count);
|
||||
|
||||
@ -69,8 +69,7 @@ pub fn main() anyerror!void
|
||||
bounds = MeshBoundingBox(model.meshes[0]);
|
||||
|
||||
// TODO: Move camera position from target enough distance to visualize model properly
|
||||
}
|
||||
else if (IsFileExtension(droppedFiles[0], ".png")) // Texture file formats supported
|
||||
} else if (IsFileExtension(droppedFiles[0], ".png")) // Texture file formats supported
|
||||
{
|
||||
// Unload current model texture and load new one
|
||||
UnloadTexture(texture);
|
||||
@ -83,17 +82,13 @@ pub fn main() anyerror!void
|
||||
}
|
||||
|
||||
// Select model on mouse click
|
||||
if (IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
if (IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) {
|
||||
// Check collision between ray and box
|
||||
//if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds))
|
||||
//{
|
||||
// selected = !selected;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// selected = false;
|
||||
//}
|
||||
if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds)) {
|
||||
selected = !selected;
|
||||
} else {
|
||||
selected = false;
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
@ -105,7 +100,7 @@ pub fn main() anyerror!void
|
||||
|
||||
camera.Begin();
|
||||
|
||||
//DrawModel(model, position, 1.0, WHITE); // Draw 3d model with texture
|
||||
DrawModel(model, position, 1.0, WHITE); // Draw 3d model with texture
|
||||
|
||||
DrawGrid(20, 10.0); // Draw a grid
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user