All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Model.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "Models.h"
7 #include "ModelMesh.h"
8 #include "Lighting.h"
9 #include "Rendering.h"
10 #include "ITextureFileLoader.h"
11 #include "IFileIO.h"
12 #include "AsyncTexturing.h"
13 #include "IAsyncTextureObserver.h"
14 
15 #include <vector>
16 #include <string>
17 
18 namespace Eegeo
19 {
20  namespace IO
21  {
22  namespace POD
23  {
24  class PODTexture;
25  class PODScene;
26  }
27  }
28 
29  class FrustumRadar;
30  class Node;
31  class SceneAnimator;
32 
33  enum
34  {
35  kModelLoadFlagNone = 0x00000000,
36  kModelLoadFlagPreLit = 0x00000001,
37 
38  kModelLoadFlagDefault = kModelLoadFlagNone
39  };
40 
42  {
43  std::vector <ModelMesh*> m_pMeshList;
44  std::vector <Node*> m_pNodeList;
45 
46  typedef std::vector<Eegeo::Rendering::AsyncTexturing::IAsyncTexture*> TTextures;
47  TTextures m_textures;
48 
49  typedef std::vector <ModelMaterial*> TMaterialPtrVec;
50  TMaterialPtrVec m_pMaterialList;
51 
52  Node* m_pRootNode;
53  SceneAnimator* m_pAnimator;
54 
55  int m_numOfTexturesComplete;
56 
57  void AssignObjects();
58 
59  void UpdateMaterialTextures();
60 
61  static std::string GetTextureName(const IO::POD::PODTexture* podTexture);
62 
63  static void InitFromPODScene(Model& model, const IO::POD::PODScene& podScene, Eegeo::Rendering::AsyncTexturing::IAsyncTextureRequestor* pTextureRequestor, const std::string& texturePath, u32 modelLoadFlags, HeightCB createHeightData = NULL);
64 
65  public:
66 
67  Model();
68  ~Model ();
69 
70  void Update (void);
71  void UpdateAnimator (float dt);
72 
73  void Draw (Eegeo::Rendering::GLState& glState, Eegeo::Lighting::GlobalFogging& fogging, Eegeo::FrustumRadar* pFrustum = NULL, const bool drawSolid=true, const bool drawAlpha=true);
74 
75  Node* GetRootNode ();
76 
77  u32 GetNumNodes ();
78  Node* GetNode (u32 nodeIndex);
79  Node* FindNode (const char* nodeName);
80  Node* FindNode (u32 hash);
81 
82  ModelMaterial* GetMaterial (u32 materialIndex);
83  bool TryGetMaterialByName(const std::string& materialName, ModelMaterial*& out_pFoundMaterial) const;
84  u32 GetNumMaterials ();
85  u32 GetNumTextures () const;
86 
87 
88  void OnTextureLoadSuccess(const Rendering::AsyncTexturing::IAsyncTexture& loadedTexture);
89  void OnTextureLoadFail(const Rendering::AsyncTexturing::IAsyncTexture& loadedTexture);
90 
91  static Model* CreateFromPODScene(const IO::POD::PODScene& podScene, Eegeo::Rendering::AsyncTexturing::IAsyncTextureRequestor* pTextureRequestor, const std::string& texturePath);
92 
93  static Model* CreateFromPODStream(std::istream& stream, size_t size,
94  Eegeo::Rendering::AsyncTexturing::IAsyncTextureRequestor* pTextureRequestor, const std::string& texturePath);
95 
96  static Model* CreateFromBuffer(const std::vector<Byte>& buffer,
97  Eegeo::Rendering::AsyncTexturing::IAsyncTextureRequestor* pTextureRequestor, const std::string& texturePath);
98 
99  static Model* CreateFromPODFile(const char* filename, Helpers::IFileIO& fileIO, Eegeo::Rendering::AsyncTexturing::IAsyncTextureRequestor* pTextureRequestor, const std::string& texturePath);
100  };
101 }