+/*
+ * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
+ */
+
#ifndef MODEL_H
#define MODEL_H
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_file_header mdl_file_header;
+typedef struct mdl_animation mdl_animation;
+typedef struct mdl_keyframe mdl_keyframe;
+typedef struct mdl_texture mdl_texture;
+typedef struct mdl_context mdl_context;
#define MDL_SIZE_MAX 0x1000000
#define MDL_VERT_MAX 1000000
#define MDL_SUBMESH_MAX 8000
#define MDL_STRING_LENGTH_MAX 64
+enum classtype
+{
+ k_classtype_none = 0,
+ k_classtype_gate = 1,
+ k_classtype_spawn = 3,
+ k_classtype_water = 4,
+ k_classtype_route_node = 8,
+ k_classtype_route = 9,
+ k_classtype_bone = 10,
+ k_classtype_skeleton = 11,
+ k_classtype_skin = 12,
+ k_classtype_audio = 14,
+ k_classtype_trigger = 100,
+ k_classtype_logic_achievement = 101,
+ k_classtype_logic_relay = 102
+};
+
+enum mdl_shader
+{
+ k_shader_standard = 0,
+ k_shader_standard_cutout = 1,
+ k_shader_terrain_blend = 2,
+ k_shader_standard_vertex_blend = 3,
+ k_shader_water = 4
+};
+
+enum mdl_surface_prop
+{
+ k_surface_prop_concrete = 0,
+ k_surface_prop_wood = 1,
+ k_surface_prop_grass = 2
+};
+
+enum material_flag
+{
+ k_material_flag_skate_surface = 0x1,
+ k_material_flag_collision = 0x2,
+ k_material_flag_grow_grass = 0x4,
+ k_material_flag_grind_surface = 0x8
+};
+
+enum bone_flag
+{
+ k_bone_flag_deform = 0x1,
+ k_bone_flag_ik = 0x2,
+ k_bone_flag_collider_box = 0x4,
+ k_bone_flag_collider_capsule = 0x8,
+ k_bone_flag_collider_reserved0 = 0x10,
+ k_bone_flag_collider_reserved1 = 0x20,
+ k_bone_flag_collider_reserved2 = 0x40,
+ k_bone_flag_collider_reserved3 = 0x80,
+ k_bone_flag_collider_any = k_bone_flag_collider_box |
+ k_bone_flag_collider_capsule |
+ k_bone_flag_collider_reserved0 |
+ k_bone_flag_collider_reserved1 |
+ k_bone_flag_collider_reserved2 |
+ k_bone_flag_collider_reserved3,
+ k_bone_flag_cone_constraint = 0x100,
+ k_bone_flag_force_u32 = 0xffffffff
+};
+
#pragma pack(push,1)
+/* 48 byte */
struct mdl_vert
{
- v3f co,
- norm;
- v4f colour;
- v2f uv;
+ v3f co, /* 3*32 */
+ norm; /* 3*32 */
+ v2f uv; /* 2*32 */
+
+ u8 colour[4]; /* 4*8 */
+ u16 weights[4];/* 4*16 */
+ u8 groups[4]; /* 4*8 */
};
struct mdl_submesh
u32 material_id;
};
+struct mdl_texture
+{
+ u32 pstr_name,
+ pack_offset,
+ pack_length;
+};
+
struct mdl_material
{
- u32 pstr_name;
+ u32 pstr_name,
+ shader,
+ flags,
+ surface_prop;
+
+ v4f colour,
+ colour1;
+
+ u32 tex_diffuse,
+ tex_decal,
+ tex_normal;
};
struct mdl_node
v4f q;
v3f s;
- union{ u32 submesh_start, sub_uid; };
- u32
+ u32 sub_uid, /* allocated in-file... too bad. */
+ submesh_start,
submesh_count,
classtype,
offset,
+ parent,
pstr_name;
};
-struct mdl_header
+struct mdl_keyframe
+{
+ v3f co;
+ v4f q;
+ v3f s;
+};
+
+struct mdl_animation
{
- u32 identifier, version, file_length;
+ u32 pstr_name,
+ length;
- u32 vertex_count, vertex_offset,
- indice_count, indice_offset,
- submesh_count, submesh_offset,
- material_count, material_offset,
- node_count, node_offset,
- strings_offset, entdata_offset;
+ float rate;
+
+ u32 offset;
+};
+
+struct mdl_file_header
+{
+ u32 identifier, version, file_length, pad0;
+
+ u32
+ node_count, node_offset,
+ submesh_count, submesh_offset,
+ material_count, material_offset,
+ texture_count, texture_offset,
+ anim_count, anim_offset,
+ entdata_size, entdata_offset,
+ strings_size, strings_offset,
+
+ keyframe_count, keyframe_offset,
+
+ vertex_count, vertex_offset,
+ indice_count, indice_offset,
+
+ pack_size, pack_offset;
};
/*
* Entity data structures
*/
-struct classtype_block
-{
- boxf bbx;
-};
-
struct classtype_gate
{
u32 target;
struct classtype_spawn
{
- u32 target;
+ u32 pstr_alias;
};
struct classtype_water
u32 temp;
};
-struct classtype_car_path
+struct classtype_route_node
{
u32 target, target1;
};
-struct classtype_instance
+struct classtype_route
+{
+ u32 id_start;
+ u32 pstr_name;
+ v3f colour;
+};
+
+struct classtype_bone
{
- u32 pstr_file;
+ u32 flags,
+ ik_target,
+ ik_pole;
+
+ boxf hitbox;
+
+ v3f conevx, conevy, coneva;
+ float conet;
};
-struct classtype_capsule
+struct classtype_skeleton
{
- float height, radius;
+ u32 channels,
+ ik_count,
+ collider_count,
+ anim_start,
+ anim_count;
};
-struct classtype_route_node
+struct classtype_skin
{
- u32 target, target1;
+ u32 skeleton;
};
-struct classtype_route
+struct classtype_trigger
+{
+ u32 target;
+};
+
+struct classtype_logic_relay
+{
+ u32 targets[4];
+};
+
+struct classtype_logic_achievement
{
u32 pstr_name;
- u32 id_start;
+};
+
+struct classtype_audio
+{
+ u32 pstr_file,
+ flags;
+
+ float volume;
};
#pragma pack(pop)
+
+struct mdl_context
+{
+ FILE *file;
+ mdl_file_header info;
+
+ /* each buffer becomes availible after each _load function is called */
+ mdl_node *node_buffer; /* mdl_load_metadata() */
+ mdl_submesh *submesh_buffer;
+ mdl_material *material_buffer;
+ mdl_texture *texture_buffer;
+ mdl_animation *anim_buffer;
+ void *entdata_buffer;
+ const char *string_buffer;
+
+ mdl_keyframe *keyframe_buffer; /* mdl_load_anim_data() */
+
+ mdl_vert *vertex_buffer; /* mdl_load_mesh_data() */
+ u32 *index_buffer;
+
+ void *pack; /* mdl_load_pack_data() */
+};
+
/*
* Simple mesh interface for OpenGL
*/
{
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 )
+VG_STATIC void mesh_upload( glmesh *mesh,
+ 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 );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, indice_count*sizeof(u32),
indices, GL_STATIC_DRAW );
+ /* 0: coordinates */
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, stride, (void*)0 );
glEnableVertexAttribArray( 0 );
+ /* 1: normal */
glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE,
stride, (void *)offsetof(mdl_vert, norm) );
glEnableVertexAttribArray( 1 );
- glVertexAttribPointer( 2, 4, GL_FLOAT, GL_FALSE,
- stride, (void *)offsetof(mdl_vert, colour) );
+ /* 2: uv */
+ glVertexAttribPointer( 2, 2, GL_FLOAT, GL_FALSE,
+ stride, (void *)offsetof(mdl_vert, uv) );
glEnableVertexAttribArray( 2 );
- glVertexAttribPointer( 3, 2, GL_FLOAT, GL_FALSE,
- stride, (void *)offsetof(mdl_vert, uv) );
+ /* 3: colour */
+ glVertexAttribPointer( 3, 4, GL_UNSIGNED_BYTE, GL_TRUE,
+ stride, (void *)offsetof(mdl_vert, colour) );
glEnableVertexAttribArray( 3 );
-
- VG_CHECK_GL();
+
+ /* 4: weights */
+ glVertexAttribPointer( 4, 4, GL_UNSIGNED_SHORT, GL_TRUE,
+ stride, (void *)offsetof(mdl_vert, weights) );
+ glEnableVertexAttribArray( 4 );
+
+ /* 5: groups */
+ glVertexAttribIPointer( 5, 4, GL_UNSIGNED_BYTE,
+ stride, (void *)offsetof(mdl_vert, groups) );
+ glEnableVertexAttribArray( 5 );
+
+ VG_CHECK_GL_ERR();
+
mesh->indice_count = indice_count;
+ mesh->loaded = 1;
}
-static void mesh_bind( glmesh *mesh )
+VG_STATIC void mesh_bind( glmesh *mesh )
{
glBindVertexArray( mesh->vao );
}
-static void mesh_drawn( u32 start, u32 count )
+VG_STATIC void mesh_drawn( u32 start, u32 count )
{
glDrawElements( GL_TRIANGLES, count, GL_UNSIGNED_INT,
(void *)(start*sizeof(u32)) );
}
-static void mesh_draw( glmesh *mesh )
+VG_STATIC void mesh_draw( glmesh *mesh )
{
mesh_drawn( 0, mesh->indice_count );
}
-static void mesh_free( glmesh *mesh )
+VG_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 );
+ mesh->loaded = 0;
+ }
}
+VG_STATIC void mdl_load_fatal_corrupt( mdl_context *mdl )
+{
+ fclose( mdl->file );
+ vg_file_print_invalid( mdl->file );
+ vg_fatal_exit_loop( "Corrupt model" );
+}
/*
* Model implementation
+ *
+ * TODO.
+ *
+ * you have two api options for loading a model, first, the easy way:
+ * mdl_load ...
+ * will put the entire model straight into the linear_alloc
+ *
+ * or, to target different allocators:
+ *
+ * mdl_open
+ * mdl_load_metadata
+ * mdl_load_vertex_data
+ * mdl_load_indice_data
+ * mdl_close
+ *
+ * these should ideally be called in quick succession to limit stalls.
*/
-static mdl_header *mdl_load( const char *path )
+/*
+ * if calling mdl_open, and the file does not exist, the game will fatal quit
+ */
+VG_STATIC void mdl_open( mdl_context *mdl, const char *path )
{
- i64 size;
- mdl_header *header = vg_asset_read_s( path, &size );
+ memset( mdl, 0, sizeof( mdl_context ) );
+ mdl->file = fopen( path, "rb" );
- /*
- * Check file is valid
- */
- if( !header )
+ if( !mdl->file )
{
- vg_error( "Could not open '%s'\n", path );
- return NULL;
+ vg_error( "mdl_open('%s'): %s\n", path, strerror(errno) );
+ vg_fatal_exit_loop( "see above for details" );
}
- if( size < sizeof(mdl_header) )
- {
- free( header );
- vg_error( "Invalid file '%s' (too small for header)\n", path );
- return NULL;
- }
+ u64 l = fread( &mdl->info, sizeof(mdl_file_header), 1, mdl->file );
+ if( l != 1 )
+ mdl_load_fatal_corrupt( mdl );
+}
+
+/*
+ * Load all metadata (everything up until the large buffers). Probs at most 50k
+ */
+VG_STATIC void mdl_load_metadata( mdl_context *mdl, void *lin_alloc )
+{
+ assert( mdl->file );
+
+ u64 lheader = sizeof(mdl_file_header),
+ ldata = mdl->info.keyframe_offset - lheader;
- if( header->file_length != size )
+ void *all_data = vg_linear_alloc( lin_alloc, ldata );
+
+ fseek( mdl->file, lheader, SEEK_SET );
+ u64 l = fread( all_data, ldata, 1, mdl->file );
+
+ if( l != 1 )
{
- vg_error( "Invalid file '%s'"
- "(wrong .file_length, %ub != real file size %ub)\n",
- path, header->file_length, size );
- free( header );
- return NULL;
+ vg_file_print_invalid( mdl->file );
+ vg_fatal_exit_loop( "Corrupt model" );
}
- /*
- * Validate offsets and memory sections, to ensure all arrays are in-bounds,
- * and that they do not overlap.
- */
+ mdl->node_buffer = all_data + (mdl->info.node_offset - lheader);
+ mdl->submesh_buffer = all_data + (mdl->info.submesh_offset - lheader);
+ mdl->material_buffer = all_data + (mdl->info.material_offset - lheader);
+ mdl->texture_buffer = all_data + (mdl->info.texture_offset - lheader);
+ mdl->anim_buffer = all_data + (mdl->info.anim_offset - lheader);
+ mdl->entdata_buffer = all_data + (mdl->info.entdata_offset - lheader);
+ mdl->string_buffer = all_data + (mdl->info.strings_offset - lheader);
+}
+
+/*
+ * Load just the mesh data
+ */
+VG_STATIC void mdl_load_mesh_data( mdl_context *mdl, void *lin_alloc )
+{
+ assert( mdl->file );
+
+ u64 size_verts = vg_align8( mdl->info.vertex_count * sizeof(mdl_vert) ),
+ size_index = vg_align8( mdl->info.indice_count * sizeof(u32) );
- struct memregion
+ mdl->vertex_buffer = vg_linear_alloc( lin_alloc, size_verts );
+ mdl->index_buffer = vg_linear_alloc( lin_alloc, size_index );
+
{
- const char *desc;
- u32 count, max_count, size, offset;
+ fseek( mdl->file, mdl->info.vertex_offset, SEEK_SET );
+ u64 l = fread( mdl->vertex_buffer, size_verts, 1, mdl->file );
+ if( l != 1 )
+ mdl_load_fatal_corrupt( mdl );
}
- regions[] = {
- {
- "Vertices",
- header->vertex_count, MDL_VERT_MAX,
- sizeof(mdl_vert), header->vertex_offset
- },
- {
- "Indices",
- header->indice_count, MDL_INDICE_MAX,
- sizeof(u32), header->indice_offset
- },
- {
- "Submesh",
- header->submesh_count, MDL_SUBMESH_MAX,
- sizeof(mdl_submesh), header->submesh_offset
- },
- {
- "Materials",
- header->material_count, MDL_MATERIAL_MAX,
- sizeof(mdl_material), header->material_offset
- },
- {
- "Nodes",
- header->node_count, MDL_NODE_MAX,
- sizeof(mdl_node), header->node_count
- }
- };
-
- for( int i=0; i<vg_list_size(regions); i++ )
{
- struct memregion *ri = ®ions[i];
+ fseek( mdl->file, mdl->info.indice_offset, SEEK_SET );
+ u64 l = fread( mdl->index_buffer, size_index, 1, mdl->file );
+ if( l != 1 )
+ mdl_load_fatal_corrupt( mdl );
+ }
+}
- if( ri->count == 0 )
- continue;
+/*
+ * Load animation data
+ */
+VG_STATIC void mdl_load_anim_data( mdl_context *mdl, void *lin_alloc )
+{
+ assert( mdl->file );
- if( ri->count > ri->max_count )
- {
- free( header );
- vg_error( "'%s': '%s' buffer exceeds the maximum (%u/%u)\n",
- path, ri->desc, ri->count, ri->max_count );
- return NULL;
- }
+ if( mdl->info.keyframe_count == 0 )
+ return;
+
+ u64 size_kf = vg_align8( mdl->info.keyframe_count * sizeof(mdl_keyframe) );
+ mdl->keyframe_buffer = vg_linear_alloc( lin_alloc, size_kf );
+
+ fseek( mdl->file, mdl->info.keyframe_offset, SEEK_SET );
+ u64 l = fread( mdl->keyframe_buffer, size_kf, 1, mdl->file );
+ if( l != 1 )
+ mdl_load_fatal_corrupt( mdl );
+}
- if( ri->offset >= header->file_length )
- {
- free( header );
- vg_error( "'%s': '%s' buffer offset is out of range\n",
- path, ri->desc );
- return NULL;
- }
+/*
+ * Load pack contents
+ *
+ * TODO request specific files (low)
+ */
+VG_STATIC void mdl_load_pack_data( mdl_context *mdl, void *lin_alloc )
+{
+ assert( mdl->file );
- if( ri->offset + ri->size*ri->count > header->file_length )
- {
- free( header );
- vg_error( "'%s': '%s' buffer size is out of range\n",
- path, ri->desc );
- return NULL;
- }
+ if( mdl->info.pack_size == 0 )
+ return;
+
+ mdl->pack = vg_linear_alloc( lin_alloc, vg_align8( mdl->info.pack_size ) );
+ fseek( mdl->file, mdl->info.pack_offset, SEEK_SET );
- for( int j=0; j<vg_list_size(regions); j++ )
- {
- struct memregion *rj = ®ions[j];
- if( rj->count == 0 )
- continue;
+ u64 l = fread( mdl->pack, mdl->info.pack_size, 1, mdl->file );
+ if( l != 1 )
+ mdl_load_fatal_corrupt( mdl );
+}
- if( ri->offset >= rj->offset &&
- (ri->offset+ri->size*ri->count < rj->offset+rj->size*rj->count))
- {
- free( header );
- vg_error( "'%s': '%s' buffer overlaps '%s'\n",
- path, ri->desc, rj->desc );
- return NULL;
- }
- }
- }
+/*
+ * close file handle
+ */
+VG_STATIC void mdl_close( mdl_context *mdl )
+{
+ fclose( mdl->file );
+ mdl->file = NULL;
+}
- /*
- * Pointer validation TODO(workshop)
- */
+/* open a model. TODO: make this flags ( ANIM_DATA|MESH_DATA ... ) */
+VG_STATIC mdl_context *mdl_load_full( void *lin_alloc, const char *path )
+{
+ /* Inspect the header by opening it, give us the size needed */
+ mdl_context temp_ctx;
+ mdl_open( &temp_ctx, path );
- /*
- * strings TODO(workshop)
- */
+ /* create allocator */
+ u32 tot_size = temp_ctx.info.file_length + sizeof( mdl_context ) + 64;
+ void *data = vg_create_linear_allocator( lin_alloc, tot_size,
+ VG_MEMORY_SYSTEM );
- return header;
-}
+ /* copy context and load all other data */
+ mdl_context *ctx = vg_linear_alloc( data, sizeof(mdl_context) );
+ memcpy( ctx, &temp_ctx, sizeof(mdl_context) );
-static void *mdl_baseptr( mdl_header *mdl, u32 offset )
-{
- return (void *)mdl + offset;
+ mdl_load_metadata( ctx, data );
+ mdl_load_anim_data( ctx, data );
+ mdl_load_mesh_data( ctx, data );
+ mdl_load_pack_data( ctx, data );
+ mdl_close( ctx );
+
+ return ctx;
}
-static const char *mdl_pstr( mdl_header *mdl, u32 pstr )
+/*
+ * Item getters
+ * ----------------------------------------------------------------------------
+ * TODO: Clamp access and oob errors
+ */
+VG_STATIC const char *mdl_pstr( mdl_context *mdl, u32 pstr )
{
- return (const char *)(mdl_baseptr( mdl, mdl->strings_offset )) + pstr;
+ return mdl->string_buffer + pstr;
}
-static mdl_node *mdl_node_from_id( mdl_header *mdl, u32 id )
+VG_STATIC mdl_node *mdl_node_from_id( mdl_context *mdl, u32 id )
{
- return ((mdl_node *)mdl_baseptr( mdl, mdl->node_offset )) + id;
+ return &mdl->node_buffer[id];
}
-static mdl_node *mdl_node_from_name( mdl_header *mdl, const char *name )
+VG_STATIC mdl_node *mdl_node_from_name( mdl_context *mdl, const char *name )
{
- for( int i=0; i<mdl->node_count; i++ )
+ for( int i=0; i < mdl->info.node_count; i++ )
{
mdl_node *pnode = mdl_node_from_id( mdl, i );
return NULL;
}
-static mdl_submesh *mdl_submesh_from_id( mdl_header *mdl, u32 id )
-{
- if( id >= mdl->submesh_count )
- return NULL;
-
- return ((mdl_submesh *)mdl_baseptr( mdl, mdl->submesh_offset )) + id;
-}
-
-static mdl_submesh *mdl_node_submesh( mdl_header *mdl, mdl_node *node, u32 i )
-{
- if( i >= node->submesh_count )
- return NULL;
-
- return mdl_submesh_from_id( mdl, node->submesh_start+i );
-}
-
-static u32 *mdl_submesh_indices( mdl_header *mdl, mdl_submesh *sm )
+VG_STATIC mdl_submesh *mdl_node_submesh( mdl_context *mdl,
+ mdl_node *node, u32 i )
{
- return ((u32 *)mdl_baseptr( mdl, mdl->indice_offset )) + sm->indice_start;
+ return &mdl->submesh_buffer[ node->submesh_start+i ];
}
-static mdl_vert *mdl_submesh_vertices( mdl_header *mdl, mdl_submesh *sm )
+VG_STATIC u32 *mdl_submesh_indices( mdl_context *mdl, mdl_submesh *sm )
{
- return ((mdl_vert *)mdl_baseptr(mdl,mdl->vertex_offset)) + sm->vertex_start;
+ return &mdl->index_buffer[ sm->indice_start ];
}
-static mdl_material *mdl_material_from_id( mdl_header *mdl, u32 id )
+VG_STATIC mdl_vert *mdl_submesh_vertices( mdl_context *mdl, mdl_submesh *sm )
{
- return ((mdl_material *)mdl_baseptr(mdl,mdl->material_offset)) + id;
+ return &mdl->vertex_buffer[ sm->vertex_start ];
}
-static void mdl_node_transform( mdl_node *pnode, m4x3f transform )
+VG_STATIC void mdl_node_transform( mdl_node *pnode, m4x3f transform )
{
q_m3x3( pnode->q, transform );
v3_muls( transform[0], pnode->s[0], transform[0] );
v3_copy( pnode->co, transform[3] );
}
-static void mdl_unpack_submesh( mdl_header *mdl, glmesh *mesh, mdl_submesh *sm )
+/* upload a mesh based on file submesh */
+VG_STATIC void mdl_unpack_submesh( mdl_context *mdl, glmesh *mesh,
+ mdl_submesh *sm )
{
mesh_upload( mesh, mdl_submesh_vertices( mdl, sm ), sm->vertex_count,
mdl_submesh_indices( mdl, sm ), sm->indice_count );
}
-static void mdl_unpack_glmesh( mdl_header *mdl, glmesh *mesh )
+/* upload entire mesh from model */
+VG_STATIC void mdl_unpack_glmesh( mdl_context *mdl, glmesh *mesh )
{
- u32 offset = mdl_submesh_from_id( mdl, 0 )->vertex_count;
+ u32 offset = mdl->submesh_buffer[0].vertex_count;
- for( int i=1; i< mdl->submesh_count; i++ )
+ for( int i=1; i< mdl->info.submesh_count; i++ )
{
- mdl_submesh *sm = mdl_submesh_from_id( mdl, i );
- u32 *indices = mdl_submesh_indices( mdl, sm );
+ mdl_submesh *sm = &mdl->submesh_buffer[i];
+ u32 *indices = mdl_submesh_indices( mdl, sm );
for( u32 j=0; j<sm->indice_count; j++ )
indices[j] += offset;
offset += sm->vertex_count;
}
- mdl_vert *vertex_base = mdl_baseptr( mdl, mdl->vertex_offset );
- u32 *indice_base = mdl_baseptr( mdl, mdl->indice_offset );
-
- mesh_upload( mesh, vertex_base, mdl->vertex_count,
- indice_base, mdl->indice_count );
+ mesh_upload( mesh, mdl->vertex_buffer, mdl->info.vertex_count,
+ mdl->index_buffer, mdl->info.indice_count );
}
-static void mdl_draw_submesh( mdl_submesh *sm )
+VG_STATIC void mdl_draw_submesh( mdl_submesh *sm )
{
mesh_drawn( sm->indice_start, sm->indice_count );
}
-static void *mdl_get_entdata( mdl_header *mdl, mdl_node *pnode )
+VG_STATIC void *mdl_get_entdata( mdl_context *mdl, mdl_node *pnode )
+{
+ return mdl->entdata_buffer + pnode->offset;
+}
+
+VG_STATIC mdl_keyframe *mdl_get_animdata( mdl_context *mdl, mdl_animation *anim )
{
- return mdl_baseptr( mdl, mdl->entdata_offset ) + pnode->offset;
+ return mdl->keyframe_buffer + anim->offset;
}
-static void mdl_link_materials( mdl_header *root, mdl_header *child )
+VG_STATIC void mdl_link_materials( mdl_context *root, mdl_context *child )
{
u32 lookup[MDL_MATERIAL_MAX];
- for( int i=0; i<child->material_count; i++ )
+ for( int i=0; i<child->info.material_count; i++ )
{
- mdl_material *mi = mdl_material_from_id( child, i );
+ mdl_material *mi = &child->material_buffer[i];
const char *si = mdl_pstr( child, mi->pstr_name );
lookup[i] = 0;
- for( int j=0; j<root->material_count; j++ )
+ for( int j=0; j<root->info.material_count; j++ )
{
- mdl_material *mj = mdl_material_from_id( root, j );
+ mdl_material *mj = &root->material_buffer[j];
const char *sj = mdl_pstr( root, mj->pstr_name );
if( !strcmp( si, sj ) )
}
}
- for( int i=0; i<child->submesh_count; i++ )
+ for( int i=0; i<child->info.submesh_count; i++ )
{
- mdl_submesh *sm = mdl_submesh_from_id( child, i );
- sm->material_id = lookup[sm->material_id];
+ mdl_submesh *sm = &child->submesh_buffer[i];
+ sm->material_id = lookup[sm->material_id];
}
}
+VG_STATIC void mdl_invert_uv_coordinates( mdl_context *mdl )
+{
+ for( int i=0; i<mdl->info.vertex_count; i++ )
+ {
+ mdl_vert *vert = &mdl->vertex_buffer[i];
+ vert->uv[1] = 1.0f-vert->uv[1];
+ }
+}
#endif