@@ -461,6 +461,13 @@ static struct surface *create_surface(const struct model *model, int arg_surface
461461 return surface_init (surface_w , surface_h , surface_size_x , surface_size_y );
462462}
463463
464+ const char * get_file_extension (const char * filename )
465+ {
466+ const char * dot = strrchr (filename , '.' );
467+ if (!dot || dot == filename ) return NULL ;
468+ return dot + 1 ;
469+ }
470+
464471int main (int argc , char * argv [])
465472{
466473 if (argc == 1 )
@@ -495,9 +502,32 @@ int main(int argc, char *argv[])
495502
496503 struct model * model ;
497504
498- if (!(model = model_load_from_obj (args .input_file , args .color_support )))
499- return 1 ;
500- model_invert_z (model ); // Required by the OBJ format.
505+ const char * fileExt = get_file_extension (args .input_file );
506+ if (fileExt == NULL )
507+ {
508+ fprintf (stderr , "ERROR: Input file has no extension.\n" );
509+ exit (1 );
510+ }
511+ else if (strcmp (fileExt , "obj" ) == 0 )
512+ {
513+ if (!(model = model_load_from_obj (args .input_file , args .color_support )))
514+ return 1 ;
515+ model_invert_z (model ); // Required by the OBJ format.
516+ }
517+ else if (strcmp (fileExt , "stl" ) == 0 )
518+ {
519+ if (args .color_support )
520+ {
521+ fprintf (stderr , "WARN: Colors are not supported in STL format.\n" );
522+ }
523+ if (!(model = model_load_from_stl (args .input_file )))
524+ return 1 ;
525+ }
526+ else
527+ {
528+ fprintf (stderr , "ERROR: Input file has unsupported extension.\n" );
529+ exit (1 );
530+ }
501531
502532 if (model -> vertex_count == 0 )
503533 {
0 commit comments