OMKMaterialAnimator.cpp

Go to the documentation of this file.
00001 /************************************************************************/
00002 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */
00003 /* 1993-2002, thereinafter the Software                                 */
00004 /*                                                                      */
00005 /* The Software has been developped within the Siames Project.          */
00006 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */
00007 /* property rights                                                      */
00008 /*                                                                      */
00009 /* The Software has been registered with the Agence pour la Protection  */
00010 /* des Programmes (APP) under registration number                       */
00011 /* IDDN.FR.001.510008.00.S.P.2001.000.41200                             */
00012 /*                                                                      */
00013 /* This file may be distributed under the terms of the Q Public License */
00014 /* version 1.0 as defined by Trolltech AS of Norway and appearing in    */
00015 /* the file LICENSE.QPL included in the packaging of this file.         */
00016 /*                                                                      */
00017 /* Licensees holding valid specific licenses issued by INRIA, CNRS or   */
00018 /* Universite Rennes 1 for the software may use this file in            */
00019 /* acordance with that specific license                                 */
00020 /************************************************************************/
00021 #include "OMKMaterialAnimator.h"
00022 
00023 #include "OMKOgreVis.h"
00024 #include "OMKOgreObject.h"
00025 #include "OgreMovableObject.h"
00026 #include "OMKParametersAccessor.h"
00027 #include "OMKEntityMaterialAction.h"
00028 
00029 using namespace OMK ;
00030 using namespace OMK::Vis ;
00031 using namespace OMK::Type ;
00032 using std::string;
00033 using Ogre::SceneNode;
00034 using Ogre::MovableObject;
00035 using Ogre::Entity;
00036 
00037 
00038 //===========================================================================
00039 // MaterialAnimator
00040 //===========================================================================
00041 
00042 //-------------------------------------------------------------------------
00043 // registration for both:  string and bool
00044 //-------------------------------------------------------------------------
00045 REGISTER_TEMPLATE_ANIMATOR_FACTORY( MaterialAnimator< OMK::Type::StringType >, "MaterialAnimator" ) ;
00046 REGISTER_TEMPLATE_ANIMATOR_FACTORY( MaterialAnimator< OMK::Type::BoolType >, "MaterialBoolAnimator" ) ;
00047 
00048 //-------------------------------------------------------------------------
00049 // constructor
00050 //-------------------------------------------------------------------------
00051 template< typename Type >
00052 MaterialAnimator< Type >::MaterialAnimator( VisualObject& visualObject, 
00053                                     const Name& id, 
00054                                     const ConfigurationParameterDescriptor& node ) 
00055 : OgreAnimatorT< Type>( visualObject, id, node ),
00056   _materialName(),
00057   _node( 0 ),
00058   _modified( false )
00059 {
00060   Ogre::SceneNode* sceneNode = dynamic_cast< Ogre::SceneNode *>( &this->getNode() ) ;
00061   OMASSERTM( sceneNode, "No scene node found !" ) ;
00062   OgreObject* ogreObject = dynamic_cast< OgreObject* >( &this->getVisualObject() ) ;
00063   OMASSERTM( ogreObject, "The visual object must be a OgreObject" ) ;
00064   _node = ogreObject->getNodeMaterialOrig()->find( sceneNode ) ;
00065 
00066     std::string initMat;
00067   if ( ParametersAccessor::get( &node, "changeInitMaterial", initMat ) )
00068   {
00069     _node->doAction( MaterialSetMaterialName( initMat ) ) ;
00070   }
00071 
00072   ParametersAccessor::get( &node, "material", _materialName ) ;
00073 }
00074 
00075 //-------------------------------------------------------------------------
00076 // destructor
00077 //-------------------------------------------------------------------------
00078 template< typename Type >
00079 MaterialAnimator< Type >::~MaterialAnimator()
00080 {
00081 }
00082 
00083 //-------------------------------------------------------------------------
00084 // doIt
00085 //-------------------------------------------------------------------------
00086 template< typename Type >
00087 void MaterialAnimator< Type >::doIt( bool activate )
00088 {
00089   OMTRACEID("OMK::MaterialAnimator"," modi " << _modified << " new " << activate );
00090   if( activate != _modified )
00091   {
00092     _modified = activate ;
00093     if( _modified )
00094     {
00095       OMTRACEID("OMK::MaterialAnimator"," copy" );
00096       _node->createCopyAndUpdateWith( this ) ;
00097     }
00098     else
00099     {
00100       OMTRACEID("OMK::MaterialAnimator"," UNDO " );
00101       _node->undoFor( this, true ) ;
00102     }
00103   }
00104 }
00105 
00106 //-------------------------------------------------------------------------
00107 // update
00108 //-------------------------------------------------------------------------
00109 template< typename Type >
00110 void MaterialAnimator< Type >::update( NodeMaterial* node ) 
00111 {
00112   node->doAction( MaterialSetMaterialName( _materialName ) ) ;
00113 }
00114 
00115 //-------------------------------------------------------------------------
00116 // getMaterialName
00117 //-------------------------------------------------------------------------
00118 template< typename Type >
00119 Ogre::String MaterialAnimator< Type >::getMaterialName( const Ogre::String& name ) const 
00120 { 
00121   return  _materialName ;
00122 }
00123 
00124 //-------------------------------------------------------------------------
00125 // undo
00126 //-------------------------------------------------------------------------
00127 template< typename Type >
00128 void MaterialAnimator< Type >::undo( NodeMaterial* node ) 
00129 {
00130   // must do nothing
00131   // the default destroy the material !!!
00132 }
00133 
00134 //-------------------------------------------------------------------------
00135 // Specific instanciations of selfProcessVis 
00136 //-------------------------------------------------------------------------
00137 namespace OMK
00138 {
00139 namespace Vis
00140 {
00141 // selfProcessVis for string
00142 template<>
00143 void MaterialAnimator< OMK::Type::StringType >::selfProcessVis( const OMK::Type::StringType& value ) 
00144 {
00145   OMTRACEID("OMK::MaterialAnimator"," got " << value );
00146   std::string str( value.getValue() ) ;
00147   std::transform( str.begin(), str.end(), str.begin(), toupper ) ;
00148   bool newModified = !_modified ;
00149   if( str == "ON" )
00150   {
00151     newModified = true ;
00152   }
00153   else if( str == "OFF" )
00154   {
00155     newModified = false ;
00156   }
00157   doIt( newModified ) ;
00158 }
00159 // selfProcessVis for bool
00160 template<>
00161 void MaterialAnimator< OMK::Type::BoolType >::selfProcessVis( const OMK::Type::BoolType& value ) 
00162 {
00163   OMTRACEID("OMK::MaterialAnimator"," got " << value );
00164   doIt( value.getValue() ) ;
00165 }
00166 } //namespace OMK
00167 } //namespace Vis
00168 //-------------------------------------------------------------------------
00169 

logo OpenMask

Documentation generated on Mon Jun 9 11:45:56 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007