瀏覽代碼

Review models examples

pull/787/head
Ray 5 年之前
父節點
當前提交
be6d237b9e
共有 12 個檔案被更改,包括 44 行新增33 行删除
  1. +1
    -1
      examples/models/models_cubicmap.c
  2. +1
    -1
      examples/models/models_heightmap.c
  3. +7
    -7
      examples/models/models_material_pbr.c
  4. +12
    -1
      examples/models/models_mesh_generation.c
  5. +3
    -3
      examples/models/models_mesh_picking.c
  6. +1
    -1
      examples/models/models_obj_loading.c
  7. +9
    -9
      examples/models/models_obj_viewer.c
  8. +3
    -3
      examples/models/models_skybox.c
  9. +3
    -3
      examples/models/models_yaw_pitch_roll.c
  10. +1
    -1
      examples/shaders/shaders_custom_uniform.c
  11. +2
    -2
      examples/shaders/shaders_model_shader.c
  12. +1
    -1
      examples/shaders/shaders_postprocessing.c

+ 1
- 1
examples/models/models_cubicmap.c 查看文件

@ -31,7 +31,7 @@ int main()
// NOTE: By default each cube is mapped to one part of texture atlas
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
model.material.maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position

+ 1
- 1
examples/models/models_heightmap.c 查看文件

@ -29,7 +29,7 @@ int main()
Mesh mesh = GenMeshHeightmap(image, (Vector3){ 16, 8, 16 }); // Generate heightmap mesh (RAM and VRAM)
Model model = LoadModelFromMesh(mesh); // Load model from generated mesh
model.material.maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Define model position
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM

+ 7
- 7
examples/models/models_material_pbr.c 查看文件

@ -38,16 +38,16 @@ int main()
// Load model and PBR material
Model model = LoadModel("resources/pbr/trooper.obj");
MeshTangents(&model.mesh);
model.material = LoadMaterialPBR((Color){ 255, 255, 255, 255 }, 1.0f, 1.0f);
MeshTangents(&model.meshes[0]);
model.materials[0] = LoadMaterialPBR((Color){ 255, 255, 255, 255 }, 1.0f, 1.0f);
// Define lights attributes
// NOTE: Shader is passed to every light on creation to define shader bindings internally
Light lights[MAX_LIGHTS] = {
CreateLight(LIGHT_POINT, (Vector3){ LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 0, 255 }, model.material.shader),
CreateLight(LIGHT_POINT, (Vector3){ 0.0f, LIGHT_HEIGHT, LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 255, 0, 255 }, model.material.shader),
CreateLight(LIGHT_POINT, (Vector3){ -LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 0, 255, 255 }, model.material.shader),
CreateLight(LIGHT_DIRECTIONAL, (Vector3){ 0.0f, LIGHT_HEIGHT*2.0f, -LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 255, 255 }, model.material.shader)
CreateLight(LIGHT_POINT, (Vector3){ LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 0, 255 }, model.materials[0].shader),
CreateLight(LIGHT_POINT, (Vector3){ 0.0f, LIGHT_HEIGHT, LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 255, 0, 255 }, model.materials[0].shader),
CreateLight(LIGHT_POINT, (Vector3){ -LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 0, 0, 255, 255 }, model.materials[0].shader),
CreateLight(LIGHT_DIRECTIONAL, (Vector3){ 0.0f, LIGHT_HEIGHT*2.0f, -LIGHT_DISTANCE }, (Vector3){ 0.0f, 0.0f, 0.0f }, (Color){ 255, 0, 255, 255 }, model.materials[0].shader)
};
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
@ -64,7 +64,7 @@ int main()
// Send to material PBR shader camera view position
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
SetShaderValue(model.material.shader, model.material.shader.locs[LOC_VECTOR_VIEW], cameraPos, UNIFORM_VEC3);
SetShaderValue(model.materials[0].shader, model.materials[0].shader.locs[LOC_VECTOR_VIEW], cameraPos, UNIFORM_VEC3);
//----------------------------------------------------------------------------------
// Draw

+ 12
- 1
examples/models/models_mesh_generation.c 查看文件

