From Roger James, "These fix a couple of problems in the ac3d writer.

1. Number of child node of the world object set incorrectly in when scene contains shape drawables.

2. Incorrect handling of line primitives."
This commit is contained in:
Robert Osfield
2007-06-06 11:34:19 +00:00
parent 36d50301cf
commit 87c9b39c98
3 changed files with 47 additions and 2 deletions

View File

@@ -162,6 +162,28 @@ void Geode::OutputPolygon(const int iCurrentMaterial, const unsigned int surface
}
}
//======= draw array length cases
void Geode::OutputLineDARR(const int iCurrentMaterial, const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout)
{
unsigned int vindex = drawArrayLengths->getFirst();
for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr <drawArrayLengths->end(); ++primItr)
{
unsigned int localPrimLength;
localPrimLength = 2;
for(GLsizei primCount = 0; primCount < *primItr; ++primCount)
{
if ((primCount%localPrimLength)==0)
{
OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
}
OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
++vindex;
}
}
}
void Geode::OutputTriangleDARR(const int iCurrentMaterial, const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout)
{
@@ -183,6 +205,7 @@ void Geode::OutputTriangleDARR(const int iCurrentMaterial, const unsigned int su
}
}
void Geode::OutputQuadsDARR(const int iCurrentMaterial, const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout)
{
@@ -980,6 +1003,9 @@ void Geode::ProcessGeometry(ostream& fout, const unsigned int ioffset)
const osg::DrawArrayLengths* drawArrayLengths = static_cast<const osg::DrawArrayLengths*>(primitiveset);
switch(mode)
{
case(osg::PrimitiveSet::LINES):
OutputLineDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout);
break;
case(osg::PrimitiveSet::TRIANGLES):
OutputTriangleDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout);
break;

View File

@@ -31,6 +31,8 @@ namespace ac3d
void OutputPolygon(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, std::ostream& fout);
//== output for prims with draw array lengths
void OutputLineDARR(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, std::ostream& fout);
void OutputTriangleDARR(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, std::ostream& fout);
void OutputTriangleStripDARR(const int iCurrentMaterial,const unsigned int surfaceFlags,

View File

@@ -127,13 +127,30 @@ class ReaderWriterAC : public osgDB::ReaderWriter
std::vector<const osg::Geode *>::iterator itr;
fout << "AC3Db" << std::endl;
// output the Materials
for (itr=glist.begin();itr!= glist.end();itr++) {
int iNumGeodesWithGeometry = 0;
for (itr=glist.begin();itr!= glist.end();itr++)
{
iNumMaterials.push_back(const_cast<ac3d::Geode*>(static_cast<const ac3d::Geode*>(*itr))->ProcessMaterial(fout,itr-glist.begin()));
unsigned int iNumDrawables = (*itr)->getNumDrawables();
int iNumGeometries = 0;
for (unsigned int i = 0; i < iNumDrawables; i++)
{
const osg::Drawable* pDrawable = (*itr)->getDrawable(i);
if (NULL != pDrawable)
{
const osg::Geometry *pGeometry = pDrawable->asGeometry();
if (NULL != pGeometry)
iNumGeometries++;
}
if (iNumGeometries > 0)
iNumGeodesWithGeometry++;
}
}
// output the Geometry
unsigned int nfirstmat=0;
fout << "OBJECT world" << std::endl;
fout << "kids " << (glist.end()-glist.begin()) << std::endl;
fout << "kids " << iNumGeodesWithGeometry << std::endl;
for (itr=glist.begin();itr!= glist.end();itr++) {
const_cast<ac3d::Geode*>(static_cast<const ac3d::Geode*>(*itr))->ProcessGeometry(fout,nfirstmat);
nfirstmat+=iNumMaterials[itr-glist.begin()];