X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=model.h;h=9558d1e42b22480284e863982c2c770a0c45ce4b;hb=39378a28bc0b7c9beaf9f2191f5dc51b8c8865a0;hp=a1bf8ec24b70aa358abbe7f451c0cc20f196e7d3;hpb=a1a05787ada52089f30c533fb26b745554c07512;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/model.h b/model.h index a1bf8ec..9558d1e 100644 --- a/model.h +++ b/model.h @@ -7,7 +7,7 @@ typedef struct model model; typedef struct glmesh glmesh; typedef struct submodel submodel; typedef struct model_vert model_vert; -typedef struct scene scene; +typedef struct model_marker model_marker; typedef struct sdf_primative sdf_primative; typedef enum esdf_type esdf_type; @@ -18,7 +18,8 @@ struct model u32 vertex_count, indice_count, - layer_count; + layer_count, + marker_count; }; struct sdf_primative @@ -54,6 +55,14 @@ struct submodel char name[32]; }; +struct model_marker +{ + v3f co; + v4f q; + v3f s; + char name[32]; +}; + struct model_vert { v3f co, @@ -125,15 +134,21 @@ static void mesh_draw( glmesh *mesh ) /* * Helper functions for file offsets + * TODO: Revise this */ static submodel *model_get_submodel( model *mdl, int id ) { return ((submodel*)(mdl+1)) + id; } +static model_marker *model_get_marker( model *mdl, int id ) +{ + return ((model_marker*)model_get_submodel(mdl,mdl->layer_count)) + id; +} + static model_vert *model_vertex_base( model *mdl ) { - return (model_vert *)model_get_submodel( mdl, mdl->layer_count ); + return (model_vert *)model_get_marker( mdl, mdl->marker_count ); } static u32 *model_indice_base( model *mdl ) @@ -164,11 +179,31 @@ static submodel *submodel_get( model *mdl, const char *name ) return NULL; } +static model_marker *model_marker_get( model *mdl, const char *name ) +{ + for( int i=0; imarker_count; i++ ) + { + model_marker *mk = model_get_marker( mdl,i ); + + if( !strcmp( mk->name, name ) ) + return mk; + } + + return NULL; +} + static void submodel_draw( submodel *sm ) { mesh_drawn( sm->indice_start, sm->indice_count ); } +static void model_unpack_submodel( model *model, glmesh *mesh, submodel *sm ) +{ + mesh_upload( mesh, + model_vertex_base( model ) + sm->vertex_start, sm->vertex_count, + model_indice_base( model ) + sm->indice_start, sm->indice_count ); +} + static void model_unpack( model *model, glmesh *mesh ) { u32 offset = model_get_submodel( model, 0 )->vertex_count; @@ -188,4 +223,11 @@ static void model_unpack( model *model, glmesh *mesh ) model_indice_base( model ), model->indice_count ); } +static void mesh_free( glmesh *mesh ) +{ + glDeleteVertexArrays( 1, &mesh->vao ); + glDeleteBuffers( 1, &mesh->ebo ); + glDeleteBuffers( 1, &mesh->vbo ); +} + #endif