2 * Copyright (C) 2021-2024 Mt.ZERO Software, Harry Godden - All Rights Reserved
7 #define MDL_VERSION_MIN 101
8 #define MDL_VERSION_NR 105
11 k_shader_standard
= 0,
12 k_shader_standard_cutout
= 1,
13 k_shader_terrain_blend
= 2,
14 k_shader_standard_vertex_blend
= 3,
16 k_shader_invisible
= 5,
17 k_shader_boundary
= 6,
21 k_shader_foliage
= 10,
22 k_shader_override
= 30000
25 enum mdl_surface_prop
{
26 k_surface_prop_concrete
= 0,
27 k_surface_prop_wood
= 1,
28 k_surface_prop_grass
= 2,
29 k_surface_prop_tiles
= 3,
30 k_surface_prop_metal
= 4,
31 k_surface_prop_snow
= 5,
32 k_surface_prop_sand
= 6
36 k_material_flag_skate_target
= 0x0001,
37 k_material_flag_collision
= 0x0002,
38 k_material_flag_grow_grass
= 0x0004,
39 k_material_flag_grindable
= 0x0008,
40 k_material_flag_invisible
= 0x0010,
41 k_material_flag_boundary
= 0x0020,
42 k_material_flag_preview_visibile
= 0x0040,
43 k_material_flag_walking
= 0x0080,
45 k_material_flag_ghosts
=
46 k_material_flag_boundary
|
47 k_material_flag_invisible
|
48 k_material_flag_walking
60 u8 colour
[4]; /* 4*8 */
61 u16 weights
[4];/* 4*16 */
62 u8 groups
[4]; /* 4*8 */
67 typedef u32 mdl_indice
;
69 typedef struct mdl_context mdl_context
;
70 typedef struct mdl_array_ptr mdl_array_ptr
;
71 typedef struct mdl_vert mdl_vert
;
72 typedef struct mdl_transform mdl_transform
;
73 typedef struct mdl_submesh mdl_submesh
;
74 typedef struct mdl_material mdl_material
;
75 typedef struct mdl_bone mdl_bone
;
76 typedef struct mdl_armature mdl_armature
;
77 typedef struct mdl_animation mdl_animation
;
78 typedef struct mdl_transform mdl_keyframe
;
79 typedef struct mdl_mesh mdl_mesh
;
80 typedef struct mdl_file mdl_file
;
81 typedef struct mdl_texture mdl_texture
;
82 typedef struct mdl_array mdl_array
;
83 typedef struct mdl_header mdl_header
;
85 typedef struct glmesh glmesh
;
99 static void transform_identity( mdl_transform
*transform
)
101 v3_zero( transform
->co
);
102 q_identity( transform
->q
);
103 v3_fill( transform
->s
, 1.0f
);
106 static void mdl_transform_vector( mdl_transform
*transform
, v3f vec
, v3f dest
)
108 v3_mul( transform
->s
, vec
, dest
);
109 q_mulv( transform
->q
, dest
, dest
);
112 static void mdl_transform_point( mdl_transform
*transform
, v3f co
, v3f dest
)
114 mdl_transform_vector( transform
, co
, dest
);
115 v3_add( transform
->co
, dest
, dest
);
118 static void mdl_transform_mul( mdl_transform
*a
, mdl_transform
*b
,
121 mdl_transform_point( a
, b
->co
, d
->co
);
122 q_mul( a
->q
, b
->q
, d
->q
);
124 v3_mul( a
->s
, b
->s
, d
->s
);
137 u32 tex_diffuse
, /* Indexes start from 1. 0 if missing. */
153 v3f conevx
, conevy
, coneva
;
159 k_bone_flag_deform
= 0x00000001,
160 k_bone_flag_ik
= 0x00000002,
161 k_bone_flag_cone_constraint
= 0x00000004
166 k_bone_collider_none
= 0,
167 k_bone_collider_box
= 1,
168 k_bone_collider_capsule
= 2
173 mdl_transform transform
;
196 u16 material_id
, flags
;
201 k_submesh_flag_none
= 0x0000,
202 k_submesh_flag_consumed
= 0x0001
207 mdl_transform transform
;
211 entity_id
, /* upper 16 bits: type, lower 16 bits: index */
264 /* animation buffers */
270 u32 pack_base_offset
;
276 void mesh_bind( glmesh
*mesh
);
277 void mesh_drawn( u32 start
, u32 count
);
278 void mesh_draw( glmesh
*mesh
);
279 void mesh_free( glmesh
*mesh
);
281 /* file context management */
282 void mdl_open( mdl_context
*mdl
, const char *path
, void *lin_alloc
);
283 void mdl_close( mdl_context
*mdl
);
286 int _mdl_load_array( mdl_context
*mdl
, mdl_array_ptr
*ptr
,
287 const char *name
, void *lin_alloc
, u32 stride
);
288 #define MDL_LOAD_ARRAY( MDL, PTR, STRUCT, ALLOCATOR ) \
289 _mdl_load_array( MDL, PTR, #STRUCT, ALLOCATOR, sizeof(STRUCT) )
292 void *mdl_arritm( mdl_array_ptr
*arr
, u32 index
);
293 u32
mdl_arrcount( mdl_array_ptr
*arr
);
296 void mdl_fread_pack_file( mdl_context
*mdl
, mdl_file
*info
, void *dst
);
298 /* standard array groups */
299 int mdl_load_animation_block( mdl_context
*mdl
, void *lin_alloc
);
300 int mdl_load_metadata_block( mdl_context
*mdl
, void *lin_alloc
);
301 int mdl_load_mesh_block( mdl_context
*mdl
, void *lin_alloc
);
304 void mdl_async_load_glmesh( mdl_context
*mdl
, glmesh
*mesh
, u32
*fixup_table
);
306 /* load textures and mesh */
307 void mdl_async_full_load_std( mdl_context
*mdl
);
310 void mdl_draw_submesh( mdl_submesh
*sm
);
311 mdl_mesh
*mdl_find_mesh( mdl_context
*mdl
, const char *name
);
314 const char *mdl_pstr( mdl_context
*mdl
, u32 pstr
);
315 int mdl_pstreq( mdl_context
*mdl
, u32 pstr
, const char *str
, u32 djb2
);
316 #define MDL_CONST_PSTREQ( MDL, Q, CONSTSTR )\
317 mdl_pstreq( MDL, Q, CONSTSTR, vg_strdjb2( CONSTSTR ) )
319 void mdl_transform_m4x3( mdl_transform
*transform
, m4x3f mtx
);