The changes to osgpreview.cpp are for the first issue, while the changes to
utility.h are for the second way of solving the second issue.

Ryan

On Tue, May 24, 2011 at 12:59 PM, Javier Taibo <[email protected]>wrote:

>  Hi Ryan,
>
>  Thank you for the patches. Can you send the whole files instead of
> patches, please? You can zip all files together to make it easy.
>
>  Thank you!
>
>
>  Best Regards,
>
>
> On Tue, May 24, 2011 at 7:28 PM, Ryan Pavlik <[email protected]> wrote:
> > Hello all,
> > I've attached small patches to two issues I've found with Maya2OSG.
> > One allows it to build successfully with the current 2.8 branch - there
> are
> > some manipulators not available in this branch so we just disable them by
> > checking the osg version.
> > The other issue was ambiguity in calling inTolerance, preventing me from
> > building successfully on VC9 x64.  I solved this two different ways: take
> > your pick of which way you prefer.
> >
> > I've made inTolerance a template function with a single parameter type
> and
> > explicitly specified the template parameter in the one case.
> (fix-vc9-build)
> > inTolerance is a template function with three parameter types, and
> > static_casts all arguments to the type of the tolerance parameter before
> > doing math.  This one doesn't require explicit template param
> specification,
> > and seems "more correct" to me, or at least more explicit in how it
> works. I
> > personally prefer this one. (alternate-fix-build)
> >
> > These patches were made against the latest svn trunk of maya2osg using
> > tortoisesvn.
> > Ryan
> > --
> > Ryan Pavlik
> > HCI Graduate Student
> > Virtual Reality Applications Center
> > Iowa State University
> >
> > [email protected]
> > http://academic.cleardefinition.com
> >
> > _______________________________________________
> > osg-users mailing list
> > [email protected]
> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
> >
>
>
>
> --
> Javier Taibo
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



-- 
Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

[email protected]
http://academic.cleardefinition.com
/**
    Maya2OSG - A toolkit for exporting Maya scenes to OpenSceneGraph
    Copyright (C) 2010-2011 Javier Taibo <[email protected]>

    This file is part of Maya2OSG.

    Maya2OSG is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Maya2OSG 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
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Maya2OSG.  If not, see <http://www.gnu.org/licenses/>.
*/

// This is previewer is a modified version of OSG application "osgviewer"

#include "osgpreview.h"
#include "version.h"

#include <maya/MArgList.h>
#include <maya/MStringArray.h>

#include <osg/Version>
#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osg/CoordinateSystemNode>

#include <osg/Switch>
#include <osgText/Text>

#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>

#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#if OSG_MIN_VERSION_REQUIRED(2,9,5)
#include <osgGA/OrbitManipulator>
#include <osgGA/SphericalManipulator>
#endif


void* OSGPreview::creator()
{
	return new OSGPreview();
}

