OpenMW
|
00001 /* 00002 OpenMW - The completely unofficial reimplementation of Morrowind 00003 Copyright (C) 2008-2010 Nicolay Korslund 00004 Email: < korslund@gmail.com > 00005 WWW: http://openmw.sourceforge.net/ 00006 00007 This file (ogre_nif_loader.h) is part of the OpenMW package. 00008 00009 OpenMW is distributed as free software: you can redistribute it 00010 and/or modify it under the terms of the GNU General Public License 00011 version 3, as published by the Free Software Foundation. 00012 00013 This program is distributed in the hope that it will be useful, but 00014 WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 version 3 along with this program. If not, see 00020 http://www.gnu.org/licenses/ . 00021 00022 */ 00023 00024 #ifndef OPENMW_COMPONENTS_NIFOGRE_OGRENIFLOADER_HPP 00025 #define OPENMW_COMPONENTS_NIFOGRE_OGRENIFLOADER_HPP 00026 00027 #include <OgreResource.h> 00028 #include <OgreMaterial.h> 00029 #include <OgreController.h> 00030 00031 #include <vector> 00032 #include <string> 00033 #include <map> 00034 00035 00036 // FIXME: This namespace really doesn't do anything Nif-specific. Any supportable 00037 // model format should go through this. 00038 namespace NifOgre 00039 { 00040 00044 class MaterialControllerManager 00045 { 00046 public: 00047 ~MaterialControllerManager(); 00048 00050 Ogre::MaterialPtr getWritableMaterial (Ogre::MovableObject* movable); 00051 00052 private: 00053 std::map<Ogre::MovableObject*, Ogre::MaterialPtr> mClonedMaterials; 00054 }; 00055 00056 typedef std::multimap<float,std::string> TextKeyMap; 00057 static const char sTextKeyExtraDataID[] = "TextKeyExtraData"; 00058 struct ObjectScene { 00059 Ogre::Entity *mSkelBase; 00060 std::vector<Ogre::Entity*> mEntities; 00061 std::vector<Ogre::ParticleSystem*> mParticles; 00062 std::vector<Ogre::Light*> mLights; 00063 00064 // Nodes that should always face the camera when rendering 00065 std::vector<Ogre::Node*> mBillboardNodes; 00066 00067 Ogre::SceneManager* mSceneMgr; 00068 00069 // The maximum length on any of the controllers. For animations with controllers, but no text keys, consider this the animation length. 00070 float mMaxControllerLength; 00071 00072 std::map<int,TextKeyMap> mTextKeys; 00073 00074 MaterialControllerManager mMaterialControllerMgr; 00075 00076 std::vector<Ogre::Controller<Ogre::Real> > mControllers; 00077 00078 ObjectScene(Ogre::SceneManager* sceneMgr) : mSkelBase(0), mMaxControllerLength(0), mSceneMgr(sceneMgr) 00079 { } 00080 00081 ~ObjectScene(); 00082 00083 // Rotate nodes in mBillboardNodes so they face the given camera 00084 void rotateBillboardNodes(Ogre::Camera* camera); 00085 }; 00086 00087 typedef Ogre::SharedPtr<ObjectScene> ObjectScenePtr; 00088 00089 00090 class Loader 00091 { 00092 public: 00093 static ObjectScenePtr createObjects(Ogre::Entity *parent, const std::string &bonename, 00094 Ogre::SceneNode *parentNode, 00095 std::string name, 00096 const std::string &group="General"); 00097 00098 static ObjectScenePtr createObjects(Ogre::SceneNode *parentNode, 00099 std::string name, 00100 const std::string &group="General"); 00101 00102 static ObjectScenePtr createObjectBase(Ogre::SceneNode *parentNode, 00103 std::string name, 00104 const std::string &group="General"); 00105 00106 static void createKfControllers(Ogre::Entity *skelBase, 00107 const std::string &name, 00108 TextKeyMap &textKeys, 00109 std::vector<Ogre::Controller<Ogre::Real> > &ctrls); 00110 }; 00111 00112 // FIXME: Should be with other general Ogre extensions. 00113 template<typename T> 00114 class NodeTargetValue : public Ogre::ControllerValue<T> 00115 { 00116 protected: 00117 Ogre::Node *mNode; 00118 00119 public: 00120 NodeTargetValue(Ogre::Node *target) : mNode(target) 00121 { } 00122 00123 virtual Ogre::Quaternion getRotation(T value) const = 0; 00124 virtual Ogre::Vector3 getTranslation(T value) const = 0; 00125 virtual Ogre::Vector3 getScale(T value) const = 0; 00126 00127 void setNode(Ogre::Node *target) 00128 { mNode = target; } 00129 Ogre::Node *getNode() const 00130 { return mNode; } 00131 }; 00132 typedef Ogre::SharedPtr<NodeTargetValue<Ogre::Real> > NodeTargetValueRealPtr; 00133 00134 } 00135 00136 #endif