From a3b2ac63b35e3fa46921fdf1de8a4fa65a2e6949 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 25 Sep 2017 13:59:13 +0200 Subject: [PATCH 1/4] obj plugin: Fix bug not using specular color (Ks) for illumination mode > 2 See paragraph "Illumination models" at http://paulbourke.net/dataformats/mtl/ for details. --- src/osgPlugins/obj/ReaderWriterOBJ.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osgPlugins/obj/ReaderWriterOBJ.cpp b/src/osgPlugins/obj/ReaderWriterOBJ.cpp index 00cc880dc..8b50ddff1 100644 --- a/src/osgPlugins/obj/ReaderWriterOBJ.cpp +++ b/src/osgPlugins/obj/ReaderWriterOBJ.cpp @@ -356,7 +356,7 @@ void ReaderWriterOBJ::buildMaterialToStateSetMap(obj::Model& model, MaterialToSt osg_material->setDiffuse(osg::Material::FRONT_AND_BACK,material.diffuse); osg_material->setEmission(osg::Material::FRONT_AND_BACK,material.emissive); - if (material.illum == 2) { + if (material.illum >= 2) { osg_material->setSpecular(osg::Material::FRONT_AND_BACK,material.specular); } else { osg_material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0,0,0,1)); From 361ea5d15d218e4f0d687193a3374d5321575624 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 15 Jul 2019 14:29:26 +0200 Subject: [PATCH 2/4] obj plugin: add option "NsIfNotPresent=" for setting the specular exponent of a material if not present --- src/osgPlugins/obj/ReaderWriterOBJ.cpp | 11 ++++++++++- src/osgPlugins/obj/obj.h | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) 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) {} From 2e33cf0abc8cc123114f66326d55c662ca08a863 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 15 Jan 2018 14:22:18 +0100 Subject: [PATCH 3/4] obj plugin: Fix not writing material shininess --- src/osgPlugins/obj/OBJWriterNodeVisitor.cpp | 4 ++++ src/osgPlugins/obj/OBJWriterNodeVisitor.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/osgPlugins/obj/OBJWriterNodeVisitor.cpp b/src/osgPlugins/obj/OBJWriterNodeVisitor.cpp index eaaec1187..6a5277c27 100644 --- a/src/osgPlugins/obj/OBJWriterNodeVisitor.cpp +++ b/src/osgPlugins/obj/OBJWriterNodeVisitor.cpp @@ -425,6 +425,7 @@ OBJWriterNodeVisitor::OBJMaterial::OBJMaterial(osg::Material* mat, osg::Texture* diffuse(1,1,1,1), ambient(0.2,0.2,0.2,1), specular(0,0,0,1), + shininess(-1), image("") { static unsigned int s_objmaterial_id = 0; @@ -437,6 +438,7 @@ OBJWriterNodeVisitor::OBJMaterial::OBJMaterial(osg::Material* mat, osg::Texture* diffuse = mat->getDiffuse(osg::Material::FRONT); ambient = mat->getAmbient(osg::Material::FRONT); specular = mat->getSpecular(osg::Material::FRONT); + shininess = mat->getShininess(osg::Material::FRONT)*1000.0f/128.0f; } if (tex) { @@ -454,6 +456,8 @@ std::ostream& operator<<(std::ostream& fout, const OBJWriterNodeVisitor::OBJMate fout << " " << "Ka " << mat.ambient << std::endl; fout << " " << "Kd " << mat.diffuse << std::endl; fout << " " << "Ks " << mat.specular << std::endl; + if (mat.shininess != -1) + fout << " " << "Ns " << mat.shininess<< std::endl; if(!mat.image.empty()) fout << " " << "map_Kd " << mat.image << std::endl; diff --git a/src/osgPlugins/obj/OBJWriterNodeVisitor.h b/src/osgPlugins/obj/OBJWriterNodeVisitor.h index 8dc16a0d5..8a9cf8f6f 100644 --- a/src/osgPlugins/obj/OBJWriterNodeVisitor.h +++ b/src/osgPlugins/obj/OBJWriterNodeVisitor.h @@ -116,6 +116,7 @@ class OBJWriterNodeVisitor: public osg::NodeVisitor { OBJMaterial(osg::Material* mat, osg::Texture* tex); osg::Vec4 diffuse, ambient, specular; + float shininess; std::string image; std::string name; }; From cbf5b14f615d21cd3984e85201612219bf734ac6 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 16 Jan 2018 10:23:36 +0100 Subject: [PATCH 4/4] obj plugin: Fix bug not adding first vertex index on writing GL_LINExxx array types --- src/osgPlugins/obj/OBJWriterNodeVisitor.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/osgPlugins/obj/OBJWriterNodeVisitor.cpp b/src/osgPlugins/obj/OBJWriterNodeVisitor.cpp index 6a5277c27..81ce5fee6 100644 --- a/src/osgPlugins/obj/OBJWriterNodeVisitor.cpp +++ b/src/osgPlugins/obj/OBJWriterNodeVisitor.cpp @@ -384,7 +384,7 @@ void ObjPrimitiveIndexWriter::drawArrays(GLenum mode,GLint first,GLsizei count) for(GLsizei i=0;i