X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=model.h;h=6f99fb61d77044d489147a9fa9a9a32b97569a3a;hb=2e4531dfd7bd0d9a0776fda1a62653806d85eb3b;hp=ca7c0b1d5f73d95c1a913fd5857fa552b9eb368e;hpb=23a1be081ab9e378cba49a23b8ed4d4082b580c1;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/model.h b/model.h index ca7c0b1..6f99fb6 100644 --- a/model.h +++ b/model.h @@ -29,19 +29,21 @@ typedef struct mdl_context mdl_context; 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 + k_classtype_none = 000, + k_classtype_bone = 001, + k_classtype_skeleton = 002, + k_classtype_skin = 003, + k_classtype_world_light = 004, + + k_classtype_gate = 100, + k_classtype_nonlocal_gate = 101, + k_classtype_spawn = 200, + k_classtype_water = 300, + k_classtype_route = 400, + k_classtype_route_node = 401, + k_classtype_audio = 500, + k_classtype_audio_sprite = 502, + k_classtype_volume_audio = 600, }; enum mdl_shader @@ -57,26 +59,50 @@ enum mdl_surface_prop { k_surface_prop_concrete = 0, k_surface_prop_wood = 1, - k_surface_prop_grass = 2 + k_surface_prop_grass = 2, + k_surface_prop_tiles = 3 }; enum material_flag { k_material_flag_skate_surface = 0x1, k_material_flag_collision = 0x2, - k_material_flag_grow_grass = 0x4 + 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; - v2f uv; - u8 colour[4]; - u16 weights[4]; - u8 groups[4]; + 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 @@ -169,81 +195,101 @@ struct mdl_file_header * Entity data structures */ -struct classtype_gate +struct classtype_bone /* 001 */ { - u32 target; - v3f dims; + u32 flags, + ik_target, + ik_pole; + + boxf hitbox; + + v3f conevx, conevy, coneva; + float conet; }; -struct classtype_spawn +struct classtype_skeleton /* 002 */ { - u32 pstr_alias; + u32 channels, + ik_count, + collider_count, + anim_start, + anim_count; }; -struct classtype_water +struct classtype_skin /* 003 */ { - u32 temp; + u32 skeleton; }; -struct classtype_route_node +struct classtype_world_light /* 004 */ { - u32 target, target1; + enum light_type + { + k_light_type_point, + k_light_type_spot, + k_light_type_point_nighttime_only, + k_light_type_spot_nighttime_only + } + type; + + v4f colour; /* RGB, Energy */ + float angle, range; }; -struct classtype_route + +struct classtype_gate /* 100, 101 */ { - u32 id_start; - u32 pstr_name; - v3f colour; + u32 target; + v3f dims; }; -struct classtype_bone +struct classtype_spawn /* 200 */ { - u32 deform, - ik_target, - ik_pole, - collider, - use_limits; - - v3f angle_limits[2]; - boxf hitbox; + u32 pstr_alias; }; -struct classtype_skeleton +struct classtype_water /* 300 */ { - u32 channels, - ik_count, - collider_count, - anim_start, - anim_count; + u32 temp; }; -struct classtype_skin +struct classtype_route /* 400 */ { - u32 skeleton; + u32 id_start; + u32 pstr_name; + v3f colour; }; -struct classtype_trigger +struct classtype_route_node /* 401 */ { - u32 target; + u32 target, target1; }; -struct classtype_logic_relay + +struct classtype_audio /* 500 */ { - u32 targets[4]; + u32 pstr_file, + flags; + + float volume; }; -struct classtype_logic_achievement +struct classtype_audio_sprite /* 501 */ { - u32 pstr_name; + u32 audio, + category; + + float probability; }; -struct classtype_audio +struct classtype_volume_audio /* 600 */ { - u32 pstr_file, - flags; + u32 category; +}; - float volume; +struct classtype_volume_event /* 601 */ +{ + u32 event; }; #pragma pack(pop) @@ -448,8 +494,8 @@ VG_STATIC void mdl_load_mesh_data( mdl_context *mdl, void *lin_alloc ) { assert( mdl->file ); - u64 size_verts = mdl->info.vertex_count * sizeof(mdl_vert), - size_index = mdl->info.indice_count * sizeof(u32); + u64 size_verts = vg_align8( mdl->info.vertex_count * sizeof(mdl_vert) ), + size_index = vg_align8( mdl->info.indice_count * sizeof(u32) ); mdl->vertex_buffer = vg_linear_alloc( lin_alloc, size_verts ); mdl->index_buffer = vg_linear_alloc( lin_alloc, size_index ); @@ -478,7 +524,7 @@ VG_STATIC void mdl_load_anim_data( mdl_context *mdl, void *lin_alloc ) if( mdl->info.keyframe_count == 0 ) return; - u64 size_kf = mdl->info.keyframe_count * sizeof(mdl_keyframe); + 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 ); @@ -499,7 +545,7 @@ VG_STATIC void mdl_load_pack_data( mdl_context *mdl, void *lin_alloc ) if( mdl->info.pack_size == 0 ) return; - mdl->pack = vg_linear_alloc( lin_alloc, mdl->info.pack_size ); + mdl->pack = vg_linear_alloc( lin_alloc, vg_align8( mdl->info.pack_size ) ); fseek( mdl->file, mdl->info.pack_offset, SEEK_SET ); u64 l = fread( mdl->pack, mdl->info.pack_size, 1, mdl->file ); @@ -524,7 +570,7 @@ VG_STATIC mdl_context *mdl_load_full( void *lin_alloc, const char *path ) mdl_open( &temp_ctx, path ); /* create allocator */ - u32 tot_size = temp_ctx.info.file_length + sizeof( mdl_context ); + 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 ); @@ -674,5 +720,13 @@ VG_STATIC void mdl_link_materials( mdl_context *root, mdl_context *child ) } } +VG_STATIC void mdl_invert_uv_coordinates( mdl_context *mdl ) +{ + for( int i=0; iinfo.vertex_count; i++ ) + { + mdl_vert *vert = &mdl->vertex_buffer[i]; + vert->uv[1] = 1.0f-vert->uv[1]; + } +} #endif