forked from JTippetts/U3DTerrainEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BindTerrainEdit.pkg
223 lines (180 loc) · 9.03 KB
/
BindTerrainEdit.pkg
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
$#include <Urho3D/LuaScript/ToluaUtils.h>
$#include "TerrainEdit.h"
$#include "NodeGraphLink.h"
$using namespace Urho3D;
$using namespace anl;
struct BrushSettings
{
float radius, max, power, hardness;
BrushSettings();
BrushSettings(float r, float mx, float p, float h);
};
struct MaskSettings
{
bool usemask0, usemask1, usemask2;
bool invertmask0, invertmask1, invertmask2;
MaskSettings();
MaskSettings(bool um0, bool im0, bool um1, bool im1, bool um2, bool im2);
};
class TerrainEdit// : public Object
{
//URHO3D_OBJECT(TerrainEdit, Object);
public:
//TerrainEdit(Context *context);
TerrainEdit();
~TerrainEdit();
bool Initialize(Scene *scene, int tw, int th, int bw, int bh, Vector3 spacing, bool use16bit=true);
void SetTerrainSize(int w, int h, Vector3 spacing, bool use16bit=true);
void SetBlendMaskSize(int w, int h);
void SetTerrainSpacing(Vector3 spacing);
Vector2 WorldToNormalized(Vector3 world);
Vector3 NormalizedToWorld(Vector2 normalized);
IntVector2 WorldToTerrain(Vector3 world);
IntVector2 WorldToBlend(Vector3 world);
Vector3 TerrainToWorld(IntVector2 terrain);
Vector3 BlendToWorld(IntVector2 blend);
Vector2 TerrainToNormalized(IntVector2 terrain);
Vector2 BlendToNormalized(IntVector2 blend);
IntVector2 NormalizedToBlend(Vector2 norm);
IntVector2 NormalizedToTerrain(Vector2 norm);
void SetHeightValue(int x, int y, float val);
float GetHeightValue(int x, int y);
float GetHeightValue(Vector3 worldpos);
float GetHeightValueFromNormalized(Vector2 nrm);
void GetHeightMap(CArray2Dd &buffer);
int GetTerrainWidth();
int GetTerrainHeight();
int GetBlendWidth();
int GetBlendHeight();
void SetHeightBuffer(CArray2Dd &buffer, MaskSettings &masksettings);
void SetLayerBuffer(CArray2Dd &buffer, int layer, MaskSettings &masksettings);
void SetLayerBufferMax(CArray2Dd &buffer, int layer, MaskSettings &masksettings);
void BlendHeightBuffer(CArray2Dd &buffer, CArray2Dd &blend, MaskSettings &masksettings);
void SetMaskBuffer(CArray2Dd &buffer, int which);
void ApplyHeightBrush(float x, float z, float dt, BrushSettings &brush, MaskSettings &masksettings);
void ApplyBlendBrush(float x, float z, int layer, float dt, BrushSettings &brush, MaskSettings &masksettings);
void ApplyMaskBrush(float x, float z, int which, float dt, BrushSettings &brush, MaskSettings &masksettings);
void ApplySmoothBrush(float x, float z, float dt, BrushSettings &brush, MaskSettings &masksettings);
void SetBrushCursorHeight(CustomGeometry *brush, float groundx, float groundz);
void InvertMask(int which);
void ClearMask(int which);
void ClearAllMasks();
void InvertLayer(int which);
void ClearLayer(int which);
void ClearAllLayers();
void InvertHeight();
void ClearHeight();
Material *GetMaterial();
Terrain *GetTerrain();
void SetMaterialSettings(bool triplanar, bool smoothing, bool normalmapping, bool reduce);
void SaveHeightMap(const String &filename);
void SaveBlend0(const String &filename);
void SaveBlend1(const String &filename);
void SaveMask(const String &filename);
void LoadHeightMap(const String &filename);
void LoadBlend0(const String &filename);
void LoadBlend1(const String &filename);
void LoadMask(const String &filename);
void GetSteepness(CArray2Dd &buffer, float threshold, float fade);
void GetCavityMap(CArray2Dd &buffer, float sampleradius, float scale, float bias, float intensity, unsigned int iterations);
Vector3 GetTerrainSpacing();
void SaveTerrainNormalMap(const String &filename);
};
Vector2 WorldToNormalized(Image *height, Terrain *terrain, Vector3 world);
Vector3 NormalizedToWorld(Image *height, Terrain *terrain, Vector2 normalized);
void SetHeightValue(Image *height, int x, int y, float val);
float GetHeightValue(Image *height, int x, int y);
void ApplyHeightBrush(Terrain *terrain, Image *height, Image *mask, float x, float z, float radius, float max, float power, float hardness, bool usemask0, bool usemask1, bool usemask2, float dt);
void ApplyBlendBrush(Terrain *terrain, Image *height, Image *blend, Image *mask, float x, float z, float radius, float mx, float power, float hardness, int layer, bool usemask0, bool usemask1, bool usemask2, float dt);
void ApplyBlendBrush8(Terrain *terrain, Image *height, Image *blend0, Image *blend1, Image *mask, float x, float z, float radius, float mx, float power, float hardness, int layer, bool usemask0, bool usemask1, bool usemask2, float dt);
void ApplyMaskBrush(Terrain *terrain, Image *height, Image *mask, float x, float z, float radius, float mx, float power, float hardness, float dt, int which);
void ApplySmoothBrush(Terrain *terrain, Image *height, Image *mask, float x, float z, float radius, float max, float power, float hardness, bool usemask0, bool usemask1, bool usemask2, float dt);
void ApplySpeckleBrush(Terrain *terrain, Image *height, Image *color, Image *mask, float x, float z, float radius, float mx, float power, float hardness, Color c1, Color c2, bool usemask, float dt);
void SetBrushCursorHeight(Terrain *terrain, CustomGeometry *brush, float groundx, float groundz);
void InvertMask(Image *mask);
void RenderANLKernelToHeight(Image *height, Image *mask, CKernel *kernel, double lowRange=0, double highRange=1, bool useMask=false, bool invertMask=false);
struct RasterVertex
{
float x_, y_;
float val_;
RasterVertex();
RasterVertex(float x, float y, float val);
RasterVertex(const RasterVertex &rhs);
~RasterVertex();
};
class RasterVertexList
{
RasterVertexList();
RasterVertexList(int size, RasterVertex value);
RasterVertexList(int size);
RasterVertexList(const RasterVertexList& a);
~RasterVertexList();
inline int size();
inline int capacity();
inline int bytes();
void fill(RasterVertex val);
void swap(RasterVertexList& a);
RasterVertex &at(int i);
void resize(int width);
void reserve(int cap);
inline bool empty();
inline void push_back(const RasterVertex& value);
const RasterVertex& front() const;
const RasterVertex& back() const;
};
void RasterizeTriangle(CArray2Dd *buffer, RasterVertex v1, RasterVertex v2, RasterVertex v3);
void RasterizeQuadStrip(CArray2Dd *buffer, RasterVertexList *strip);
void BlendHeightWithRasterizedBuffer(Image *height, CArray2Dd *buffer, CArray2Dd *blend, Image *mask=0, bool useMask=false, bool invertMask=false);
void BlendColorWithRasterizedBuffer(Image *img, CArray2Dd *buffer, Color endColor, Image *mask=0, bool useMask=false, bool invertMask=false);
void BlendRasterizedBuffer8(Image *img, Image *other, CArray2Dd *buffer, int layer, Image *mask=0, bool useMask=false, bool invertMask=false);
void BlendRasterizedBuffer8Max(Image *img, Image *other, CArray2Dd *buffer, int layer, Image *mask=0, bool useMask=false, bool invertMask=false);
void TessellateLineList(RasterVertexList *in, RasterVertexList *out, int steps);
void ApplyBedFunction(CArray2Dd *buffer, float hardness, bool quintic);
void BuildQuadStrip(RasterVertexList *in, RasterVertexList *out, float width);
void BuildQuadStripVarying(RasterVertexList *in, RasterVertexList *out, float startwidth, float endwidth);
void RenderANLKernelToBuffer(CArray2Dd *buffer, CKernel *kernel, float lowrange=0, float highrange=1);
void RenderANLKernelToImage(Image *buffer, CKernel *kernel, float lowrange, float highrange);
void SetHeightFromRasterBuffer(Image *height, CArray2Dd *buffer, Image *mask=0, bool useMask=false, bool invertMask=false);
void CopyImageInto(Image *dest, Image *src, int x, int y);
bool IsPowerOfTwo(int n);
Image* GetNextImageLevel(Image *i);
void ExtractLayerToBuffer(Image *blend1, Image *blend2, CArray2Dd *buffer, int layer);
float GetLayerBlend(Image *blend1, Image *blend2, int x, int y, int layer);
void SetLayerBlend(Image *blend1, Image *blend2, int x, int y, int layer, float v);
bool LoadImage(Context *c, Image *i, const char *fname);
void DistortBuffer(CArray2Dd *buffer, CArray2Dd *xd, CArray2Dd *yd, double power);
void SteepnessTerrain(Image *blend0, Image *blend1, Image *hmap, Terrain *terrain, Image *mask, float threshold, float fade, unsigned int layer, bool usemask, bool invertmask);
class NodeGraphLinkSource : public Button
{
//NodeGraphLink *CreateLink(NodeGraphLinkDest *target);
void AddLink(NodeGraphLink *link);
void RemoveLink(NodeGraphLinkDest *target);
void RemoveLink(NodeGraphLink *link);
int GetNumLinks();
NodeGraphLink *GetLink(int which);
NodeGraphLink *GetLink(NodeGraphLinkDest *target);
void SetRoot(UIElement *root);
void ClearRoot();
UIElement *GetRoot();
};
class NodeGraphLinkDest : public Button
{
void SetLink(NodeGraphLink *link);
void ClearLink();
NodeGraphLink *GetLink();
};
class NodeGraphLink : public Object
{
void SetSource(NodeGraphLinkSource *src);
void ClearSource();
void SetTarget(NodeGraphLinkDest *dest);
void ClearTarget();
NodeGraphLinkSource *GetSource();
NodeGraphLinkDest *GetTarget();
void SetImageRect(IntRect &rect);
};
class NodeGraphLinkPane : public BorderImage
{
NodeGraphLink *CreateLink(NodeGraphLinkSource *source, NodeGraphLinkDest *target);
void RemoveLink(NodeGraphLink *link);
};