File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -5567,6 +5567,15 @@ static Model LoadVOX(const char *fileName)
55675567unsigned char * m3d_loaderhook (char * fn , unsigned int * len ) { return LoadFileData ((const char * )fn , (int * )len ); }
55685568void m3d_freehook (void * data ) { UnloadFileData ((unsigned char * )data ); }
55695569
5570+ // Comparison function for qsort
5571+ static int m3d_compare_faces (const void * a , const void * b )
5572+ {
5573+ m3df_t * fa = (m3df_t * )a ;
5574+ m3df_t * fb = (m3df_t * )b ;
5575+
5576+ return (fa -> materialid - fb -> materialid );
5577+ }
5578+
55705579// Load M3D mesh data
55715580static Model LoadM3D (const char * fileName )
55725581{
@@ -5614,6 +5623,9 @@ static Model LoadM3D(const char *fileName)
56145623 // We always need a default material, so we add +1
56155624 model .materialCount ++ ;
56165625
5626+ // failsafe, model should already have faces grouped by material
5627+ qsort (m3d -> face , m3d -> numface , sizeof (m3df_t ), m3d_compare_faces );
5628+
56175629 model .meshes = (Mesh * )RL_CALLOC (model .meshCount , sizeof (Mesh ));
56185630 model .meshMaterial = (int * )RL_CALLOC (model .meshCount , sizeof (int ));
56195631 model .materials = (Material * )RL_CALLOC (model .materialCount + 1 , sizeof (Material ));
You can’t perform that action at this time.
0 commit comments