MStatus OSGPreview::doIt( const MArgList & args )
{
	MStringArray argStringArray;
	for( unsigned int i = 0 ; i < args.length() ; ++i ) {
		argStringArray.append( args.asString( i ) ) ;
	}

	int argc = args.length() + 1;
	char **argv = (char **)malloc(argc * sizeof(char *));
	argv[0] = "osgpreview";

	argStringArray.get(argv+1);
    osg::ArgumentParser arguments(&argc, argv);

    osgViewer::Viewer viewer(arguments);

    unsigned int helpType = 0;
    if ((helpType = arguments.readHelpType()))
    {
        arguments.getApplicationUsage()->write(std::cout, helpType);
        return MStatus::kFailure;
    }

    // report any errors if they have occurred when parsing the program arguments.
    if (arguments.errors())
    {
        arguments.writeErrorMessages(std::cout);
        return MStatus::kFailure;
    }

    if (arguments.argc()<=1)
    {
        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
        return MStatus::kFailure;
    }

    std::string url, username, password;
    while(arguments.read("--login",url, username, password))
    {
        if (!osgDB::Registry::instance()->getAuthenticationMap())
        {
            osgDB::Registry::instance()->setAuthenticationMap(new osgDB::AuthenticationMap);
            osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails(
                url,
                new osgDB::AuthenticationDetails(username, password)
            );
        }
    }

    // set up the camera manipulators.
    {
        osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;

        keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
        keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
        keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
        keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
#if OSG_MIN_VERSION_REQUIRED(2,9,5)
        keyswitchManipulator->addMatrixManipulator( '5', "Orbit", new osgGA::OrbitManipulator() );
        keyswitchManipulator->addMatrixManipulator( '6', "FirstPerson", new osgGA::FirstPersonManipulator() );
        keyswitchManipulator->addMatrixManipulator( '7', "Spherical", new osgGA::SphericalManipulator() );
#endif

        std::string pathfile;
        char keyForAnimationPath = '8';
        while (arguments.read("-p",pathfile))
        {
            osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
            if (apm || !apm->valid())
            {
                unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
                keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
                keyswitchManipulator->selectMatrixManipulator(num);
                ++keyForAnimationPath;
            }
        }

        if ( arguments.read("--noautohomeview") ) {
            osg::Vec3 eye, center, up;
            viewer.getCamera()->getViewMatrixAsLookAt( eye, center, up );
            keyswitchManipulator->setHomePosition( eye, center, up );
        }

        viewer.setCameraManipulator( keyswitchManipulator.get() );
    }

    // add the state manipulator
    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );

    // add the thread model handler
    viewer.addEventHandler(new osgViewer::ThreadingHandler);

    // add the window size toggle handler
    viewer.addEventHandler(new osgViewer::WindowSizeHandler);

    // add the stats handler
    viewer.addEventHandler(new osgViewer::StatsHandler);

    // add the help handler
    viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));

    // add the record camera path handler
    viewer.addEventHandler(new osgViewer::RecordCameraPathHandler);

    // add the LOD Scale handler
    viewer.addEventHandler(new osgViewer::LODScaleHandler);

    // add the screen capture handler
    viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);

    // load the data
    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
    if (!loadedModel)
    {
        std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
        return MStatus::kFailure;
    }

    // any option left unread are converted into errors to write out later.
    arguments.reportRemainingOptionsAsUnrecognized();

    // report any errors if they have occurred when parsing the program arguments.
    if (arguments.errors())
    {
        arguments.writeErrorMessages(std::cout);
        return MStatus::kFailure;
    }

    // optimize the scene graph, remove redundant nodes and state etc.
    osgUtil::Optimizer optimizer;
    optimizer.optimize(loadedModel.get());

    viewer.setSceneData( loadedModel.get() );

    viewer.realize();

    viewer.run();

	free(argv);

	return MStatus::kSuccess;
}
#ifndef _UTILITY_H_
#define _UTILITY_H_


// ----- Maya -----------------------------------------------------------------------
#include <maya/MColor.h>
#include <maya/MPoint.h>
#include <maya/MMatrix.h>
#include <maya/MVector.h>
#include <maya/MFloatPoint.h>


// ----- OSG ------------------------------------------------------------------------
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Matrixd>
#include <osg/Matrixf>


// CHECK if distance from BASE is in TOLERANCE
template<typename ToleranceType, typename T1, typename T2>
inline bool inTolerance( T1 base , T2 match , ToleranceType tolerance )  {
	return ( static_cast<ToleranceType>(base) - tolerance <= static_cast<ToleranceType>(match) ) && ( static_cast<ToleranceType>(base) + tolerance >= static_cast<ToleranceType>(match) ) ;
}

template < typename SCALAR , typename VEC >
static VEC roundTolerance( SCALAR base , VEC match , SCALAR tolerance )  {
	for( uint i = 0 ; i < VEC::num_components ; ++i )
		if ( inTolerance( base , match[ i ] , tolerance ) )
			match[ i ] = base ;

	return match ;
}

//------------------------------------------------------------------------------
static inline void assign( MFloatPoint & mFloatPoint , const osg::Vec3 & osgVec3 )  {
	mFloatPoint[ 0 ] = osgVec3[ 0 ] ;
	mFloatPoint[ 1 ] = osgVec3[ 1 ] ;
	mFloatPoint[ 2 ] = osgVec3[ 2 ] ;
}