@ -39,7 +39,7 @@ int main()
models[7] = LoadModelFromMesh(GenMeshPoly(5, 2.0f));
// Set checked texture as default diffuse component for all models material
for (int i = 0; i < NUM_MODELS; i++) models[i].material.maps[MAP_DIFFUSE].texture = texture;
for (int i = 0; i < NUM_MODELS; i++) models[i].materials[0].maps[MAP_DIFFUSE].texture = texture;
// Define the camera to look into our 3d world
Camera camera = {{ 5.0f, 5.0f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
@ -65,6 +65,17 @@ int main()
{
currentModel = (currentModel + 1)%NUM_MODELS; // Cycle between the textures
}
if (IsKeyPressed(KEY_RIGHT))
{
currentModel++;
if (currentModel >= NUM_MODELS) currentModel = 0;
}
else if (IsKeyPressed(KEY_LEFT))
{
currentModel--;
if (currentModel < 0) currentModel = NUM_MODELS - 1;
}
//----------------------------------------------------------------------------------
// Draw

+ 3
- 3
examples/models/models_mesh_picking.c 查看文件

@ -26,7 +26,7 @@ int main()
// Define the camera to look into our 3d world
Camera camera = { 0 };
camera.position = (Vector3){ 20.0f, 20.0f, 20.0f }; // Camera position
camera.position = (Vector3){ 20.0f, 20.0f, 20.0f }; // Camera position
camera.target = (Vector3){ 0.0f, 8.0f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.6f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 45.0f; // Camera field-of-view Y
@ -36,10 +36,10 @@ int main()
Model tower = LoadModel("resources/models/turret.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/models/turret_diffuse.png"); // Load model texture
tower.material.maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture
tower.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture
Vector3 towerPos = { 0.0f, 0.0f, 0.0f }; // Set model position
BoundingBox towerBBox = MeshBoundingBox(tower.mesh); // Get mesh bounding box
BoundingBox towerBBox = MeshBoundingBox(tower.meshes[0]); // Get mesh bounding box
bool hitMeshBBox = false;
bool hitTriangle = false;

+ 1
- 1
examples/models/models_obj_loading.c 查看文件

@ -30,7 +30,7 @@ int main()
Model model = LoadModel("resources/models/castle.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/models/castle_diffuse.png"); // Load model texture
model.material.maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
SetTargetFPS(60); // Set our game to run at 60 frames-per-second

+ 9
- 9
examples/models/models_obj_viewer.c 查看文件

@ -27,13 +27,13 @@ int main()
Model model = LoadModel("resources/models/turret.obj"); // Load default model obj
Texture2D texture = LoadTexture("resources/models/turret_diffuse.png"); // Load default model texture
model.material.maps[MAP_DIFFUSE].texture = texture; // Bind texture to model
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Bind texture to model
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
BoundingBox bounds = MeshBoundingBox(model.mesh); // Set model bounds
bool selected = false; // Selected object flag
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
BoundingBox bounds = MeshBoundingBox(model.meshes[0]); // Set model bounds
bool selected = false; // Selected object flag
SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
char objFilename[64] = "turret.obj";
@ -54,15 +54,15 @@ int main()
{
if (IsFileExtension(droppedFiles[0], ".obj"))
{
UnloadMesh(&model.mesh);
model.mesh = LoadMesh(droppedFiles[0]);
bounds = MeshBoundingBox(model.mesh);
UnloadMesh(&model.meshes[0]);
model.meshes[0] = LoadMesh(droppedFiles[0]);
bounds = MeshBoundingBox(model.meshes[0]);
}
else if (IsFileExtension(droppedFiles[0], ".png"))
{
UnloadTexture(texture);
texture = LoadTexture(droppedFiles[0]);
model.material.maps[MAP_DIFFUSE].texture = texture;
model.materials[0].maps[MAP_DIFFUSE].texture = texture;
}
strcpy(objFilename, GetFileName(droppedFiles[0]));

+ 3
- 3
examples/models/models_skybox.c 查看文件

@ -29,8 +29,8 @@ int main()
// Load skybox shader and set required locations
// NOTE: Some locations are automatically set at shader loading
skybox.material.shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs");
SetShaderValue(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, UNIFORM_INT);
skybox.materials[0].shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs");
SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, UNIFORM_INT);
// Load cubemap shader and setup required shader locations
Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs");
@ -41,7 +41,7 @@ int main()
// Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture
// NOTE: New texture is generated rendering to texture, shader computes the sphre->cube coordinates mapping
skybox.material.maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512);
skybox.materials[0].maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512);
UnloadTexture(texHDR); // Texture not required anymore, cubemap already generated
UnloadShader(shdrCubemap); // Unload cubemap generation shader, not required anymore

+ 3
- 3
examples/models/models_yaw_pitch_roll.c 查看文件

@ -37,10 +37,10 @@ int main()
RenderTexture2D framebuffer = LoadRenderTexture(192, 192);
// Model loading
Model model = LoadModel("resources/plane.obj"); // Load OBJ model
model.material.maps[MAP_DIFFUSE].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture
Model model = LoadModel("resources/plane.obj"); // Load OBJ model
model.materials[0].maps[MAP_DIFFUSE].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture
GenTextureMipmaps(&model.material.maps[MAP_DIFFUSE].texture);
GenTextureMipmaps(&model.materials[0].maps[MAP_DIFFUSE].texture);
Camera camera = { 0 };
camera.position = (Vector3){ 0.0f, 60.0f, -120.0f };// Camera position perspective

+ 1
- 1
examples/shaders/shaders_custom_uniform.c 查看文件

@ -45,7 +45,7 @@ int main()
Model model = LoadModel("resources/models/barracks.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/models/barracks_diffuse.png"); // Load model texture (diffuse map)
model.material.maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position

+ 2
- 2
examples/shaders/shaders_model_shader.c 查看文件

@ -50,8 +50,8 @@ int main()
// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/grayscale.fs", GLSL_VERSION));
model.material.shader = shader; // Set shader effect to 3d model
model.material.maps[MAP_DIFFUSE].texture = texture; // Bind texture to model
model.materials[0].shader = shader; // Set shader effect to 3d model
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Bind texture to model
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position

+ 1
- 1
examples/shaders/shaders_postprocessing.c 查看文件

@ -74,7 +74,7 @@ int main()
Model model = LoadModel("resources/models/church.obj"); // Load OBJ model
Texture2D texture = LoadTexture("resources/models/church_diffuse.png"); // Load model texture (diffuse map)
model.material.maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position

Loading…
取消
儲存