From 423fce13211b07d83ceca2548228602523f51acf Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Mon, 17 Jan 2011 10:06:15 +0000 Subject: [PATCH] automatically detect the color format (integer between 0 and 255 or floats between 0 and 1) --- wrap/io_trimesh/import_obj.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/wrap/io_trimesh/import_obj.h b/wrap/io_trimesh/import_obj.h index 97c6380b..81a3daed 100644 --- a/wrap/io_trimesh/import_obj.h +++ b/wrap/io_trimesh/import_obj.h @@ -291,10 +291,13 @@ public: { if(numTokens>=7) { - unsigned char r = (unsigned char) ((ScalarType) atof(tokens[4].c_str()) * 255.0); - unsigned char g = (unsigned char) ((ScalarType) atof(tokens[5].c_str()) * 255.0); - unsigned char b = (unsigned char) ((ScalarType) atof(tokens[6].c_str()) * 255.0); - unsigned char alpha = (unsigned char) ((numTokens>=8 ? (ScalarType) atof(tokens[7].c_str()) : 1) * 255.0); + ScalarType rf(atof(tokens[4].c_str())), gf(atof(tokens[5].c_str())), bf(atof(tokens[6].c_str())); + ScalarType scaling = (rf<=1 && gf<=1 && bf<=1) ? 255. : 1; + + unsigned char r = (unsigned char) ((ScalarType) atof(tokens[4].c_str()) * scaling); + unsigned char g = (unsigned char) ((ScalarType) atof(tokens[5].c_str()) * scaling); + unsigned char b = (unsigned char) ((ScalarType) atof(tokens[6].c_str()) * scaling); + unsigned char alpha = (unsigned char) ((numTokens>=8 ? (ScalarType) atof(tokens[7].c_str()) : 1) * scaling); (*vi).C() = Color4b(r, g, b, alpha); } else