2 * Copyright (C) 2021-2024 Mt.ZERO Software, Harry Godden - All Rights Reserved
7 #define MDL_VERSION_MIN 101
8 #define MDL_VERSION_NR 106
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
);
134 #if (MDL_VERSION_MIN <= 105)
135 struct mdl_material_v105
145 u32 tex_diffuse
, /* Indexes start from 1. 0 if missing. */
163 /* -> vg_msg containing KV properties */
166 void *compiled
; /* -> shader specific structure for render */
182 v3f conevx
, conevy
, coneva
;
188 k_bone_flag_deform
= 0x00000001,
189 k_bone_flag_ik
= 0x00000002,
190 k_bone_flag_cone_constraint
= 0x00000004
195 k_bone_collider_none
= 0,
196 k_bone_collider_box
= 1,
197 k_bone_collider_capsule
= 2
202 mdl_transform transform
;
225 u16 material_id
, flags
;
230 k_submesh_flag_none
= 0x0000,
231 k_submesh_flag_consumed
= 0x0001
236 mdl_transform transform
;
240 entity_id
, /* upper 16 bits: type, lower 16 bits: index */
287 /* animation buffers */
293 u32 pack_base_offset
;
299 void mesh_bind( glmesh
*mesh
);
300 void mesh_drawn( u32 start
, u32 count
);
301 void mesh_draw( glmesh
*mesh
);
302 void mesh_free( glmesh
*mesh
);
304 /* file context management */
305 void mdl_open( mdl_context
*mdl
, const char *path
, void *lin_alloc
);
306 void mdl_close( mdl_context
*mdl
);
309 int _mdl_load_array( mdl_context
*mdl
, mdl_array_ptr
*ptr
,
310 const char *name
, void *lin_alloc
, u32 stride
);
311 #define MDL_LOAD_ARRAY( MDL, PTR, STRUCT, ALLOCATOR ) \
312 _mdl_load_array( MDL, PTR, #STRUCT, ALLOCATOR, sizeof(STRUCT) )
315 void *mdl_arritm( mdl_array_ptr
*arr
, u32 index
);
316 u32
mdl_arrcount( mdl_array_ptr
*arr
);
319 void mdl_fread_pack_file( mdl_context
*mdl
, mdl_file
*info
, void *dst
);
321 /* standard array groups */
322 int mdl_load_animation_block( mdl_context
*mdl
, void *lin_alloc
);
323 int mdl_load_metadata_block( mdl_context
*mdl
, void *lin_alloc
);
324 int mdl_load_mesh_block( mdl_context
*mdl
, void *lin_alloc
);
325 int mdl_load_materials( mdl_context
*mdl
, void *lin_alloc
);
328 void mdl_async_load_glmesh( mdl_context
*mdl
, glmesh
*mesh
, u32
*fixup_table
);
330 /* load textures and mesh */
331 void mdl_async_full_load_std( mdl_context
*mdl
);
334 void mdl_draw_submesh( mdl_submesh
*sm
);
335 mdl_mesh
*mdl_find_mesh( mdl_context
*mdl
, const char *name
);
336 mdl_submesh
*mdl_find_submesh( mdl_context
*mdl
, const char *mesh_name
);
339 const char *mdl_pstr( mdl_context
*mdl
, u32 pstr
);
340 int mdl_pstreq( mdl_context
*mdl
, u32 pstr
, const char *str
, u32 djb2
);
341 #define MDL_CONST_PSTREQ( MDL, Q, CONSTSTR )\
342 mdl_pstreq( MDL, Q, CONSTSTR, vg_strdjb2( CONSTSTR ) )
344 void mdl_transform_m4x3( mdl_transform
*transform
, m4x3f mtx
);