root/OpenSceneGraph/trunk/src/osgPlugins/ac/Geode.cpp @ 12597

Revision 12597, 61.6 kB (checked in by robert, 3 years ago)

Resolved warnings reported by g++ 4.6's -Wunused-but-set-variable.

Warnings were:

/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osg/ShapeDrawable.cpp: In member function ‘void PrimitiveShapeVisitor::createHalfSphere(unsigned int, unsigned int, float, int, float, const Matrix&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osg/ShapeDrawable.cpp:1409:11: warning: variable ‘nzBase’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osg/ShapeDrawable.cpp:1410:11: warning: variable ‘nRatioBase’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp: In function ‘osgUtil::Triangle_list osgUtil::fillHole(osg::Vec3Array*, std::vector<unsigned int, std::allocator<unsigned int> >)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp:569:27: warning: variable ‘ptest’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp: In member function ‘bool osgUtil::DelaunayTriangulator::triangulate()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp:979:45: warning: variable ‘curp’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/RenderStage.cpp: In member function ‘void osgUtil::RenderStage::runCameraSetUp(osg::RenderInfo?&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/RenderStage.cpp:631:18: warning: variable ‘stencilAttached’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/FadeText.cpp: In member function ‘void FadeTextPolytopeData::buildPolytope()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/FadeText.cpp:74:20: warning: variable ‘edge23’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/FadeText.cpp:75:20: warning: variable ‘edge30’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/Text.cpp: In member function ‘void osgText::Text::computeBackdropPositions(unsigned int) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/Text.cpp:747:10: warning: variable ‘is_valid_size’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/NodeTrackerManipulator.cpp: In member function ‘virtual bool osgGA::NodeTrackerManipulator::performMovementLeftMouseButton(double, double, double)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/NodeTrackerManipulator.cpp:257:21: warning: variable ‘lookVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/NodeTrackerManipulator.cpp:259:21: warning: variable ‘upVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/TerrainManipulator.cpp: In member function ‘virtual bool osgGA::TerrainManipulator::performMovementMiddleMouseButton(double, double, double)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/TerrainManipulator.cpp:217:11: warning: variable ‘lookVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/TerrainManipulator.cpp:219:11: warning: variable ‘upVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgVolume/FixedFunctionTechnique.cpp: In member function ‘virtual void osgVolume::FixedFunctionTechnique::init()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgVolume/FixedFunctionTechnique.cpp:124:30: warning: variable ‘tf’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgParticle/FluidProgram.cpp: In member function ‘virtual void osgParticle::FluidProgram::execute(double)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgParticle/FluidProgram.cpp:38:23: warning: variable ‘velBefore’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgShadow/ParallelSplitShadowMap.cpp: In member function ‘virtual void osgShadow::ParallelSplitShadowMap::cull(osgUtil::CullVisitor?&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgShadow/ParallelSplitShadowMap.cpp:593:22: warning: variable ‘bb’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgTerrain/GeometryTechnique.cpp: In member function ‘virtual void osgTerrain::GeometryTechnique::generateGeometry(osgTerrain::GeometryTechnique::BufferData?&, osgTerrain::Locator*, const osg::Vec3d&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgTerrain/GeometryTechnique.cpp:777:12: warning: variable ‘i_sampleFactor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgTerrain/GeometryTechnique.cpp:778:12: warning: variable ‘j_sampleFactor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp: In function ‘osg::Image* ReadDDSFile(std::istream&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp:314:10: warning: variable ‘is3dImage’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp: In function ‘bool WriteDDSFile(const osg::Image*, std::ostream&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp:721:10: warning: variable ‘is3dImage’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/hdr/hdrloader.cpp: In static member function ‘static bool HDRLoader::load(const char*, bool, HDRLoaderResult&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/hdr/hdrloader.cpp:101:10: warning: variable ‘cmd’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/vtf/ReaderWriterVTF.cpp: In function ‘osg::Image* ReadVTFFile(std::istream&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/vtf/ReaderWriterVTF.cpp:360:23: warning: variable ‘base’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/jp2/ReaderWriterJP2.cpp: In function ‘int putdata(jas_stream_t*, jas_image_t*, int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/jp2/ReaderWriterJP2.cpp:41:13: warning: variable ‘linelen’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertToInventor.cpp: In member function ‘void ConvertToInventor::processGeometry(const osg::Geometry*, ConvertToInventor::InventorState?*)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertToInventor.cpp:1639:10: warning: variable ‘ok’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertFromInventor.cpp: In member function ‘virtual SbBool? SoVRMLImageTextureOsg::readInstance(SoInput?*, short unsigned int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertFromInventor.cpp:1264:16: warning: variable ‘retval’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp: In member function ‘virtual void flt::Face::readRecord(flt::RecordInputStream?&, flt::Document&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp:369:19: warning: variable ‘secondaryPackedColor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp: In member function ‘virtual void flt::Mesh::readRecord(flt::RecordInputStream?&, flt::Document&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp:942:19: warning: variable ‘secondaryPackedColor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp: In member function ‘virtual osgDB::ReaderWriter::ReadResult? FLTReaderWriter::readNode(std::istream&, const Options*) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp:427:40: warning: variable ‘pos’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ive/ShapeAttributeList.cpp: In member function ‘void ive::ShapeAttributeList::write(ive::DataOutputStream?*)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ive/ShapeAttributeList.cpp:31:48: warning: variable ‘it’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp: In member function ‘void ac3d::Geode::ProcessGeometry?(std::ostream&, unsigned int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:806:35: warning: variable ‘fRep_s’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:806:43: warning: variable ‘fRep_t’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:807:35: warning: variable ‘fOffset_s’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:807:46: warning: variable ‘fOffset_t’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:932:38: warning: variable ‘primLength’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_geom.cpp: In member function ‘virtual bool trpgGeometry::Write(trpgWriteBuffer&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_geom.cpp:615:19: warning: variable ‘u’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_material.cpp: In member function ‘int trpgMatTable::AddMaterial?(const trpgMaterial&, bool)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_material.cpp:103:10: warning: variable ‘spaceInTable’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_rarchive.cpp: In member function ‘virtual bool trpgr_Archive::ReadHeader?(bool)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_rarchive.cpp:261:14: warning: variable ‘headerHasTexTable’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp: In member function ‘ZRESULT TUnzip::Get(int, ZIPENTRY*)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp:4055:8: warning: variable ‘hidden’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp:4055:22: warning: variable ‘system’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp:4055:36: warning: variable ‘archive’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/ZipArchive.cpp: In member function ‘virtual bool ZipArchive::getFileNames(osgDB::Archive::FileNameList?&) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/ZipArchive.cpp:91:37: warning: variable ‘iterEnd’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/pvr/ReaderWriterPVR.cpp: In member function ‘osgDB::ReaderWriter::ReadResult? ReaderWriterPVR::readPVRStream(std::istream&) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/pvr/ReaderWriterPVR.cpp:155:14: warning: variable ‘hasAlpha’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp: In function ‘osg::Geometry* create3DSphericalDisplayDistortionMesh(const Vec3&, const Vec3&, const Vec3&, double, double, osg::Image*, const Matrix&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp:737:15: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp: In function ‘osg::Geometry* createParoramicSphericalDisplayDistortionMesh(const Vec3&, const Vec3&, const Vec3&, double, double, osg::Image*, const Matrix&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp:1130:19: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp:1118:15: warning: variable ‘dx’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/GraphicsWindowX11.cpp: In member function ‘virtual void osgViewer::GraphicsWindowX11::checkEvents()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/GraphicsWindowX11.cpp:1181:10: warning: variable ‘destroyWindowRequested’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/cfg/ConfigParser.cpp: In member function ‘bool osgProducer::CameraConfig::parseFile(const string&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/cfg/ConfigParser.cpp:2247:13: warning: variable ‘result’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgQt/QGraphicsViewAdapter.cpp: In member function ‘bool osgQt::QGraphicsViewAdapter::handlePointerEvent(int, int, int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgQt/QGraphicsViewAdapter.cpp:344:17: warning: variable ‘viewportGeometry’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp: In function ‘osg::Node* createDistortionSubgraph(osg::Node*, const Vec4&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp:125:19: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp:126:19: warning: variable ‘texcoord’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp: In function ‘osg::Geometry* createDomeDistortionMesh(const Vec3&, const Vec3&, const Vec3&, osg::ArgumentParser?&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp:358:15: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgposter/osgposter.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgposter/osgposter.cpp:253:31: warning: variable ‘outputTiles’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgthreadedterrain/osgthreadedterrain.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgthreadedterrain/osgthreadedterrain.cpp:669:10: warning: variable ‘readParameter’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgtext3D/TextNode.cpp: In member function ‘virtual void osgText::Layout::layout(osgText::TextNode?&) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgtext3D/TextNode.cpp:80:11: warning: variable ‘characterHeightScale’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgvolume/osgvolume.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgvolume/osgvolume.cpp:678:38: warning: variable ‘internalFormatMode’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp: In function ‘bool windowMouseOver(osgWidget::Event&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp:27:24: warning: variable ‘xy’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp: In function ‘bool widgetMouseOver(osgWidget::Event&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp:35:24: warning: variable ‘xy’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/p3d/ReaderWriterP3D.cpp: In member function ‘osg::Node* ReaderWriterP3DXML::parseXmlGraph(osgDB::XmlNode?*, bool, osgDB::Options*) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/p3d/ReaderWriterP3D.cpp:2121:10: warning: variable ‘readSlide’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/applications/present3D/present3D.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/applications/present3D/present3D.cpp:639:10: warning: variable ‘sizesSpecified’ set but not used [-Wunused-but-set-variable]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*  Code for writing AC3D format files, constructs one object per Geode
2 * since geodes only have 1 material, and AC3D allows multiple materials you
3 * may not get an exact vopy of an ac3d file used as input.
4 *
5 * originally by Roger James.
6 * upgraded to different types of Geometry primitive by Geoff Michel.
7 * Old GeoSet parsing code is commented out - will be removed eventually.
8 */
9#include <assert.h>
10#include <list>
11#include <osg/Material>
12#include <osg/Texture2D>
13#include <osg/Drawable>
14#include <osg/Geometry>
15#include <limits>
16#include <iomanip>
17
18#include "Exception.h"
19#include "Geode.h"
20
21using namespace ac3d;
22using namespace std;
23
24
25
26void Geode::OutputVertex(int Index, const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices, ostream& fout)
27{
28    int LocalTexIndex;
29    int LocalVertexIndex;
30    if (NULL == pVertexIndices)
31        LocalVertexIndex = Index;
32    else
33        LocalVertexIndex = pVertexIndices->index(Index);
34    if (NULL != pTexCoords)
35    {
36        // Got some tex coords
37        // Check for an index
38        if (NULL != pTexIndices)
39            // Access tex coord array indirectly
40            LocalTexIndex = pTexIndices->index(Index);
41        else
42            LocalTexIndex  = Index;
43        fout << LocalVertexIndex << " " << pTexCoords[LocalTexIndex][0] << " " << pTexCoords[LocalTexIndex][1] << std::endl;
44    }
45    else
46        fout << LocalVertexIndex << " 0 0" << std::endl;
47}
48
49void Geode::OutputLines(const int iCurrentMaterial, const unsigned int surfaceFlags,
50                           const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, ostream& fout)
51{
52    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();
53    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd; vindex+=2)
54    {
55        OutputSurfHead(iCurrentMaterial,surfaceFlags,2, fout);
56        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
57        OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout);
58    }
59}
60void Geode::OutputLineStrip(const int iCurrentMaterial, const unsigned int surfaceFlags,
61                           const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, ostream& fout)
62{
63    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();
64    OutputSurfHead(iCurrentMaterial,surfaceFlags,indexEnd-drawArray->getFirst(), fout);
65    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd; ++vindex)
66    {
67        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
68    }
69}
70void Geode::OutputLineLoop(const int iCurrentMaterial, const unsigned int surfaceFlags,
71                           const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, ostream& fout)
72{
73    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();
74    OutputSurfHead(iCurrentMaterial,surfaceFlags,indexEnd-drawArray->getFirst(), fout);
75    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd; ++vindex)
76    {
77        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
78    }
79}
80void Geode::OutputTriangle(const int iCurrentMaterial, const unsigned int surfaceFlags,
81                           const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, ostream& fout)
82{
83    unsigned int primCount = 0;
84    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();
85    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd; ++vindex,++primCount)
86    {
87       
88        if ((primCount%3) == 0)
89        {
90            OutputSurfHead(iCurrentMaterial,surfaceFlags,3, fout);
91        }
92        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
93    }
94}
95void Geode::OutputTriangleStrip(const int iCurrentMaterial, const unsigned int surfaceFlags,
96                            const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, std::ostream& fout)
97{
98    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();
99    unsigned int evenodd=0;
100    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd-2; ++vindex, evenodd++)
101    {
102       
103        OutputSurfHead(iCurrentMaterial,surfaceFlags,3, fout);
104        if (evenodd%2==0) {
105            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
106            OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout);
107        } else {
108            OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout);
109            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
110        }
111        OutputVertex(vindex+2, pVertexIndices, pTexCoords, pTexIndices, fout);
112    }
113}
114void Geode::OutputTriangleFan(const int iCurrentMaterial, const unsigned int surfaceFlags,
115                           const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, std::ostream& fout)
116{
117    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();
118    for(unsigned int vindex=drawArray->getFirst()+1; vindex<indexEnd-1; ++vindex)
119    {
120        OutputSurfHead(iCurrentMaterial,surfaceFlags,3, fout);
121        OutputVertex(drawArray->getFirst(), pVertexIndices, pTexCoords, pTexIndices, fout);
122        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
123        OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout);
124    }
125}
126void Geode::OutputQuads(const int iCurrentMaterial, const unsigned int surfaceFlags,
127                            const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, std::ostream& fout)
128{
129    unsigned int primCount = 0;
130    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();
131    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd; ++vindex,++primCount)
132    {
133       
134        if ((primCount%4) == 0)
135        {
136            OutputSurfHead(iCurrentMaterial,surfaceFlags,4, fout);
137        }
138        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
139    }
140}
141void Geode::OutputQuadStrip(const int iCurrentMaterial, const unsigned int surfaceFlags,
142                            const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, std::ostream& fout)
143{
144    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();
145    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd-2; vindex+=2)
146    {
147        OutputSurfHead(iCurrentMaterial,surfaceFlags,4, fout);
148        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
149        OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout);
150        OutputVertex(vindex+3, pVertexIndices, pTexCoords, pTexIndices, fout);
151        OutputVertex(vindex+2, pVertexIndices, pTexCoords, pTexIndices, fout);
152    }
153}
154void Geode::OutputPolygon(const int iCurrentMaterial, const unsigned int surfaceFlags,
155                            const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrays* drawArray, std::ostream& fout)
156{
157    unsigned int indexEnd = drawArray->getFirst() + drawArray->getCount();
158    OutputSurfHead(iCurrentMaterial,surfaceFlags,drawArray->getCount(), fout);
159    for(unsigned int vindex=drawArray->getFirst(); vindex<indexEnd; vindex++)
160    {
161        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
162    }
163}
164//=======  draw array length cases
165void Geode::OutputLineDARR(const int iCurrentMaterial, const unsigned int surfaceFlags,
166        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout)
167{
168    unsigned int vindex = drawArrayLengths->getFirst();
169    for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr <drawArrayLengths->end(); ++primItr)
170    {
171        unsigned int localPrimLength;
172        localPrimLength = 2;
173       
174        for(GLsizei primCount = 0; primCount < *primItr; ++primCount)
175        {
176            if ((primCount%localPrimLength)==0)
177            {
178                OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
179            }
180            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
181            ++vindex;
182        }
183       
184    }
185}
186
187void Geode::OutputTriangleDARR(const int iCurrentMaterial, const unsigned int surfaceFlags,
188        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout)
189{
190    unsigned int vindex = drawArrayLengths->getFirst();
191    for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr <drawArrayLengths->end(); ++primItr)
192    {
193        unsigned int localPrimLength;
194        localPrimLength = 3;
195       
196        for(GLsizei primCount = 0; primCount < *primItr; ++primCount)
197        {
198            if ((primCount%localPrimLength)==0)
199            {
200                OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
201            }
202            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
203            ++vindex;
204        }
205       
206    }
207}
208
209void Geode::OutputQuadsDARR(const int iCurrentMaterial, const unsigned int surfaceFlags,
210        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout)
211{
212    unsigned int vindex = drawArrayLengths->getFirst();
213    for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr <drawArrayLengths->end()-4; primItr+=4)
214    {
215        unsigned int localPrimLength;
216        localPrimLength = 4;
217       
218        for(GLsizei primCount = 0; primCount < *primItr; ++primCount)
219        {
220            OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
221            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
222            OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout);
223            OutputVertex(vindex+2, pVertexIndices, pTexCoords, pTexIndices, fout);
224            OutputVertex(vindex+3, pVertexIndices, pTexCoords, pTexIndices, fout);
225            vindex+=4;
226        }
227       
228    }
229}
230void Geode::OutputQuadStripDARR(const int iCurrentMaterial, const unsigned int surfaceFlags,
231        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout)
232{
233    unsigned int vindex = drawArrayLengths->getFirst();
234    for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr <drawArrayLengths->end()-2; primItr+=2)
235    {
236        unsigned int localPrimLength;
237        localPrimLength = *primItr;
238       
239        for(GLsizei primCount = 0; primCount < *primItr; ++primCount)
240        {
241            OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
242            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
243            OutputVertex(vindex+1, pVertexIndices, pTexCoords, pTexIndices, fout);
244            OutputVertex(vindex+3, pVertexIndices, pTexCoords, pTexIndices, fout);
245            OutputVertex(vindex+2, pVertexIndices, pTexCoords, pTexIndices, fout);
246            vindex+=2;
247        }
248       
249    }
250}
251void Geode::OutputPolygonDARR(const int iCurrentMaterial, const unsigned int surfaceFlags,
252        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout)
253{
254    unsigned int vindex = drawArrayLengths->getFirst();
255    for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr <drawArrayLengths->end(); ++primItr)
256    {
257        unsigned int localPrimLength;
258        localPrimLength = *primItr;
259       
260        for(GLsizei primCount = 0; primCount < *primItr; ++primCount)
261        {
262            if ((primCount%localPrimLength)==0)
263            {
264                OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
265            }
266            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
267            ++vindex;
268        }
269       
270    }
271}
272void Geode::OutputTriangleStripDARR(const int iCurrentMaterial, const unsigned int surfaceFlags,
273        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout)
274{
275    unsigned int vindex = drawArrayLengths->getFirst();
276    for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr <drawArrayLengths->end(); ++primItr)
277    {
278        // RFJ!!!!!!!!!! fixes for indexing
279        int localPrimLength= *primItr;
280        bool evenodd=true;
281       
282        for(GLsizei primCount = 0; primCount < localPrimLength - 2; ++primCount)
283        {
284            OutputSurfHead(iCurrentMaterial, surfaceFlags, 3, fout);
285            if (evenodd) {
286                OutputVertex(vindex + primCount, pVertexIndices, pTexCoords, pTexIndices, fout);
287                OutputVertex(vindex + primCount + 1, pVertexIndices, pTexCoords, pTexIndices, fout);
288            } else {
289                OutputVertex(vindex + primCount + 1 , pVertexIndices, pTexCoords, pTexIndices, fout);
290                OutputVertex(vindex + primCount, pVertexIndices, pTexCoords, pTexIndices, fout);
291            }
292            OutputVertex(vindex + primCount + 2, pVertexIndices, pTexCoords, pTexIndices, fout);
293            evenodd=!evenodd;
294        }       
295        vindex += localPrimLength;
296    }
297}
298void Geode::OutputTriangleFanDARR(const int iCurrentMaterial, const unsigned int surfaceFlags,
299        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,const osg::DrawArrayLengths* drawArrayLengths, ostream& fout)
300{
301    unsigned int vindex = drawArrayLengths->getFirst();
302    for(osg::DrawArrayLengths::const_iterator primItr = drawArrayLengths->begin(); primItr <drawArrayLengths->end(); ++primItr)
303    {
304        int localPrimLength = *primItr;
305       
306        for(GLsizei primCount = 0; primCount < localPrimLength - 2; primCount++)
307        {
308            OutputSurfHead(iCurrentMaterial,surfaceFlags,3, fout);
309            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
310            OutputVertex(vindex+1+primCount, pVertexIndices, pTexCoords, pTexIndices, fout);
311            OutputVertex(vindex+2+primCount, pVertexIndices, pTexCoords, pTexIndices, fout);
312        }
313        vindex += localPrimLength;
314    }
315}
316
317// DrawElements .... Ubyte
318void Geode::OutputTriangleDelsUByte(const int iCurrentMaterial, const unsigned int surfaceFlags,
319                                    const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
320                                    const osg::DrawElementsUByte* drawElements, ostream& fout)
321{
322    unsigned int primLength =3;
323   
324    unsigned int primCount = 0;
325    for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItr<drawElements->end(); ++primCount,++primItr)
326    {
327        if ((primCount%primLength) == 0)
328        {
329            OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout);
330        }
331       
332        unsigned int vindex=*primItr;
333        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
334    }
335}
336void Geode::OutputTriangleStripDelsUByte(const int iCurrentMaterial, const unsigned int surfaceFlags,
337        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
338        const osg::DrawElementsUByte* drawElements, ostream& fout)
339{
340    unsigned int localPrimLength = 3;
341    bool evenodd=true;
342    for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-2; ++primItr)
343    {
344       
345        unsigned int vindex=*primItr;
346        unsigned int vindexp1=*(primItr+1);
347        unsigned int vindexp2=*(primItr+2);
348        OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
349        if (evenodd) {
350            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
351            OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
352        } else {
353            OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
354            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
355        }
356        OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout);
357        evenodd=!evenodd;
358    }
359}
360void Geode::OutputTriangleFanDelsUByte(const int iCurrentMaterial, const unsigned int surfaceFlags,
361        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
362        const osg::DrawElementsUByte* drawElements, ostream& fout)
363{
364    const unsigned int localPrimLength = 3;
365    unsigned int vindex=*(drawElements->begin());
366    for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-2; ++primItr)
367    {   
368        unsigned int vindexp1=*(primItr+1);
369        unsigned int vindexp2=*(primItr+2);
370        OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
371       
372        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
373        OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
374        OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout);
375    }
376}
377void Geode::OutputQuadStripDelsUByte(const int iCurrentMaterial, const unsigned int surfaceFlags,
378        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
379        const osg::DrawElementsUByte* drawElements, ostream& fout)
380{
381    const unsigned int localPrimLength=4;
382    for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-3; primItr+=2)
383    {
384        unsigned int vindex=*primItr;
385       
386        unsigned int vindexp1=*(primItr+1);
387        unsigned int vindexp2=*(primItr+3);
388        unsigned int vindexp3=*(primItr+2);
389        OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
390       
391        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
392        OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
393        OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout);
394        OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout);
395    }
396}
397void Geode::OutputQuadsDelsUByte(const int iCurrentMaterial, const unsigned int surfaceFlags,
398        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
399        const osg::DrawElementsUByte* drawElements, ostream& fout)
400{
401    const unsigned int localPrimLength=4;
402    for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-3; primItr+=4)
403    {
404        unsigned int vindex=*primItr;
405       
406        unsigned int vindexp1=*(primItr+1);
407        unsigned int vindexp2=*(primItr+2);
408        unsigned int vindexp3=*(primItr+3);
409        OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
410       
411        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
412        OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
413        OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout);
414        OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout);
415    }
416}
417void Geode::OutputPolygonDelsUByte(const int iCurrentMaterial, const unsigned int surfaceFlags,
418        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
419        const osg::DrawElementsUByte* drawElements, ostream& fout)
420{
421    unsigned int primLength =drawElements->size();
422    unsigned int primCount = 0;
423
424    OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout);
425    for(osg::DrawElementsUByte::const_iterator primItr=drawElements->begin(); primItr<drawElements->end(); ++primCount,++primItr)
426    {
427        unsigned int vindex=*primItr;
428        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
429    }
430}
431// DrawElements .... UShort
432void Geode::OutputTriangleDelsUShort(const int iCurrentMaterial, const unsigned int surfaceFlags,
433        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
434        const osg::DrawElementsUShort* drawElements, ostream& fout)
435{
436    unsigned int primLength =3;
437   
438    unsigned int primCount = 0;
439    for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItr<drawElements->end(); ++primCount,++primItr)
440    {
441       
442        if ((primCount%primLength) == 0)
443        {
444            OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout);
445        }
446       
447        unsigned int vindex=*primItr;
448        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
449    }
450}
451void Geode::OutputTriangleStripDelsUShort(const int iCurrentMaterial, const unsigned int surfaceFlags,
452        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
453        const osg::DrawElementsUShort* drawElements, ostream& fout)
454{
455    unsigned int localPrimLength = 3;
456    bool evenodd=true;
457    for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-2; ++primItr)
458    {
459        unsigned int vindex=*primItr;
460        unsigned int vindexp1=*(primItr+1);
461        unsigned int vindexp2=*(primItr+2);
462        OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
463        if (evenodd) {
464            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
465            OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
466        } else {
467            OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
468            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
469        }
470        OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout);
471        evenodd=!evenodd;
472    }
473}
474void Geode::OutputTriangleFanDelsUShort(const int iCurrentMaterial, const unsigned int surfaceFlags,
475        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
476        const osg::DrawElementsUShort* drawElements, ostream& fout)
477{
478    const unsigned int localPrimLength = 3;
479    unsigned int vindex=*(drawElements->begin());
480    for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-2; ++primItr)
481    {   
482        unsigned int vindexp1=*(primItr+1);
483        unsigned int vindexp2=*(primItr+2);
484        OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
485       
486        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
487        OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
488        OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout);
489    }
490}
491void Geode::OutputQuadStripDelsUShort(const int iCurrentMaterial, const unsigned int surfaceFlags,
492        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
493        const osg::DrawElementsUShort* drawElements, ostream& fout)
494{
495    const unsigned int localPrimLength=4;
496    for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-3; primItr+=2)
497    {
498        unsigned int vindex=*primItr;
499       
500        unsigned int vindexp1=*(primItr+1);
501        unsigned int vindexp2=*(primItr+3);
502        unsigned int vindexp3=*(primItr+2);
503        OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
504       
505        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
506        OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
507        OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout);
508        OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout);
509    }
510}
511void Geode::OutputQuadsDelsUShort(const int iCurrentMaterial, const unsigned int surfaceFlags,
512        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
513        const osg::DrawElementsUShort* drawElements, ostream& fout)
514{
515    const unsigned int localPrimLength=4;
516    for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-3; primItr+=4)
517    {
518        unsigned int vindex=*primItr;
519       
520        unsigned int vindexp1=*(primItr+1);
521        unsigned int vindexp2=*(primItr+2);
522        unsigned int vindexp3=*(primItr+3);
523        OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
524       
525        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
526        OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
527        OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout);
528        OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout);
529    }
530}
531void Geode::OutputPolygonDelsUShort(const int iCurrentMaterial, const unsigned int surfaceFlags,
532        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
533        const osg::DrawElementsUShort* drawElements, ostream& fout)
534{
535    unsigned int primLength =drawElements->size();
536    unsigned int primCount = 0;
537
538    OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout);
539    for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItr<drawElements->end(); ++primCount,++primItr)
540    {
541        unsigned int vindex=*primItr;
542        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
543    }
544}
545// DrawElements .... UInt
546void Geode::OutputTriangleDelsUInt(const int iCurrentMaterial, const unsigned int surfaceFlags,
547        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
548        const osg::DrawElementsUInt* drawElements, ostream& fout)
549{
550    unsigned int primLength =3;
551   
552    unsigned int primCount = 0;
553    for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr<drawElements->end(); ++primCount,++primItr)
554    {
555       
556        if ((primCount%primLength) == 0)
557        {
558            OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout);
559        }
560       
561        unsigned int vindex=*primItr;
562        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
563    }
564}
565void Geode::OutputTriangleStripDelsUInt(const int iCurrentMaterial, const unsigned int surfaceFlags,
566        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
567        const osg::DrawElementsUInt* drawElements, ostream& fout)
568{
569    unsigned int localPrimLength = 3;
570    bool evenodd=true;
571    for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-2; ++primItr)
572    {
573       
574        unsigned int vindex=*primItr;
575        unsigned int vindexp1=*(primItr+1);
576        unsigned int vindexp2=*(primItr+2);
577        OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
578        if (evenodd) {
579            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
580            OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
581        } else {
582            OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
583            OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
584        }
585        OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout);
586        evenodd=!evenodd;
587    }
588}
589void Geode::OutputTriangleFanDelsUInt(const int iCurrentMaterial, const unsigned int surfaceFlags,
590        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
591        const osg::DrawElementsUInt* drawElements, ostream& fout)
592{
593    const unsigned int localPrimLength = 3;
594    unsigned int vindex=*(drawElements->begin());
595    for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-2; ++primItr)
596    {   
597        unsigned int vindexp1=*(primItr+1);
598        unsigned int vindexp2=*(primItr+2);
599        OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
600       
601        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
602        OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
603        OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout);
604    }
605}
606void Geode::OutputQuadStripDelsUInt(const int iCurrentMaterial, const unsigned int surfaceFlags,
607        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
608        const osg::DrawElementsUInt* drawElements, ostream& fout)
609{
610    const unsigned int localPrimLength = 4;
611    for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-3; primItr+=2)
612    {
613        unsigned int vindex=*primItr;
614       
615        unsigned int vindexp1=*(primItr+1);
616        unsigned int vindexp2=*(primItr+3);
617        unsigned int vindexp3=*(primItr+2);
618        OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
619       
620        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
621        OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
622        OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout);
623        OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout);
624    }
625}
626void Geode::OutputQuadsDelsUInt(const int iCurrentMaterial, const unsigned int surfaceFlags,
627        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
628        const osg::DrawElementsUInt* drawElements, ostream& fout)
629{
630    const unsigned int localPrimLength=4;
631    for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr<drawElements->end()-3; primItr+=4)
632    {
633        unsigned int vindex=*primItr;
634       
635        unsigned int vindexp1=*(primItr+1);
636        unsigned int vindexp2=*(primItr+2);
637        unsigned int vindexp3=*(primItr+3);
638        OutputSurfHead(iCurrentMaterial,surfaceFlags,localPrimLength, fout);
639       
640        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
641        OutputVertex(vindexp1, pVertexIndices, pTexCoords, pTexIndices, fout);
642        OutputVertex(vindexp2, pVertexIndices, pTexCoords, pTexIndices, fout);
643        OutputVertex(vindexp3, pVertexIndices, pTexCoords, pTexIndices, fout);
644    }
645}
646void Geode::OutputPolygonDelsUInt(const int iCurrentMaterial, const unsigned int surfaceFlags,
647        const osg::IndexArray *pVertexIndices, const osg::Vec2 *pTexCoords, const osg::IndexArray *pTexIndices,
648        const osg::DrawElementsUInt* drawElements, ostream& fout)
649{
650    unsigned int primLength =drawElements->size();
651    unsigned int primCount = 0;
652
653    OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout);
654    for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr<drawElements->end(); ++primCount,++primItr)
655    {
656        unsigned int vindex=*primItr;
657        OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
658    }
659}
660
661
662const int Geode::ProcessMaterial(ostream& fout, const unsigned int igeode)
663{
664    // outputs materials from one geode
665    // extended for multiple geode models, GWM 2003.
666    // called before all the geometry as ac3d expects all materials in the header.
667    // returns number of materials made
668    unsigned int i;
669    const unsigned int iNumDrawables = getNumDrawables();
670    const osg::StateSet::RefAttributePair* pRAP;
671    unsigned int iNumMaterials=0;
672    // Let ac3d optimise the file
673    // whiz round and get a list of materials
674    // these may be duplicates of materials on other Geode/geometry sets.
675
676    // Scan for materials
677    for (i = 0; i < iNumDrawables; i++)
678    {
679        const osg::Drawable* Drawable = getDrawable(i);
680        if (Drawable) {
681            const osg::StateSet* theState = Drawable->getStateSet();
682            if (theState) {
683                pRAP = theState->getAttributePair(osg::StateAttribute::MATERIAL);
684                if (NULL != pRAP)
685                {
686                    const osg::Material *pMaterial = dynamic_cast<const osg::Material*>(pRAP->first.get());
687                    if (NULL != pMaterial)
688                    {
689                        const osg::Vec4& Diffuse = pMaterial->getDiffuse(osg::Material::FRONT_AND_BACK);
690                        const osg::Vec4& Ambient = pMaterial->getAmbient(osg::Material::FRONT_AND_BACK);
691                        const osg::Vec4& Emissive = pMaterial->getEmission(osg::Material::FRONT_AND_BACK);
692                        const osg::Vec4& Specular = pMaterial->getSpecular(osg::Material::FRONT_AND_BACK);
693                        fout << "MATERIAL "
694                            << "\"osg"<<igeode<<"mat"<<i
695                            << "\" rgb " << Diffuse[0] << " " << Diffuse[1] << " " << Diffuse[2] << " "
696                            << "amb " << Ambient[0] << " " << Ambient[1] << " " << Ambient[2] << " "
697                            << "emis " << Emissive[0] << " " << Emissive[1] << " " << Emissive[2] << " "
698                            << "spec " << Specular[0] << " " << Specular[1] << " " << Specular[2] << " "
699                            << "shi " << (int)pMaterial->getShininess(osg::Material::FRONT_AND_BACK) << " "
700                            << "trans " << 1.0 - Diffuse[3] << std::endl;
701                        iNumMaterials++;
702                    }
703                }
704            }
705        }
706    }
707    return iNumMaterials;
708}
709void Geode::ProcessGeometry(ostream& fout, const unsigned int ioffset)
710{
711    // outputs one geode
712    // extended for multiple geode models, GWM 2003.
713    unsigned int i, j; //, k, m;
714    const unsigned int iNumDrawables = getNumDrawables();
715    int iNumMaterials = 0;
716    const osg::StateSet::RefAttributePair* pRAP=NULL;
717    // Let ac3d optimise the file
718    // whiz round and get a list of materails
719    // write them out
720    // write out an object for each drawable.
721    // Write out world object
722    int ngeometry=0; // not all drawables are geometry, text is not converted to facets.
723    for (i = 0; i < iNumDrawables; i++)
724    { // so here we count the geometries to be converted to AC3D
725        const osg::Drawable* Drawable = getDrawable(i);
726        if (Drawable) {
727            const osg::Geometry *pGeometry = Drawable->asGeometry();
728            if (NULL != pGeometry) ngeometry++;
729        }
730    }
731    if (ngeometry>1) { // create a group
732        fout << "OBJECT group" << std::endl;
733        fout << "kids " << ngeometry << std::endl;
734    }
735
736    // Process each drawable in turn
737    for (i = 0; i < iNumDrawables; i++)
738    {
739        const osg::Drawable* Drawable = getDrawable(i);
740        if (Drawable) {
741            const osg::StateSet* theState = Drawable->getStateSet();
742            const osg::Geometry *pGeometry = Drawable->asGeometry();
743            if (NULL != pGeometry)
744            {
745                int iCurrentMaterial = -1;
746               
747                if (theState) {
748                    pRAP = theState->getAttributePair(osg::StateAttribute::MATERIAL);
749                    if (NULL != pRAP)
750                    {
751                        iCurrentMaterial = ioffset+iNumMaterials;
752                        iNumMaterials++;
753                    }
754                }
755               
756                //const osg::Vec3Array
757                const osg::Array *pVertexArray = pGeometry->getVertexArray();
758                if (NULL != pVertexArray)
759                {
760                    const unsigned int iNumVertices = pVertexArray->getNumElements(); // size();
761                    const osg::IndexArray *pVertexIndices = pGeometry->getVertexIndices();
762                    const osg::IndexArray * pTexIndices = pGeometry->getTexCoordIndices(0);
763                    const osg::Vec2 *pTexCoords = NULL;
764                    fout << "OBJECT poly" << std::endl;
765                    fout << "name \"" << getName() << "\"" << std::endl;
766                   
767                    // Use zero offset co-ordinate as location IS OPTIONAL
768                    // fout << "loc " << "0 0 0" << std::endl;
769                    /* you could have an offset for the coordinates;  it was suggested that the first coord would do.
770                    if((*pVertexArray).getType()==osg::Array::Vec3ArrayType) {
771                    const osg::Vec3Array *verts=static_cast<const osg::Vec3Array*>(pVertexArray);
772                    fout << (*verts)[0][0] << " " << (*verts)[0][1] << " " << (*verts)[0][2] << std::endl;
773                    } else if((*pVertexArray).getType()==osg::Array::Vec2ArrayType) {
774                    const osg::Vec2Array *verts=static_cast<const osg::Vec2Array*>(pVertexArray);
775                    fout << (*verts)[0][0] << " " << (*verts)[0][1] << " " << 0 << std::endl;
776                    } else if((*pVertexArray).getType()==osg::Array::Vec4ArrayType) {
777                    const osg::Vec4Array *verts=static_cast<const osg::Vec4Array*>(pVertexArray);
778                    fout << (*verts)[0][0] << " " << (*verts)[0][1] << " " << (*verts)[0][2] << std::endl;
779                    }
780                    << (*pVertexArray)[0][0] << " "
781                    << (*pVertexArray)[0][1] << " "
782                    << (*pVertexArray)[0][2] << std::endl; */
783                   
784                    // Check for a texture
785                    if (theState)
786                    {
787                    const osg::StateSet::TextureModeList& TextureModeList = theState->getTextureModeList();
788                    const osg::StateSet::TextureAttributeList& TextureAttributeList = theState->getTextureAttributeList();
789                    if (TextureAttributeList.size() > 0)
790                    {
791                        // Dont yet know how to handle more than one texture
792                        assert(TextureAttributeList.size() == 1);
793                        assert(TextureModeList.size() == 1);
794                        const osg::StateSet::ModeList& ModeList = TextureModeList[0];
795                        assert(ModeList.size() == 1);
796                        // Check for a single mode of GL_TEXTURE_2D and ON
797                                                osg::StateSet::ModeList::value_type ModeValuePair = *ModeList.begin();
798                        assert(ModeValuePair.first == GL_TEXTURE_2D);
799                        assert(ModeValuePair.second == osg::StateAttribute::ON);
800                        const osg::StateSet::AttributeList& AttributeList = TextureAttributeList[0];
801                        //                    assert(AttributeList.size() == 1);
802                        const osg::Texture2D *pTexture2D = dynamic_cast<const osg::Texture2D*>(AttributeList.begin()->second.first.get());
803                        //                    assert(NULL != pTexture2D);
804                        if (NULL != pTexture2D)
805                        {
806                            float fRep_s, fRep_t;
807                            float fOffset_s, fOffset_t;
808                           
809                            pTexCoords = (const osg::Vec2*)pGeometry->getTexCoordArray(0)->getDataPointer();
810                           
811                            // OK now see if I can calcualate the repeats
812                            osg::Texture::WrapMode eWrapMode_s = pTexture2D->getWrap(osg::Texture::WRAP_S);
813                            //osg::Texture::WrapMode eWrapMode_t = pTexture2D->getWrap(osg::Texture::WRAP_T);
814                           
815                            if (eWrapMode_s == osg::Texture::REPEAT)
816                            {
817                                if (NULL != pTexCoords)
818                                {
819                                    // Find max min s coords
820                                    float fMin = std::numeric_limits<float>::max();
821                                    float fMax = std::numeric_limits<float>::min();
822                                    unsigned int iNumTexCoords = pGeometry->getTexCoordArray(0)->getNumElements();
823                                   
824                                    for (j = 0; j < iNumTexCoords; j++)
825                                    {
826                                        if (pTexCoords[j][0] > fMax)
827                                            fMax = pTexCoords[j][0];
828                                        if (pTexCoords[j][0] < fMin)
829                                            fMin = pTexCoords[j][0];
830                                    }
831                                    fRep_s = fMax - fMin;
832                                    fOffset_s = fMin;
833                                    fMin = std::numeric_limits<float>::max();
834                                    fMax = std::numeric_limits<float>::min();
835                                    for (j = 0; j < iNumTexCoords; j++)
836                                    {
837                                        if (pTexCoords[j][1] > fMax)
838                                            fMax = pTexCoords[j][1];
839                                        if (pTexCoords[j][1] < fMin)
840                                            fMin = pTexCoords[j][1];
841                                    }
842                                    fRep_t = fMax - fMin;
843                                    fOffset_t = fMin;
844                                }
845                                else
846                                {
847                                    fRep_s = 1.0;
848                                    fOffset_s = 0.0;
849                                    fRep_t = 1.0;
850                                    fOffset_t = 0.0;
851                                }
852                            }
853                            else
854                            {
855                                fRep_s = 1.0;
856                                fOffset_s = 0.0;
857                                fRep_t = 1.0;
858                                fOffset_t = 0.0;
859                            }
860                            { // replace back slash with / for ac3d convention GWM Sep 2003
861                                std::string fname=pTexture2D->getImage()->getFileName();
862                                unsigned int pos;
863                                for (pos=0; pos< fname.length(); pos++) {
864                                    if (fname[pos] == '\\') fname[pos]='/';
865                                }
866                                fout << "texture \"" << fname << "\"" << std::endl;
867                            }
868//                            fout << "texrep " << fRep_s << " " << fRep_t << std::endl;
869//                            fout << "texoff " << fOffset_s << " " << fOffset_s << std::endl;
870                            // Temp frig
871                            fout << "texrep 1 1" << std::endl;
872                            fout << "texoff 0 0" << std::endl;
873                        }
874                    }
875                    }
876                   
877                    fout << "numvert " << iNumVertices << std::endl;
878                    for (j = 0; j < iNumVertices; j++)
879                    { // use 3 types of osg::Vec for coordinates....
880                        if((*pVertexArray).getType()==osg::Array::Vec3ArrayType) {
881                            const osg::Vec3Array *verts=static_cast<const osg::Vec3Array*>(pVertexArray);
882                            fout << (*verts)[j][0] << " " << (*verts)[j][1] << " " << (*verts)[j][2] << std::endl;
883                        } else if((*pVertexArray).getType()==osg::Array::Vec2ArrayType) {
884                            const osg::Vec2Array *verts=static_cast<const osg::Vec2Array*>(pVertexArray);
885                            fout << (*verts)[j][0] << " " << (*verts)[j][1] << " " << 0 << std::endl;
886                        } else if((*pVertexArray).getType()==osg::Array::Vec4ArrayType) {
887                            const osg::Vec4Array *verts=static_cast<const osg::Vec4Array*>(pVertexArray);
888                            fout << (*verts)[j][0] << " " << (*verts)[j][1] << " " << (*verts)[j][2] << std::endl;
889                        }
890                    }
891                   
892                   
893                    // Generate a surface for each primitive
894                    unsigned int iNumSurfaces = 0; // complex tri-strip etc prims use more triangles
895                    osg::Geometry::PrimitiveSetList::const_iterator pItr;
896                    for(pItr = pGeometry->getPrimitiveSetList().begin(); pItr != pGeometry->getPrimitiveSetList().end(); ++pItr) {
897                        const osg::PrimitiveSet* primitiveset = pItr->get();
898                        //const osg::PrimitiveSet::Type type = primitiveset->getType();
899                        unsigned int iNumPrimitives = primitiveset->getNumPrimitives();
900                        unsigned int iNumIndices = primitiveset->getNumIndices();
901                        GLenum mode=primitiveset->getMode();
902                        switch(mode) {
903                        case(osg::PrimitiveSet::POINTS):
904                            iNumSurfaces+=1; // all points go in one big list
905                            break;
906                        case(osg::PrimitiveSet::LINES): // each line is a pair of vertices
907                        case(osg::PrimitiveSet::TRIANGLES): // each tri = 3 verts
908                        case(osg::PrimitiveSet::QUADS):
909                        case(osg::PrimitiveSet::LINE_LOOP):
910                        case(osg::PrimitiveSet::LINE_STRIP):
911                        case(osg::PrimitiveSet::POLYGON):
912                            iNumSurfaces+=iNumPrimitives;
913                            break;
914                        case(osg::PrimitiveSet::TRIANGLE_STRIP):
915                        case(osg::PrimitiveSet::TRIANGLE_FAN):
916                            iNumSurfaces+=iNumIndices-2*iNumPrimitives;
917                            break;
918                        case(osg::PrimitiveSet::QUAD_STRIP):
919                            iNumSurfaces+=(iNumIndices-2*iNumPrimitives)/2;
920                            break;
921                        default:
922                            break; // unknown shape
923                        }
924                    }
925                    fout << "numsurf " << iNumSurfaces << std::endl;
926                   
927                    for(pItr = pGeometry->getPrimitiveSetList().begin(); pItr != pGeometry->getPrimitiveSetList().end(); ++pItr)
928                    {
929                        const osg::PrimitiveSet* primitiveset = pItr->get();
930                        GLenum mode=primitiveset->getMode();
931                       
932                        unsigned int surfaceFlags = 0x00;
933                       
934                        switch(mode)
935                        {
936                        case(osg::PrimitiveSet::POINTS):
937                            surfaceFlags = 0x02;
938                            break;
939                        case(osg::PrimitiveSet::LINES):
940                            surfaceFlags = 0x02;
941                            break;
942                        case(osg::PrimitiveSet::TRIANGLES):
943                            break;
944                        case(osg::PrimitiveSet::QUADS):
945                            break;
946                        default:
947                            break; // compute later when =0.
948                        }
949                       
950//                        osg::StateAttribute::GLModeValue backface =theState->getMode(osg::StateAttribute::CULLFACE);
951//                        if (backface==osg::StateAttribute::ON) surfaceFlags |= 0x10;
952//                        else if (backface==osg::StateAttribute::OFF) surfaceFlags &= 0x0f;
953                        const osg::DrawArrays* drawArray = static_cast<const osg::DrawArrays*>(primitiveset);
954                        switch(primitiveset->getType())
955                        {
956                        case(osg::PrimitiveSet::DrawArraysPrimitiveType):
957                            {
958                                switch(mode)
959                                {
960                                case(osg::PrimitiveSet::POINTS):
961                                    break;
962                                case(osg::PrimitiveSet::LINES):
963                                    OutputLines(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout);
964                                    break;
965                                case(osg::PrimitiveSet::LINE_LOOP):
966                                    OutputLineLoop(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout);
967                                    break;
968                                case(osg::PrimitiveSet::LINE_STRIP):
969                                    OutputLineStrip(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout);
970                                    break;
971                                case(osg::PrimitiveSet::TRIANGLES):
972                                    OutputTriangle(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout);
973                                    break;
974                                case(osg::PrimitiveSet::QUADS):
975                                    OutputQuads(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout);
976                                    break;
977                                case(osg::PrimitiveSet::TRIANGLE_STRIP):
978                                    OutputTriangleStrip(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout);
979                                    break;
980                                case(osg::PrimitiveSet::TRIANGLE_FAN):
981                                    OutputTriangleFan(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout);
982                                    break;
983                                case(osg::PrimitiveSet::QUAD_STRIP):
984                                    OutputQuadStrip(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout);
985                                    break;
986                                case(osg::PrimitiveSet::POLYGON):
987                                    OutputPolygon(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArray, fout);
988                                    break;
989                                default:
990                                    break; // unknown shape
991                                }
992                                break;
993                            }
994                        case(osg::PrimitiveSet::DrawArrayLengthsPrimitiveType):
995                            {
996                               
997                                const osg::DrawArrayLengths* drawArrayLengths = static_cast<const osg::DrawArrayLengths*>(primitiveset);
998                                switch(mode)
999                                {
1000                                case(osg::PrimitiveSet::LINES):
1001                                    OutputLineDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout);
1002                                    break;
1003                                case(osg::PrimitiveSet::TRIANGLES):
1004                                    OutputTriangleDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout);
1005                                    break;
1006                                case(osg::PrimitiveSet::QUADS):
1007                                    OutputQuadsDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout);
1008                                    break;
1009                                case(osg::PrimitiveSet::TRIANGLE_STRIP):
1010                                    OutputTriangleStripDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout);
1011                                    break;
1012                                case(osg::PrimitiveSet::TRIANGLE_FAN):
1013                                    OutputTriangleFanDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout);
1014                                    break;
1015                                case(osg::PrimitiveSet::QUAD_STRIP):
1016                                    OutputQuadStripDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout);
1017                                    break;
1018                                case(osg::PrimitiveSet::POLYGON):
1019                                    OutputPolygonDARR(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawArrayLengths, fout);
1020                                    break;
1021                                default:
1022                                    break; // unknown shape
1023                                }
1024                                break;
1025                            }
1026                        case(osg::PrimitiveSet::DrawElementsUBytePrimitiveType):
1027                            {
1028                                const osg::DrawElementsUByte* drawElements = static_cast<const osg::DrawElementsUByte*>(primitiveset);
1029                                switch(mode)
1030                                {
1031                                case(osg::PrimitiveSet::TRIANGLES):
1032                                    OutputTriangleDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1033                                    break;
1034                                case(osg::PrimitiveSet::QUADS):
1035                                    OutputQuadsDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1036                                    break;
1037                                case(osg::PrimitiveSet::TRIANGLE_STRIP):
1038                                    OutputTriangleStripDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1039                                    break;
1040                                case(osg::PrimitiveSet::TRIANGLE_FAN):
1041                                    OutputTriangleFanDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1042                                    break;
1043                                case(osg::PrimitiveSet::QUAD_STRIP):
1044                                    OutputQuadStripDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1045                                    break;
1046                                case(osg::PrimitiveSet::POLYGON):
1047                                    OutputPolygonDelsUByte(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1048                                    break;
1049                                default:
1050                                    break; // unknown shape
1051                                }
1052                               
1053                                break;
1054                            }
1055                        case(osg::PrimitiveSet::DrawElementsUShortPrimitiveType):
1056                            {
1057                                const osg::DrawElementsUShort* drawElements = static_cast<const osg::DrawElementsUShort*>(primitiveset);
1058                                switch(mode)
1059                                {
1060                                case(osg::PrimitiveSet::TRIANGLES):
1061                                    OutputTriangleDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1062                                    break;
1063                                case(osg::PrimitiveSet::QUADS):
1064                                    OutputQuadsDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1065                                    break;
1066                                case(osg::PrimitiveSet::TRIANGLE_STRIP):
1067                                    OutputTriangleStripDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1068                                    break;
1069                                case(osg::PrimitiveSet::TRIANGLE_FAN):
1070                                    OutputTriangleFanDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1071                                    break;
1072                                case(osg::PrimitiveSet::QUAD_STRIP):
1073                                    OutputQuadStripDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1074                                    break;
1075                                case(osg::PrimitiveSet::POLYGON):
1076                                    OutputPolygonDelsUShort(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1077                                    break;
1078                                default:
1079                                    break; // unknown shape
1080                                }
1081/*                                if (primLength == 0)
1082                                if (primLength == 0)
1083                                    primLength = primitiveset->getNumIndices();
1084                               
1085                                const osg::DrawElementsUShort* drawElements = static_cast<const osg::DrawElementsUShort*>(primitiveset);
1086                               
1087                                unsigned int primCount = 0;   
1088                               
1089                                for(osg::DrawElementsUShort::const_iterator primItr=drawElements->begin(); primItr!=drawElements->end(); ++primCount,++primItr)
1090                                {
1091                                   
1092                                    if ((primCount%primLength) == 0)
1093                                    {
1094        OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout);
1095                                    }
1096                                   
1097                                    unsigned int vindex=*primItr;
1098                                    OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
1099                                } */
1100                               
1101                                break;
1102                            }
1103                        case(osg::PrimitiveSet::DrawElementsUIntPrimitiveType):
1104                            {
1105                                const osg::DrawElementsUInt* drawElements = static_cast<const osg::DrawElementsUInt*>(primitiveset);
1106                                switch(mode)
1107                                {
1108                                case(osg::PrimitiveSet::TRIANGLES):
1109                                    OutputTriangleDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1110                                    break;
1111                                case(osg::PrimitiveSet::QUADS):
1112                                    OutputQuadsDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1113                                    break;
1114                                case(osg::PrimitiveSet::TRIANGLE_STRIP):
1115                                    OutputTriangleStripDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1116                                    break;
1117                                case(osg::PrimitiveSet::TRIANGLE_FAN):
1118                                    OutputTriangleFanDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1119                                    break;
1120                                case(osg::PrimitiveSet::QUAD_STRIP):
1121                                    OutputQuadStripDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1122                                    break;
1123                                case(osg::PrimitiveSet::POLYGON):
1124                                    OutputPolygonDelsUInt(iCurrentMaterial,surfaceFlags, pVertexIndices, pTexCoords, pTexIndices, drawElements, fout);
1125                                    break;
1126                                default:
1127                                    break; // unknown shape
1128                                }
1129/*                                if (primLength == 0)
1130                                if (primLength == 0)
1131                                    primLength = primitiveset->getNumIndices();
1132                               
1133                                const osg::DrawElementsUInt* drawElements = static_cast<const osg::DrawElementsUInt*>(primitiveset);
1134                               
1135                                unsigned int primCount=0;
1136                                for(osg::DrawElementsUInt::const_iterator primItr=drawElements->begin(); primItr!=drawElements->end(); ++primCount,++primItr)
1137                                {
1138                                   
1139                                    if ((primCount%primLength)==0)
1140                                    {
1141        OutputSurfHead(iCurrentMaterial,surfaceFlags,primLength, fout);
1142                                    }
1143                                   
1144                                    unsigned int vindex=*primItr;
1145                                    OutputVertex(vindex, pVertexIndices, pTexCoords, pTexIndices, fout);
1146                                } */
1147                               
1148                                break;
1149                            }
1150                        default:
1151                            {
1152                                break;
1153                            }
1154                        }
1155                    }
1156                }
1157                fout << "kids 0" << endl;
1158            }
1159        }
1160        else
1161        { // not sure what else it could be, but perhaps, perhaps, perhaps.
1162        }
1163    }
1164}
Note: See TracBrowser for help on using the browser.