My first Blender model- Acorn

This commit is contained in:
2025-09-13 19:16:33 -05:00
parent 28f5bde1bc
commit d0eb63ba03
5 changed files with 460 additions and 16 deletions

39
main.c
View File

@@ -6,7 +6,7 @@
#include "stdlib.h"
#include "stdint.h"
#include "rlgl.h"
#include <float.h> // for FLT_MAX
#include "float.h"
//----------------------------------------------------------------------------------
// Defines and Macros
@@ -183,6 +183,11 @@ int main(void)
float wall_pitch = 0.0f; // rotate around X
float wall_roll = 0.0f; // rotate around Z
Model acorn = LoadModel("resources/3d_models/my_models/my_acorn.glb");
Vector3 acorn_position = { 0.0f, 0.0f, 0.0f };
float acorn_yaw = 0.0f; // rotate around Y
float acorn_pitch = 0.0f; // rotate around X
float acorn_roll = 0.0f; // rotate around Z
// Load a 2D image as texture for the billboard
//Billboards always point toward the active camera.
@@ -277,6 +282,7 @@ int main(void)
//Apply shader to wall
ApplyFogShaderToModel(&wall, fog);
ApplyFogShaderToModel(&acorn, fog);
// Defaults for opaque geometry (no alpha cut)
float cutoffOpaque = 0.0f;
@@ -293,7 +299,7 @@ int main(void)
float spotAngleDeg = 35.0f; //cone angle
float spotCos = cosf(DEG2RAD * (spotAngleDeg * 0.5f));
float spotSoft = 0.10f;
float lightRange = 100.0f;
float lightRange = 150.0f;//100.0f;
float lightFade = 1.0f;
float intensity = 0.25f; // try 0.71.5 to taste
float beamSpread = 0.05f; // try 0.150.35; higher = less “laser” at distance
@@ -371,14 +377,14 @@ int main(void)
UpdateBody(&g, g.player.lookRotation.x, sideway, forward, IsKeyDown(KEY_SPACE), crouching);
// Build wall collider (scale must match your DrawModelEx scale)
BoundingBox wallBox = MakeModelWorldAABB(wall, wall_position, (Vector3){5,5,5}, wall_yaw);
BoundingBox acornBox = MakeModelWorldAABB(acorn, acorn_position, (Vector3){0.25,0.25,0.25}, acorn_yaw);
// Collide player vs wall (XZ slide)
ResolveAgainstBoxXZ(&g, wallBox);
ResolveAgainstBoxXZ(&g, acornBox);
// put near your update logic
float B = 123;
float B = 122;
float T = 1.0f; // wall half-thickness
float H = 4.0f; // wall height
@@ -431,17 +437,17 @@ int main(void)
// wall editor
if (IsKeyDown(KEY_RIGHT) && IsKeyDown(KEY_LEFT_SHIFT)) wall_position.x += 0.5f;
else if (IsKeyPressed(KEY_RIGHT)) wall_position.x += 0.5f;
if (IsKeyDown(KEY_RIGHT) && IsKeyDown(KEY_LEFT_SHIFT)) acorn_position.x += 0.5f;
else if (IsKeyPressed(KEY_RIGHT)) acorn_position.x += 0.5f;
if (IsKeyDown(KEY_LEFT) && IsKeyDown(KEY_LEFT_SHIFT)) wall_position.x -= 0.5f;
else if (IsKeyPressed(KEY_LEFT)) wall_position.x -= 0.5f;
if (IsKeyDown(KEY_LEFT) && IsKeyDown(KEY_LEFT_SHIFT)) acorn_position.x -= 0.5f;
else if (IsKeyPressed(KEY_LEFT)) acorn_position.x -= 0.5f;
if (IsKeyDown(KEY_UP) && IsKeyDown(KEY_LEFT_SHIFT)) wall_position.z += 0.5f;
else if (IsKeyPressed(KEY_UP)) wall_position.z += 0.5f;
if (IsKeyDown(KEY_UP) && IsKeyDown(KEY_LEFT_SHIFT)) acorn_position.z += 0.5f;
else if (IsKeyPressed(KEY_UP)) acorn_position.z += 0.5f;
if (IsKeyDown(KEY_DOWN) && IsKeyDown(KEY_LEFT_SHIFT)) wall_position.z -= 0.5f;
else if (IsKeyPressed(KEY_DOWN)) wall_position.z -= 0.5f;
if (IsKeyDown(KEY_DOWN) && IsKeyDown(KEY_LEFT_SHIFT)) acorn_position.z -= 0.5f;
else if (IsKeyPressed(KEY_DOWN)) acorn_position.z -= 0.5f;
@@ -509,11 +515,11 @@ int main(void)
BeginShaderMode(fog);
//DrawModel(wall, wall_position, 5.0, WHITE);
DrawModelEx(wall, wall_position, (Vector3){0,1,0}, wall_yaw, (Vector3){5,5,5}, WHITE);
DrawModelEx(acorn, acorn_position, (Vector3){0,1,0}, wall_yaw, (Vector3){0.25,0.25,0.25}, WHITE);
RenderTrees(&g, tree, treepos, treeSize);
//DrawBillboard(g.player.camera, sign, bbPos, bbSize, WHITE); //zombie
DrawPerimeter(wall, 123.0f, 1.5f);
DrawPerimeter(wall, 122.0f, 1.5f);
EndShaderMode();
@@ -554,6 +560,7 @@ int main(void)
UnloadTexture(tree); // frees tree texture
UnloadTexture(sign);
UnloadModel(wall);
UnloadModel(acorn);
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
@@ -810,7 +817,7 @@ static inline void DrawTreeBillboardStable(Camera cam, Texture2D tex, Vector3 gr
static void RenderTrees(Master* g, Texture2D tree, Vector3 baseTreePos, float treeSize)
{
const int floorExtent = FLOOR_EXTENT;
const int floorExtent = FLOOR_EXTENT - 3;
const float tileSize = TILE_SIZE;
// Placement knobs

Binary file not shown.

View File

@@ -0,0 +1,437 @@
{
"accessors": [
{
"bufferView": 2,
"componentType": 5126,
"count": 640,
"max": [
1.0230355262756348,
1.0230355262756348,
0.9522716403007507
],
"min": [
-1.0230355262756348,
-1.0230356454849243,
-0.8872347474098206
],
"type": "VEC3"
},
{
"bufferView": 2,
"byteOffset": 7680,
"componentType": 5126,
"count": 640,
"max": [
0.9824470281600952,
0.9824470281600952,
0.9976038336753845
],
"min": [
-0.9824470281600952,
-0.9824469089508057,
-0.9747763872146606
],
"type": "VEC3"
},
{
"bufferView": 1,
"componentType": 5126,
"count": 640,
"max": [
0.8750001192092896,
1.0000001192092896
],
"min": [
0.1250000149011612,
0.0
],
"type": "VEC2"
},
{
"bufferView": 0,
"componentType": 5125,
"count": 960,
"type": "SCALAR"
},
{
"bufferView": 2,
"byteOffset": 15360,
"componentType": 5126,
"count": 1216,
"max": [
0.893750011920929,
0.8937500715255737,
0.9249112606048584
],
"min": [
-0.893750011920929,
-0.8937501907348633,
-4.531409203423209e-08
],
"type": "VEC3"
},
{
"bufferView": 2,
"byteOffset": 29952,
"componentType": 5126,
"count": 1216,
"max": [
0.9797981381416321,
0.9797983765602112,
0.9933796525001526
],
"min": [
-0.9797965288162231,
-0.9797996282577515,
-0.9942163825035095
],
"type": "VEC3"
},
{
"bufferView": 1,
"byteOffset": 5120,
"componentType": 5126,
"count": 1216,
"max": [
0.8750001192092896,
1.0000001192092896
],
"min": [
0.5,
0.0
],
"type": "VEC2"
},
{
"bufferView": 0,
"byteOffset": 3840,
"componentType": 5125,
"count": 1824,
"type": "SCALAR"
},
{
"bufferView": 2,
"byteOffset": 44544,
"componentType": 5126,
"count": 1536,
"max": [
0.7051442861557007,
0.7051441669464111,
1.0
],
"min": [
-0.7051442861557007,
-0.7051442265510559,
-1.0
],
"type": "VEC3"
},
{
"bufferView": 2,
"byteOffset": 62976,
"componentType": 5126,
"count": 1536,
"max": [
0.9916059970855713,
0.9916059374809265,
0.9975945949554443
],
"min": [
-0.9916058778762817,
-0.9916059970855713,
-0.9998875260353088
],
"type": "VEC3"
},
{
"bufferView": 1,
"byteOffset": 14848,
"componentType": 5126,
"count": 1536,
"max": [
0.8750001192092896,
1.0000001192092896
],
"min": [
0.125,
0.0
],
"type": "VEC2"
},
{
"bufferView": 0,
"byteOffset": 11136,
"componentType": 5125,
"count": 2304,
"type": "SCALAR"
}
],
"asset": {
"extras": {
"author": "TheMightyHitcher (https://sketchfab.com/TheMightyHitcher)",
"license": "CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)",
"source": "https://sketchfab.com/3d-models/low-poly-acorn-7b3c999e1353488ba553993b9218cd10",
"title": "Low Poly Acorn"
},
"generator": "Sketchfab-15.95.0",
"version": "2.0"
},
"bufferViews": [
{
"buffer": 0,
"byteLength": 20352,
"name": "floatBufferViews",
"target": 34963
},
{
"buffer": 0,
"byteLength": 27136,
"byteOffset": 20352,
"byteStride": 8,
"name": "floatBufferViews",
"target": 34962
},
{
"buffer": 0,
"byteLength": 81408,
"byteOffset": 47488,
"byteStride": 12,
"name": "floatBufferViews",
"target": 34962
}
],
"buffers": [
{
"byteLength": 128896,
"uri": "scene.bin"
}
],
"materials": [
{
"doubleSided": true,
"name": "Material",
"pbrMetallicRoughness": {
"baseColorFactor": [
0.190178,
0.0729788,
0.0138984,
1.0
],
"metallicFactor": 0.0,
"roughnessFactor": 0.9790637525374586
}
},
{
"doubleSided": true,
"name": "Acorn1",
"pbrMetallicRoughness": {
"baseColorFactor": [
0.076576,
0.0223255,
0.00686098,
1.0
],
"metallicFactor": 0.0,
"roughnessFactor": 0.9926785280489079
}
}
],
"meshes": [
{
"name": "Cube_Material_0",
"primitives": [
{
"attributes": {
"NORMAL": 1,
"POSITION": 0,
"TEXCOORD_0": 2
},
"indices": 3,
"material": 0,
"mode": 4
}
]
},
{
"name": "Cube.001_Acorn1_0",
"primitives": [
{
"attributes": {
"NORMAL": 5,
"POSITION": 4,
"TEXCOORD_0": 6
},
"indices": 7,
"material": 1,
"mode": 4
}
]
},
{
"name": "Cube.002_Acorn1_0",
"primitives": [
{
"attributes": {
"NORMAL": 9,
"POSITION": 8,
"TEXCOORD_0": 10
},
"indices": 11,
"material": 1,
"mode": 4
}
]
}
],
"nodes": [
{
"children": [
1
],
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
2.220446049250313e-16,
-1.0,
0.0,
0.0,
1.0,
2.220446049250313e-16,
0.0,
0.0,
0.0,
0.0,
1.0
],
"name": "Sketchfab_model"
},
{
"children": [
2
],
"matrix": [
0.009999999776482582,
0.0,
0.0,
0.0,
0.0,
0.0,
0.009999999776482582,
0.0,
0.0,
-0.009999999776482582,
0.0,
0.0,
0.0,
0.0,
0.0,
1.0
],
"name": "4d29c6035a3e4d51b0b3c164b827543f.fbx"
},
{
"children": [
3,
5,
7
],
"name": "RootNode"
},
{
"children": [
4
],
"matrix": [
100.0,
0.0,
0.0,
0.0,
0.0,
-1.629206793918314e-05,
-99.99999999999868,
0.0,
0.0,
99.99999999999868,
-1.629206793918314e-05,
0.0,
0.0,
93.53653717041016,
0.0,
1.0
],
"name": "Cube"
},
{
"mesh": 0,
"name": "Cube_Material_0"
},
{
"children": [
6
],
"matrix": [
149.15550231933594,
0.0,
0.0,
0.0,
0.0,
-2.4300515772896097e-05,
-149.15550231933398,
0.0,
0.0,
149.15550231933398,
-2.4300515772896097e-05,
0.0,
0.0,
140.1503448486328,
0.0,
1.0
],
"name": "Cube.001"
},
{
"mesh": 1,
"name": "Cube.001_Acorn1_0"
},
{
"children": [
8
],
"matrix": [
22.640613555908203,
0.0,
0.0,
0.0,
0.0,
-3.6886241423764725e-06,
-22.640613555907905,
0.0,
0.0,
22.640613555907905,
-3.6886241423764725e-06,
0.0,
0.0,
286.8188171386719,
0.0,
1.0
],
"name": "Cube.002"
},
{
"mesh": 2,
"name": "Cube.002_Acorn1_0"
}
],
"scene": 0,
"scenes": [
{
"name": "Sketchfab_Scene",
"nodes": [
0
]
}
]
}

Binary file not shown.

Binary file not shown.