00001 /****************************************************************************** 00002 * SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3 * 00003 * (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify it * 00006 * under the terms of the GNU General Public License as published by the Free * 00007 * Software Foundation; either version 2 of the License, or (at your option) * 00008 * any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, but WITHOUT * 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * 00013 * more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License along * 00016 * with this program; if not, write to the Free Software Foundation, Inc., 51 * 00017 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 00018 ******************************************************************************* 00019 * SOFA :: Applications * 00020 * * 00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,* 00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza, * 00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy * 00024 * * 00025 * Contact information: contact@sofa-framework.org * 00026 ******************************************************************************/ 00027 #ifndef OGREVISUALMODEL_H 00028 #define OGREVISUALMODEL_H 00029 00030 #include <Ogre.h> 00031 #include <sofa/gui/qt/viewer/qtogre/DotSceneLoader.h> 00032 00033 #include <sofa/defaulttype/Vec3Types.h> 00034 #include <sofa/core/VisualModel.h> 00035 #include <sofa/core/componentmodel/behavior/MappedModel.h> 00036 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h> 00037 #include <sofa/component/visualmodel/VisualModelImpl.h> 00038 // SOFA -> OGRE3D conversion 00039 00040 namespace sofa 00041 { 00042 00043 namespace component 00044 { 00045 00046 namespace visualmodel 00047 { 00048 template<class T> 00049 Ogre::Vector3 conv(const sofa::defaulttype::Vec<3,T>& v) 00050 { 00051 return Ogre::Vector3((float)v[0], (float)v[1], (float)v[2]); 00052 } 00053 00054 // SOFA <- OGRE3D conversion 00055 00056 template<class T> 00057 sofa::defaulttype::Vec3f conv(const Ogre::Vector3& v) 00058 { 00059 return sofa::defaulttype::Vec3f((float)v[0], (float)v[1], (float)v[2]); 00060 } 00061 00062 class OgreVisualModel : public sofa::component::visualmodel::VisualModelImpl//, public sofa::core::componentmodel::behavior::MappedModel<sofa::defaulttype::ExtVec3fTypes> 00063 { 00064 public: 00065 00066 static bool lightSwitched; 00067 Data<std::string> materialname; 00068 00069 00070 //Initial Position of a OgreVisualModel 00071 float dx,dy,dz,scale; 00072 00073 int meshRevision; 00074 00075 int getNbTriangles() 00076 { 00077 sofa::core::componentmodel::topology::BaseMeshTopology* topology = dynamic_cast<sofa::core::componentmodel::topology::BaseMeshTopology*>(getContext()->getTopology()); 00078 if (useTopology && topology) 00079 { 00080 return topology->getNbTriangles() + 2*topology->getNbQuads(); 00081 } 00082 else return (this->triangles.size() + 2*this->quads.size()); 00083 } 00084 00085 Ogre::MeshPtr ogreMesh; 00086 Ogre::Entity* ogreEntity; 00087 Ogre::SceneNode* ogreNode; 00088 00089 Ogre::HardwareVertexBufferSharedPtr vBuffer; 00090 Ogre::HardwareIndexBufferSharedPtr iBuffer; 00091 00092 OgreVisualModel(); 00093 00094 std::string getOgreName(); 00095 00096 00097 void parse(core::objectmodel::BaseObjectDescription* ); 00098 00099 void reinit(); 00100 00101 virtual void attach(Ogre::SceneManager* sceneMgr); 00102 00103 // GL method -> do nothing for Ogre 00104 virtual void draw() {} 00105 // GL method -> do nothing for Ogre 00106 virtual void initTextures() {} 00107 00108 virtual void updateVisual(); 00109 00110 00111 static int counter; 00112 protected: 00113 ResizableExtVector<Vec<2,float> > mirror_tex; 00114 void uploadVertices(); 00115 00116 void uploadIndices(); 00117 00118 void computeNormals(); 00119 00120 void computeBounds(); 00121 00122 void updateMaterial(Ogre::MaterialPtr &mat); 00123 std::string uniqueName(void); 00124 std::string submesh_material; 00125 }; 00126 } 00127 } 00128 } 00129 #endif
1.5.7.1