checking files in to move development location

This commit is contained in:
Don BURNS
2001-10-13 06:22:49 +00:00
parent 5b3a52547a
commit fef731c689
4 changed files with 212 additions and 49 deletions

View File

@@ -2,7 +2,9 @@
include ../../../Make/makedefs
C++FILES = \
osgconv.cpp
osgconv.cpp\
orientationconverter.cpp
TARGET = ../../../bin/osgconv

View File

@@ -0,0 +1,34 @@
#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 setConversion( const osg::Vec3 &from, const osg::Vec3 &to);
void convert( osg::Node &node );
private :
OrientationConverter( const OrientationConverter& ) {}
OrientationConverter& operator = (const OrientationConverter& ) { return *this; }
osg::Matrix _mat;
class ConvertVisitor : public osg::NodeVisitor
{
public :
ConvertVisitor() : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN){}
virtual void apply( osg::Node &node ) { traverse( node ); }
virtual void apply( osg::Geode &geode );
};
ConvertVisitor _cv;
};
#endif

View File

@@ -0,0 +1,47 @@
#include <stdio.h>
#include "OrientationConverter.h"
using namespace osg;
OrientationConverter::OrientationConverter( void )
{
_mat.makeIdent();
}
void OrientationConverter::setConversion( const Vec3 &from, const Vec3 &to )
{
// This is the default OpenGL UP vector
Vec3 A( 0, 1, 0 );
// if from is not equal to the default, we must first rotate beteen A and from
if( A != from )
{
;
}
// Now do a rotation between A and to
Quat q;
q.makeRot( A, to );
q.get( _mat );
}
void OrientationConverter::convert( Node &node )
{
_cv.apply( node );
}
void OrientationConverter::ConvertVisitor::apply( Geode &geode )
{
int numdrawables = geode.getNumDrawables();
for( int i = 0; i < numdrawables; i++ )
{
Drawable *dbl = geode.getDrawable( i );
if( dbl->isSameKindAs
}
}

View File

@@ -1,76 +1,154 @@
#include <stdio.h>
#include <osg/Group>
#include <osg/Notify>
#include <osg/Vec3>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
int main( int argc, char **argv )
#include "OrientationConverter.h"
typedef std::vector<std::string> FileNameList;
static bool do_convert = false;
static void usage( const char *prog, const char *msg )
{
osg::notify(osg::NOTICE)<<endl;
osg::notify(osg::NOTICE) << msg << endl;
osg::notify(osg::NOTICE)<<endl;
osg::notify(osg::NOTICE)<<"usage:"<<endl;
osg::notify(osg::NOTICE)<<" " << prog << " [options] infile1 [infile2 ...] outfile"<<endl;
osg::notify(osg::NOTICE)<<endl;
osg::notify(osg::NOTICE)<<"options:"<<endl;
osg::notify(osg::NOTICE)<<" -l libraryName - load plugin of name libraryName"<<endl;
osg::notify(osg::NOTICE)<<" i.e. -l osgdb_pfb"<<endl;
osg::notify(osg::NOTICE)<<" Useful for loading reader/writers which can load"<<endl;
osg::notify(osg::NOTICE)<<" other file formats in addition to its extension."<<endl;
osg::notify(osg::NOTICE)<<" -e extensionName - load reader/wrter plugin for file extension"<<endl;
osg::notify(osg::NOTICE)<<" i.e. -e pfb"<<endl;
osg::notify(osg::NOTICE)<<" Useful short hand for specifying full library name as"<<endl;
osg::notify(osg::NOTICE)<<" done with -l above, as it automatically expands to the"<<endl;
osg::notify(osg::NOTICE)<<" full library name appropriate for each platform."<<endl;
osg::notify(osg::NOTICE)<<" -o orientation - Convert geometry from input files to output files."<<endl;
if (argc<2)
{
osg::notify(osg::NOTICE)<<endl;
osg::notify(osg::NOTICE)<<"usage:"<<endl;
osg::notify(osg::NOTICE)<<" osgconv [options] infile1 [infile2 ...] outfile"<<endl;
osg::notify(osg::NOTICE)<<endl;
osg::notify(osg::NOTICE)<<"options:"<<endl;
osg::notify(osg::NOTICE)<<" -l libraryName - load plugin of name libraryName"<<endl;
osg::notify(osg::NOTICE)<<" i.e. -l osgdb_pfb"<<endl;
osg::notify(osg::NOTICE)<<" Useful for loading reader/writers which can load"<<endl;
osg::notify(osg::NOTICE)<<" other file formats in addition to its extension."<<endl;
osg::notify(osg::NOTICE)<<" -e extensionName - load reader/wrter plugin for file extension"<<endl;
osg::notify(osg::NOTICE)<<" i.e. -e pfb"<<endl;
osg::notify(osg::NOTICE)<<" Useful short hand for specifying full library name as"<<endl;
osg::notify(osg::NOTICE)<<" done with -l above, as it automatically expands to the"<<endl;
osg::notify(osg::NOTICE)<<" full library name appropriate for each platform."<<endl;
osg::notify(osg::NOTICE)<<endl;
return 0;
}
typedef std::vector<std::string> FileNameList;
FileNameList fileNames;
for(int i = 1; i < argc; i++ )
osg::notify(osg::NOTICE)<<
" Format of orientation argument must be the following:\n"
"\n"
" X1,Y1,Z1-X2,Y2,Z2\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 output file.\n"
" For example, to convert a model built in a Y-Up coordinate system\n"
" to a model with a Z-up coordinate system, the argument looks like\n"
"\n"
" 0,1,0-0,0,1"
"\n"
<< endl;
}
static bool
parse_args( int argc, char **argv, FileNameList &fileNames, OrientationConverter &oc )
{
int nexti;
for(int i = 1; i < argc; i=nexti )
{
nexti = i+1;
if (argv[i][0]=='-')
{
switch(argv[i][1])
{
case('l'):
++i;
if (i<argc)
{
osgDB::Registry::instance()->loadLibrary(argv[i]);
}
break;
case('e'):
++i;
if (i<argc)
{
std::string libName = osgDB::Registry::instance()->createLibraryNameForExt(argv[i]);
osgDB::Registry::instance()->loadLibrary(libName);
}
break;
}
for( unsigned int j = 1; j < strlen( argv[i] ); j++ )
{
switch(argv[i][j])
{
case('e'):
if (nexti<argc)
{
std::string libName = osgDB::Registry::instance()->createLibraryNameForExt(argv[nexti++]);
osgDB::Registry::instance()->loadLibrary(libName);
}
else
{
usage( argv[0], "Extension option requires an argument." );
return false;
}
break;
case('l'):
if (nexti<argc)
{
osgDB::Registry::instance()->loadLibrary(argv[nexti++]);
}
else
{
usage( argv[0], "Library option requires an argument." );
return false;
}
break;
case 'o' :
if( nexti < argc )
{
osg::Vec3 from, to;
if( sscanf( argv[nexti++], "%f,%f,%f-%f,%f,%f",
&from[0], &from[1], &from[2],
&to[0], &to[1], &to[2] ) != 6 )
{
usage( argv[0], "Orientation argument format incorrect." );
return false;
}
oc.setConversion( from, to );
do_convert = true;
}
else
{
usage( argv[0], "Orientation conversion option requires an argument." );
return false;
}
break;
default :
std::string a = "Invalide option " ;
a += "'";
a += argv[i][j] ;
a += "'.";
usage( argv[0], a.c_str() );
return false;
break;
}
}
} else
{
fileNames.push_back(argv[i]);
}
}
if (fileNames.empty())
{
osg::notify(osg::NOTICE)<<"No files specfied."<<endl;
return 1;
usage( argv[0], "No files specified." );
return false;
}
return true;
}
int main( int argc, char **argv )
{
FileNameList fileNames;
OrientationConverter oc;
if( parse_args( argc, argv, fileNames, oc ) == false )
return -1;
if (fileNames.size()==1)
{
osg::Node* root = osgDB::readNodeFile(fileNames.front());
if( do_convert )
oc.convert( *root );
if (root)
{
osgDB::writeNodeFile(*root,"converted.osg");
@@ -98,9 +176,12 @@ int main( int argc, char **argv )
group->addChild(child);
}
}
if( do_convert )
oc.convert(*group);
if (group->getNumChildren()==0)
{
osg::notify(osg::NOTICE)<<"Error no data loaded."<<endl;
return 1;
}
@@ -112,7 +193,6 @@ int main( int argc, char **argv )
{
osgDB::writeNodeFile(*group,fileNameOut);
}
}
return 0;