diff --git a/src/osgPlugins/obj/ReaderWriterOBJ.cpp b/src/osgPlugins/obj/ReaderWriterOBJ.cpp index 8b50ddff1..fc4cb993c 100644 --- a/src/osgPlugins/obj/ReaderWriterOBJ.cpp +++ b/src/osgPlugins/obj/ReaderWriterOBJ.cpp @@ -72,6 +72,7 @@ public: supportsOption("BUMP=", "Set texture unit for bumpmap texture"); supportsOption("DISPLACEMENT=", "Set texture unit for displacement texture"); supportsOption("REFLECTION=", "Set texture unit for reflection texture"); + supportsOption("NsIfNotPresent=", "set specular exponent if not present"); supportsOption("precision=","Set the floating point precision when writing out files"); } @@ -156,6 +157,7 @@ protected: TextureAllocationMap textureUnitAllocation; /// Coordinates precision. int precision; + int specularExponent; ObjOptionsStruct() { @@ -166,6 +168,7 @@ protected: fixBlackMaterials = true; noReverseFaces = false; precision = std::numeric_limits::digits10 + 2; + specularExponent = -1; } }; @@ -361,7 +364,8 @@ void ReaderWriterOBJ::buildMaterialToStateSetMap(obj::Model& model, MaterialToSt } else { osg_material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0,0,0,1)); } - osg_material->setShininess(osg::Material::FRONT_AND_BACK,(material.Ns/1000.0f)*128.0f ); // note OBJ shiniess is 0..1000. + int ns = material.Ns != -1 ? material.Ns : localOptions.specularExponent != -1 ? localOptions.specularExponent : 0; + osg_material->setShininess(osg::Material::FRONT_AND_BACK,(ns/1000.0f)*128.0f ); // note OBJ shiniess is 0..1000. if (material.ambient[3]!=1.0 || material.diffuse[3]!=1.0 || @@ -887,6 +891,11 @@ ReaderWriterOBJ::ObjOptionsStruct ReaderWriterOBJ::parseOptions(const osgDB::Rea localOptions.precision = val; } } + else if (pre_equals == "NsIfNotPresent") + { + int value = atoi(post_equals.c_str()); + localOptions.specularExponent = value ; + } else if (post_equals.length()>0) { obj::Material::Map::TextureMapType type = obj::Material::Map::UNKNOWN; diff --git a/src/osgPlugins/obj/obj.h b/src/osgPlugins/obj/obj.h index b100ac88d..9d79c533a 100644 --- a/src/osgPlugins/obj/obj.h +++ b/src/osgPlugins/obj/obj.h @@ -43,7 +43,7 @@ public: illum(2), Tf(0.0f,0.0f,0.0f,1.0f), Ni(0), - Ns(0), + Ns(-1), // textureReflection(false), alpha(1.0f) {}