48 lines
1.0 KiB
C
48 lines
1.0 KiB
C
#include "model.h"
|
|
|
|
#include <assert.h>
|
|
#include <stdlib.h>
|
|
|
|
model_t model_init(size_t vertex_count, size_t index_count)
|
|
{
|
|
model_t model = {
|
|
.indices = malloc(index_count * sizeof(index_t)),
|
|
.index_count = index_count,
|
|
.vertices = malloc(vertex_count * sizeof(vertex_t)),
|
|
.vertex_count = vertex_count,
|
|
};
|
|
return model;
|
|
}
|
|
|
|
void model_cleanup(model_t *m)
|
|
{
|
|
if (m->vertices != nullptr) {
|
|
free(m->vertices);
|
|
m->vertices = nullptr;
|
|
m->vertex_count = 0;
|
|
}
|
|
if (m->indices != nullptr) {
|
|
free(m->indices);
|
|
m->indices = nullptr;
|
|
m->index_count = 0;
|
|
}
|
|
if (m->bones != nullptr) {
|
|
free(m->bones);
|
|
m->bones = nullptr;
|
|
}
|
|
if (m->inverse_bind_matrices != nullptr) {
|
|
free(m->inverse_bind_matrices);
|
|
m->inverse_bind_matrices = nullptr;
|
|
}
|
|
if (m->animation.times_us != nullptr) {
|
|
free(m->animation.times_us);
|
|
m->animation.times_us = nullptr;
|
|
}
|
|
if (m->animation.keyframes != nullptr) {
|
|
free(m->animation.keyframes);
|
|
m->animation.keyframes = nullptr;
|
|
}
|
|
m->vertex_count = m->index_count = m->bone_count
|
|
= m->animation.keyframe_count = 0;
|
|
}
|