Fixed the already working models that I broke when introducing GLTFReadValue.
Improved the example for gltf models to be able to switch between a few models.
This commit is contained in:
parent
47313dd601
commit
eee29c5ef1
|
|
@ -39,7 +39,18 @@ int main(void)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.type = CAMERA_PERSPECTIVE; // Camera mode type
|
camera.type = CAMERA_PERSPECTIVE; // Camera mode type
|
||||||
|
|
||||||
Model model = LoadModel("resources/gltf/Avocado.glb"); // Load the animated model mesh and
|
Model model[7];
|
||||||
|
|
||||||
|
model[0] = LoadModel("resources/gltf/raylib_32x32.glb");
|
||||||
|
model[1] = LoadModel("resources/gltf/rigged_figure.glb");
|
||||||
|
model[2] = LoadModel("resources/gltf/Avocado.glb");
|
||||||
|
model[3] = LoadModel("resources/gltf/GearboxAssy.glb");
|
||||||
|
model[4] = LoadModel("resources/gltf/BoxAnimated.glb");
|
||||||
|
model[5] = LoadModel("resources/gltf/AnimatedTriangle.gltf");
|
||||||
|
model[6] = LoadModel("resources/gltf/AnimatedMorphCube.glb");
|
||||||
|
|
||||||
|
int currentModel = 0;
|
||||||
|
int modelCount = 7;
|
||||||
|
|
||||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
|
|
@ -54,16 +65,34 @@ int main(void)
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera);
|
UpdateCamera(&camera);
|
||||||
|
|
||||||
|
if(IsKeyReleased(KEY_RIGHT))
|
||||||
|
{
|
||||||
|
currentModel++;
|
||||||
|
if(currentModel == modelCount)
|
||||||
|
{
|
||||||
|
currentModel = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(IsKeyReleased(KEY_LEFT))
|
||||||
|
{
|
||||||
|
currentModel--;
|
||||||
|
if(currentModel < 0)
|
||||||
|
{
|
||||||
|
currentModel = modelCount - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(SKYBLUE);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
DrawModelEx(model, position, (Vector3){ 0.0f, 1.0f, 0.0f }, 180.0f, (Vector3){ 15.0f, 15.0f, 15.0f }, WHITE);
|
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
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
|
|
||||||
|
|
@ -78,7 +107,10 @@ int main(void)
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
UnloadModel(model); // Unload model
|
for(int i = 0; i < modelCount; i++)
|
||||||
|
{
|
||||||
|
UnloadModel(model[i]); // Unload model
|
||||||
|
}
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
BIN
examples/models/resources/gltf/Textures/raylib_32x32.png
Normal file
BIN
examples/models/resources/gltf/Textures/raylib_32x32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 189 B |
BIN
examples/models/resources/gltf/raylib_32x32.glb
Normal file
BIN
examples/models/resources/gltf/raylib_32x32.glb
Normal file
Binary file not shown.
|
|
@ -3678,7 +3678,7 @@ static bool GLTFReadValue(cgltf_accessor* acc, unsigned int index, void* variabl
|
||||||
if(acc->buffer_view == NULL || acc->buffer_view->buffer == NULL || acc->buffer_view->buffer->data == NULL)
|
if(acc->buffer_view == NULL || acc->buffer_view->buffer == NULL || acc->buffer_view->buffer->data == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
void* readPosition = ((char*)acc->buffer_view->buffer->data) + (index * stride) + acc->buffer_view->offset;
|
void* readPosition = ((char*)acc->buffer_view->buffer->data) + (index * stride) + acc->buffer_view->offset + acc->offset;
|
||||||
memcpy(variable, readPosition, stride);
|
memcpy(variable, readPosition, stride);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user