Added an optional argument for doing model orientations in osgconv using
degrees and axis rather than two vectors.
This commit is contained in:
@@ -20,6 +20,11 @@ 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);
|
||||
|
||||
@@ -11,6 +11,7 @@ class OrientationConverter {
|
||||
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);
|
||||
|
||||
|
||||
@@ -77,34 +77,39 @@ static void usage( const char *prog, const char *msg )
|
||||
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"
|
||||
"\n"
|
||||
" X1,Y1,Z1-X2,Y2,Z2\n"
|
||||
"\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. For example, to convert a model built\n"
|
||||
" in a Y-Up coordinate system to a model with a Z-up\n"
|
||||
" coordinate system, the argument looks like\n"
|
||||
"\n"
|
||||
" 0,1,0-0,0,1"
|
||||
"\n"
|
||||
<< std::endl;
|
||||
" 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;
|
||||
"\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;
|
||||
"\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;
|
||||
}
|
||||
|
||||
static bool
|
||||
@@ -120,8 +125,8 @@ parse_args( int argc, char **argv, FileNameList &fileNames,
|
||||
|
||||
if (argv[i][0]=='-')
|
||||
{
|
||||
for( unsigned int j = 1; j < strlen( argv[i] ); j++ )
|
||||
{
|
||||
for( unsigned int j = 1; j < strlen( argv[i] ); j++ )
|
||||
{
|
||||
switch(argv[i][j])
|
||||
{
|
||||
case 'O':
|
||||
@@ -132,8 +137,8 @@ parse_args( int argc, char **argv, FileNameList &fileNames,
|
||||
opt = opt+" "+argv[nexti++];
|
||||
}
|
||||
else {
|
||||
usage( argv[0], "ReaderWriter option requires an argument." );
|
||||
return false;
|
||||
usage( argv[0], "ReaderWriter option requires an argument." );
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -143,11 +148,11 @@ parse_args( int argc, char **argv, FileNameList &fileNames,
|
||||
std::string libName = osgDB::Registry::instance()->createLibraryNameForExtension(argv[nexti++]);
|
||||
osgDB::Registry::instance()->loadLibrary(libName);
|
||||
}
|
||||
else
|
||||
{
|
||||
usage( argv[0], "Extension option requires an argument." );
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
usage( argv[0], "Extension option requires an argument." );
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case('l'):
|
||||
@@ -155,85 +160,101 @@ parse_args( int argc, char **argv, FileNameList &fileNames,
|
||||
{
|
||||
osgDB::Registry::instance()->loadLibrary(argv[nexti++]);
|
||||
}
|
||||
else
|
||||
{
|
||||
usage( argv[0], "Library option requires an argument." );
|
||||
return false;
|
||||
}
|
||||
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.setRotation( from, to );
|
||||
do_convert = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
usage( argv[0], "Orientation conversion 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 )
|
||||
{
|
||||
float degrees;
|
||||
osg::Vec3 axis;
|
||||
// Try deg-axis format
|
||||
if( sscanf( argv[nexti], "%f-%f,%f,%f",
|
||||
°rees, &axis[0], &axis[1], &axis[2] ) != 4 )
|
||||
{
|
||||
usage( argv[0], "Orientation argument format incorrect." );
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
oc.setRotation( degrees, axis );
|
||||
do_convert = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
oc.setRotation( from, to );
|
||||
do_convert = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
usage( argv[0], "Orientation conversion option requires an argument." );
|
||||
return false;
|
||||
}
|
||||
nexti++;
|
||||
break;
|
||||
|
||||
case 't' :
|
||||
if( nexti < argc )
|
||||
{
|
||||
osg::Vec3 trans(0,0,0);
|
||||
if( sscanf( argv[nexti++], "%f,%f,%f",
|
||||
&trans[0], &trans[1], &trans[2] ) != 3 )
|
||||
{
|
||||
usage( argv[0], "Translation argument format incorrect." );
|
||||
return false;
|
||||
}
|
||||
oc.setTranslation( trans );
|
||||
do_convert = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
usage( argv[0], "Translation conversion option requires an argument." );
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 't' :
|
||||
if( nexti < argc )
|
||||
{
|
||||
osg::Vec3 trans(0,0,0);
|
||||
if( sscanf( argv[nexti++], "%f,%f,%f",
|
||||
&trans[0], &trans[1], &trans[2] ) != 3 )
|
||||
{
|
||||
usage( argv[0], "Translation argument format incorrect." );
|
||||
return false;
|
||||
}
|
||||
oc.setTranslation( trans );
|
||||
do_convert = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
usage( argv[0], "Translation conversion option requires an argument." );
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 's' :
|
||||
if( nexti < argc )
|
||||
{
|
||||
osg::Vec3 scale(0,0,0);
|
||||
if( sscanf( argv[nexti++], "%f,%f,%f",
|
||||
&scale[0], &scale[1], &scale[2] ) != 3 )
|
||||
{
|
||||
usage( argv[0], "Scale argument format incorrect." );
|
||||
return false;
|
||||
}
|
||||
oc.setScale( scale );
|
||||
do_convert = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
usage( argv[0], "Scale conversion option requires an argument." );
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 's' :
|
||||
if( nexti < argc )
|
||||
{
|
||||
osg::Vec3 scale(0,0,0);
|
||||
if( sscanf( argv[nexti++], "%f,%f,%f",
|
||||
&scale[0], &scale[1], &scale[2] ) != 3 )
|
||||
{
|
||||
usage( argv[0], "Scale argument format incorrect." );
|
||||
return false;
|
||||
}
|
||||
oc.setScale( scale );
|
||||
do_convert = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
usage( argv[0], "Scale conversion option requires an argument." );
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
std::string a = "Invalid option " ;
|
||||
a += "'";
|
||||
a += argv[i][j] ;
|
||||
a += "'.";
|
||||
usage( argv[0], a.c_str() );
|
||||
return false;
|
||||
break;
|
||||
default :
|
||||
std::string a = "Invalid option " ;
|
||||
a += "'";
|
||||
a += argv[i][j] ;
|
||||
a += "'.";
|
||||
usage( argv[0], a.c_str() );
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
fileNames.push_back(argv[i]);
|
||||
@@ -242,7 +263,7 @@ parse_args( int argc, char **argv, FileNameList &fileNames,
|
||||
|
||||
if (fileNames.empty())
|
||||
{
|
||||
usage( argv[0], "No files specified." );
|
||||
usage( argv[0], "No files specified." );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -281,7 +302,7 @@ int main( int argc, char **argv )
|
||||
|
||||
|
||||
if( do_convert )
|
||||
root = oc.convert( root.get() );
|
||||
root = oc.convert( root.get() );
|
||||
|
||||
if (root.valid())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user