//------------------------------------------------------------------------------
static inline void assign( osg::Vec3 & osgVec3 , const MPoint & mPoint )  {
	osgVec3[ 0 ] = mPoint[ 0 ] ;
	osgVec3[ 1 ] = mPoint[ 1 ] ;
	osgVec3[ 2 ] = mPoint[ 2 ] ;
}


//------------------------------------------------------------------------------
static inline void assign( MFloatVector & mFloatVector , const osg::Vec3 & osgVec3 )  {
	mFloatVector[ 0 ] = osgVec3[ 0 ] ;
	mFloatVector[ 1 ] = osgVec3[ 1 ] ;
	mFloatVector[ 2 ] = osgVec3[ 2 ] ;
}

//------------------------------------------------------------------------------
static inline void assign( osg::Vec3 & osgVec3 , const MFloatVector & mFloatVector )  {
	osgVec3[ 0 ] = mFloatVector[ 0 ] ;
	osgVec3[ 1 ] = mFloatVector[ 1 ] ;
	osgVec3[ 2 ] = mFloatVector[ 2 ] ;
}

//------------------------------------------------------------------------------
static inline void assign( MVector & mVector , const osg::Vec3 & osgVec3 )  {
	mVector[ 0 ] = osgVec3[ 0 ] ;
	mVector[ 1 ] = osgVec3[ 1 ] ;
	mVector[ 2 ] = osgVec3[ 2 ] ;
}

//------------------------------------------------------------------------------
static inline void assign( osg::Vec3 & osgVec3 , const MVector & mVector )  {
	osgVec3[ 0 ] = mVector[ 0 ] ;
	osgVec3[ 1 ] = mVector[ 1 ] ;
	osgVec3[ 2 ] = mVector[ 2 ] ;
}


//------------------------------------------------------------------------------
static inline void assign( MVector & mColor , const osg::Vec4 & osgVec4 )  {
	mColor[ 0 ] = osgVec4[ 0 ] ;
	mColor[ 1 ] = osgVec4[ 1 ] ;
	mColor[ 2 ] = osgVec4[ 2 ] ;
	mColor[ 3 ] = osgVec4[ 3 ] ;
}

//------------------------------------------------------------------------------
static inline void assign( osg::Vec4 & osgVec4 , const MColor & mColor )  {
	osgVec4[ 0 ] = mColor[ 0 ] ;
	osgVec4[ 1 ] = mColor[ 1 ] ;
	osgVec4[ 2 ] = mColor[ 2 ] ;
	osgVec4[ 3 ] = mColor[ 3 ] ;
}

//------------------------------------------------------------------------------
static inline void assign( osg::Matrixf & osgMatrix , const MMatrix & mMatrix )  {
	osgMatrix = osg::Matrixf(
		mMatrix( 0 , 0 ) , mMatrix( 0 , 1 ) , mMatrix( 0 , 2 ) , mMatrix( 0 , 3 ) ,
		mMatrix( 1 , 0 ) , mMatrix( 1 , 1 ) , mMatrix( 1 , 2 ) , mMatrix( 1 , 3 ) ,
		mMatrix( 2 , 0 ) , mMatrix( 2 , 1 ) , mMatrix( 2 , 2 ) , mMatrix( 2 , 3 ) ,
		mMatrix( 3 , 0 ) , mMatrix( 3 , 1 ) , mMatrix( 3 , 2 ) , mMatrix( 3 , 3 ) ) ;
}

//------------------------------------------------------------------------------
static inline void assign( osg::Matrixd & osgMatrix , const MMatrix & mMatrix )  {
	osgMatrix = osg::Matrixd(
		mMatrix( 0 , 0 ) , mMatrix( 0 , 1 ) , mMatrix( 0 , 2 ) , mMatrix( 0 , 3 ) ,
		mMatrix( 1 , 0 ) , mMatrix( 1 , 1 ) , mMatrix( 1 , 2 ) , mMatrix( 1 , 3 ) ,
		mMatrix( 2 , 0 ) , mMatrix( 2 , 1 ) , mMatrix( 2 , 2 ) , mMatrix( 2 , 3 ) ,
		mMatrix( 3 , 0 ) , mMatrix( 3 , 1 ) , mMatrix( 3 , 2 ) , mMatrix( 3 , 3 ) ) ;
}
#endif	// _UTILITY_H_
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to