root/OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/GeometryRecords.cpp @ 12597

Revision 12597, 45.0 kB (checked in by robert, 4 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/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14//
15// OpenFlight® loader for OpenSceneGraph
16//
17//  Copyright (C) 2005-2007  Brede Johansen
18//
19
20#include <assert.h>
21#include <osg/Geode>
22#include <osg/Billboard>
23#include <osg/Geometry>
24#include <osg/Texture2D>
25#include <osg/CullFace>
26#include <osg/BlendFunc>
27#include <osgUtil/TransformAttributeFunctor>
28#include "Registry.h"
29#include "Document.h"
30#include "RecordInputStream.h"
31
32#include <algorithm>
33
34namespace flt {
35
36template<class ARRAY>
37void reverseWindingOrder( ARRAY* data, GLenum mode, GLint first, GLint last )
38{
39    switch( mode )
40    {
41    case osg::PrimitiveSet::TRIANGLES:
42    case osg::PrimitiveSet::QUADS:
43    case osg::PrimitiveSet::POLYGON:
44        // reverse all the vertices.
45        std::reverse(data->begin()+first, data->begin()+last);
46        break;
47    case osg::PrimitiveSet::TRIANGLE_STRIP:
48    case osg::PrimitiveSet::QUAD_STRIP:
49        // reverse only the shared edges.
50        for( GLint i = first; i < last-1; i+=2 )
51        {
52            std::swap( (*data)[i], (*data)[i+1] );
53        }
54        break;
55    case osg::PrimitiveSet::TRIANGLE_FAN:
56        // reverse all vertices except the first vertex.
57        std::reverse(data->begin()+first+1, data->begin()+last);
58        break;
59    }
60}
61
62void addDrawableAndReverseWindingOrder( osg::Geode* geode )
63{
64    // Replace double sided polygons by duplicating the drawables and inverting the normals.
65    std::vector<osg::Geometry*> new_drawables;
66
67    for (size_t i=0; i<geode->getNumDrawables(); ++i)
68    {
69        const osg::Geometry* geometry = dynamic_cast<const osg::Geometry*>(geode->getDrawable(i));
70        if(geometry)
71        {
72            osg::Geometry* geom = new osg::Geometry(*geometry
73                , osg::CopyOp::DEEP_COPY_ARRAYS | osg::CopyOp::DEEP_COPY_PRIMITIVES);
74            new_drawables.push_back(geom);
75
76            for( size_t i = 0; i < geom->getNumPrimitiveSets( ); ++i )
77            {
78                osg::DrawArrays* drawarray = dynamic_cast<osg::DrawArrays*>( geom->getPrimitiveSet( i ) );
79                if( drawarray )
80                {
81                    GLint first = drawarray->getFirst();
82                    GLint last  = drawarray->getFirst()+drawarray->getCount();
83
84                    // Invert vertex order.
85                    osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geom->getVertexArray());
86                    if( vertices )
87                    {
88                        reverseWindingOrder( vertices, drawarray->getMode(), first, last );
89                    }
90
91                    if( geom->getNormalBinding( ) == osg::Geometry::BIND_PER_VERTEX )
92                    {
93                        osg::Vec3Array* normals = dynamic_cast<osg::Vec3Array*>(geom->getNormalArray());
94                        if( normals )
95                        {
96                            // First, invert the direction of the normals.
97                            for( GLint i = first; i < last; ++i )
98                            {
99                                (*normals)[i] = -(*normals)[i];
100                            }
101                            reverseWindingOrder( normals, drawarray->getMode(), first, last );
102                        }
103                    }
104
105                    if( geom->getColorBinding( ) == osg::Geometry::BIND_PER_VERTEX )
106                    {
107                        osg::Vec4Array* colors = dynamic_cast<osg::Vec4Array*>(geom->getColorArray());
108                        if( colors )
109                        {
110                            reverseWindingOrder( colors, drawarray->getMode(), first, last );
111                        }
112                    }
113
114                    for( size_t i = 0; i < geom->getNumTexCoordArrays(); ++i )
115                    {
116                        osg::Vec2Array* UVs = dynamic_cast<osg::Vec2Array*>(geom->getTexCoordArray(i));
117                        if( UVs )
118                        {
119                            reverseWindingOrder( UVs, drawarray->getMode(), first, last );
120                        }
121                    }
122                }
123            }
124        }
125    }
126
127    // Now add the new geometry drawable.
128    for( size_t i = 0; i < new_drawables.size( ); ++i )
129    {
130        geode->addDrawable( new_drawables[i] );
131    }
132}
133
134/* Face record
135 */
136class Face : public PrimaryRecord
137{
138    // flags
139    static const unsigned int TERRAIN_BIT      = 0x80000000u >> 0;
140    static const unsigned int NO_COLOR_BIT     = 0x80000000u >> 1;
141    static const unsigned int NO_ALT_COLOR_BIT = 0x80000000u >> 2;
142    static const unsigned int PACKED_COLOR_BIT = 0x80000000u >> 3;
143    static const unsigned int FOOTPRINT_BIT    = 0x80000000u >> 4;    // Terrain culture cutout
144    static const unsigned int HIDDEN_BIT       = 0x80000000u >> 5;
145    static const unsigned int ROOFLINE_BIT     = 0x80000000u >> 6;
146
147    osg::Vec4   _primaryColor;
148    uint8       _drawFlag;
149    uint8       _template;
150    uint16      _transparency;
151    uint32      _flags;
152    uint8       _lightMode;
153
154    osg::ref_ptr<osg::Geode> _geode;
155    osg::ref_ptr<osg::Geometry> _geometry;
156
157public:
158
159    Face() :
160        _primaryColor(1,1,1,1),
161        _drawFlag(SOLID_NO_BACKFACE),
162        _template(FIXED_NO_ALPHA_BLENDING),
163        _transparency(0),
164        _flags(0),
165        _lightMode(FACE_COLOR)
166    {
167    }
168
169    META_Record(Face)
170
171    META_setID(_geode)
172    META_setComment(_geode)
173    META_setMultitexture(_geode)
174
175    // draw mode
176    enum DrawMode
177    {
178        SOLID_BACKFACED = 0,
179        SOLID_NO_BACKFACE = 1,
180        WIREFRAME_CLOSED = 2,
181        WIREFRAME_NOT_CLOSED = 3,
182        SURROUND_ALTERNATE_COLOR = 4,
183        OMNIDIRECTIONAL_LIGHT = 8,
184        UNIDIRECTIONAL_LIGHT = 9,
185        BIDIRECTIONAL_LIGHT = 10
186    };
187
188    inline DrawMode getDrawMode() const { return (DrawMode)_drawFlag; }
189
190    // lighting
191    enum LightMode
192    {
193        FACE_COLOR = 0,
194        VERTEX_COLOR = 1,
195        FACE_COLOR_LIGHTING = 2,
196        VERTEX_COLOR_LIGHTING = 3
197    };
198
199    inline LightMode getLightMode() const { return (LightMode)_lightMode; }
200    inline bool isLit() const { return (_lightMode==FACE_COLOR_LIGHTING) || (_lightMode==VERTEX_COLOR_LIGHTING); }
201    inline bool isGouraud() const { return (_lightMode==VERTEX_COLOR) || (_lightMode==VERTEX_COLOR_LIGHTING); }
202
203    // flags
204    inline bool noColor()         const { return (_flags & NO_COLOR_BIT)!=0; }
205    inline bool isHidden()        const { return (_flags & HIDDEN_BIT)!=0; }
206    inline bool isTerrain()       const { return (_flags & TERRAIN_BIT)!=0; }
207    inline bool isFootprint()     const { return (_flags & FOOTPRINT_BIT)!=0; }
208    inline bool isRoofline()      const { return (_flags & ROOFLINE_BIT)!=0; }
209    inline bool packedColorMode() const { return (_flags & PACKED_COLOR_BIT)!=0; }
210
211    // billboard
212    enum TemplateMode
213    {
214        FIXED_NO_ALPHA_BLENDING = 0,
215        FIXED_ALPHA_BLENDING = 1,
216        AXIAL_ROTATE_WITH_ALPHA_BLENDING = 2,
217        POINT_ROTATE_WITH_ALPHA_BLENDING = 4
218    };
219
220    inline TemplateMode getTemplateMode() const { return (TemplateMode)_template; }
221
222    // transparency & alpha
223    inline bool isAlphaBlend() const
224    {
225        return (_template==FIXED_ALPHA_BLENDING) ||
226               (_template==AXIAL_ROTATE_WITH_ALPHA_BLENDING) ||
227               (_template==POINT_ROTATE_WITH_ALPHA_BLENDING);
228    }
229
230    inline osg::Vec4 getPrimaryColor() const { return _primaryColor; }
231    inline float getTransparency() const { return (float)_transparency / 65535.0f; }
232    inline bool isTransparent() const { return _transparency > 0; }
233
234    virtual void addChild(osg::Node& child)
235    {
236        // Add subface to parent.
237        if (_parent.valid())
238            _parent->addChild(child);
239    }
240
241    virtual void addVertex(Vertex& vertex)
242    {
243        osg::Vec3Array* vertices = getOrCreateVertexArray(*_geometry);
244        vertices->push_back(vertex._coord);
245
246        if (isGouraud())
247        {
248            osg::Vec4Array* colors = getOrCreateColorArray(*_geometry);
249            if (vertex.validColor())
250            {
251                colors->push_back(vertex._color);
252            }
253            else
254            {
255                // Use face color if vertex color is -1 in a gouraud polygon.
256                // http://www.multigen-paradigm.com/ubb/Forum1/HTML/000967.html
257                colors->push_back(_primaryColor);
258            }
259        }
260
261        bool strict = false; // prepare for "strict" reader option.
262        if (strict)
263        {
264            if (vertex.validNormal())
265            {
266                osg::Vec3Array* normals = getOrCreateNormalArray(*_geometry);
267                normals->push_back(vertex._normal);
268            }
269        }
270        else
271        {
272            // Add normal only if lit.
273            if (isLit())
274            {
275                osg::Vec3Array* normals = getOrCreateNormalArray(*_geometry);
276
277                if (vertex.validNormal())
278                    normals->push_back(vertex._normal);
279                else // if lit and no normal in Vertex
280                {
281                    // Use previous normal if available.
282                    if (normals->empty())
283                        normals->push_back(osg::Vec3(0,0,1));
284                    else
285                        normals->push_back(normals->back());
286                }
287            }
288        }
289
290        for (int layer=0; layer<Vertex::MAX_LAYERS; layer++)
291        {
292            if (vertex.validUV(layer))
293            {
294                osg::Vec2Array* UVs = getOrCreateTextureArray(*_geometry,layer);
295                UVs->push_back(vertex._uv[layer]);
296            }
297        }
298    }
299
300    virtual void addVertexUV(int unit, const osg::Vec2& uv)
301    {
302        osg::Vec2Array* UVs = getOrCreateTextureArray(*_geometry,unit);
303        UVs->push_back(uv);
304    }
305
306    virtual void addMorphVertex(Vertex& vertex0, Vertex& /*vertex100*/)
307    {
308        osg::Vec3Array* vertices = getOrCreateVertexArray(*_geometry);
309        vertices->push_back(vertex0._coord);
310
311        if (isGouraud())
312        {
313            osg::Vec4Array* colors = getOrCreateColorArray(*_geometry);
314            if (vertex0.validColor())
315            {
316                colors->push_back(vertex0._color);
317            }
318            else
319            {
320                // Use face color if vertex color is -1 in a gouraud polygon.
321                // http://www.multigen-paradigm.com/ubb/Forum1/HTML/000967.html
322                colors->push_back(_primaryColor);
323            }
324        }
325
326        if (vertex0.validNormal())
327        {
328            osg::Vec3Array* normals = getOrCreateNormalArray(*_geometry);
329            normals->push_back(vertex0._normal);
330        }
331
332        for (int layer=0; layer<Vertex::MAX_LAYERS; layer++)
333        {
334            if (vertex0.validUV(layer))
335            {
336                osg::Vec2Array* UVs = getOrCreateTextureArray(*_geometry,layer);
337                UVs->push_back(vertex0._uv[layer]);
338            }
339        }
340    }
341
342protected:
343
344    virtual void readRecord(RecordInputStream& in, Document& document)
345    {
346        std::string id = in.readString(8);
347        /*int32 IRColor =*/ in.readInt32();
348        /*int16 relativePriority =*/ in.readInt16();
349        _drawFlag = in.readUInt8(SOLID_NO_BACKFACE);
350        uint8 texturedWhite = in.readUInt8();
351        int16 primaryNameIndex = in.readInt16(-1);
352        /*int16 secondaryNameIndex =*/ in.readInt16(-1);
353        in.forward(1);
354        _template = in.readUInt8(FIXED_NO_ALPHA_BLENDING);
355        /*int detailTexture =*/ in.readInt16(-1);
356        int textureIndex = in.readInt16(-1);
357        int materialIndex = in.readInt16(-1);
358        /*int16 surface =*/ in.readInt16();
359        /*int16 feature =*/ in.readInt16();
360        /*int32 IRMaterial =*/ in.readInt32(-1);
361        _transparency = in.readUInt16(0);
362        // version > 13
363        /*uint8 influenceLOD =*/ in.readUInt8();
364        /*uint8 linestyle =*/ in.readUInt8();
365        _flags = in.readUInt32(0);
366        _lightMode = in.readUInt8(FACE_COLOR);
367        in.forward(7);
368        osg::Vec4 primaryPackedColor = in.readColor32();
369        /*osg::Vec4 secondaryPackedColor =*/ in.readColor32();
370        // version >= VERSION_15_1
371        /*int textureMappingIndex =*/ in.readInt16(-1);
372        in.forward(2);
373        int primaryColorIndex = in.readInt32(-1);
374        /*int alternateColorIndex =*/ in.readInt32(-1);
375        // version >= 16
376        in.forward(2);
377        int shaderIndex = in.readInt16(-1);
378
379        // Create Geode or Billboard.
380        switch (_template)
381        {
382        case AXIAL_ROTATE_WITH_ALPHA_BLENDING:
383            {
384                osg::Billboard* billboard = new osg::Billboard;
385                billboard->setMode(osg::Billboard::AXIAL_ROT);
386                _geode = billboard;
387            }
388            break;
389        case POINT_ROTATE_WITH_ALPHA_BLENDING:
390            {
391                osg::Billboard* billboard = new osg::Billboard;
392                billboard->setMode(osg::Billboard::POINT_ROT_WORLD);
393                _geode = billboard;
394            }
395            break;
396        default:
397            _geode = new osg::Geode;
398        }
399
400        _geode->setDataVariance(osg::Object::STATIC);
401        _geode->setName(id);
402
403        _geometry = new osg::Geometry;
404        _geometry->setDataVariance(osg::Object::STATIC);
405        _geode->addDrawable(_geometry.get());
406
407        // StateSet
408        osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
409
410        // Hidden
411        if (isHidden())
412            _geode->setNodeMask(0);
413
414        // Face color
415        if (texturedWhite!=0 && textureIndex>=0)
416        {
417            _primaryColor = osg::Vec4(1,1,1,1);
418        }
419        else
420        {
421            if (packedColorMode())
422            {
423                _primaryColor = primaryPackedColor;
424            }
425            else
426            {
427                if (document.version() < VERSION_15_1)
428                    _primaryColor = document.getColorPool()->getColor(primaryNameIndex);
429
430                else // >= VERSION_15_1
431                    _primaryColor = document.getColorPool()->getColor(primaryColorIndex);
432            }
433        }
434
435        // Lighting
436        stateset->setMode(GL_LIGHTING, isLit() ? osg::StateAttribute::ON : osg::StateAttribute::OFF);
437
438        // Material
439        if (isLit() || materialIndex>=0)
440        {
441            // MaterialPool will return a "default" material if no material is defined for materialIndex.
442            // http://www.multigen-paradigm.com/ubb/Forum1/HTML/000228.html
443            osg::Vec4 col = _primaryColor;
444            col.a() = 1.0f - getTransparency();
445            osg::Material* material = document.getOrCreateMaterialPool()->getOrCreateMaterial(materialIndex,col);
446            stateset->setAttribute(material);
447        }
448
449        // Shaders
450        if (shaderIndex >= 0)
451        {
452            ShaderPool* sp = document.getOrCreateShaderPool();
453            osg::Program* program = sp->get(shaderIndex);
454            if (program)
455                stateset->setAttributeAndModes(program, osg::StateAttribute::ON);
456        }
457
458         // Texture
459        TexturePool* tp = document.getOrCreateTexturePool();
460        osg::StateSet* textureStateSet = tp->get(textureIndex);
461        if (textureStateSet)
462        {
463            // Merge face stateset with texture stateset
464            stateset->merge(*textureStateSet);
465        }
466
467        // Cull face
468        switch(_drawFlag)
469        {
470        case SOLID_BACKFACED:     // Enable backface culling
471        {
472            static osg::ref_ptr<osg::CullFace> cullFace = new osg::CullFace(osg::CullFace::BACK);
473            stateset->setAttributeAndModes(cullFace.get(), osg::StateAttribute::ON);
474            break;
475        }
476        case SOLID_NO_BACKFACE:   // Disable backface culling
477            if( document.getReplaceDoubleSidedPolys( ) )
478            {
479                static osg::ref_ptr<osg::CullFace> cullFace = new osg::CullFace(osg::CullFace::BACK);
480                stateset->setAttributeAndModes(cullFace.get(), osg::StateAttribute::ON);
481            }
482            else
483            {
484                stateset->setMode(GL_CULL_FACE,osg::StateAttribute::OFF);
485            }
486            break;
487        }
488
489        // Subface
490        if (document.subfaceLevel() > 0)
491        {
492            stateset->setAttributeAndModes(document.getSubSurfacePolygonOffset(document.subfaceLevel()), osg::StateAttribute::ON);
493            stateset->setAttribute(document.getSubSurfaceDepth());
494
495            stateset->setRenderBinDetails(document.subfaceLevel(),"RenderBin");
496        }
497
498        _geode->setStateSet(stateset.get());
499
500        // Add to parent.
501        if (_parent.valid())
502            _parent->addChild(*_geode);
503    }
504
505    osg::PrimitiveSet::Mode getPrimitiveSetMode(int numVertices)
506    {
507        switch(getDrawMode())
508        {
509            case WIREFRAME_NOT_CLOSED:
510                return osg::PrimitiveSet::LINE_STRIP;
511            case WIREFRAME_CLOSED:
512                return osg::PrimitiveSet::LINE_LOOP;
513            case OMNIDIRECTIONAL_LIGHT:
514            case UNIDIRECTIONAL_LIGHT:
515            case BIDIRECTIONAL_LIGHT:
516                return osg::PrimitiveSet::POINTS;
517            default: break;
518        }
519
520        switch (numVertices)
521        {
522            case 1: return osg::PrimitiveSet::POINTS;
523            case 2: return osg::PrimitiveSet::LINES;
524            case 3: return osg::PrimitiveSet::TRIANGLES;
525            case 4: return osg::PrimitiveSet::QUADS;
526            default: break;
527        }
528
529        return osg::PrimitiveSet::POLYGON;
530    }
531
532    virtual void dispose(Document& document)
533    {
534        if (_geode.valid())
535        {
536            // Insert transform(s)
537            if (_matrix.valid())
538            {
539                insertMatrixTransform(*_geode,*_matrix,_numberOfReplications);
540            }
541
542            // Add primitives, set bindings etc.
543            for (unsigned int i=0; i<_geode->getNumDrawables(); ++i)
544            {
545                osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(_geode->getDrawable(i));
546                if (geometry)
547                {
548                    osg::Array* vertices = geometry->getVertexArray();
549                    if (vertices)
550                    {
551                        GLint first = 0;
552                        GLsizei count = vertices->getNumElements();
553                        osg::PrimitiveSet::Mode mode = getPrimitiveSetMode(count);
554                        geometry->addPrimitiveSet(new osg::DrawArrays(mode,first,count));
555                    }
556
557                    // Color binding
558                    if (isGouraud())
559                    {
560                        // Color per vertex
561                        geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
562                    }
563                    else
564                    {
565                        // Color per face
566                        osg::Vec4 col = getPrimaryColor();
567                        col[3] = 1.0f - getTransparency();
568
569                        geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
570                        osg::Vec4Array* colors = new osg::Vec4Array(1);
571                        (*colors)[0] = col;
572                        geometry->setColorArray(colors);
573                    }
574
575                    // Normal binding
576                    if (isLit())
577                    {
578                        geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX );
579                    }
580                    else
581                    {
582                        geometry->setNormalBinding(osg::Geometry::BIND_OFF);
583                        geometry->setNormalArray(NULL);
584                    }
585                }
586            }
587
588            if( getDrawMode( ) == SOLID_NO_BACKFACE && document.getReplaceDoubleSidedPolys( ) )
589            {
590                addDrawableAndReverseWindingOrder( _geode.get() );
591            }
592
593            osg::StateSet* stateset =  _geode->getOrCreateStateSet();
594
595            // Translucent image?
596            bool isImageTranslucent = false;
597            if (document.getUseTextureAlphaForTransparancyBinning())
598            {
599                for (unsigned int i=0; i<stateset->getTextureAttributeList().size(); ++i)
600                {
601                    osg::StateAttribute* sa = stateset->getTextureAttribute(i,osg::StateAttribute::TEXTURE);
602                    osg::Texture2D* texture = dynamic_cast<osg::Texture2D*>(sa);
603                    if (texture)
604                    {
605                        osg::Image* image = texture->getImage();
606                        if (image && image->isImageTranslucent())
607                            isImageTranslucent = true;
608                    }
609                }
610            }
611
612            // Transparent Material?
613            bool isMaterialTransparent = false;
614            osg::Material* material = dynamic_cast<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL));
615            if (material)
616            {
617                isMaterialTransparent = material->getDiffuse(osg::Material::FRONT).a() < 0.99f;
618            }
619
620            // Enable alpha blend?
621            if (isAlphaBlend() || isTransparent() || isImageTranslucent || isMaterialTransparent)
622            {
623                static osg::ref_ptr<osg::BlendFunc> blendFunc = new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
624                stateset->setAttributeAndModes(blendFunc.get(), osg::StateAttribute::ON);
625                stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
626            }
627
628            if (document.getUseBillboardCenter())
629            {
630                // Set billboard rotation point to center of face.
631                osg::Billboard* billboard = dynamic_cast<osg::Billboard*>(_geode.get());
632                if (billboard)
633                {
634                    for (unsigned int i=0; i<billboard->getNumDrawables(); ++i)
635                    {
636                        osg::BoundingBox bb = billboard->getDrawable(i)->getBound();
637                        billboard->setPosition(i,bb.center());
638
639                        osgUtil::TransformAttributeFunctor tf(osg::Matrix::translate(-bb.center()));
640                        billboard->getDrawable(i)->accept(tf);
641
642                        billboard->getDrawable(i)->dirtyBound();
643                    }
644                   
645                    billboard->dirtyBound();
646                }
647            }
648        }
649    }
650};
651
652REGISTER_FLTRECORD(Face, FACE_OP)
653
654
655
656/** VertexList -
657  * The VertexList is a leaf record.
658  * Possible parents: Face, Mesh & LightPoint
659  */
660class VertexListRecord : public PrimaryRecord
661{
662public:
663
664    VertexListRecord() {}
665
666    META_Record(VertexListRecord)
667
668    virtual void addVertex(Vertex& vertex)
669    {
670        // forward vertex to parent.
671        if (_parent.valid())
672            _parent->addVertex(vertex);
673    }
674
675    virtual void addVertexUV(int layer,const osg::Vec2& uv)
676    {
677        // forward uv to parent.
678        if (_parent.valid())
679            _parent->addVertexUV(layer,uv);
680    }
681
682protected:
683
684    virtual ~VertexListRecord() {}
685
686    virtual void readRecord(RecordInputStream& in, Document& document)
687    {
688        VertexPool* vp = document.getVertexPool();
689        if (vp)
690        {
691            int vertices = (in.getRecordSize()-4) / 4;
692
693            // Use the Vertex pool as a record stream.
694            RecordInputStream inVP(vp->rdbuf());
695            for (int n=0; n<vertices; n++)
696            {
697                // Get position of vertex.
698                uint32 pos = in.readUInt32();
699
700                // Get vertex from vertex pool.
701                inVP.seekg((std::istream::pos_type)pos);
702                inVP.readRecord(document);
703            }
704        }
705    }
706};
707
708
709REGISTER_FLTRECORD(VertexListRecord, VERTEX_LIST_OP)
710
711
712
713/** MorphVertexList -
714  * The MorphVertexList is a leaf record.
715  */
716class MorphVertexList : public PrimaryRecord
717{
718    enum Mode
719    {
720        UNDEFINED,
721        MORPH_0,
722        MORPH_100
723    };
724
725    Mode _mode;
726    Vertex _vertex0;
727    Vertex _vertex100;
728
729public:
730
731    MorphVertexList():
732        _mode(UNDEFINED)
733    {
734    }
735
736    META_Record(MorphVertexList)
737
738    virtual void addVertex(Vertex& vertex)
739    {
740        switch (_mode)
741        {
742        case MORPH_0:
743            _vertex0 = vertex;
744            break;
745        case MORPH_100:
746            _vertex100 = vertex;
747
748            // forward vertex to parent.
749            if (_parent.valid())
750                _parent->addMorphVertex(_vertex0, _vertex100);
751            break;
752        case UNDEFINED:
753            break;
754        }
755    }
756
757    //virtual void addVertexUV(int layer,const osg::Vec2& uv)
758    //{
759    //    // forward uv to parent.
760    //    if (_parent.valid())
761    //        _parent->addVertexUV(layer,uv);
762    //}
763
764protected:
765
766    virtual ~MorphVertexList() {}
767
768    virtual void readRecord(RecordInputStream& in, Document& document)
769    {
770        VertexPool* vp = document.getVertexPool();
771        if (vp)
772        {
773            int vertices = (in.getRecordSize()-4) / 8;
774
775            // Use the Vertex pool as a record stream.
776            RecordInputStream inVP(vp->rdbuf());
777            for (int n=0; n<vertices; n++)
778            {
779                // Get position of vertex.
780                uint32 offset0 = in.readUInt32();
781                uint32 offset100 = in.readUInt32();
782
783                // Get vertex from vertex pool.
784
785                // 0%
786                _mode = MORPH_0;
787                inVP.seekg((std::istream::pos_type)offset0);
788                inVP.readRecord(document);
789
790                // 100%
791                _mode = MORPH_100;
792                inVP.seekg((std::istream::pos_type)offset100);
793                inVP.readRecord(document);
794            }
795        }
796    }
797};
798
799REGISTER_FLTRECORD(MorphVertexList, MORPH_VERTEX_LIST_OP)
800
801
802
803/* Mesh record
804 */
805class Mesh : public PrimaryRecord
806{
807    // flags
808    static const unsigned int TERRAIN_BIT      = 0x80000000u >> 0;
809    static const unsigned int NO_COLOR_BIT     = 0x80000000u >> 1;
810    static const unsigned int NO_ALT_COLOR_BIT = 0x80000000u >> 2;
811    static const unsigned int PACKED_COLOR_BIT = 0x80000000u >> 3;
812    static const unsigned int FOOTPRINT_BIT    = 0x80000000u >> 4;    // Terrain culture cutout
813    static const unsigned int HIDDEN_BIT       = 0x80000000u >> 5;
814    static const unsigned int ROOFLINE_BIT     = 0x80000000u >> 6;
815
816    osg::Vec4   _primaryColor;
817    uint8       _drawFlag;
818    uint8       _template;
819    uint16      _transparency;
820    uint32      _flags;
821    uint8       _lightMode;
822
823    osg::ref_ptr<osg::Geode> _geode;
824
825public:
826
827    Mesh() :
828        _primaryColor(1,1,1,1),
829        _drawFlag(SOLID_NO_BACKFACE),
830        _template(FIXED_NO_ALPHA_BLENDING),
831        _transparency(0),
832        _flags(0),
833        _lightMode(FACE_COLOR)
834    {
835    }
836
837    META_Record(Mesh)
838
839    META_setID(_geode)
840    META_setComment(_geode)
841    META_setMultitexture(_geode)
842
843    // draw mode
844    enum DrawMode
845    {
846        SOLID_BACKFACED = 0,
847        SOLID_NO_BACKFACE = 1,
848        WIREFRAME_CLOSED = 2,
849        WIREFRAME_NOT_CLOSED = 3,
850        SURROUND_ALTERNATE_COLOR = 4,
851        OMNIDIRECTIONAL_LIGHT = 8,
852        UNIDIRECTIONAL_LIGHT = 9,
853        BIDIRECTIONAL_LIGHT = 10
854    };
855
856    inline DrawMode getDrawMode() const { return (DrawMode)_drawFlag; }
857
858    // lighting
859    enum LightMode
860    {
861        FACE_COLOR = 0,
862        VERTEX_COLOR = 1,
863        FACE_COLOR_LIGHTING = 2,
864        VERTEX_COLOR_LIGHTING = 3
865    };
866
867    inline LightMode getLightMode() const { return (LightMode)_lightMode; }
868    inline bool isLit() const { return (_lightMode==FACE_COLOR_LIGHTING) || (_lightMode==VERTEX_COLOR_LIGHTING); }
869    inline bool isGouraud() const { return (_lightMode==VERTEX_COLOR) || (_lightMode==VERTEX_COLOR_LIGHTING); }
870
871    // flags
872    inline bool noColor()         const { return (_flags & NO_COLOR_BIT)!=0; }
873    inline bool isHidden()        const { return (_flags & HIDDEN_BIT)!=0; }
874    inline bool isTerrain()       const { return (_flags & TERRAIN_BIT)!=0; }
875    inline bool isFootprint()     const { return (_flags & FOOTPRINT_BIT)!=0; }
876    inline bool isRoofline()      const { return (_flags & ROOFLINE_BIT)!=0; }
877    inline bool packedColorMode() const { return (_flags & PACKED_COLOR_BIT)!=0; }
878
879    // billboard
880    enum TemplateMode
881    {
882        FIXED_NO_ALPHA_BLENDING = 0,
883        FIXED_ALPHA_BLENDING = 1,
884        AXIAL_ROTATE_WITH_ALPHA_BLENDING = 2,
885        POINT_ROTATE_WITH_ALPHA_BLENDING = 4
886    };
887
888    inline TemplateMode getTemplateMode() const { return (TemplateMode)_template; }
889
890    // transparency & alpha
891    inline bool isAlphaBlend() const
892    {
893        return (_template==FIXED_ALPHA_BLENDING) ||
894               (_template==AXIAL_ROTATE_WITH_ALPHA_BLENDING) ||
895               (_template==POINT_ROTATE_WITH_ALPHA_BLENDING);
896    }
897
898    inline osg::Vec4 getPrimaryColor() const { return _primaryColor; }
899    inline float getTransparency() const { return (float)_transparency / 65535.0f; }
900    inline bool isTransparent() const { return _transparency > 0; }
901
902    virtual void addChild(osg::Node& child)
903    {
904        // Add subface to parent.
905        if (_parent.valid())
906            _parent->addChild(child);
907    }
908
909    virtual void addGeometry(osg::Geometry& geometry)
910    {
911        _geode->addDrawable(&geometry);
912    }
913
914protected:
915
916    virtual void readRecord(RecordInputStream& in, Document& document)
917    {
918        std::string id = in.readString(8);
919        in.forward(4);
920        /*int32 IRColor =*/ in.readInt32();
921        /*int16 relativePriority =*/ in.readInt16();
922        _drawFlag = in.readUInt8(SOLID_NO_BACKFACE);
923        uint8 texturedWhite = in.readUInt8();
924        int16 primaryNameIndex = in.readInt16(-1);
925        /*int16 secondaryNameIndex =*/ in.readInt16(-1);
926        in.forward(1);
927        _template = in.readUInt8(FIXED_NO_ALPHA_BLENDING);
928        /*int detailTexture =*/ in.readInt16(-1);
929        int textureIndex = in.readInt16(-1);
930        int materialIndex = in.readInt16(-1);
931        /*int16 surface =*/ in.readInt16();
932        /*int16 feature =*/ in.readInt16();
933        /*int32 IRMaterial =*/ in.readInt32(-1);
934        _transparency = in.readUInt16(0);
935        // version > 13
936        /*uint8 influenceLOD =*/ in.readUInt8();
937        /*uint8 linestyle =*/ in.readUInt8();
938        _flags = in.readUInt32(0);
939        _lightMode = in.readUInt8(FACE_COLOR);
940        in.forward(7);
941        osg::Vec4 primaryPackedColor = in.readColor32();
942        /*osg::Vec4 secondaryPackedColor =*/ in.readColor32();
943        // version >= VERSION_15_1
944        /*int textureMappingIndex =*/ in.readInt16(-1);
945        in.forward(2);
946        int primaryColorIndex = in.readInt32(-1);
947        /*int alternateColorIndex =*/ in.readInt32(-1);
948        // version >= 16
949        in.forward(2);
950        int shaderIndex = in.readInt16(-1);
951
952        // Create Geode or Billboard.
953        switch (_template)
954        {
955        case AXIAL_ROTATE_WITH_ALPHA_BLENDING:
956            {
957                osg::Billboard* billboard = new osg::Billboard;
958                billboard->setMode(osg::Billboard::AXIAL_ROT);
959                _geode = billboard;
960            }
961            break;
962        case POINT_ROTATE_WITH_ALPHA_BLENDING:
963            {
964                osg::Billboard* billboard = new osg::Billboard;
965                billboard->setMode(osg::Billboard::POINT_ROT_WORLD);
966                _geode = billboard;
967            }
968            break;
969        default:
970            _geode = new osg::Geode;
971        }
972
973        _geode->setDataVariance(osg::Object::STATIC);
974        _geode->setName(id);
975
976        // StateSet
977        osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
978
979        // Hidden
980        if (isHidden())
981            _geode->setNodeMask(0);
982
983        // Face color
984        if (texturedWhite!=0 && textureIndex>=0)
985        {
986            _primaryColor = osg::Vec4(1,1,1,1);
987        }
988        else
989        {
990            if (packedColorMode())
991            {
992                _primaryColor = primaryPackedColor;
993            }
994            else
995            {
996                if (document.version() < VERSION_15_1)
997                    _primaryColor = document.getColorPool()->getColor(primaryNameIndex);
998
999                else // >= VERSION_15_1
1000                    _primaryColor = document.getColorPool()->getColor(primaryColorIndex);
1001            }
1002        }
1003
1004        // Lighting
1005        stateset->setMode(GL_LIGHTING, isLit() ? osg::StateAttribute::ON : osg::StateAttribute::OFF);
1006
1007        // Material
1008        if (isLit() || materialIndex>=0)
1009        {
1010            // MaterialPool will return a "default" material if no material is defined for materialIndex.
1011            // http://www.multigen-paradigm.com/ubb/Forum1/HTML/000228.html
1012            osg::Vec4 col = _primaryColor;
1013            col.a() = 1.0f - getTransparency();
1014            osg::Material* material = document.getOrCreateMaterialPool()->getOrCreateMaterial(materialIndex,col);
1015            stateset->setAttribute(material);
1016        }
1017
1018        // Shaders
1019        if (shaderIndex >= 0)
1020        {
1021            ShaderPool* sp = document.getOrCreateShaderPool();
1022            osg::Program* program = sp->get(shaderIndex);
1023            if (program)
1024                stateset->setAttributeAndModes(program, osg::StateAttribute::ON);
1025        }
1026
1027         // Texture
1028        TexturePool* tp = document.getOrCreateTexturePool();
1029        osg::StateSet* textureStateSet = tp->get(textureIndex);
1030        if (textureStateSet)
1031        {
1032            // Merge face stateset with texture stateset
1033            stateset->merge(*textureStateSet);
1034        }
1035
1036        // Cull face
1037        switch(_drawFlag)
1038        {
1039        case SOLID_BACKFACED:     // Enable backface culling
1040        {
1041            static osg::ref_ptr<osg::CullFace> cullFace = new osg::CullFace(osg::CullFace::BACK);
1042            stateset->setAttributeAndModes(cullFace.get(), osg::StateAttribute::ON);
1043            break;
1044        }
1045        case SOLID_NO_BACKFACE:   // Disable backface culling
1046            if( document.getReplaceDoubleSidedPolys( ) )
1047            {
1048                static osg::ref_ptr<osg::CullFace> cullFace = new osg::CullFace(osg::CullFace::BACK);
1049                stateset->setAttributeAndModes(cullFace.get(), osg::StateAttribute::ON);
1050            }
1051            else
1052            {
1053                stateset->setMode(GL_CULL_FACE,osg::StateAttribute::OFF);
1054            }
1055            break;
1056        }
1057
1058        // Subface
1059        if (document.subfaceLevel() > 0)
1060        {
1061            stateset->setAttributeAndModes(document.getSubSurfacePolygonOffset(document.subfaceLevel()), osg::StateAttribute::ON);
1062            stateset->setAttribute(document.getSubSurfaceDepth());
1063
1064            stateset->setRenderBinDetails(document.subfaceLevel(),"RenderBin");
1065        }
1066
1067        _geode->setStateSet(stateset.get());
1068
1069        // Add to parent.
1070        if (_parent.valid())
1071            _parent->addChild(*_geode);
1072    }
1073
1074    virtual void dispose(Document& document)
1075    {
1076        if (_geode.valid())
1077        {
1078            // Insert transform(s)
1079            if (_matrix.valid())
1080            {
1081                insertMatrixTransform(*_geode,*_matrix,_numberOfReplications);
1082            }
1083
1084            if( getDrawMode( ) == SOLID_NO_BACKFACE && document.getReplaceDoubleSidedPolys( ) )
1085            {
1086                addDrawableAndReverseWindingOrder( _geode.get() );
1087            }
1088
1089            osg::StateSet* stateset =  _geode->getOrCreateStateSet();
1090
1091            // Translucent image?
1092            bool isImageTranslucent = false;
1093            if (document.getUseTextureAlphaForTransparancyBinning())
1094            {
1095                for (unsigned int i=0; i<stateset->getTextureAttributeList().size(); ++i)
1096                {
1097                    osg::StateAttribute* sa = stateset->getTextureAttribute(i,osg::StateAttribute::TEXTURE);
1098                    osg::Texture2D* texture = dynamic_cast<osg::Texture2D*>(sa);
1099                    if (texture)
1100                    {
1101                        osg::Image* image = texture->getImage();
1102                        if (image && image->isImageTranslucent())
1103                            isImageTranslucent = true;
1104                    }
1105                }
1106            }
1107
1108            // Transparent Material?
1109            bool isMaterialTransparent = false;
1110            osg::Material* material = dynamic_cast<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL));
1111            if (material)
1112            {
1113                isMaterialTransparent = material->getDiffuse(osg::Material::FRONT).a() < 0.99f;
1114            }
1115
1116            // Enable alpha blend?
1117            if (isAlphaBlend() || isTransparent() || isImageTranslucent || isMaterialTransparent)
1118            {
1119                static osg::ref_ptr<osg::BlendFunc> blendFunc = new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
1120                stateset->setAttributeAndModes(blendFunc.get(), osg::StateAttribute::ON);
1121                stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
1122            }
1123
1124            if (document.getUseBillboardCenter())
1125            {
1126                // Set billboard rotation point to center of face.
1127                osg::Billboard* billboard = dynamic_cast<osg::Billboard*>(_geode.get());
1128                if (billboard)
1129                {
1130                    for (unsigned int i=0; i<billboard->getNumDrawables(); ++i)
1131                    {
1132                        osg::BoundingBox bb = billboard->getDrawable(i)->getBound();
1133                        billboard->setPosition(i,bb.center());
1134
1135                        osgUtil::TransformAttributeFunctor tf(osg::Matrix::translate(-bb.center()));
1136                        billboard->getDrawable(i)->accept(tf);
1137
1138                        billboard->getDrawable(i)->dirtyBound();
1139                    }
1140                   
1141                    billboard->dirtyBound();
1142                }
1143            }
1144        }
1145    }
1146};
1147
1148REGISTER_FLTRECORD(Mesh, MESH_OP)
1149
1150
1151
1152
1153/** LocalVertexPool -
1154  */
1155class LocalVertexPool : public Record
1156{
1157    // Attribute Mask
1158    static const unsigned int HAS_POSITION      = 0x80000000u >> 0;
1159    static const unsigned int HAS_COLOR_INDEX   = 0x80000000u >> 1;
1160    static const unsigned int HAS_RGBA_COLOR    = 0x80000000u >> 2;
1161    static const unsigned int HAS_NORMAL        = 0x80000000u >> 3;
1162    static const unsigned int HAS_BASE_UV       = 0x80000000u >> 4;
1163    static const unsigned int HAS_UV_LAYER1     = 0x80000000u >> 5;
1164    static const unsigned int HAS_UV_LAYER2     = 0x80000000u >> 6;
1165    static const unsigned int HAS_UV_LAYER3     = 0x80000000u >> 7;
1166    static const unsigned int HAS_UV_LAYER4     = 0x80000000u >> 8;
1167    static const unsigned int HAS_UV_LAYER5     = 0x80000000u >> 9;
1168    static const unsigned int HAS_UV_LAYER6     = 0x80000000u >> 10;
1169    static const unsigned int HAS_UV_LAYER7     = 0x80000000u >> 11;
1170
1171public:
1172
1173    LocalVertexPool() {}
1174
1175    META_Record(LocalVertexPool)
1176
1177protected:
1178
1179    virtual ~LocalVertexPool() {}
1180
1181    virtual void readRecord(RecordInputStream& in, Document& document)
1182    {
1183
1184        uint32 vertices = in.readUInt32();
1185        uint32 mask = in.readUInt32();
1186
1187        osg::ref_ptr<VertexList> _vertexList = new VertexList(vertices);
1188
1189
1190        for (unsigned int n=0; n<vertices; n++)
1191        {
1192            Vertex vertex;
1193
1194            if (mask & HAS_POSITION)
1195            {
1196                osg::Vec3d coord = in.readVec3d();
1197                vertex.setCoord(coord*document.unitScale());
1198
1199                if (!coord.valid())
1200                {
1201                    OSG_NOTICE<<"Warning: data error detected in LocalVertexPool::readRecord coord="<<coord.x()<<" "<<coord.y()<<" "<<coord.z()<<std::endl;
1202                }
1203            }
1204
1205            if (mask & HAS_COLOR_INDEX)
1206            {
1207                uint32 alphaIndex = in.readUInt32();
1208                int index = alphaIndex & 0x00ffffff;
1209                uint8 alpha = alphaIndex >> 24;
1210                osg::Vec4 color = document.getColorPool()->getColor(index);
1211                color.a() = (float)alpha/255;
1212                vertex.setColor(color);
1213
1214                if (!color.valid())
1215                {
1216                    OSG_NOTICE<<"Warning: data error detected in LocalVertexPool::readRecord color="<<color.r()<<" "<<color.g()<<" "<<color.b()<<" "<<color.a()<<std::endl;
1217                }
1218            }
1219
1220            if (mask & HAS_RGBA_COLOR)
1221            {
1222                osg::Vec4f color = in.readColor32();
1223                vertex.setColor(color);
1224
1225                if (!color.valid())
1226                {
1227                    OSG_NOTICE<<"Warning: data error detected in LocalVertexPool::readRecord color="<<color.r()<<" "<<color.g()<<" "<<color.b()<<" "<<color.a()<<std::endl;
1228                }
1229            }
1230
1231            if (mask & HAS_NORMAL)
1232            {
1233                osg::Vec3f normal = in.readVec3f();
1234                vertex.setNormal(normal);
1235
1236                if (!normal.valid())
1237                {
1238                    OSG_NOTICE<<"Warning: data error detected in LocalVertexPool::readRecord normal="<<normal.x()<<" "<<normal.y()<<" "<<normal.z()<<std::endl;
1239                }
1240            }
1241
1242            for (unsigned int layer=0; layer<8; layer++)
1243            {
1244                if (mask & (HAS_BASE_UV >> layer))
1245                {
1246                    osg::Vec2f uv = in.readVec2f();
1247                    vertex.setUV(layer,uv);
1248                   
1249                    if (!uv.valid())
1250                    {
1251                        OSG_NOTICE<<"Warning: data error detected in LocalVertexPool::readRecord uv="<<uv.x()<<" "<<uv.y()<<std::endl;
1252                    }
1253
1254                }
1255            }
1256
1257            (*_vertexList)[n] = vertex;
1258        }
1259
1260        if (_parent.valid())
1261            _parent->setLocalVertexPool(_vertexList.get());
1262
1263    }
1264};
1265
1266REGISTER_FLTRECORD(LocalVertexPool, LOCAL_VERTEX_POOL_OP)
1267
1268
1269
1270
1271/** MeshPrimitive -
1272  */
1273class MeshPrimitive : public PrimaryRecord
1274{
1275    enum PrimitiveType
1276    {
1277        TRIANGLE_STRIP = 1,
1278        TRIANGLE_FAN = 2,
1279        QUADRILATERAL_STRIP = 3,
1280        INDEXED_POLYGON = 4
1281    };
1282
1283public:
1284
1285    MeshPrimitive() {}
1286
1287    META_Record(MeshPrimitive)
1288
1289protected:
1290
1291    virtual ~MeshPrimitive() {}
1292
1293    virtual void readRecord(RecordInputStream& in, Document& /*document*/)
1294    {
1295        Mesh* mesh = dynamic_cast<Mesh*>(_parent.get());
1296        if (!mesh) return;
1297
1298        VertexList* vertexList = mesh->getLocalVertexPool();
1299        if (!vertexList) return;
1300
1301        int16 type = in.readInt16();
1302        uint16 indexSize = in.readUInt16();
1303        uint32 vertexCount = in.readUInt32();
1304
1305        GLenum mode = 0;
1306        switch(type)
1307        {
1308        case TRIANGLE_STRIP:
1309            mode = osg::PrimitiveSet::TRIANGLE_STRIP;
1310            break;
1311        case TRIANGLE_FAN:
1312            mode = osg::PrimitiveSet::TRIANGLE_FAN;
1313            break;
1314        case QUADRILATERAL_STRIP:
1315            mode = osg::PrimitiveSet::QUAD_STRIP;
1316            break;
1317        case INDEXED_POLYGON:
1318            mode = osg::PrimitiveSet::POLYGON;
1319            break;
1320        }
1321
1322        osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
1323        geometry->addPrimitiveSet(new osg::DrawArrays(mode,0,vertexCount));
1324
1325        for (unsigned int n=0; n<vertexCount; n++)
1326        {
1327            unsigned int index = 0;
1328            switch (indexSize)
1329            {
1330            case 1:
1331                index = in.readUInt8();
1332                break;
1333            case 2:
1334                index = in.readUInt16();
1335                break;
1336            case 4:
1337                index = in.readUInt32();
1338                break;
1339            }
1340           
1341            if (index < vertexList->size())
1342            {
1343                Vertex& vertex = (*vertexList)[index];
1344
1345                osg::Vec3Array* vertices = getOrCreateVertexArray(*geometry);
1346                vertices->push_back(vertex._coord);
1347
1348                if (vertex.validColor())
1349                {
1350                    osg::Vec4Array* colors = getOrCreateColorArray(*geometry);
1351                    colors->push_back(vertex._color);
1352                }
1353
1354                if (vertex.validNormal())
1355                {
1356                    osg::Vec3Array* normals = getOrCreateNormalArray(*geometry);
1357                    normals->push_back(vertex._normal);
1358                }
1359
1360                for (int layer=0; layer<Vertex::MAX_LAYERS; layer++)
1361                {
1362                    if (vertex.validUV(layer))
1363                    {
1364                        osg::Vec2Array* UVs = getOrCreateTextureArray(*geometry,layer);
1365                        UVs->push_back(vertex._uv[layer]);
1366                    }
1367                }
1368            }
1369        }
1370
1371        // Color binding
1372        if (mesh->isGouraud())
1373        {
1374            // Color per vertex
1375            geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
1376        }
1377        else
1378        {
1379            // Color per face
1380            osg::Vec4 col = mesh->getPrimaryColor();
1381            col[3] = 1.0f - mesh->getTransparency();
1382
1383            geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
1384            osg::Vec4Array* colors = new osg::Vec4Array(1);
1385            (*colors)[0] = col;
1386            geometry->setColorArray(colors);
1387        }
1388
1389        // Normal binding
1390        if (mesh->isLit())
1391        {
1392            geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX );
1393        }
1394        else
1395        {
1396            geometry->setNormalBinding(osg::Geometry::BIND_OFF);
1397            geometry->setNormalArray(NULL);
1398        }
1399
1400        mesh->addGeometry(*geometry);
1401
1402    }
1403};
1404
1405REGISTER_FLTRECORD(MeshPrimitive, MESH_PRIMITIVE_OP)
1406
1407
1408
1409} // end namespace
1410
1411
1412
Note: See TracBrowser for help on using the browser.