Cleaned up usage of BIND_PER_PRIMITIVE where possible.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
#include <osg/Config>
|
||||
#ifndef OSG_USE_DEPRECATED_GEOMETRY_METHODS
|
||||
#define OSG_USE_DEPRECATED_GEOMETRY_METHODS 1
|
||||
#endif
|
||||
|
||||
#include "ConvertFromInventor.h"
|
||||
|
||||
#include "PendulumCallback.h"
|
||||
|
||||
@@ -587,12 +587,12 @@ osg::Quat DataInputStream::readQuat(){
|
||||
osg::Geometry::AttributeBinding DataInputStream::readBinding(){
|
||||
char c = readChar();
|
||||
|
||||
if (_verboseOutput) std::cout<<"read/writeBinding() ["<<(int)c<<"]"<<std::endl;
|
||||
if (_verboseOutput) std::cout<<"readBinding() ["<<(int)c<<"]"<<std::endl;
|
||||
|
||||
switch((int)c){
|
||||
case 0: return osg::Geometry::BIND_OFF;
|
||||
case 1: return osg::Geometry::BIND_OVERALL;
|
||||
case 2: return osg::Geometry::BIND_PER_PRIMITIVE;
|
||||
case 2: return 3 /*osg::Geometry::BIND_PER_PRIMITIVE*/;
|
||||
case 3: return osg::Geometry::BIND_PER_PRIMITIVE_SET;
|
||||
case 4: return osg::Geometry::BIND_PER_VERTEX;
|
||||
default:
|
||||
|
||||
@@ -509,11 +509,11 @@ void DataOutputStream::writeQuat(const osg::Quat& q){
|
||||
|
||||
void DataOutputStream::writeBinding(osg::Geometry::AttributeBinding b){
|
||||
switch(b){
|
||||
case osg::Geometry::BIND_OFF: writeChar((char) 0); break;
|
||||
case osg::Geometry::BIND_OVERALL: writeChar((char) 1); break;
|
||||
case osg::Geometry::BIND_PER_PRIMITIVE: writeChar((char) 2); break;
|
||||
case osg::Geometry::BIND_PER_PRIMITIVE_SET: writeChar((char) 3); break;
|
||||
case osg::Geometry::BIND_PER_VERTEX: writeChar((char) 4); break;
|
||||
case osg::Geometry::BIND_OFF: writeChar((char) 0); break;
|
||||
case osg::Geometry::BIND_OVERALL: writeChar((char) 1); break;
|
||||
case static_cast<osg::Geometry::AttributeBinding>(3): writeChar((char) 2); break; /*osg::Geometry::BIND_PER_PRIMITIVE*/
|
||||
case osg::Geometry::BIND_PER_PRIMITIVE_SET: writeChar((char) 3); break;
|
||||
case osg::Geometry::BIND_PER_VERTEX: writeChar((char) 4); break;
|
||||
default: throwException("Unknown binding in DataOutputStream::writeBinding()");
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,8 @@ void Normals::MakeNormalsVisitor::apply( Geode &geode )
|
||||
Geometry *geom = dynamic_cast<Geometry *>(geode.getDrawable(i));
|
||||
if( geom )
|
||||
{
|
||||
if (geom->containsDeprecatedData()) geom->fixDeprecatedData();
|
||||
|
||||
Vec3Array *coords = dynamic_cast<Vec3Array*>(geom->getVertexArray());
|
||||
if( coords == 0L )
|
||||
continue;
|
||||
@@ -85,7 +87,7 @@ void Normals::MakeNormalsVisitor::apply( Geode &geode )
|
||||
_local_coords->push_back( v );
|
||||
_local_coords->push_back( (v + n));
|
||||
}
|
||||
else // BIND_PER_PRIMITIVE_SET, BIND_PER_PRIMITIVE, BIND_PER_VERTEX
|
||||
else // BIND_PER_PRIMITIVE_SET, BIND_PER_VERTEX
|
||||
{
|
||||
Geometry::PrimitiveSetList& primitiveSets = geom->getPrimitiveSetList();
|
||||
Geometry::PrimitiveSetList::iterator itr;
|
||||
@@ -121,10 +123,7 @@ void Normals::MakeNormalsVisitor::apply( Geode &geode )
|
||||
{
|
||||
_processPrimitive( 3, coord_index, normals_index, binding );
|
||||
coord_index += 3;
|
||||
if( binding == Geometry::BIND_PER_PRIMITIVE )
|
||||
normals_index++;
|
||||
else
|
||||
normals_index+=3;
|
||||
normals_index+=3;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -150,10 +149,7 @@ void Normals::MakeNormalsVisitor::apply( Geode &geode )
|
||||
{
|
||||
_processPrimitive( 4, coord_index, normals_index, binding );
|
||||
coord_index += 4;
|
||||
if( binding == Geometry::BIND_PER_PRIMITIVE )
|
||||
normals_index++;
|
||||
else
|
||||
normals_index+=4;
|
||||
normals_index +=4;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -169,11 +165,7 @@ void Normals::MakeNormalsVisitor::apply( Geode &geode )
|
||||
//OSG_WARN << "j=" << j << " num_prim=" << num_prim << std::endl;
|
||||
_processPrimitive(num_prim, coord_index, normals_index, binding);
|
||||
coord_index += num_prim;
|
||||
if (binding == Geometry::BIND_PER_PRIMITIVE) {
|
||||
++normals_index;
|
||||
} else {
|
||||
normals_index += num_prim;
|
||||
}
|
||||
normals_index += num_prim;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -198,13 +190,9 @@ void Normals::MakeNormalsVisitor::_processPrimitive( unsigned int nv,
|
||||
{
|
||||
Vec3 v(0,0,0);
|
||||
Vec3 n(0,0,0);
|
||||
if( _mode == SurfaceNormals || binding == Geometry::BIND_PER_PRIMITIVE )
|
||||
if( _mode == SurfaceNormals )
|
||||
{
|
||||
if( binding == Geometry::BIND_PER_PRIMITIVE )
|
||||
{
|
||||
n = *(normals++);
|
||||
}
|
||||
else if( binding == Geometry::BIND_PER_VERTEX )
|
||||
if( binding == Geometry::BIND_PER_VERTEX )
|
||||
{
|
||||
for( unsigned int i = 0; i < nv; i++ )
|
||||
n += *(normals++);
|
||||
|
||||
@@ -136,8 +136,6 @@ class ObjPrimitiveIndexWriter : public osg::PrimitiveIndexFunctor {
|
||||
write(i2);
|
||||
write(i3);
|
||||
_fout << std::endl;
|
||||
// not sure if this is correct?
|
||||
if(_geo->getNormalBinding() && _geo->getNormalBinding() == osg::Geometry::BIND_PER_PRIMITIVE) ++_normalIndex;
|
||||
}
|
||||
|
||||
// operator for lines
|
||||
@@ -147,8 +145,6 @@ class ObjPrimitiveIndexWriter : public osg::PrimitiveIndexFunctor {
|
||||
write(i1);
|
||||
write(i2);
|
||||
_fout << std::endl;
|
||||
// not sure if this is correct?
|
||||
if(_geo->getNormalBinding() && _geo->getNormalBinding() == osg::Geometry::BIND_PER_PRIMITIVE) ++_normalIndex;
|
||||
}
|
||||
|
||||
// operator for points
|
||||
@@ -157,8 +153,6 @@ class ObjPrimitiveIndexWriter : public osg::PrimitiveIndexFunctor {
|
||||
_fout << "p ";
|
||||
write(i1);
|
||||
_fout << std::endl;
|
||||
// not sure if this is correct?
|
||||
if(_geo->getNormalBinding() && _geo->getNormalBinding() == osg::Geometry::BIND_PER_PRIMITIVE) ++_normalIndex;
|
||||
}
|
||||
|
||||
virtual void begin(GLenum mode)
|
||||
@@ -524,6 +518,8 @@ void OBJWriterNodeVisitor::processGeometry(osg::Geometry* geo, osg::Matrix& m) {
|
||||
_fout << std::endl;
|
||||
_fout << "o " << getUniqueName( geo->getName().empty() ? geo->className() : geo->getName() ) << std::endl;
|
||||
|
||||
if (geo->containsDeprecatedData()) geo->fixDeprecatedData();
|
||||
|
||||
processStateSet(_currentStateSet.get());
|
||||
|
||||
processArray("v", geo->getVertexArray(), m, false);
|
||||
|
||||
@@ -97,17 +97,41 @@ private:
|
||||
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
|
||||
|
||||
geom->setVertexArray(_vertex.get());
|
||||
geom->setNormalArray(_normal.get());
|
||||
geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);
|
||||
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, _numFacets * 3));
|
||||
|
||||
|
||||
if (_normal.valid())
|
||||
{
|
||||
// need to convert per triangle normals to per vertex
|
||||
osg::ref_ptr<osg::Vec3Array> perVertexNormals = new osg::Vec3Array;
|
||||
perVertexNormals->reserveArray(_normal->size() * 3);
|
||||
for(osg::Vec3Array::iterator itr = _normal->begin();
|
||||
itr != _normal->end();
|
||||
++itr)
|
||||
{
|
||||
perVertexNormals->push_back(*itr);
|
||||
}
|
||||
|
||||
geom->setNormalArray(perVertexNormals.get());
|
||||
geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
|
||||
}
|
||||
|
||||
if (_color.valid())
|
||||
{
|
||||
// need to convert per triangle colours to per vertex
|
||||
OSG_INFO << "STL file with color" << std::endl;
|
||||
geom->setColorArray(_color.get());
|
||||
geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE);
|
||||
osg::ref_ptr<osg::Vec4Array> perVertexColours = new osg::Vec4Array;
|
||||
perVertexColours->reserveArray(_color->size() * 3);
|
||||
for(osg::Vec4Array::iterator itr = _color->begin();
|
||||
itr != _color->end();
|
||||
++itr)
|
||||
{
|
||||
perVertexColours->push_back(*itr);
|
||||
}
|
||||
geom->setColorArray(perVertexColours.get());
|
||||
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
|
||||
}
|
||||
|
||||
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, _numFacets * 3));
|
||||
|
||||
osgUtil::TriStripVisitor tristripper;
|
||||
tristripper.stripify(*geom);
|
||||
|
||||
|
||||
@@ -268,6 +268,8 @@ void ToVRML::apply(osg::Drawable* drawable) {
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
void ToVRML::apply(osg::Geometry* geom) {
|
||||
|
||||
if (geom->containsDeprecatedData()) geom->fixDeprecatedData();
|
||||
|
||||
// are all primitives faces or line ?
|
||||
GLenum mode;
|
||||
osg::PrimitiveSet::Type type;
|
||||
@@ -1128,12 +1130,6 @@ void ToVRML::writeNormal(osg::Geometry* geom, std::vector<int>& primitiveSetFace
|
||||
_fout << indent() << n[0] << " " << n[1] << " " << n[2] << ",\n";
|
||||
}
|
||||
|
||||
} else if (geom->getNormalBinding() == osg::Geometry::BIND_PER_PRIMITIVE) {
|
||||
for (unsigned int j = 0; j < (*nArray).size(); j++) {
|
||||
n = (*nArray)[j];
|
||||
_fout << indent() << n[0] << " " << n[1] << " " << n[2] << ",\n";
|
||||
}
|
||||
|
||||
} else if (geom->getNormalBinding() == osg::Geometry::BIND_PER_PRIMITIVE_SET) {
|
||||
for (unsigned int j = 0; j < (*nArray).size(); j++) {
|
||||
n = (*nArray)[j];
|
||||
@@ -1282,12 +1278,6 @@ void ToVRML::writeColor(osg::Geometry* geom, std::vector<int>& primitiveSetFaces
|
||||
_fout << indent() << c[0] << " " << c[1] << " " << c[2] << ",\n";
|
||||
}
|
||||
|
||||
} else if (geom->getColorBinding() == osg::Geometry::BIND_PER_PRIMITIVE) {
|
||||
for (unsigned int j = 0; j < (*cArray).size(); j++) {
|
||||
c = (*cArray)[j];
|
||||
_fout << indent() << c[0] << " " << c[1] << " " << c[2] << ",\n";
|
||||
}
|
||||
|
||||
} else if (geom->getColorBinding() == osg::Geometry::BIND_PER_PRIMITIVE_SET) {
|
||||
for (unsigned int j = 0; j < (*cArray).size(); j++) {
|
||||
c = (*cArray)[j];
|
||||
|
||||
Reference in New Issue
Block a user