Removed redundant examples, that have been moved to the applications directory
This commit is contained in:
parent
451a27ac65
commit
a06ca64061
@ -1,18 +0,0 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgarchive.cpp\
|
||||
|
||||
LIBS += -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
INSTFILES = \
|
||||
$(CXXFILES)\
|
||||
GNUmakefile.inst=GNUmakefile
|
||||
|
||||
EXEC = osgarchive
|
||||
|
||||
INC += $(X_INC)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
|
@ -1,13 +0,0 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgarchive.cpp\
|
||||
|
||||
LIBS += -losgDB losgUtil -losg $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
EXEC = osgarchive
|
||||
|
||||
INC += $(X_INC)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
@ -1,184 +0,0 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* freely and without restriction, both in commericial and non commericial applications,
|
||||
* as long as this copyright notice is maintained.
|
||||
*
|
||||
* This application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#include <osg/Timer>
|
||||
#include <osg/ArgumentParser>
|
||||
#include <osg/ApplicationUsage>
|
||||
|
||||
#include <osgDB/Archive>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
#include <osgDB/FileUtils>
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.");
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
||||
|
||||
// if user request help write it out to cout.
|
||||
if (arguments.read("-h") || arguments.read("--help"))
|
||||
{
|
||||
arguments.getApplicationUsage()->write(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string archiveFilename;
|
||||
while (arguments.read("-a",archiveFilename) || arguments.read("--archive",archiveFilename))
|
||||
{
|
||||
}
|
||||
|
||||
bool insert = false;
|
||||
while (arguments.read("-i") || arguments.read("--insert"))
|
||||
{
|
||||
insert = true;
|
||||
}
|
||||
|
||||
bool extract = false;
|
||||
while (arguments.read("-e") || arguments.read("--extract"))
|
||||
{
|
||||
extract = true;
|
||||
}
|
||||
|
||||
bool list = false;
|
||||
while (arguments.read("-l") || arguments.read("--list"))
|
||||
{
|
||||
list = true;
|
||||
}
|
||||
|
||||
typedef std::vector<std::string> FileNameList;
|
||||
FileNameList files;
|
||||
for(int pos=1;pos<arguments.argc();++pos)
|
||||
{
|
||||
if (!arguments.isOption(pos))
|
||||
{
|
||||
if (insert)
|
||||
{
|
||||
std::string filePath = osgDB::findDataFile(arguments[pos]);
|
||||
osgDB::FileType fileType = osgDB::fileType(filePath);
|
||||
if (fileType==osgDB::REGULAR_FILE)
|
||||
{
|
||||
files.push_back(arguments[pos]);
|
||||
}
|
||||
else if (fileType==osgDB::DIRECTORY)
|
||||
{
|
||||
osgDB::DirectoryContents directory = osgDB::getDirectoryContents(arguments[pos]);
|
||||
files.insert(files.end(),directory.begin(),directory.end());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
files.push_back(arguments[pos]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// any option left unread are converted into errors to write out later.
|
||||
arguments.reportRemainingOptionsAsUnrecognized();
|
||||
|
||||
// report any errors if they have occured when parsing the program aguments.
|
||||
if (arguments.errors())
|
||||
{
|
||||
arguments.writeErrorMessages(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (archiveFilename.empty())
|
||||
{
|
||||
std::cout<<"Please specify an archive name using --archive filename"<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!insert && !extract && !list)
|
||||
{
|
||||
std::cout<<"Please specify an operation on the archive, either --insert, --extract or --list"<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (insert && extract)
|
||||
{
|
||||
std::cout<<"Cannot insert and extract files from the archive at one time, please use either --insert or --extract."<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osgDB::Archive> archive;
|
||||
|
||||
if (insert)
|
||||
{
|
||||
archive = osgDB::openArchive(archiveFilename, osgDB::Archive::WRITE);
|
||||
|
||||
if (archive.valid())
|
||||
{
|
||||
for (FileNameList::iterator itr=files.begin();
|
||||
itr!=files.end();
|
||||
++itr)
|
||||
{
|
||||
std::cout<<"reading "<<*itr<<std::endl;
|
||||
osg::ref_ptr<osg::Object> obj = osgDB::readObjectFile(*itr);
|
||||
if (obj.valid())
|
||||
{
|
||||
std::cout<<" write to archive "<<*itr<<std::endl;
|
||||
archive->writeObject(*obj, *itr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
archive = osgDB::openArchive(archiveFilename, osgDB::Archive::READ);
|
||||
|
||||
if (extract && archive.valid())
|
||||
{
|
||||
for (FileNameList::iterator itr=files.begin();
|
||||
itr!=files.end();
|
||||
++itr)
|
||||
{
|
||||
osg::Timer_t start = osg::Timer::instance()->tick();
|
||||
osgDB::ReaderWriter::ReadResult result = archive->readObject(*itr);
|
||||
osg::ref_ptr<osg::Object> obj = result.getObject();
|
||||
std::cout<<"readObejct time = "<<osg::Timer::instance()->delta_m(start,osg::Timer::instance()->tick())<<std::endl;
|
||||
if (obj.valid())
|
||||
{
|
||||
if (obj.valid()) osgDB::writeObjectFile(*obj, *itr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (list && archive.valid())
|
||||
{
|
||||
std::cout<<"List of files in archive:"<<std::endl;
|
||||
osgDB::Archive::FileNameList fileNames;
|
||||
if (archive->getFileNames(fileNames))
|
||||
{
|
||||
for(osgDB::Archive::FileNameList::const_iterator itr=fileNames.begin();
|
||||
itr!=fileNames.end();
|
||||
++itr)
|
||||
{
|
||||
std::cout<<" "<<*itr<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout<<std::endl;
|
||||
std::cout<<"Master file "<<archive->getMasterFileName()<<std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
GeoSet.cpp\
|
||||
IO_GeoSet.cpp\
|
||||
OrientationConverter.cpp\
|
||||
osgconv.cpp\
|
||||
|
||||
HEADERFILES = \
|
||||
OrientationConverter.h
|
||||
|
||||
LIBS += -losgProducer -lProducer -losgText -losg -losgUtil -losgGA -losgDB $(GL_LIBS) $(OTHER_LIBS)
|
||||
|
||||
INSTFILES = \
|
||||
$(CXXFILES)\
|
||||
$(HEADERFILES)\
|
||||
GNUmakefile.inst=GNUmakefile
|
||||
|
||||
EXEC = osgconv
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
@ -1,21 +0,0 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
GeoSet.cpp\
|
||||
IO_GeoSet.cpp\
|
||||
OrientationConverter.cpp\
|
||||
osgconv.cpp\
|
||||
|
||||
LIBS += -losgProducer -lProducer -losgText -losg -losgUtil -losgDB $(GL_LIBS) $(OTHER_LIBS)
|
||||
|
||||
EXEC = osgconv
|
||||
|
||||
INSTFILES =\
|
||||
$(CXXFILES)\
|
||||
Makefile.inst=Makefile
|
||||
|
||||
INC += $(PRODUCER_INCLUDE_DIR) $(X_INC)
|
||||
LDFLAGS += $(PRODUCER_LIB_DIR)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
File diff suppressed because it is too large
Load Diff
@ -1,414 +0,0 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OSG_GEOSET
|
||||
#define OSG_GEOSET 1
|
||||
|
||||
#include <osg/Drawable>
|
||||
#include <osg/Vec2>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec4>
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
// forward declare so that we don't need to include the header.
|
||||
class Geometry;
|
||||
|
||||
/** Note, osg::GeoSet is now deprecated, please use osg::Geometry instead.
|
||||
osg::GeoSet will be kept through to the beta release for
|
||||
backwards compatability only.
|
||||
|
||||
Encapsulates OpenGL drawing primitives, geometry and
|
||||
optional binding of normal, color and texture coordinates. Used
|
||||
for representing the visible objects in the scene. State attributes
|
||||
for a GeoSet are maintained in StateSet which the GeoSet maintains
|
||||
a referenced counted pointer to. Both GeoSet's and StateSet's can
|
||||
be shared for optimal memory usage and graphics performance.
|
||||
*/
|
||||
class GeoSet : public Drawable
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
|
||||
enum PrimitiveType {
|
||||
NO_TYPE,
|
||||
POINTS,
|
||||
LINES,
|
||||
LINE_STRIP,
|
||||
FLAT_LINE_STRIP,
|
||||
LINE_LOOP,
|
||||
TRIANGLES,
|
||||
TRIANGLE_STRIP,
|
||||
FLAT_TRIANGLE_STRIP,
|
||||
TRIANGLE_FAN,
|
||||
FLAT_TRIANGLE_FAN,
|
||||
QUADS,
|
||||
QUAD_STRIP,
|
||||
POLYGON
|
||||
};
|
||||
|
||||
enum BindingType {
|
||||
BIND_OFF,
|
||||
BIND_OVERALL,
|
||||
BIND_PERPRIM,
|
||||
BIND_PERVERTEX,
|
||||
BIND_DEFAULT
|
||||
};
|
||||
|
||||
enum InterleaveArrayType {
|
||||
IA_OFF,
|
||||
IA_V2F,
|
||||
IA_V3F,
|
||||
IA_C4UB_V2F,
|
||||
IA_C4UB_V3F,
|
||||
IA_C3F_V3F,
|
||||
IA_N3F_V3F,
|
||||
IA_C4F_N3F_V3F,
|
||||
IA_T2F_V3F,
|
||||
IA_T4F_V4F,
|
||||
IA_T2F_C4UB_V3F,
|
||||
IA_T2F_C3F_V3F,
|
||||
IA_T2F_N3F_V3F,
|
||||
IA_T2F_C4F_N3F_V3F,
|
||||
IA_T4F_C4F_N3F_V4F
|
||||
};
|
||||
|
||||
|
||||
struct IndexPointer
|
||||
{
|
||||
|
||||
mutable unsigned int _size;
|
||||
bool _is_ushort;
|
||||
union _TPtr
|
||||
{
|
||||
GLushort* _ushort;
|
||||
GLuint* _uint;
|
||||
} _ptr;
|
||||
|
||||
IndexPointer() { _size=0;_is_ushort=true;_ptr._ushort = (GLushort*)0; }
|
||||
|
||||
inline bool operator == (const IndexPointer& ip) const
|
||||
{
|
||||
return _size == ip._size &&
|
||||
_is_ushort == ip._is_ushort &&
|
||||
_ptr._ushort == ip._ptr._ushort;
|
||||
}
|
||||
|
||||
inline bool valid() const
|
||||
{
|
||||
return _ptr._ushort != (GLushort*)0;
|
||||
}
|
||||
|
||||
inline bool null() const
|
||||
{
|
||||
return _ptr._ushort == (GLushort*)0;
|
||||
}
|
||||
|
||||
inline void setToNull()
|
||||
{
|
||||
_size = 0;
|
||||
_is_ushort = true;
|
||||
_ptr._ushort = (GLushort*)0;
|
||||
}
|
||||
|
||||
inline void set(unsigned int size,GLushort* data)
|
||||
{
|
||||
_size = size;
|
||||
_is_ushort = true;
|
||||
_ptr._ushort = data;
|
||||
}
|
||||
|
||||
|
||||
void set(unsigned int size,GLuint* data)
|
||||
{
|
||||
_size = size;
|
||||
_is_ushort = false;
|
||||
_ptr._uint = data;
|
||||
}
|
||||
|
||||
inline unsigned int maxIndex() const
|
||||
{
|
||||
unsigned int max = 0;
|
||||
if (_is_ushort)
|
||||
{
|
||||
for(unsigned int ai = 0; ai < _size; ai++ )
|
||||
if( _ptr._ushort[ai] > max ) max = _ptr._ushort[ai];
|
||||
}
|
||||
else
|
||||
{
|
||||
for(unsigned int ai = 0; ai < _size; ai++ )
|
||||
if( _ptr._uint[ai] > max ) max = _ptr._uint[ai];
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
inline GLint operator [] (const GLuint pos) const
|
||||
{
|
||||
if (_is_ushort) return _ptr._ushort[pos];
|
||||
else return _ptr._uint[pos];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
GeoSet();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
GeoSet(const GeoSet& geoset,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual Object* cloneType() const { return new GeoSet(); }
|
||||
|
||||
virtual Object* clone(const CopyOp& copyop) const { return new GeoSet(*this,copyop); }
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const GeoSet*>(obj)!=NULL; }
|
||||
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return "GeoSet"; }
|
||||
|
||||
|
||||
// data access methods.
|
||||
inline void setNumPrims( int n ) { _numprims = n; _numcoords=0;}
|
||||
inline int getNumPrims() const { return _numprims; }
|
||||
|
||||
void setPrimType( PrimitiveType type );
|
||||
inline PrimitiveType getPrimType() const { return _primtype; }
|
||||
|
||||
inline void setPrimLengths( int *lens ) { _primLengths = lens; }
|
||||
inline int *getPrimLengths() { return _primLengths; }
|
||||
inline int *getPrimLengths() const { return _primLengths; }
|
||||
|
||||
void computeNumVerts() const;
|
||||
|
||||
/** get the number of coords required by the defined primitives. */
|
||||
inline int getNumCoords() const
|
||||
{ if( _numcoords == 0 ) computeNumVerts(); return _numcoords; }
|
||||
/** get a pointer to Vec3 coord array. */
|
||||
inline Vec3* getCoords() { return _coords; }
|
||||
/** get a const pointer to Vec3 coord array. */
|
||||
inline const Vec3* getCoords() const { return _coords; }
|
||||
/** get the number of indices required by the defined primitives. */
|
||||
inline int getNumCoordIndices() const { return _cindex._size; }
|
||||
/** get the coord index array. */
|
||||
inline IndexPointer& getCoordIndices() { return _cindex; }
|
||||
/** get the const coord index array. */
|
||||
inline const IndexPointer& getCoordIndices() const { return _cindex; }
|
||||
/** set the coords (i.e the geometry) of the geoset.*/
|
||||
void setCoords( Vec3 *cp );
|
||||
/** set the coords (i.e the geometry) and ushort indices of the geoset.
|
||||
To reduce memory footprint and bandwidth for small datasets it is
|
||||
recommended the ushort indices are used instead of unit indices.*/
|
||||
void setCoords( Vec3 *cp, GLushort *ci );
|
||||
/** set the coords (i.e the geometry) and unsigned int indices of the geoset.
|
||||
Unless your data set exceeds 65536 indices prefer ushort indices
|
||||
over unsigned int indices, only use this unit indices version if necessary.*/
|
||||
void setCoords( Vec3 *cp, GLuint *ci );
|
||||
/** set the coords (i.e the geometry) and indices of the geoset.*/
|
||||
void setCoords( Vec3 *cp, IndexPointer& ip );
|
||||
|
||||
/** get the number of normals required by the defined primitives and normals binding.*/
|
||||
inline int getNumNormals() const { return _numnormals; }
|
||||
/** get a pointer to Vec3 normal array. */
|
||||
inline Vec3* getNormals() { return _normals; }
|
||||
/** get a const pointer to Vec3 normal array. */
|
||||
inline const Vec3* getNormals() const { return _normals; }
|
||||
/** get the number of normal indices required by the defined primitives and normals binding.*/
|
||||
inline int getNumNormalIndices() const { return _nindex._size; }
|
||||
/** get the normal index array. */
|
||||
inline IndexPointer& getNormalIndices() { return _nindex; }
|
||||
/** get the const normal index array. */
|
||||
inline const IndexPointer& getNormalIndices() const { return _nindex; }
|
||||
/** set the normals of the geoset.*/
|
||||
void setNormals( Vec3 *np );
|
||||
/** set the normals and normal indices of the geoset.*/
|
||||
void setNormals( Vec3 *np, GLushort *ni );
|
||||
/** set the normals and normal indices of the geoset.*/
|
||||
void setNormals( Vec3 *np, GLuint *ni );
|
||||
/** set the normals and normal indices of the geoset.*/
|
||||
void setNormals( Vec3 *np, IndexPointer& ip );
|
||||
/** set the normals binding to the vertices/primitives/overall.*/
|
||||
void setNormalBinding( BindingType binding );
|
||||
inline BindingType getNormalBinding() const { return _normal_binding; }
|
||||
|
||||
/** get the number of colors required by the defined primitives and color binding.*/
|
||||
inline int getNumColors() const { return _numcolors; }
|
||||
/** get a pointer to Vec4 color array. */
|
||||
inline Vec4* getColors() { return _colors; }
|
||||
/** get a pointer to Vec4 color array. */
|
||||
inline const Vec4* getColors() const { return _colors; }
|
||||
/** get the number of colors indices required by the defined primitives and color binding.*/
|
||||
inline int getNumColorIndices() const { return _colindex._size; }
|
||||
/** get the color index array. */
|
||||
inline IndexPointer& getColorIndices() { return _colindex; }
|
||||
/** get the const color index array. */
|
||||
inline const IndexPointer& getColorIndices() const { return _colindex; }
|
||||
/** set the colors of the geoset.*/
|
||||
void setColors( Vec4 *cp );
|
||||
/** set the colors and color indices of the geoset.*/
|
||||
void setColors( Vec4 *cp, GLushort *li );
|
||||
/** set the colors and color indices of the geoset.*/
|
||||
void setColors( Vec4 *cp, GLuint *li );
|
||||
/** set the colors and color indices of the geoset.*/
|
||||
void setColors( Vec4 *cp, IndexPointer& ip );
|
||||
/** set the color binding to the vertices/primitives/overall.*/
|
||||
void setColorBinding( BindingType binding );
|
||||
inline BindingType getColorBinding() const { return _color_binding; }
|
||||
|
||||
/** get the number of texture coords required by the defined primitives and textures binding.*/
|
||||
inline int getNumTextureCoords() const { return _numtcoords; }
|
||||
/** get a pointer to Vec4 color array. */
|
||||
inline Vec2* getTextureCoords() { return _tcoords; }
|
||||
/** get a pointer to Vec4 color array. */
|
||||
inline const Vec2* getTextureCoords() const { return _tcoords; }
|
||||
/** get the number of texture coord indices required by the defined primitives and texture binding.*/
|
||||
inline int getNumTextureIndices() const { return _tindex._size; }
|
||||
/** get the texture index array. */
|
||||
inline IndexPointer& getTextureIndices() { return _tindex; }
|
||||
/** get the texture index array. */
|
||||
inline const IndexPointer& getTextureIndices() const { return _tindex; }
|
||||
/** set the texture coords of the geoset.*/
|
||||
void setTextureCoords( Vec2 *tc );
|
||||
/** set the texture coords and texture coord indices of the geoset.*/
|
||||
void setTextureCoords( Vec2 *tc, GLushort *ti );
|
||||
/** set the texture coords and texture coord indices of the geoset.*/
|
||||
void setTextureCoords( Vec2 *tc, GLuint *ti );
|
||||
/** set the texture coords and texture indices of the geoset.*/
|
||||
void setTextureCoords( Vec2 *tc, IndexPointer& ip );
|
||||
/** set the texture coord binding to the vertices/primitives/overall.*/
|
||||
void setTextureBinding( BindingType binding );
|
||||
inline BindingType getTextureBinding() const { return _texture_binding; }
|
||||
|
||||
/** get the number of texture coords required by the defined primitives and textures binding.*/
|
||||
inline int getNumInterleavedCoords() const { return _numcoords; }
|
||||
/** get a pointer to interleaved float array. */
|
||||
inline void* getInterleavedArray() { return _iarray; }
|
||||
/** get a const pointer to interleaved float array. */
|
||||
inline const void* getInterleavedArray() const { return _iarray; }
|
||||
/** get the number of texture coord indices required by the defined primitives and texture binding.*/
|
||||
inline int getNumInterleavedIndices() const { return _iaindex._size; }
|
||||
/** get the texture index array. */
|
||||
inline IndexPointer& getInterleavedIndices() { return _iaindex; }
|
||||
/** get the interleaved index array. */
|
||||
inline const IndexPointer& getInterleavedIndices() const { return _iaindex; }
|
||||
/** get the interleaved array storage format. */
|
||||
inline InterleaveArrayType getInterleavedFormat() const { return _iaformat; }
|
||||
|
||||
/** set the interleaved arrays of the geoset.*/
|
||||
void setInterleavedArray( InterleaveArrayType format, float *ia );
|
||||
void setInterleavedArray( InterleaveArrayType format, float *ia, GLushort *iai );
|
||||
void setInterleavedArray( InterleaveArrayType format, float *ia, GLuint *iai );
|
||||
void setInterleavedArray( InterleaveArrayType format, float *ia, IndexPointer& iai );
|
||||
|
||||
/** draw geoset directly ignoring an OpenGL display list which could be attached.
|
||||
* This is the internal draw method which does the drawing itself,
|
||||
* and is the method to override when deriving from GeoSet for user-drawn objects.
|
||||
*/
|
||||
virtual void drawImplementation(State&) const {}
|
||||
|
||||
bool check() const;
|
||||
|
||||
|
||||
/** function object which is used to handling the clean up of attribute arrays
|
||||
* associated with GeoSet's. A default is provided which assumes that all
|
||||
* momory attached to the GeoSet is owned by this GeoSet and can be deleted
|
||||
* using delete []. If this is not the cause derive your own AttributeDeleteFunctor
|
||||
* a specify your own memory deletion operation.*/
|
||||
struct AttributeDeleteFunctor : public osg::Referenced
|
||||
{
|
||||
// see GeoSet.cpp for implemention.
|
||||
virtual void operator() (GeoSet* gset);
|
||||
};
|
||||
|
||||
/** set an alternative AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/
|
||||
void setAttributeDeleteFunctor(AttributeDeleteFunctor* adf) { _adf = adf; }
|
||||
|
||||
/** get the current AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/
|
||||
AttributeDeleteFunctor* getAttributeDeleteFunctor() { return _adf.get(); }
|
||||
|
||||
/** get the current AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/
|
||||
const AttributeDeleteFunctor* getAttributeDeleteFunctor() const { return _adf.get(); }
|
||||
|
||||
/** return true, osg::GeoSet does support accept(AttributeFunctor&).*/
|
||||
virtual bool supports(AttributeFunctor&) const { return true; }
|
||||
|
||||
/** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
|
||||
virtual void accept(AttributeFunctor& af);
|
||||
|
||||
/** return true, osg::GeoSet does support accept(ConstAttributeFunctor&).*/
|
||||
virtual bool supports(ConstAttributeFunctor&) const { return true; }
|
||||
|
||||
/** accept an ConstAttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
|
||||
virtual void accept(ConstAttributeFunctor& af) const;
|
||||
|
||||
/** return true, osg::GeoSet does support accept(PrimitiveFunctor&) .*/
|
||||
virtual bool supports(PrimitiveFunctor&) const { return true; }
|
||||
|
||||
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
|
||||
virtual void accept(PrimitiveFunctor& pf) const;
|
||||
|
||||
/** convinience function for converting GeoSet's to equivilant Geometry nodes.*/
|
||||
Geometry* convertToGeometry();
|
||||
|
||||
protected:
|
||||
|
||||
GeoSet& operator = (const GeoSet&) { return *this;}
|
||||
|
||||
virtual ~GeoSet();
|
||||
|
||||
virtual bool computeBound() const;
|
||||
|
||||
ref_ptr<AttributeDeleteFunctor> _adf;
|
||||
|
||||
int _numprims;
|
||||
PrimitiveType _primtype;
|
||||
int _needprimlen;
|
||||
unsigned int _oglprimtype;
|
||||
int *_primLengths;
|
||||
mutable unsigned char _primlength;
|
||||
unsigned char _flat_shaded_skip;
|
||||
|
||||
mutable int _numcoords;
|
||||
Vec3 *_coords;
|
||||
mutable IndexPointer _cindex;
|
||||
|
||||
BindingType _normal_binding;
|
||||
mutable int _numnormals;
|
||||
Vec3 *_normals;
|
||||
IndexPointer _nindex;
|
||||
|
||||
BindingType _color_binding;
|
||||
mutable int _numcolors;
|
||||
Vec4 *_colors;
|
||||
IndexPointer _colindex;
|
||||
|
||||
BindingType _texture_binding;
|
||||
mutable int _numtcoords;
|
||||
Vec2 *_tcoords;
|
||||
IndexPointer _tindex;
|
||||
|
||||
void *_iarray;
|
||||
IndexPointer _iaindex;
|
||||
InterleaveArrayType _iaformat;
|
||||
unsigned int _ogliaformat;
|
||||
|
||||
|
||||
int _fast_path;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,69 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osgUtil/Optimizer>
|
||||
|
||||
#include "OrientationConverter.h"
|
||||
|
||||
using namespace osg;
|
||||
|
||||
OrientationConverter::OrientationConverter( void )
|
||||
{
|
||||
R.makeIdentity();
|
||||
T.makeIdentity();
|
||||
_trans_set = false;
|
||||
S.makeIdentity();
|
||||
}
|
||||
|
||||
void OrientationConverter::setRotation( const Vec3 &from, const Vec3 &to )
|
||||
{
|
||||
R = Matrix::rotate( from, to );
|
||||
}
|
||||
|
||||
void OrientationConverter::setRotation( float degrees, const Vec3 &axis )
|
||||
{
|
||||
R = Matrix::rotate( osg::DegreesToRadians(degrees), axis );
|
||||
}
|
||||
|
||||
void OrientationConverter::setTranslation( const Vec3 &trans )
|
||||
{
|
||||
T = Matrix::translate(trans);
|
||||
_trans_set = true;
|
||||
}
|
||||
|
||||
void OrientationConverter::setScale( const Vec3 &scale )
|
||||
{
|
||||
S = Matrix::scale(scale);
|
||||
}
|
||||
|
||||
|
||||
Node* OrientationConverter::convert( Node *node )
|
||||
{
|
||||
// Order of operations here is :
|
||||
// 1. Translate to world origin (0,0,0)
|
||||
// 2. Rotate to new orientation
|
||||
// 3. Scale in new orientation coordinates
|
||||
// 4. If an absolute translation was specified then
|
||||
// - translate to absolute translation in world coordinates
|
||||
// else
|
||||
// - translate back to model's original origin.
|
||||
BoundingSphere bs = node->getBound();
|
||||
Matrix C = Matrix::translate( -bs.center() );
|
||||
if( _trans_set == false )
|
||||
T = Matrix::translate( bs.center() );
|
||||
|
||||
osg::Group* root = new osg::Group;
|
||||
osg::MatrixTransform* transform = new osg::MatrixTransform;
|
||||
|
||||
transform->setDataVariance(osg::Object::STATIC);
|
||||
transform->setMatrix( C * R * S * T );
|
||||
|
||||
root->addChild(transform);
|
||||
transform->addChild(node);
|
||||
|
||||
osgUtil::Optimizer::FlattenStaticTransformsVisitor fstv;
|
||||
root->accept(fstv);
|
||||
fstv.removeTransforms(root);
|
||||
|
||||
return root->getChild(0);
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
#ifndef _ORIENTATION_CONVERTER_H
|
||||
#define _ORIENTATION_CONVERTER_H
|
||||
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/Node>
|
||||
#include <osg/Geode>
|
||||
|
||||
class OrientationConverter {
|
||||
public :
|
||||
OrientationConverter(void);
|
||||
void setRotation( const osg::Vec3 &from,
|
||||
const osg::Vec3 &to );
|
||||
void setRotation( float degrees, const osg::Vec3 &axis );
|
||||
void setTranslation( const osg::Vec3 &trans);
|
||||
void setScale( const osg::Vec3 &trans);
|
||||
|
||||
/** return the root of the updated subgraph as the subgraph
|
||||
* the node passed in my flatten during optimization.*/
|
||||
osg::Node* convert( osg::Node* node );
|
||||
|
||||
private :
|
||||
OrientationConverter( const OrientationConverter& ) {}
|
||||
OrientationConverter& operator = (const OrientationConverter& ) { return *this; }
|
||||
|
||||
osg::Matrix R, T, S;
|
||||
bool _trans_set;
|
||||
|
||||
};
|
||||
#endif
|
@ -1,636 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <osg/ArgumentParser>
|
||||
#include <osg/ApplicationUsage>
|
||||
#include <osg/Group>
|
||||
#include <osg/Notify>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/Texture3D>
|
||||
#include <osg/BlendFunc>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/ReaderWriter>
|
||||
|
||||
#include <osgUtil/Optimizer>
|
||||
#include <osgUtil/SmoothingVisitor>
|
||||
|
||||
#include <osgProducer/Viewer>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "OrientationConverter.h"
|
||||
#include "GeoSet.h"
|
||||
|
||||
typedef std::vector<std::string> FileNameList;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Convert GeoSet To Geometry Visitor.
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** ConvertGeoSetsToGeometryVisitor all the old GeoSet Drawables to the new Geometry Drawables.*/
|
||||
class ConvertGeoSetsToGeometryVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
ConvertGeoSetsToGeometryVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
|
||||
|
||||
virtual void apply(osg::Geode& geode)
|
||||
{
|
||||
for(unsigned int i=0;i<geode.getNumDrawables();++i)
|
||||
{
|
||||
osg::GeoSet* geoset = dynamic_cast<osg::GeoSet*>(geode.getDrawable(i));
|
||||
if (geoset)
|
||||
{
|
||||
osg::Geometry* geom = geoset->convertToGeometry();
|
||||
if (geom)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Successfully converted GeoSet to Geometry"<<std::endl;
|
||||
geode.replaceDrawable(geoset,geom);
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"*** Failed to convert GeoSet to Geometry"<<std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void apply(osg::Node& node) { traverse(node); }
|
||||
|
||||
};
|
||||
|
||||
class GraphicsContext {
|
||||
public:
|
||||
GraphicsContext()
|
||||
{
|
||||
rs = new Producer::RenderSurface;
|
||||
rs->setWindowRectangle(0,0,1,1);
|
||||
rs->useBorder(false);
|
||||
rs->useConfigEventThread(false);
|
||||
rs->realize();
|
||||
std::cout<<"Realized window"<<std::endl;
|
||||
}
|
||||
|
||||
virtual ~GraphicsContext()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
Producer::ref_ptr<Producer::RenderSurface> rs;
|
||||
};
|
||||
|
||||
class CompressTexturesVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
CompressTexturesVisitor(osg::Texture::InternalFormatMode internalFormatMode):
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_internalFormatMode(internalFormatMode) {}
|
||||
|
||||
virtual void apply(osg::Node& node)
|
||||
{
|
||||
if (node.getStateSet()) apply(*node.getStateSet());
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
virtual void apply(osg::Geode& node)
|
||||
{
|
||||
if (node.getStateSet()) apply(*node.getStateSet());
|
||||
|
||||
for(unsigned int i=0;i<node.getNumDrawables();++i)
|
||||
{
|
||||
osg::Drawable* drawable = node.getDrawable(i);
|
||||
if (drawable && drawable->getStateSet()) apply(*drawable->getStateSet());
|
||||
}
|
||||
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
virtual void apply(osg::StateSet& stateset)
|
||||
{
|
||||
// search for the existance of any texture object attributes
|
||||
for(unsigned int i=0;i<stateset.getTextureAttributeList().size();++i)
|
||||
{
|
||||
osg::Texture* texture = dynamic_cast<osg::Texture*>(stateset.getTextureAttribute(i,osg::StateAttribute::TEXTURE));
|
||||
if (texture)
|
||||
{
|
||||
_textureSet.insert(texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void compress()
|
||||
{
|
||||
GraphicsContext context;
|
||||
|
||||
osg::ref_ptr<osg::State> state = new osg::State;
|
||||
|
||||
for(TextureSet::iterator itr=_textureSet.begin();
|
||||
itr!=_textureSet.end();
|
||||
++itr)
|
||||
{
|
||||
osg::Texture* texture = const_cast<osg::Texture*>(itr->get());
|
||||
|
||||
osg::Texture2D* texture2D = dynamic_cast<osg::Texture2D*>(texture);
|
||||
osg::Texture3D* texture3D = dynamic_cast<osg::Texture3D*>(texture);
|
||||
|
||||
osg::Image* image = texture2D ? texture2D->getImage() : texture3D ? texture3D->getImage() : 0;
|
||||
if (image &&
|
||||
(image->getPixelFormat()==GL_RGB || image->getPixelFormat()==GL_RGBA) &&
|
||||
(image->s()>=32 && image->t()>=32))
|
||||
{
|
||||
texture->setInternalFormatMode(_internalFormatMode);
|
||||
|
||||
// get OpenGL driver to create texture from image.
|
||||
texture->apply(*state);
|
||||
|
||||
image->readImageFromCurrentTexture(0,true);
|
||||
|
||||
texture->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef std::set< osg::ref_ptr<osg::Texture> > TextureSet;
|
||||
TextureSet _textureSet;
|
||||
osg::Texture::InternalFormatMode _internalFormatMode;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class FixTransparencyVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
enum FixTransparencyMode
|
||||
{
|
||||
NO_TRANSPARANCY_FIXING,
|
||||
MAKE_OPAQUE_TEXTURE_STATESET_OPAQUE,
|
||||
MAKE_ALL_STATESET_OPAQUE,
|
||||
};
|
||||
|
||||
FixTransparencyVisitor(FixTransparencyMode mode=MAKE_OPAQUE_TEXTURE_STATESET_OPAQUE):
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_numTransparent(0),
|
||||
_numOpaque(0),
|
||||
_numTransparentMadeOpaque(0),
|
||||
_mode(mode)
|
||||
{
|
||||
std::cout<<"Running FixTransparencyVisitor..."<<std::endl;
|
||||
}
|
||||
|
||||
~FixTransparencyVisitor()
|
||||
{
|
||||
std::cout<<" Number of Transparent StateSet "<<_numTransparent<<std::endl;
|
||||
std::cout<<" Number of Opaque StateSet "<<_numOpaque<<std::endl;
|
||||
std::cout<<" Number of Transparent State made Opaque "<<_numTransparentMadeOpaque<<std::endl;
|
||||
}
|
||||
|
||||
virtual void apply(osg::Node& node)
|
||||
{
|
||||
if (node.getStateSet()) isTransparent(*node.getStateSet());
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
virtual void apply(osg::Geode& node)
|
||||
{
|
||||
if (node.getStateSet()) isTransparent(*node.getStateSet());
|
||||
|
||||
for(unsigned int i=0;i<node.getNumDrawables();++i)
|
||||
{
|
||||
osg::Drawable* drawable = node.getDrawable(i);
|
||||
if (drawable && drawable->getStateSet()) isTransparent(*drawable->getStateSet());
|
||||
}
|
||||
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
virtual bool isTransparent(osg::StateSet& stateset)
|
||||
{
|
||||
bool hasTranslucentTexture = false;
|
||||
bool hasBlendFunc = dynamic_cast<osg::BlendFunc*>(stateset.getAttribute(osg::StateAttribute::BLENDFUNC))!=0;
|
||||
bool hasTransparentRenderingHint = stateset.getRenderingHint()==osg::StateSet::TRANSPARENT_BIN;
|
||||
bool hasDepthSortBin = (stateset.getRenderBinMode()==osg::StateSet::USE_RENDERBIN_DETAILS)?(stateset.getBinName()=="DepthSortedBin"):false;
|
||||
bool hasTexture = false;
|
||||
|
||||
|
||||
// search for the existance of any texture object attributes
|
||||
for(unsigned int i=0;i<stateset.getTextureAttributeList().size();++i)
|
||||
{
|
||||
osg::Texture* texture = dynamic_cast<osg::Texture*>(stateset.getTextureAttribute(i,osg::StateAttribute::TEXTURE));
|
||||
if (texture)
|
||||
{
|
||||
hasTexture = true;
|
||||
for (unsigned int im=0;im<texture->getNumImages();++im)
|
||||
{
|
||||
osg::Image* image = texture->getImage(im);
|
||||
if (image && image->isImageTranslucent()) hasTranslucentTexture = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasTranslucentTexture || hasBlendFunc || hasTransparentRenderingHint || hasDepthSortBin)
|
||||
{
|
||||
++_numTransparent;
|
||||
|
||||
bool makeNonTransparent = false;
|
||||
|
||||
switch(_mode)
|
||||
{
|
||||
case(MAKE_OPAQUE_TEXTURE_STATESET_OPAQUE):
|
||||
if (hasTexture && !hasTranslucentTexture)
|
||||
{
|
||||
makeNonTransparent = true;
|
||||
}
|
||||
break;
|
||||
case(MAKE_ALL_STATESET_OPAQUE):
|
||||
makeNonTransparent = true;
|
||||
break;
|
||||
default:
|
||||
makeNonTransparent = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (makeNonTransparent)
|
||||
{
|
||||
stateset.removeAttribute(osg::StateAttribute::BLENDFUNC);
|
||||
stateset.removeMode(GL_BLEND);
|
||||
stateset.setRenderingHint(osg::StateSet::DEFAULT_BIN);
|
||||
++_numTransparentMadeOpaque;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
++_numOpaque;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int _numTransparent;
|
||||
unsigned int _numOpaque;
|
||||
unsigned int _numTransparentMadeOpaque;
|
||||
FixTransparencyMode _mode;
|
||||
};
|
||||
|
||||
class PruneStateSetVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
PruneStateSetVisitor():
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_numStateSetRemoved(0)
|
||||
{
|
||||
std::cout<<"Running PruneStateSet..."<<std::endl;
|
||||
}
|
||||
|
||||
~PruneStateSetVisitor()
|
||||
{
|
||||
std::cout<<" Number of StateState removed "<<_numStateSetRemoved<<std::endl;
|
||||
}
|
||||
|
||||
virtual void apply(osg::Node& node)
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
node.setStateSet(0);
|
||||
++_numStateSetRemoved;
|
||||
}
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
virtual void apply(osg::Geode& node)
|
||||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
node.setStateSet(0);
|
||||
++_numStateSetRemoved;
|
||||
}
|
||||
|
||||
for(unsigned int i=0;i<node.getNumDrawables();++i)
|
||||
{
|
||||
osg::Drawable* drawable = node.getDrawable(i);
|
||||
if (drawable && drawable->getStateSet())
|
||||
{
|
||||
drawable->setStateSet(0);
|
||||
++_numStateSetRemoved;
|
||||
}
|
||||
}
|
||||
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
unsigned int _numStateSetRemoved;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void usage( const char *prog, const char *msg )
|
||||
{
|
||||
if (msg)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<< std::endl;
|
||||
osg::notify(osg::NOTICE) << msg << std::endl;
|
||||
}
|
||||
osg::notify(osg::NOTICE)<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<"usage:"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" " << prog << " [options] infile1 [infile2 ...] outfile"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<"options:"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" -O option - ReaderWriter option"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" --compressed - Enable the usage of compressed textures,"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" defaults to OpenGL ARB compressed textures."<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" --compressed-arb - Enable the usage of OpenGL ARB compressed textures"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" --compressed-dxt1 - Enable the usage of S3TC DXT1 compressed textures"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" --compressed-dxt3 - Enable the usage of S3TC DXT3 compressed textures"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" --compressed-dxt5 - Enable the usage of S3TC DXT5 compressed textures"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" --fix-transparency - fix stateset which are curerntly declared as transprent,"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" but should be opaque. Defaults to using the "<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" fixTranspancyMode MAKE_OPAQUE_TEXTURE_STATESET_OPAQUE."<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" --fix-transparency-mode <mode_string> - fix stateset which are curerntly declared as"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" transprent but should be opaque. The mode_string determines"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" algorithm is used to fix the transparency, options are: "<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" MAKE_OPAQUE_TEXTURE_STATESET_OPAQUE,"<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<" MAKE_ALL_STATESET_OPAQUE."<<std::endl;
|
||||
|
||||
osg::notify(osg::NOTICE)<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" -l libraryName - load plugin of name libraryName"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" i.e. -l osgdb_pfb"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" Useful for loading reader/writers which can load"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" other file formats in addition to its extension."<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" -e extensionName - load reader/wrter plugin for file extension"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" i.e. -e pfb"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" Useful short hand for specifying full library name as"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" done with -l above, as it automatically expands to the"<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" full library name appropriate for each platform."<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" -o orientation - Convert geometry from input files to output files."<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<
|
||||
" Format of orientation argument must be the following:\n"
|
||||
"\n"
|
||||
" X1,Y1,Z1-X2,Y2,Z2\n"
|
||||
" or\n"
|
||||
" degrees-A0,A1,A2\n"
|
||||
"\n"
|
||||
" where X1,Y1,Z1 represent the UP vector in the input\n"
|
||||
" files and X2,Y2,Z2 represent the UP vector of the\n"
|
||||
" output file, or degrees is the rotation angle in degrees\n"
|
||||
" around axis (A0,A1,A2). For example, to convert a model\n"
|
||||
" built in a Y-Up coordinate system to a model with a Z-up\n"
|
||||
" coordinate system, the argument may look like\n"
|
||||
"\n"
|
||||
" 0,1,0-0,0,1"
|
||||
"\n"
|
||||
" or\n"
|
||||
" -90-1,0,0\n"
|
||||
"\n" << std::endl;
|
||||
osg::notify(osg::NOTICE)<<" -t translation - Convert spatial position of output files. Format of\n"
|
||||
" translation argument must be the following :\n"
|
||||
"\n"
|
||||
" X,Y,Z\n"
|
||||
"\n"
|
||||
" where X, Y, and Z represent the coordinates of the\n"
|
||||
" absolute position in world space\n"
|
||||
<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" -s scale - Scale size of model. Scale argument must be the \n"
|
||||
" following :\n"
|
||||
"\n"
|
||||
" SX,SY,SZ\n"
|
||||
"\n"
|
||||
" where SX, SY, and SZ represent the scale factors\n"
|
||||
" Caution: Scaling will be done in destination orientation\n"
|
||||
<< std::endl;
|
||||
osg::notify(osg::NOTICE)<< std::endl;
|
||||
osg::notify(osg::NOTICE)<<" --smooth - Smooth the surface by regenerating surface normals on\n"
|
||||
" all geometry"<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.");
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
||||
|
||||
|
||||
// if user request help write it out to cout.
|
||||
if (arguments.read("-h") || arguments.read("--help"))
|
||||
{
|
||||
usage( arguments.getApplicationName().c_str(), 0 );
|
||||
//arguments.getApplicationUsage()->write(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (arguments.argc()<=1)
|
||||
{
|
||||
arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
|
||||
return 1;
|
||||
}
|
||||
|
||||
FileNameList fileNames;
|
||||
OrientationConverter oc;
|
||||
bool do_convert = false;
|
||||
|
||||
std::string str;
|
||||
while (arguments.read("-O",str))
|
||||
{
|
||||
osgDB::ReaderWriter::Options* options = new osgDB::ReaderWriter::Options;
|
||||
options->setOptionString(str);
|
||||
osgDB::Registry::instance()->setOptions(options);
|
||||
}
|
||||
|
||||
std::string ext;
|
||||
while (arguments.read("-e",ext))
|
||||
{
|
||||
std::string libName = osgDB::Registry::instance()->createLibraryNameForExtension(ext);
|
||||
osgDB::Registry::instance()->loadLibrary(libName);
|
||||
}
|
||||
|
||||
std::string libName;
|
||||
while (arguments.read("-l",libName))
|
||||
{
|
||||
osgDB::Registry::instance()->loadLibrary(libName);
|
||||
}
|
||||
|
||||
while (arguments.read("-o",str))
|
||||
{
|
||||
osg::Vec3 from, to;
|
||||
if( sscanf( str.c_str(), "%f,%f,%f-%f,%f,%f",
|
||||
&from[0], &from[1], &from[2],
|
||||
&to[0], &to[1], &to[2] )
|
||||
!= 6 )
|
||||
{
|
||||
float degrees;
|
||||
osg::Vec3 axis;
|
||||
// Try deg-axis format
|
||||
if( sscanf( str.c_str(), "%f-%f,%f,%f",
|
||||
°rees, &axis[0], &axis[1], &axis[2] ) != 4 )
|
||||
{
|
||||
usage( argv[0], "Orientation argument format incorrect." );
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
oc.setRotation( degrees, axis );
|
||||
do_convert = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
oc.setRotation( from, to );
|
||||
do_convert = true;
|
||||
}
|
||||
}
|
||||
|
||||
while (arguments.read("-s",str))
|
||||
{
|
||||
osg::Vec3 scale(0,0,0);
|
||||
if( sscanf( str.c_str(), "%f,%f,%f",
|
||||
&scale[0], &scale[1], &scale[2] ) != 3 )
|
||||
{
|
||||
usage( argv[0], "Scale argument format incorrect." );
|
||||
return 1;
|
||||
}
|
||||
oc.setScale( scale );
|
||||
do_convert = true;
|
||||
}
|
||||
|
||||
while (arguments.read("-t",str))
|
||||
{
|
||||
osg::Vec3 trans(0,0,0);
|
||||
if( sscanf( str.c_str(), "%f,%f,%f",
|
||||
&trans[0], &trans[1], &trans[2] ) != 3 )
|
||||
{
|
||||
usage( argv[0], "Translation argument format incorrect." );
|
||||
return 1;
|
||||
}
|
||||
oc.setTranslation( trans );
|
||||
do_convert = true;
|
||||
}
|
||||
|
||||
|
||||
FixTransparencyVisitor::FixTransparencyMode fixTransparencyMode = FixTransparencyVisitor::NO_TRANSPARANCY_FIXING;
|
||||
std::string fixString;
|
||||
while(arguments.read("--fix-transparency")) fixTransparencyMode = FixTransparencyVisitor::MAKE_OPAQUE_TEXTURE_STATESET_OPAQUE;
|
||||
while(arguments.read("--fix-transparency-mode",fixString))
|
||||
{
|
||||
if (fixString=="MAKE_OPAQUE_TEXTURE_STATESET_OPAQUE") fixTransparencyMode = FixTransparencyVisitor::MAKE_OPAQUE_TEXTURE_STATESET_OPAQUE;
|
||||
if (fixString=="MAKE_ALL_STATESET_OPAQUE") fixTransparencyMode = FixTransparencyVisitor::MAKE_ALL_STATESET_OPAQUE;
|
||||
};
|
||||
|
||||
bool pruneStateSet = false;
|
||||
while(arguments.read("--prune-StateSet")) pruneStateSet = true;
|
||||
|
||||
osg::Texture::InternalFormatMode internalFormatMode = osg::Texture::USE_IMAGE_DATA_FORMAT;
|
||||
while(arguments.read("--compressed") || arguments.read("--compressed-arb")) { internalFormatMode = osg::Texture::USE_ARB_COMPRESSION; }
|
||||
|
||||
while(arguments.read("--compressed-dxt1")) { internalFormatMode = osg::Texture::USE_S3TC_DXT1_COMPRESSION; }
|
||||
while(arguments.read("--compressed-dxt3")) { internalFormatMode = osg::Texture::USE_S3TC_DXT3_COMPRESSION; }
|
||||
while(arguments.read("--compressed-dxt5")) { internalFormatMode = osg::Texture::USE_S3TC_DXT5_COMPRESSION; }
|
||||
|
||||
bool smooth = false;
|
||||
while(arguments.read("--smooth")) { smooth = true; }
|
||||
|
||||
|
||||
// any option left unread are converted into errors to write out later.
|
||||
arguments.reportRemainingOptionsAsUnrecognized();
|
||||
|
||||
// report any errors if they have occured when parsing the program aguments.
|
||||
if (arguments.errors())
|
||||
{
|
||||
arguments.writeErrorMessages(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(int pos=1;pos<arguments.argc();++pos)
|
||||
{
|
||||
if (!arguments.isOption(pos))
|
||||
{
|
||||
fileNames.push_back(arguments[pos]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string fileNameOut("converted.osg");
|
||||
if (fileNames.size()>1)
|
||||
{
|
||||
fileNameOut = fileNames.back();
|
||||
fileNames.pop_back();
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Node> root = osgDB::readNodeFiles(fileNames);
|
||||
|
||||
if (pruneStateSet)
|
||||
{
|
||||
PruneStateSetVisitor pssv;
|
||||
root->accept(pssv);
|
||||
}
|
||||
|
||||
if (fixTransparencyMode != FixTransparencyVisitor::NO_TRANSPARANCY_FIXING)
|
||||
{
|
||||
FixTransparencyVisitor atv(fixTransparencyMode);
|
||||
root->accept(atv);
|
||||
}
|
||||
|
||||
if ( root.valid() )
|
||||
{
|
||||
// convert the old style GeoSet to Geometry
|
||||
ConvertGeoSetsToGeometryVisitor cgtg;
|
||||
root->accept(cgtg);
|
||||
|
||||
if (smooth)
|
||||
{
|
||||
osgUtil::SmoothingVisitor sv;
|
||||
root->accept(sv);
|
||||
}
|
||||
|
||||
// optimize the scene graph, remove rendundent nodes and state etc.
|
||||
osgUtil::Optimizer optimizer;
|
||||
optimizer.optimize(root.get());
|
||||
|
||||
if( do_convert )
|
||||
root = oc.convert( root.get() );
|
||||
|
||||
if (internalFormatMode != osg::Texture::USE_IMAGE_DATA_FORMAT)
|
||||
{
|
||||
std::string ext = osgDB::getFileExtension(fileNameOut);
|
||||
if (ext=="ive")
|
||||
{
|
||||
CompressTexturesVisitor ctv(internalFormatMode);
|
||||
root->accept(ctv);
|
||||
ctv.compress();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"Warning: compressing texture only supported when outputing to .ive"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (osgDB::writeNodeFile(*root,fileNameOut))
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Data written to '"<<fileNameOut<<"'."<< std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Error no data loaded."<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgdem.cpp\
|
||||
|
||||
LIBS += -losgProducer -lProducer -losgTerrain -losgFX -losgGL2 -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
INSTFILES = \
|
||||
$(CXXFILES)\
|
||||
GNUmakefile.inst=GNUmakefile
|
||||
|
||||
EXEC = osgdem
|
||||
|
||||
INC += $(X_INC)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
|
@ -1,14 +0,0 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgdem.cpp\
|
||||
|
||||
|
||||
LIBS += -losgProducer -lProducer -losgTerrain -losgFX -losgGL2 -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
EXEC = osgdem
|
||||
|
||||
INC += $(X_INC)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
@ -1,615 +0,0 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* freely and without restriction, both in commericial and non commericial applications,
|
||||
* as long as this copyright notice is maintained.
|
||||
*
|
||||
* This application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Disable unavoidable warning messages:
|
||||
|
||||
// 4114: same type qualifier used more than once
|
||||
// 4201: nonstandard extension used : nameless struct/union
|
||||
// 4237: "keyword" reserved for future use
|
||||
// 4251: class needs to have dll-interface to export class
|
||||
// 4275: non DLL-interface class used as base for DLL-interface class
|
||||
// 4290: C++ Exception Specification ignored
|
||||
// 4503: ecorated name length exceeded, name was truncated
|
||||
// 4786: string too long - truncated to 255 characters
|
||||
|
||||
//#pragma warning(disable : 4103 4114 4201 4237 4251 4275 4290 4335 4786)
|
||||
#pragma warning(disable : 4503)
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/State>
|
||||
#include <osg/ShapeDrawable>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
#include <osgDB/ImageOptions>
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/FileUtils>
|
||||
|
||||
#include <osgUtil/Optimizer>
|
||||
#include <osgUtil/TriStripVisitor>
|
||||
#include <osgUtil/SmoothingVisitor>
|
||||
#include <osgUtil/TangentSpaceGenerator>
|
||||
|
||||
#include <osgFX/BumpMapping>
|
||||
|
||||
#include <osgProducer/Viewer>
|
||||
#include <osg/Switch>
|
||||
|
||||
#include <osgTerrain/DataSet>
|
||||
|
||||
class GraphicsContext {
|
||||
public:
|
||||
GraphicsContext()
|
||||
{
|
||||
rs = new Producer::RenderSurface;
|
||||
rs->setWindowRectangle(0,0,1,1);
|
||||
rs->useBorder(false);
|
||||
rs->useConfigEventThread(false);
|
||||
rs->realize();
|
||||
std::cout<<"Realized window"<<std::endl;
|
||||
}
|
||||
|
||||
virtual ~GraphicsContext()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
Producer::ref_ptr<Producer::RenderSurface> rs;
|
||||
};
|
||||
|
||||
osg::Matrixd computeGeoTransForRange(double xMin, double xMax, double yMin, double yMax)
|
||||
{
|
||||
osg::Matrixd matrix;
|
||||
matrix(0,0) = xMax-xMin;
|
||||
matrix(3,0) = xMin;
|
||||
|
||||
matrix(1,1) = yMax-yMin;
|
||||
matrix(3,1) = yMin;
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
|
||||
void ellipsodeTransformTest(double latitude, double longitude, double height)
|
||||
{
|
||||
osg::ref_ptr<osg::EllipsoidModel> transform = new osg::EllipsoidModel;
|
||||
|
||||
double X,Y,Z;
|
||||
double newLat, newLong, newHeight;
|
||||
|
||||
transform->convertLatLongHeightToXYZ(latitude,longitude,height,
|
||||
X,Y,Z);
|
||||
|
||||
transform->convertXYZToLatLongHeight(X,Y,Z,
|
||||
newLat,newLong,newHeight);
|
||||
|
||||
std::cout<<"lat = "<<osg::RadiansToDegrees(latitude)<<"\tlong="<<osg::RadiansToDegrees(longitude)<<"\t"<<height<<std::endl;
|
||||
std::cout<<"X = "<<X<<"\tY="<<Y<<"\tZ="<<Z<<std::endl;
|
||||
std::cout<<"lat = "<<osg::RadiansToDegrees(newLat)<<"\tlong="<<osg::RadiansToDegrees(newLong)<<"\t"<<newHeight<<std::endl;
|
||||
}
|
||||
|
||||
void processFile(std::string filename,
|
||||
osgTerrain::DataSet::Source::Type type,
|
||||
std::string currentCS,
|
||||
osg::Matrixd &geoTransform,
|
||||
bool geoTransformSet,
|
||||
bool geoTransformScale,
|
||||
bool minmaxLevelSet, unsigned int min_level, unsigned int max_level,
|
||||
unsigned int layerNum,
|
||||
osg::ref_ptr<osgTerrain::DataSet> dataset) {
|
||||
|
||||
if(filename.empty()) return;
|
||||
|
||||
if(osgDB::fileType(filename) == osgDB::REGULAR_FILE) {
|
||||
|
||||
osgTerrain::DataSet::Source* source = new osgTerrain::DataSet::Source(type, filename);
|
||||
if (source)
|
||||
{
|
||||
if (!currentCS.empty())
|
||||
{
|
||||
std::cout<<"source->setCoordySystem "<<currentCS<<std::endl;
|
||||
source->setCoordinateSystemPolicy(osgTerrain::DataSet::Source::PREFER_CONFIG_SETTINGS);
|
||||
source->setCoordinateSystem(currentCS);
|
||||
}
|
||||
|
||||
if (geoTransformSet)
|
||||
{
|
||||
std::cout<<"source->setGeoTransform "<<geoTransform<<std::endl;
|
||||
source->setGeoTransformPolicy(geoTransformScale ?
|
||||
osgTerrain::DataSet::Source::PREFER_CONFIG_SETTINGS_BUT_SCALE_BY_FILE_RESOLUTION :
|
||||
osgTerrain::DataSet::Source::PREFER_CONFIG_SETTINGS);
|
||||
source->setGeoTransform(geoTransform);
|
||||
}
|
||||
if (minmaxLevelSet)
|
||||
{
|
||||
source->setMinMaxLevel(min_level, max_level);
|
||||
}
|
||||
|
||||
source->setLayer(layerNum);
|
||||
|
||||
std::cout<<"Reading as layer = "<<layerNum<<std::endl;
|
||||
|
||||
dataset->addSource(source);
|
||||
}
|
||||
} else if (osgDB::fileType(filename) == osgDB::DIRECTORY) {
|
||||
|
||||
osgDB::DirectoryContents dirContents= osgDB::getDirectoryContents(filename);
|
||||
|
||||
// loop through directory contents and call processFile
|
||||
std::vector<std::string>::iterator i;
|
||||
std::string fullfilename;
|
||||
for(i = dirContents.begin(); i != dirContents.end(); ++i) {
|
||||
if((*i != ".") && (*i != "..")) {
|
||||
fullfilename = filename + '/' + *i;
|
||||
processFile(fullfilename, type, currentCS,
|
||||
geoTransform, geoTransformSet, geoTransformScale,
|
||||
minmaxLevelSet, min_level, max_level,
|
||||
layerNum,
|
||||
dataset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.");
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-d <filename>","Specify the digital elevation map input file to process");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-t <filename>","Specify the texture map input file to process");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-m <filename>","Specify the 3D database model input file to process");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-a <archivename>","Specify the archive to place the generated database");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-o <outputfile>","Specify the output master file to generate");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-l <numOfLevels>","Specify the number of PagedLOD levels to generate");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--levels <begin_level> <end_level>","Specify the range of lavels that the next source Texture or DEM will contribute to.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--layer <layer_num>","Specify the layer that the next source Texture will contribute to..");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-e <x> <y> <w> <h>","Extents of the model to generate");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--cs <coordinates system string>","Set the coordinates system of source imagery, DEM or destination database. The string may be any of the usual GDAL/OGR forms, complete WKT, PROJ.4, EPS");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--wkt <WKT string>","Set the coordinates system of source imagery, DEM or destination database in WellKownText form.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--wkt-file <WKT file>","Set the coordinates system of source imagery, DEM or destination database by as file containing WellKownText definition.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--skirt-ratio <float>","Set the ratio of skirt height to tile size");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--HEIGHT_FIELD","Create a height field database");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--POLYGONAL","Create a height field database");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--LOD","Create a LOD'd database");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--PagedLOD","Create a PagedLOD'd database");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-v","Set the vertical multiplier");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--compressed","Use OpenGL compression on destination imagery");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--RGB-16","Use 16bit RGB destination imagery");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--RGB-24","Use 24bit RGB destination imagery");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--max-visible-distance-of-top-level","Set the maximum visible distance that the top most tile can be viewed at");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--radius-to-max-visible-distance-ratio","Set the maximum visible distance ratio for all tiles apart from the top most tile. The maximum visuble distance is computed from the ratio * tile radius.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--no-mip-mapping","Disable mip mapping of textures");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--mip-mapping-hardware","Use mip mapped textures, and generate the mipmaps in hardware when available.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--mip-mapping-imagery","Use mip mapped textures, and generate the mipmaps in imagery.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--max-anisotropy","Max anisotropy level to use when texturing, defaults to 1.0.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--bluemarble-east","");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--bluemarble-west","");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--whole-globe","");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--geocentric","");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--range","");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--xx","");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--xt","");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--yy","");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--yt","");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--zz","");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--zt","");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--tile-image-size","Set the tile maximum image size");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--tile-terrain-size","Set the tile maximum terrain size");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--comment","Added a comment/description string to the top most node in the dataset");
|
||||
|
||||
// create DataSet.
|
||||
osg::ref_ptr<osgTerrain::DataSet> dataset = new osgTerrain::DataSet;
|
||||
|
||||
|
||||
float x,y,w,h;
|
||||
while (arguments.read("-e",x,y,w,h))
|
||||
{
|
||||
dataset->setDestinationExtents(osg::BoundingBox(x,y,0.0f,x+w,y+h,0.0f));
|
||||
}
|
||||
|
||||
while (arguments.read("--HEIGHT_FIELD"))
|
||||
{
|
||||
dataset->setGeometryType(osgTerrain::DataSet::HEIGHT_FIELD);
|
||||
}
|
||||
|
||||
while (arguments.read("--POLYGONAL"))
|
||||
{
|
||||
dataset->setGeometryType(osgTerrain::DataSet::POLYGONAL);
|
||||
}
|
||||
|
||||
while (arguments.read("--LOD"))
|
||||
{
|
||||
dataset->setDatabaseType(osgTerrain::DataSet::LOD_DATABASE);
|
||||
}
|
||||
|
||||
while (arguments.read("--PagedLOD"))
|
||||
{
|
||||
dataset->setDatabaseType(osgTerrain::DataSet::PagedLOD_DATABASE);
|
||||
}
|
||||
|
||||
while (arguments.read("--compressed")) { dataset->setTextureType(osgTerrain::DataSet::COMPRESSED_TEXTURE); }
|
||||
while (arguments.read("--RGB_16") || arguments.read("--RGB-16") ) { dataset->setTextureType(osgTerrain::DataSet::RGB_16_BIT); }
|
||||
while (arguments.read("--RGB_24") || arguments.read("--RGB-24") ) { dataset->setTextureType(osgTerrain::DataSet::RGB_24_BIT); }
|
||||
|
||||
while (arguments.read("--no_mip_mapping") || arguments.read("--no-mip-mapping")) { dataset->setMipMappingMode(osgTerrain::DataSet::NO_MIP_MAPPING); }
|
||||
while (arguments.read("--mip_mapping_hardware") || arguments.read("--mip-mapping-hardware")) { dataset->setMipMappingMode(osgTerrain::DataSet::MIP_MAPPING_HARDWARE); }
|
||||
while (arguments.read("--mip_mapping_imagery") || arguments.read("--mip-mapping-imagery")) { dataset->setMipMappingMode(osgTerrain::DataSet::MIP_MAPPING_IMAGERY); }
|
||||
|
||||
float maxAnisotropy;
|
||||
while (arguments.read("--max_anisotropy",maxAnisotropy) || arguments.read("--max-anisotropy",maxAnisotropy))
|
||||
{
|
||||
dataset->setMaxAnisotropy(maxAnisotropy);
|
||||
}
|
||||
|
||||
unsigned int image_size;
|
||||
while (arguments.read("--tile-image-size",image_size)) { dataset->setMaximumTileImageSize(image_size); }
|
||||
|
||||
unsigned int terrain_size;
|
||||
while (arguments.read("--tile-terrain-size",terrain_size)) { dataset->setMaximumTileTerrainSize(terrain_size); }
|
||||
|
||||
std::string comment;
|
||||
while (arguments.read("--comment",comment)) { dataset->setCommentString(comment); }
|
||||
|
||||
std::string archiveName;
|
||||
while (arguments.read("-a",archiveName)) { dataset->setArchiveName(archiveName); }
|
||||
|
||||
dataset->setDestinationTileBaseName("output");
|
||||
dataset->setDestinationTileExtension(".ive");
|
||||
|
||||
|
||||
unsigned int numLevels = 10;
|
||||
while (arguments.read("-l",numLevels)) {}
|
||||
|
||||
float verticalScale;
|
||||
while (arguments.read("-v",verticalScale))
|
||||
{
|
||||
dataset->setVerticalScale(verticalScale);
|
||||
}
|
||||
|
||||
float skirtRatio;
|
||||
while (arguments.read("--skirt-ratio",skirtRatio))
|
||||
{
|
||||
dataset->setSkirtRatio(skirtRatio);
|
||||
}
|
||||
|
||||
float maxVisibleDistanceOfTopLevel;
|
||||
while (arguments.read("--max_visible_distance_of_top_level",maxVisibleDistanceOfTopLevel) ||
|
||||
arguments.read("--max-visible-distance-of-top-level",maxVisibleDistanceOfTopLevel) )
|
||||
{
|
||||
dataset->setMaximumVisibleDistanceOfTopLevel(maxVisibleDistanceOfTopLevel);
|
||||
}
|
||||
|
||||
float radiusToMaxVisibleDistanceRatio;
|
||||
while (arguments.read("--radius_to_max_visible_distance_ratio",radiusToMaxVisibleDistanceRatio) ||
|
||||
arguments.read("--radius-to-max-visible-distance-ratio",radiusToMaxVisibleDistanceRatio))
|
||||
{
|
||||
dataset->setRadiusToMaxVisibleDistanceRatio(radiusToMaxVisibleDistanceRatio);
|
||||
}
|
||||
|
||||
|
||||
// if user request help write it out to cout.
|
||||
if (arguments.read("-h") || arguments.read("--help"))
|
||||
{
|
||||
arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned int maximumPossibleLevel = 30;
|
||||
|
||||
|
||||
// read the input data
|
||||
|
||||
std::string filename;
|
||||
std::string currentCS;
|
||||
osg::Matrixd geoTransform;
|
||||
bool geoTransformSet = false;
|
||||
bool geoTransformScale = false;
|
||||
double xMin, xMax, yMin, yMax;
|
||||
bool minmaxLevelSet = false;
|
||||
unsigned int min_level=0, max_level=maximumPossibleLevel;
|
||||
unsigned int currentLayerNum = 0;
|
||||
|
||||
int pos = 1;
|
||||
while(pos<arguments.argc())
|
||||
{
|
||||
std::string def;
|
||||
|
||||
if (arguments.read(pos, "--cs",def))
|
||||
{
|
||||
currentCS = !def.empty() ? osgTerrain::DataSet::coordinateSystemStringToWTK(def) : "";
|
||||
std::cout<<"--cs \""<<def<<"\" converted to "<<currentCS<<std::endl;
|
||||
}
|
||||
else if (arguments.read(pos, "--wkt",def))
|
||||
{
|
||||
currentCS = def;
|
||||
std::cout<<"--wkt "<<currentCS<<std::endl;
|
||||
}
|
||||
else if (arguments.read(pos, "--wkt-file",def))
|
||||
{
|
||||
std::ifstream in(def.c_str());
|
||||
if (in)
|
||||
{
|
||||
currentCS = "";
|
||||
while (!in.eof())
|
||||
{
|
||||
std::string line;
|
||||
in >> line;
|
||||
currentCS += line;
|
||||
}
|
||||
std::cout<<"--wkt-file "<<currentCS<<std::endl;
|
||||
}
|
||||
}
|
||||
else if (arguments.read(pos, "--geocentric"))
|
||||
{
|
||||
dataset->setConvertFromGeographicToGeocentric(true);
|
||||
std::cout<<"--geocentric "<<currentCS<<std::endl;
|
||||
}
|
||||
|
||||
else if (arguments.read(pos, "--bluemarble-east"))
|
||||
{
|
||||
currentCS = osgTerrain::DataSet::coordinateSystemStringToWTK("WGS84");
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = true;
|
||||
geoTransform = computeGeoTransForRange(0.0, 180.0, -90.0, 90.0);
|
||||
|
||||
// dataset->setConvertFromGeographicToGeocentric(true);
|
||||
std::cout<<"--bluemarble-west"<<currentCS<<" matrix="<<geoTransform<<std::endl;
|
||||
}
|
||||
|
||||
else if (arguments.read(pos, "--bluemarble-west"))
|
||||
{
|
||||
currentCS = osgTerrain::DataSet::coordinateSystemStringToWTK("WGS84");
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = true;
|
||||
geoTransform = computeGeoTransForRange(-180.0, 0.0, -90.0, 90.0);
|
||||
|
||||
// dataset->setConvertFromGeographicToGeocentric(true);
|
||||
std::cout<<"--bluemarble-west "<<currentCS<<" matrix="<<geoTransform<<std::endl;
|
||||
}
|
||||
|
||||
else if (arguments.read(pos, "--whole-globe"))
|
||||
{
|
||||
currentCS = osgTerrain::DataSet::coordinateSystemStringToWTK("WGS84");
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = true;
|
||||
geoTransform = computeGeoTransForRange(-180.0, 180.0, -90.0, 90.0);
|
||||
|
||||
// dataset->setConvertFromGeographicToGeocentric(true);
|
||||
std::cout<<"--whole-globe "<<currentCS<<" matrix="<<geoTransform<<std::endl;
|
||||
}
|
||||
|
||||
else if (arguments.read(pos, "--range", xMin, xMax, yMin, yMax))
|
||||
{
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = true;
|
||||
geoTransform = computeGeoTransForRange( xMin, xMax, yMin, yMax);
|
||||
|
||||
std::cout<<"--range, matrix="<<geoTransform<<std::endl;
|
||||
}
|
||||
|
||||
else if (arguments.read(pos, "--identity"))
|
||||
{
|
||||
geoTransformSet = false;
|
||||
geoTransform.makeIdentity();
|
||||
}
|
||||
|
||||
// x vector
|
||||
else if (arguments.read(pos, "--xx",geoTransform(0,0)))
|
||||
{
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = false;
|
||||
std::cout<<"--xx "<<geoTransform(0,0)<<std::endl;
|
||||
}
|
||||
else if (arguments.read(pos, "--xy",geoTransform(1,0)))
|
||||
{
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = false;
|
||||
std::cout<<"--xy "<<geoTransform(1,0)<<std::endl;
|
||||
}
|
||||
else if (arguments.read(pos, "--xz",geoTransform(2,0)))
|
||||
{
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = false;
|
||||
std::cout<<"--xz "<<geoTransform(2,0)<<std::endl;
|
||||
}
|
||||
else if (arguments.read(pos, "--xt",geoTransform(3,0)))
|
||||
{
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = false;
|
||||
std::cout<<"--xo "<<geoTransform(3,0)<<std::endl;
|
||||
}
|
||||
|
||||
// y vector
|
||||
else if (arguments.read(pos, "--yx",geoTransform(0,1)))
|
||||
{
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = false;
|
||||
std::cout<<"--yx "<<geoTransform(0,1)<<std::endl;
|
||||
}
|
||||
else if (arguments.read(pos, "--yy",geoTransform(1,1)))
|
||||
{
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = false;
|
||||
std::cout<<"--yy "<<geoTransform(1,1)<<std::endl;
|
||||
}
|
||||
else if (arguments.read(pos, "--yz",geoTransform(2,1)))
|
||||
{
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = false;
|
||||
std::cout<<"--yz "<<geoTransform(2,1)<<std::endl;
|
||||
}
|
||||
else if (arguments.read(pos, "--yt",geoTransform(3,1)))
|
||||
{
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = false;
|
||||
std::cout<<"--yt "<<geoTransform(3,1)<<std::endl;
|
||||
}
|
||||
|
||||
// z vector
|
||||
else if (arguments.read(pos, "--zx",geoTransform(0,2)))
|
||||
{
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = false;
|
||||
std::cout<<"--zx "<<geoTransform(0,2)<<std::endl;
|
||||
}
|
||||
else if (arguments.read(pos, "--zy",geoTransform(1,2)))
|
||||
{
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = false;
|
||||
std::cout<<"--zy "<<geoTransform(1,2)<<std::endl;
|
||||
}
|
||||
else if (arguments.read(pos, "--zz",geoTransform(2,2)))
|
||||
{
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = false;
|
||||
std::cout<<"--zz "<<geoTransform(2,2)<<std::endl;
|
||||
}
|
||||
else if (arguments.read(pos, "--zt",geoTransform(3,2)))
|
||||
{
|
||||
geoTransformSet = true;
|
||||
geoTransformScale = false;
|
||||
std::cout<<"--zt "<<geoTransform(3,2)<<std::endl;
|
||||
}
|
||||
|
||||
else if (arguments.read(pos, "--levels", min_level, max_level))
|
||||
{
|
||||
minmaxLevelSet = true;
|
||||
std::cout<<"--levels, min_level="<<min_level<<" max_level="<<max_level<<std::endl;
|
||||
}
|
||||
|
||||
else if (arguments.read(pos, "--layer", currentLayerNum))
|
||||
{
|
||||
std::cout<<"--layer layeNumber="<<currentLayerNum<<std::endl;
|
||||
}
|
||||
|
||||
else if (arguments.read(pos, "-d",filename))
|
||||
{
|
||||
std::cout<<"-d "<<filename<<std::endl;
|
||||
processFile(filename, osgTerrain::DataSet::Source::HEIGHT_FIELD, currentCS,
|
||||
geoTransform, geoTransformSet, geoTransformScale,
|
||||
minmaxLevelSet, min_level, max_level,
|
||||
currentLayerNum,
|
||||
dataset);
|
||||
|
||||
minmaxLevelSet = false;
|
||||
min_level=0; max_level=maximumPossibleLevel;
|
||||
currentLayerNum = 0;
|
||||
|
||||
currentCS = "";
|
||||
geoTransformSet = false;
|
||||
geoTransformScale = false;
|
||||
geoTransform.makeIdentity();
|
||||
|
||||
}
|
||||
else if (arguments.read(pos, "-t",filename))
|
||||
{
|
||||
std::cout<<"-t "<<filename<<std::endl;
|
||||
processFile(filename, osgTerrain::DataSet::Source::IMAGE, currentCS,
|
||||
geoTransform, geoTransformSet, geoTransformScale,
|
||||
minmaxLevelSet, min_level, max_level,
|
||||
currentLayerNum,
|
||||
dataset);
|
||||
|
||||
minmaxLevelSet = false;
|
||||
min_level=0; max_level=maximumPossibleLevel;
|
||||
currentLayerNum = 0;
|
||||
|
||||
currentCS = "";
|
||||
geoTransformSet = false;
|
||||
geoTransformScale = false;
|
||||
geoTransform.makeIdentity();
|
||||
}
|
||||
else if (arguments.read(pos, "-m",filename))
|
||||
{
|
||||
std::cout<<"-m "<<filename<<std::endl;
|
||||
processFile(filename, osgTerrain::DataSet::Source::MODEL, currentCS,
|
||||
geoTransform, geoTransformSet, geoTransformScale,
|
||||
minmaxLevelSet, min_level, max_level,
|
||||
currentLayerNum,
|
||||
dataset);
|
||||
|
||||
minmaxLevelSet = false;
|
||||
min_level=0; max_level=maximumPossibleLevel;
|
||||
currentLayerNum = 0;
|
||||
|
||||
currentCS = "";
|
||||
geoTransformSet = false;
|
||||
geoTransformScale = false;
|
||||
geoTransform.makeIdentity();
|
||||
}
|
||||
else if (arguments.read(pos, "-o",filename))
|
||||
{
|
||||
std::cout<<"-o "<<filename<<std::endl;
|
||||
|
||||
std::string path = osgDB::getFilePath(filename);
|
||||
std::string base = path.empty()?osgDB::getStrippedName(filename):
|
||||
path +'/'+ osgDB::getStrippedName(filename);
|
||||
std::string extension = '.'+osgDB::getLowerCaseFileExtension(filename);
|
||||
|
||||
dataset->setDestinationTileBaseName(base);
|
||||
dataset->setDestinationTileExtension(extension);
|
||||
|
||||
if (!currentCS.empty()) dataset->setDestinationCoordinateSystem(currentCS);
|
||||
|
||||
minmaxLevelSet = false;
|
||||
min_level=0; max_level=maximumPossibleLevel;
|
||||
|
||||
currentCS = "";
|
||||
geoTransformSet = false;
|
||||
geoTransformScale = false;
|
||||
geoTransform.makeIdentity();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// if no argument read advance to next argument.
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
|
||||
// any option left unread are converted into errors to write out later.
|
||||
arguments.reportRemainingOptionsAsUnrecognized();
|
||||
|
||||
// report any errors if they have occured when parsing the program aguments.
|
||||
if (arguments.errors())
|
||||
{
|
||||
arguments.writeErrorMessages(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// generate the database
|
||||
{
|
||||
GraphicsContext context;
|
||||
|
||||
dataset->loadSources();
|
||||
|
||||
dataset->createDestination((unsigned int)numLevels);
|
||||
|
||||
dataset->writeDestination();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgversion.cpp\
|
||||
|
||||
LIBS += -losgProducer -lProducer -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
INSTFILES = \
|
||||
$(CXXFILES)\
|
||||
GNUmakefile.inst=GNUmakefile
|
||||
|
||||
EXEC = osgversion
|
||||
|
||||
INC += $(X_INC)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
@ -1,14 +0,0 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgversion.cpp\
|
||||
|
||||
LIBS += -losgProducer -lProducer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
EXEC = osgversion
|
||||
|
||||
INC += $(PRODUCER_INCLUDE_DIR) $(X_INC)
|
||||
LDFLAGS += $(PRODUCER_LIB_DIR)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
@ -1,9 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <osg/Version>
|
||||
|
||||
|
||||
int main( int, char **)
|
||||
{
|
||||
printf( "%s\n", osgGetVersion() );
|
||||
return 0;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgviewer.cpp\
|
||||
|
||||
LIBS += -losgProducer -lProducer -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
INSTFILES = \
|
||||
$(CXXFILES)\
|
||||
GNUmakefile.inst=GNUmakefile
|
||||
|
||||
EXEC = osgviewer
|
||||
|
||||
INC += $(X_INC)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
|
@ -1,13 +0,0 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgviewer.cpp\
|
||||
|
||||
LIBS += -losgProducer -lProducer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
EXEC = osgviewer
|
||||
|
||||
INC += $(X_INC)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
@ -1,122 +0,0 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* freely and without restriction, both in commericial and non commericial applications,
|
||||
* as long as this copyright notice is maintained.
|
||||
*
|
||||
* This application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgUtil/Optimizer>
|
||||
#include <osgProducer/Viewer>
|
||||
#include <osg/CoordinateSystemNode>
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.");
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line paramters");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindigs.");
|
||||
|
||||
|
||||
// construct the viewer.
|
||||
osgProducer::Viewer viewer(arguments);
|
||||
|
||||
// set up the value with sensible default event handlers.
|
||||
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
|
||||
|
||||
// get details on keyboard and mouse bindings used by the viewer.
|
||||
viewer.getUsage(*arguments.getApplicationUsage());
|
||||
|
||||
// if user request help write it out to cout.
|
||||
bool helpAll = arguments.read("--help-all");
|
||||
unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) |
|
||||
((helpAll || arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) |
|
||||
((helpAll || arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 );
|
||||
if (helpType)
|
||||
{
|
||||
arguments.getApplicationUsage()->write(std::cout, helpType);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// report any errors if they have occured when parsing the program aguments.
|
||||
if (arguments.errors())
|
||||
{
|
||||
arguments.writeErrorMessages(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (arguments.argc()<=1)
|
||||
{
|
||||
arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
|
||||
return 1;
|
||||
}
|
||||
|
||||
osg::Timer_t start_tick = osg::Timer::instance()->tick();
|
||||
|
||||
// read the scene from the list of file specified commandline args.
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
|
||||
// if no model has been successfully loaded report failure.
|
||||
if (!loadedModel)
|
||||
{
|
||||
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// any option left unread are converted into errors to write out later.
|
||||
arguments.reportRemainingOptionsAsUnrecognized();
|
||||
|
||||
// report any errors if they have occured when parsing the program aguments.
|
||||
if (arguments.errors())
|
||||
{
|
||||
arguments.writeErrorMessages(std::cout);
|
||||
}
|
||||
|
||||
osg::Timer_t end_tick = osg::Timer::instance()->tick();
|
||||
|
||||
std::cout << "Time to load = "<<osg::Timer::instance()->delta_s(start_tick,end_tick)<<std::endl;
|
||||
|
||||
// optimize the scene graph, remove rendundent nodes and state etc.
|
||||
osgUtil::Optimizer optimizer;
|
||||
optimizer.optimize(loadedModel.get());
|
||||
|
||||
// pass the loaded scene graph to the viewer.
|
||||
viewer.setSceneData(loadedModel.get());
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
// wait for all cull and draw threads to complete.
|
||||
viewer.sync();
|
||||
|
||||
// update the scene by traversing it with the the update visitor which will
|
||||
// call all node update callbacks and animations.
|
||||
viewer.update();
|
||||
|
||||
// fire off the cull and draw traversals of the scene.
|
||||
viewer.frame();
|
||||
|
||||
}
|
||||
|
||||
// wait for all cull and draw threads to complete before exit.
|
||||
viewer.sync();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user