All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ChunkedLcmTerrainBuilder.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "IResourceBuilder.h"
7 #include "Rendering.h"
8 #include "Terrain.h"
9 #include "Helpers.h"
10 #include "ChunkedFileFormat.h"
11 #include "Space.h"
12 #include "Graphics.h"
13 #include "Collision.h"
14 #include "CollisionBvhFactory.h"
15 #include "AsyncTexturing.h"
16 #include "Config.h"
17 #include "ISceneElementInGraphObserver.h"
18 
19 #include <string>
20 #include <vector>
21 
22 namespace Eegeo
23 {
24  namespace Resources
25  {
26  namespace Terrain
27  {
28  namespace lcm
29  {
31  {
32  int lcmCode;
34 
37  : lcmCode(lcm)
38  , renderable(renderable)
39  {
40  }
41  };
42 
44  {
46  : pTerrainCollisionBvh(NULL)
47  , pTreesCollisionBvh(NULL)
48  , needsLegacyTerrainCollisionFixup(false)
49  , pAsyncTexture(NULL)
50  , nodeDepth(0)
51  {
52  }
53 
55 
56  void Clear();
57 
58  Eegeo::Collision::CollisionBvh* pTerrainCollisionBvh;
59  Eegeo::Collision::CollisionBvh* pTreesCollisionBvh;
60 
61  bool needsLegacyTerrainCollisionFixup;
62 
63  std::vector<LcmRenderableItemBuilderOutput> renderables;
64  std::vector<std::string> renderableNames;
65 
67 
68  int nodeDepth;
69  std::string keyString;
70  };
71 
73  {
74  Rendering::MeshFactories::PackedTwoTextureDiffuseMeshFactory& m_packedTwoTextureDiffuseMeshFactory;
76  Rendering::IMeshUploadService* m_pMeshUploadService;
77 
78  Heights::TerrainHeightRepository& m_terrainHeightRepository;
79  Eegeo::Collision::CollisionMeshResourceRepository& m_terrainCollisionMeshResourceRepository;
80  Eegeo::Collision::CollisionMeshResourceRepository& m_treesCollisionMeshResourceRepository;
82  Rendering::AsyncTexturing::IAsyncTexture* m_placeholderGlowmap;
83  Rendering::IMaterialProvider& m_materialProvider;
86 
87  Eegeo::Collision::CollisionBvhFactory m_terrainCollisionBvhFactory;
88  Eegeo::Collision::CollisionBvhFactory m_treesCollisionBvhFactory;
89 
90  const bool m_generateTreesCollision;
91  const bool m_alwaysUseHighFidelityWaterShader;
92 
93  const Config::ResourceBuilderConfigSection& m_resourceBuilderConfig;
96 
97  bool m_createGlowmaps;
98 
99  public:
101  Rendering::MeshFactories::PackedTwoTextureDiffuseMeshFactory& packedTwoTextureDiffuseMeshFactory,
103  Rendering::IMeshUploadService* pMeshUploadService,
104  Heights::TerrainHeightRepository& terrainHeightRepository,
105  Eegeo::Collision::CollisionMeshResourceRepository& terrainCollisionMeshResourceRepository,
106  Eegeo::Collision::CollisionMeshResourceRepository& treesCollisionMeshResourceRepository,
108  Rendering::AsyncTexturing::IAsyncTexture* placeholderGlowmap,
110  Rendering::IMaterialProvider& materialProvider,
112  const bool generateTreesCollision,
113  const bool alwaysUseHighFidelityWaterShader,
114  const Config::ResourceBuilderConfigSection& resourceBuilderConfig,
117 
119  virtual void SetCreateGlowmaps(bool createGlowmaps);
120  virtual bool Flush(const Streaming::MortonKey& key, void* input, TBuiltResources& result);
121  virtual void DestroyBuiltResource(const Streaming::MortonKey& key, void* input);
122  virtual void* BuildResource(const Streaming::MortonKey& key, const Byte* data, size_t length);
123  virtual bool AcceptsErroredRequests()
124  {
125  return true;
126  }
127  private:
128  Rendering::AsyncTexturing::IAsyncTexture& LoadGlowmapTextureChunk(IO::ChunkedFileFormat::ChunkStream& chunkStream, BinaryParsing::membuf& streamBuf, const std::string& textureName);
129 
130  void BuildLcmTerrainFromQuantizedMeshSet(IO::ChunkedFileFormat::ChunkStream& chunkStream,
131  BinaryParsing::membuf& streamBuf,
132  const Space::CubeMap::CubeMapCellInfo& cellInfo,
133  ChunkedLcmTerrainBuilderOutput& builderOutput);
134 
135  void BuildTreesFromQuantizedMeshSet(IO::ChunkedFileFormat::ChunkStream& chunkStream,
136  BinaryParsing::membuf& streamBuf,
137  const Space::CubeMap::CubeMapCellInfo& cellInfo,
138  ChunkedLcmTerrainBuilderOutput& builderOutput);
139 
140  LcmRenderableItemBuilderOutput CreateRenderableItemBuilderOutputForTree(
141  const Space::CubeMap::CubeMapCellInfo& cellInfo,
143 
144  LcmRenderableItemBuilderOutput CreateRenderableItemBuilderOutputForLcmTerrain(
145  const Space::CubeMap::CubeMapCellInfo& cellInfo,
147 
148  LcmRenderableItemBuilderOutput CreateRenderableItemBuilderOutputForWater(
149  const Space::CubeMap::CubeMapCellInfo& cellInfo,
151 
152  public:
153  static int LcmCodeFromMaterialName(const std::string& materialName);
154  static bool IsWaterLcmCode(int lcmCode);
155  static bool IsLod(const Space::CubeMap::CubeMapCellInfo& cellInfo);
156  };
157  }
158  }
159  }
160 }