1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#pragma once
#include "Configuration/UnityConfigure.h"
#if ENABLE_TERRAIN
#include "Runtime/Math/Vector2.h"
#include "Heightmap.h"
#include "Runtime/Serialize/SerializeUtility.h"
#include "Runtime/BaseClasses/BaseObject.h"
using std::vector;
class Texture2D;
class ColorRGBAf;
class TerrainData;
struct SplatPrototype
{
DECLARE_SERIALIZE (SplatPrototype)
PPtr<Texture2D> texture;
PPtr<Texture2D> normalMap;
Vector2f tileSize;
Vector2f tileOffset;
SplatPrototype ();
};
template<class TransferFunc>
void SplatPrototype::Transfer (TransferFunc& transfer)
{
TRANSFER (texture);
TRANSFER (normalMap);
TRANSFER (tileSize);
TRANSFER (tileOffset);
}
class SplatDatabase {
public:
DECLARE_SERIALIZE (SplatDatabase)
SplatDatabase (TerrainData *owner);
~SplatDatabase();
void AwakeFromLoad (AwakeFromLoadMode mode);
void Init (int splatResolution, int basemapResolution);
void GetSplatTextures (vector<Texture2D*> *dest);
int GetAlphamapResolution () { return m_AlphamapResolution; }
int GetBaseMapResolution () { return m_BaseMapResolution; }
int GetDepth () const {return m_Splats.size (); }
void SetAlphamapResolution (int res);
void SetBaseMapResolution (int res);
// Extract a copy of the alpha map in the given area
void GetAlphamaps (int xBase, int yBase, int width, int height, float* buffer);
// Set alpha map in the given area
void SetAlphamaps (int xBase, int yBase, int width, int height, float* buffer);
// Extract whole alpha map, as byte weights
void GetAlphamaps (dynamic_array<UInt8>& buffer);
// NOT IMPLEMENTED void SetResolution (int width, int height);
Texture2D *GetAlphaTexture (int index);
int GetAlphaTextureCount () { return m_AlphaTextures.size(); }
const vector<SplatPrototype> &GetSplatPrototypes () const { return m_Splats; }
void SetSplatPrototypes (const vector<SplatPrototype> &splats );
Texture2D* GetBasemap();
void UploadBasemap();
bool RecalculateBasemapIfDirty();
void RecalculateBasemap(bool allowUpload);
void SetBasemapDirty(bool dirty) { m_BaseMapDirty = dirty; }
private:
Texture2D *AllocateAlphamap (const ColorRGBAf &color);
vector<SplatPrototype> m_Splats;
vector<PPtr<Texture2D> > m_AlphaTextures;
Texture2D* m_BaseMap;
TerrainData* m_TerrainData;
int m_AlphamapResolution;
int m_BaseMapResolution;
bool m_BaseMapDirty;
};
template<class TransferFunc>
void SplatDatabase::Transfer (TransferFunc& transfer)
{
TRANSFER (m_Splats);
TRANSFER (m_AlphaTextures);
TRANSFER (m_AlphamapResolution);
TRANSFER (m_BaseMapResolution);
}
struct MonoSplatPrototype
{
ScriptingObjectPtr texture;
ScriptingObjectPtr normalMap;
Vector2f tileSize;
Vector2f tileOffset;
};
void SplatPrototypeToMono (const SplatPrototype &src, MonoSplatPrototype &dest);
void SplatPrototypeToCpp (MonoSplatPrototype &src, SplatPrototype &dest);
#endif // ENABLE_TERRAIN
|