From Mathias Froehlich, "Improovments:

- does proper edge detection with the crease angle given in the ac file
- the reader is much more verbose in case of broken files
- no more static variables
- std::stream based
- much faster, up to a factor of 50 for a polygonal test model
- if the file contains polygonal surfaces the loaded geometry is still
polygonal as long as the polygons are convex. Concave polygons are still
tesselated. Rationale: If the user needs triangular models he can throw away
that extra information with the osgUtil::Optimizer himself. But the read step
preserves as much extra information that is contained in the file as
possible. Also the polygonal models look a bit smoother than the triangular
ones.
- a huge cleanup
- the basic parsing logic from the original ac3d developer is untouched
- the writer part is untouched

The tarball contains a replacement for the src/osgPlugins/ac3d directory that
is based on the current CVS (2006-11-13).
I have tested that loader with a osgconv foo.ac /tmp/xx.ive on everyfoo. ac
file I could find (~200 from flightgear and the object database). I also run
my flightgear development with that loader -> here I see the models.
I run valgrind testcases on some selected models."
This commit is contained in:
Robert Osfield 2006-11-14 16:37:07 +00:00
parent a8378d0bfa
commit 0c6a05392b
4 changed files with 1198 additions and 874 deletions

View File

@ -7,11 +7,11 @@ namespace ac3d{
class Exception{
public:
Exception(std::string error);
~Exception();
std::string getError(){return _error;};
Exception(std::string error);
~Exception();
std::string getError(){return _error;};
private:
std::string _error;
std::string _error;
};
}

View File

@ -17,7 +17,6 @@
#include "Exception.h"
#include "Geode.h"
#include "osgac3d.h"
using namespace ac3d;
using namespace std;

View File

@ -6,92 +6,92 @@
namespace ac3d
{
class Geode : public osg::Geode
{
public:
const int ProcessMaterial(std::ostream& fout, const unsigned int igeode);
void ProcessGeometry(std::ostream& fout, const unsigned int igeode);
private:
void OutputTriangle(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);
void OutputTriangleStrip(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);
void OutputTriangleFan(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);
void OutputQuads(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);
void OutputQuadStrip(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);
void OutputLineStrip(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);
void OutputLineLoop(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);
void OutputLines(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);
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 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,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, std::ostream& fout);
void OutputTriangleFanDARR(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 OutputQuadStripDARR(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 OutputQuadsDARR(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 OutputPolygonDARR(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);
// OutputTriangleDelsUByte
// draw elements - 3 types: UByte, UShort, Uint
void OutputTriangleDelsUByte(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUByte* drawElements, std::ostream& fout);
void OutputTriangleStripDelsUByte(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUByte* drawElements, std::ostream& fout);
void OutputTriangleFanDelsUByte(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUByte* drawElements, std::ostream& fout);
void OutputQuadStripDelsUByte(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUByte* drawElements, std::ostream& fout);
void OutputQuadsDelsUByte(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUByte* drawElements, std::ostream& fout);
void OutputPolygonDelsUByte(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUByte* drawElements, std::ostream& fout);
// for UShorts
void OutputTriangleDelsUShort(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUShort* drawElements, std::ostream& fout);
void OutputTriangleStripDelsUShort(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUShort* drawElements, std::ostream& fout);
void OutputTriangleFanDelsUShort(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUShort* drawElements, std::ostream& fout);
void OutputQuadStripDelsUShort(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUShort* drawElements, std::ostream& fout);
void OutputQuadsDelsUShort(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUShort* drawElements, std::ostream& fout);
void OutputPolygonDelsUShort(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUShort* drawElements, std::ostream& fout);
// for UInts
void OutputTriangleDelsUInt(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUInt* drawElements, std::ostream& fout);
void OutputTriangleStripDelsUInt(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUInt* drawElements, std::ostream& fout);
void OutputTriangleFanDelsUInt(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUInt* drawElements, std::ostream& fout);
void OutputQuadStripDelsUInt(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUInt* drawElements, std::ostream& fout);
void OutputQuadsDelsUInt(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUInt* drawElements, std::ostream& fout);
void OutputPolygonDelsUInt(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUInt* drawElements, std::ostream& fout);
// general output for all types
void OutputVertex(int Index, const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, std::ostream& fout);
inline void OutputSurfHead(const int iCurrentMaterial,const unsigned int surfaceFlags, const int nv, std::ostream& fout) {
fout << "SURF 0x" << std::hex << ((int)surfaceFlags) << std::endl;
if (iCurrentMaterial >= 0)
fout << "mat " << std::dec << iCurrentMaterial << std::endl;
fout << "refs " << std::dec << nv << std::endl;
}
};
class Geode : public osg::Geode
{
public:
const int ProcessMaterial(std::ostream& fout, const unsigned int igeode);
void ProcessGeometry(std::ostream& fout, const unsigned int igeode);
private:
void OutputTriangle(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);
void OutputTriangleStrip(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);
void OutputTriangleFan(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);
void OutputQuads(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);
void OutputQuadStrip(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);
void OutputLineStrip(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);
void OutputLineLoop(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);
void OutputLines(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);
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 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,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, std::ostream& fout);
void OutputTriangleFanDARR(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 OutputQuadStripDARR(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 OutputQuadsDARR(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 OutputPolygonDARR(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);
// OutputTriangleDelsUByte
// draw elements - 3 types: UByte, UShort, Uint
void OutputTriangleDelsUByte(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUByte* drawElements, std::ostream& fout);
void OutputTriangleStripDelsUByte(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUByte* drawElements, std::ostream& fout);
void OutputTriangleFanDelsUByte(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUByte* drawElements, std::ostream& fout);
void OutputQuadStripDelsUByte(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUByte* drawElements, std::ostream& fout);
void OutputQuadsDelsUByte(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUByte* drawElements, std::ostream& fout);
void OutputPolygonDelsUByte(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUByte* drawElements, std::ostream& fout);
// for UShorts
void OutputTriangleDelsUShort(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUShort* drawElements, std::ostream& fout);
void OutputTriangleStripDelsUShort(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUShort* drawElements, std::ostream& fout);
void OutputTriangleFanDelsUShort(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUShort* drawElements, std::ostream& fout);
void OutputQuadStripDelsUShort(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUShort* drawElements, std::ostream& fout);
void OutputQuadsDelsUShort(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUShort* drawElements, std::ostream& fout);
void OutputPolygonDelsUShort(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUShort* drawElements, std::ostream& fout);
// for UInts
void OutputTriangleDelsUInt(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUInt* drawElements, std::ostream& fout);
void OutputTriangleStripDelsUInt(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUInt* drawElements, std::ostream& fout);
void OutputTriangleFanDelsUInt(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUInt* drawElements, std::ostream& fout);
void OutputQuadStripDelsUInt(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUInt* drawElements, std::ostream& fout);
void OutputQuadsDelsUInt(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUInt* drawElements, std::ostream& fout);
void OutputPolygonDelsUInt(const int iCurrentMaterial,const unsigned int surfaceFlags,
const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawElementsUInt* drawElements, std::ostream& fout);
// general output for all types
void OutputVertex(int Index, const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, std::ostream& fout);
inline void OutputSurfHead(const int iCurrentMaterial,const unsigned int surfaceFlags, const int nv, std::ostream& fout) {
fout << "SURF 0x" << std::hex << ((int)surfaceFlags) << std::endl;
if (iCurrentMaterial >= 0)
fout << "mat " << std::dec << iCurrentMaterial << std::endl;
fout << "refs " << std::dec << nv << std::endl;
}
};
}

File diff suppressed because it is too large Load Diff