X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=model.h;h=02e85bcd835b59c3e2639dbf0076605271da9ce3;hb=b9dedb4dd2a1e94ae76a3986716ee3c57e568213;hp=21a4e2fe2e75a4a8917d4f6af09aee44574419f4;hpb=d045af680c6b8ca267a7aded69e2e510e659d2ab;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/model.h b/model.h index 21a4e2f..02e85bc 100644 --- a/model.h +++ b/model.h @@ -10,6 +10,8 @@ typedef struct mdl_submesh mdl_submesh; typedef struct mdl_material mdl_material; typedef struct mdl_node mdl_node; typedef struct mdl_header mdl_header; +typedef struct mdl_animation mdl_animation; +typedef struct mdl_keyframe mdl_keyframe; #define MDL_SIZE_MAX 0x1000000 #define MDL_VERT_MAX 1000000 @@ -19,6 +21,24 @@ typedef struct mdl_header mdl_header; #define MDL_SUBMESH_MAX 8000 #define MDL_STRING_LENGTH_MAX 64 +enum classtype +{ + k_classtype_none = 0, + k_classtype_gate = 1, + k_classtype_block = 2, + k_classtype_spawn = 3, + k_classtype_water = 4, + k_classtype_car_path = 5, + k_classtype_instance = 6, + k_classtype_capsule = 7, + k_classtype_route_node = 8, + k_classtype_route = 9, + k_classtype_bone = 10, + k_classtype_skeleton = 11, + k_classtype_skin = 12 +}; + + #pragma pack(push,1) struct mdl_vert @@ -59,10 +79,27 @@ struct mdl_node submesh_count, classtype, offset, - children, + parent, pstr_name; }; +struct mdl_keyframe +{ + v3f co; + v4f q; + v3f s; +}; + +struct mdl_animation +{ + u32 pstr_name, + length; + + float rate; + + u32 offset; +}; + struct mdl_header { u32 identifier, version, file_length; @@ -72,8 +109,8 @@ struct mdl_header submesh_count, submesh_offset, material_count, material_offset, node_count, node_offset, - strings_offset, entdata_offset, - anim_count, anim_offset; + anim_count, anim_offset, + strings_offset, entdata_offset, animdata_offset; }; /* @@ -123,19 +160,28 @@ struct classtype_route_node struct classtype_route { - u32 pstr_name; u32 id_start; v3f colour; }; struct classtype_bone { - u32 deform; + u32 deform, + ik_target, + ik_pole, + collider, + use_limits; + + v3f angle_limits[2]; + boxf hitbox; }; struct classtype_skeleton { - u32 anim_start, + u32 channels, + ik_count, + collider_count, + anim_start, anim_count; }; @@ -154,12 +200,15 @@ struct glmesh { GLuint vao, vbo, ebo; u32 indice_count; + u32 loaded; }; static void mesh_upload( glmesh *mesh, - mdl_vert *verts, u32 vert_count, - u32 *indices, u32 indice_count ) + mdl_vert *verts, u32 vert_count, + u32 *indices, u32 indice_count ) { + //assert( mesh->loaded == 0 ); + glGenVertexArrays( 1, &mesh->vao ); glGenBuffers( 1, &mesh->vbo ); glGenBuffers( 1, &mesh->ebo ); @@ -204,9 +253,10 @@ static void mesh_upload( glmesh *mesh, stride, (void *)offsetof(mdl_vert, groups) ); glEnableVertexAttribArray( 5 ); - - VG_CHECK_GL(); + VG_CHECK_GL_ERR(); + mesh->indice_count = indice_count; + mesh->loaded = 1; } static void mesh_bind( glmesh *mesh ) @@ -227,9 +277,12 @@ static void mesh_draw( glmesh *mesh ) static void mesh_free( glmesh *mesh ) { - glDeleteVertexArrays( 1, &mesh->vao ); - glDeleteBuffers( 1, &mesh->ebo ); - glDeleteBuffers( 1, &mesh->vbo ); + if( mesh->loaded ) + { + glDeleteVertexArrays( 1, &mesh->vao ); + glDeleteBuffers( 1, &mesh->ebo ); + glDeleteBuffers( 1, &mesh->vbo ); + } } @@ -253,7 +306,7 @@ static mdl_header *mdl_load( const char *path ) if( size < sizeof(mdl_header) ) { - free( header ); + vg_free( header ); vg_error( "Invalid file '%s' (too small for header)\n", path ); return NULL; } @@ -263,7 +316,7 @@ static mdl_header *mdl_load( const char *path ) vg_error( "Invalid file '%s'" "(wrong .file_length, %ub != real file size %ub)\n", path, header->file_length, size ); - free( header ); + vg_free( header ); return NULL; } @@ -314,7 +367,7 @@ static mdl_header *mdl_load( const char *path ) if( ri->count > ri->max_count ) { - free( header ); + vg_free( header ); vg_error( "'%s': '%s' buffer exceeds the maximum (%u/%u)\n", path, ri->desc, ri->count, ri->max_count ); return NULL; @@ -322,7 +375,7 @@ static mdl_header *mdl_load( const char *path ) if( ri->offset >= header->file_length ) { - free( header ); + vg_free( header ); vg_error( "'%s': '%s' buffer offset is out of range\n", path, ri->desc ); return NULL; @@ -330,7 +383,7 @@ static mdl_header *mdl_load( const char *path ) if( ri->offset + ri->size*ri->count > header->file_length ) { - free( header ); + vg_free( header ); vg_error( "'%s': '%s' buffer size is out of range\n", path, ri->desc ); return NULL; @@ -345,7 +398,7 @@ static mdl_header *mdl_load( const char *path ) if( ri->offset >= rj->offset && (ri->offset+ri->size*ri->count < rj->offset+rj->size*rj->count)) { - free( header ); + vg_free( header ); vg_error( "'%s': '%s' buffer overlaps '%s'\n", path, ri->desc, rj->desc ); return NULL; @@ -423,6 +476,11 @@ static mdl_material *mdl_material_from_id( mdl_header *mdl, u32 id ) return ((mdl_material *)mdl_baseptr(mdl,mdl->material_offset)) + id; } +static mdl_animation *mdl_animation_from_id( mdl_header *mdl, u32 id ) +{ + return ((mdl_animation *)mdl_baseptr(mdl,mdl->anim_offset)) + id; +} + static void mdl_node_transform( mdl_node *pnode, m4x3f transform ) { q_m3x3( pnode->q, transform ); @@ -470,6 +528,11 @@ static void *mdl_get_entdata( mdl_header *mdl, mdl_node *pnode ) return mdl_baseptr( mdl, mdl->entdata_offset ) + pnode->offset; } +static mdl_keyframe *mdl_get_animdata( mdl_header *mdl, mdl_animation *anim ) +{ + return mdl_baseptr( mdl, mdl->animdata_offset ) + anim->offset; +} + static void mdl_link_materials( mdl_header *root, mdl_header *child ) { u32 lookup[MDL_MATERIAL_MAX];