Merge pull request #788 from rhabacker/3.6-obj-plugin-fixes

3.6 obj plugin fixes
This commit is contained in:
OpenSceneGraph git repository
2019-07-15 14:11:11 +01:00
committed by GitHub
4 changed files with 22 additions and 8 deletions

View File

@@ -384,7 +384,7 @@ void ObjPrimitiveIndexWriter::drawArrays(GLenum mode,GLint first,GLsizei count)
for(GLsizei i=0;i<count;++i)
{
writePoint(i);
writePoint(first + i);
}
break;
}
@@ -393,7 +393,7 @@ void ObjPrimitiveIndexWriter::drawArrays(GLenum mode,GLint first,GLsizei count)
{
for(GLsizei i=0;i<count;i+=2)
{
writeLine(i, i+1);
writeLine(first + i, first + i+1);
}
break;
}
@@ -401,7 +401,7 @@ void ObjPrimitiveIndexWriter::drawArrays(GLenum mode,GLint first,GLsizei count)
{
for(GLsizei i=1;i<count;++i)
{
writeLine(i-1, i);
writeLine(first + i-1, first + i);
}
break;
}
@@ -409,9 +409,9 @@ void ObjPrimitiveIndexWriter::drawArrays(GLenum mode,GLint first,GLsizei count)
{
for(GLsizei i=1;i<count;++i)
{
writeLine(i-1, i);
writeLine(first + i-1, first + i);
}
writeLine(count-1, 0);
writeLine(first + count-1, first + 0);
break;
}
default:
@@ -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;

View File

@@ -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;
};

View File

@@ -72,6 +72,7 @@ public:
supportsOption("BUMP=<unit>", "Set texture unit for bumpmap texture");
supportsOption("DISPLACEMENT=<unit>", "Set texture unit for displacement texture");
supportsOption("REFLECTION=<unit>", "Set texture unit for reflection texture");
supportsOption("NsIfNotPresent=<value>", "set specular exponent if not present");
supportsOption("precision=<digits>","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<double>::digits10 + 2;
specularExponent = -1;
}
};
@@ -356,12 +359,13 @@ 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));
}
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;

View File

@@ -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) {}