-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathTerrain.bindings.cs
414 lines (320 loc) · 14.6 KB
/
Terrain.bindings.cs
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
using UnityEngine.Bindings;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Scripting;
using System.Runtime.InteropServices;
namespace UnityEngine
{
// List of changes done to the terrain for OnTerrainChanged
// OnTerrainChanged is called with a bitfield of these items telling it what was changed.
[Flags]
public enum TerrainChangedFlags
{
Heightmap = 1,
TreeInstances = 2,
DelayedHeightmapUpdate = 4,
FlushEverythingImmediately = 8,
RemoveDirtyDetailsImmediately = 16,
HeightmapResolution = 32,
Holes = 64,
DelayedHolesUpdate = 128,
WillBeDestroyed = 256,
}
[Flags]
public enum TerrainRenderFlags
{
[Obsolete("TerrainRenderFlags.heightmap is obsolete, use TerrainRenderFlags.Heightmap instead. (UnityUpgradable) -> Heightmap")]
heightmap = 1,
[Obsolete("TerrainRenderFlags.trees is obsolete, use TerrainRenderFlags.Trees instead. (UnityUpgradable) -> Trees")]
trees = 2,
[Obsolete("TerrainRenderFlags.details is obsolete, use TerrainRenderFlags.Details instead. (UnityUpgradable) -> Details")]
details = 4,
[Obsolete("TerrainRenderFlags.all is obsolete, use TerrainRenderFlags.All instead. (UnityUpgradable) -> All")]
all = All,
Heightmap = 1,
Trees = 2,
Details = 4,
All = Heightmap | Trees | Details
}
[UsedByNativeCode]
[NativeHeader("Modules/Terrain/Public/Terrain.h")]
[NativeHeader("Runtime/Interfaces/ITerrainManager.h")]
[NativeHeader("TerrainScriptingClasses.h")]
[StaticAccessor("GetITerrainManager()", StaticAccessorType.Arrow)]
public sealed partial class Terrain : Behaviour
{
extern public TerrainData terrainData { get; set; }
extern public float treeDistance { get; set; }
extern public float treeBillboardDistance { get; set; }
extern public float treeCrossFadeLength { get; set; }
extern public int treeMaximumFullLODCount { get; set; }
extern public float detailObjectDistance { get; set; }
extern public float detailObjectDensity { get; set; }
extern public float heightmapPixelError { get; set; }
extern public int heightmapMaximumLOD { get; set; }
extern public int heightmapMinimumLODSimplification { get; set; }
extern public float basemapDistance { get; set; }
[NativeProperty("StaticLightmapIndexInt")]
extern public int lightmapIndex { get; set; }
[NativeProperty("DynamicLightmapIndexInt")]
extern public int realtimeLightmapIndex { get; set; }
[NativeProperty("StaticLightmapST")]
extern public Vector4 lightmapScaleOffset { get; set; }
[NativeProperty("DynamicLightmapST")]
extern public Vector4 realtimeLightmapScaleOffset { get; set; }
[Obsolete("Terrain.freeUnusedRenderingResources is obsolete; use keepUnusedRenderingResources instead.")]
[NativeProperty("FreeUnusedRenderingResourcesObsolete")]
extern public bool freeUnusedRenderingResources { get; set; }
[NativeProperty("KeepUnusedRenderingResources")]
extern public bool keepUnusedRenderingResources { get; set; }
extern public bool GetKeepUnusedCameraRenderingResources(int cameraInstanceID);
extern public void SetKeepUnusedCameraRenderingResources(int cameraInstanceID, bool keepUnused);
extern public ShadowCastingMode shadowCastingMode { get; set; }
extern public ReflectionProbeUsage reflectionProbeUsage { get; set; }
extern public void GetClosestReflectionProbes(List<ReflectionProbeBlendInfo> result);
extern public Material materialTemplate { get; set; }
extern public bool drawHeightmap { get; set; }
extern public bool allowAutoConnect { get; set; }
extern public int groupingID { get; set; }
extern public bool drawInstanced { get; set; }
extern public bool enableHeightmapRayTracing { get; set; }
extern public RenderTexture normalmapTexture { [NativeMethod("TryGetNormalMapTexture")] get; }
extern public bool drawTreesAndFoliage { get; set; }
extern public Vector3 patchBoundsMultiplier { get; set; }
extern public float SampleHeight(Vector3 worldPosition);
extern public void AddTreeInstance(TreeInstance instance);
extern public void SetNeighbors(Terrain left, Terrain top, Terrain right, Terrain bottom);
extern public float treeLODBiasMultiplier { get; set; }
extern public bool collectDetailPatches { get; set; }
extern public bool ignoreQualitySettings { get; set; }
extern public TerrainRenderFlags editorRenderFlags { get; set; }
extern public Vector3 GetPosition();
extern public void Flush();
extern internal void RemoveTrees(Vector2 position, float radius, int prototypeIndex);
[NativeMethod("CopySplatMaterialCustomProps")]
extern public void SetSplatMaterialPropertyBlock(MaterialPropertyBlock properties);
public void GetSplatMaterialPropertyBlock(MaterialPropertyBlock dest)
{
if (dest == null)
throw new ArgumentNullException("dest");
Internal_GetSplatMaterialPropertyBlock(dest);
}
[NativeMethod("GetSplatMaterialCustomProps")]
extern private void Internal_GetSplatMaterialPropertyBlock(MaterialPropertyBlock dest);
extern public bool bakeLightProbesForTrees { get; set; }
extern public bool deringLightProbesForTrees { get; set; }
extern public TreeMotionVectorModeOverride treeMotionVectorModeOverride { get; set; }
extern public bool preserveTreePrototypeLayers { get; set; }
[StaticAccessor("Terrain", StaticAccessorType.DoubleColon)]
extern static public GraphicsFormat heightmapFormat { get; }
static public TextureFormat heightmapTextureFormat
{
get { return GraphicsFormatUtility.GetTextureFormat(heightmapFormat); }
}
static public RenderTextureFormat heightmapRenderTextureFormat
{
get { return GraphicsFormatUtility.GetRenderTextureFormat(heightmapFormat); }
}
[StaticAccessor("Terrain", StaticAccessorType.DoubleColon)]
extern static public GraphicsFormat normalmapFormat { get; }
static public TextureFormat normalmapTextureFormat
{
get { return GraphicsFormatUtility.GetTextureFormat(normalmapFormat); }
}
static public RenderTextureFormat normalmapRenderTextureFormat
{
get { return GraphicsFormatUtility.GetRenderTextureFormat(normalmapFormat); }
}
[StaticAccessor("Terrain", StaticAccessorType.DoubleColon)]
extern static public GraphicsFormat holesFormat { get; }
static public RenderTextureFormat holesRenderTextureFormat
{
get { return GraphicsFormatUtility.GetRenderTextureFormat(holesFormat); }
}
[StaticAccessor("Terrain", StaticAccessorType.DoubleColon)]
extern static public GraphicsFormat compressedHolesFormat { get; }
static public TextureFormat compressedHolesTextureFormat
{
get { return GraphicsFormatUtility.GetTextureFormat(compressedHolesFormat); }
}
extern public static Terrain activeTerrain { get; }
extern public static void SetConnectivityDirty();
[NativeProperty("ActiveTerrainsScriptingArray")]
extern public static Terrain[] activeTerrains { [return:Unmarshalled] get; }
public static void GetActiveTerrains(List<Terrain> terrainList)
{
Internal_FillActiveTerrainList(terrainList);
}
extern private static void Internal_FillActiveTerrainList([NotNull] object terrainList);
[UsedByNativeCode]
extern public static GameObject CreateTerrainGameObject(TerrainData assignTerrain);
extern public Terrain leftNeighbor { get; }
extern public Terrain rightNeighbor { get; }
extern public Terrain topNeighbor { get; }
extern public Terrain bottomNeighbor { get; }
extern public UInt32 renderingLayerMask { get; set; }
}
public static partial class TerrainExtensions
{
public static void UpdateGIMaterials(this Terrain terrain)
{
if (terrain.terrainData == null)
throw new ArgumentException("Invalid terrainData.");
UpdateGIMaterialsForTerrain(terrain.GetInstanceID(), new Rect(0, 0, 1, 1));
}
public static void UpdateGIMaterials(this Terrain terrain, int x, int y, int width, int height)
{
if (terrain.terrainData == null)
throw new ArgumentException("Invalid terrainData.");
float alphamapWidth = terrain.terrainData.alphamapWidth;
float alphamapHeight = terrain.terrainData.alphamapHeight;
UpdateGIMaterialsForTerrain(terrain.GetInstanceID(), new Rect(x / alphamapWidth, y / alphamapHeight, width / alphamapWidth, height / alphamapHeight));
}
[FreeFunction]
[NativeConditional("INCLUDE_DYNAMIC_GI && ENABLE_RUNTIME_GI")]
extern internal static void UpdateGIMaterialsForTerrain(int terrainInstanceID, Rect uvBounds);
}
[NativeHeader("Modules/Terrain/Public/Tree.h")]
[ExcludeFromPreset]
public sealed partial class Tree : Component
{
[NativeProperty("TreeData")]
extern public ScriptableObject data { get; set; }
extern public bool hasSpeedTreeWind
{
[NativeMethod("HasSpeedTreeWind")]
get;
}
[NativeProperty("SpeedTreeWindAsset")]
extern public SpeedTreeWindAsset windAsset
{
[NativeMethod("GetSpeedTreeWind")]
get;
[NativeMethod("SetSpeedTreeWind")]
set;
}
}
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct SpeedTreeWindConfig9
{
public float strengthResponse;
public float directionResponse;
public float gustFrequency;
public float gustStrengthMin;
public float gustStrengthMax;
public float gustDurationMin;
public float gustDurationMax;
public float gustRiseScalar;
public float gustFallScalar;
// branch stretch limits + shared height start
public float branch1StretchLimit;
public float branch2StretchLimit;
// BranchWindLevel: Shared
public float sharedHeightStart;
public fixed float bendShared[20];
public fixed float oscillationShared[20];
public fixed float speedShared[20];
public fixed float turbulenceShared[20];
public fixed float flexibilityShared[20];
public float independenceShared;
// BranchWindLevel: Branch1
//BranchWindLevel m_sBranch1;
public fixed float bendBranch1[20];
public fixed float oscillationBranch1[20];
public fixed float speedBranch1[20];
public fixed float turbulenceBranch1[20];
public fixed float flexibilityBranch1[20];
public float independenceBranch1;
//BranchWindLevel m_sBranch2;
public fixed float bendBranch2[20];
public fixed float oscillationBranch2[20];
public fixed float speedBranch2[20];
public fixed float turbulenceBranch2[20];
public fixed float flexibilityBranch2[20];
public float independenceBranch2;
//RippleGroup m_sRipple;
public fixed float planarRipple[20];
public fixed float directionalRipple[20];
public fixed float speedRipple[20];
public fixed float flexibilityRipple[20];
public float independenceRipple;
public float shimmerRipple;
public float treeExtentX;
public float treeExtentY;
public float treeExtentZ;
public float windIndependence;
public int doShared;
public int doBranch1;
public int doBranch2;
public int doRipple;
public int doShimmer;
public int lodFade;
public float importScale;
public SpeedTreeWindConfig9()
{
// defaults from SpeedTree SDK example headers
strengthResponse = 5.0f;
directionResponse = 2.5f;
gustFrequency = 0.0f;
gustStrengthMin = 0.5f;
gustStrengthMax = 1.0f;
gustDurationMin = 1.0f;
gustDurationMax = 4.0f;
gustRiseScalar = 1.0f;
gustFallScalar = 1.0f;
branch1StretchLimit = 1.0f;
branch2StretchLimit = 1.0f;
sharedHeightStart = 0.0f;
independenceShared = 0.0f;
independenceBranch1 = 0.0f;
independenceBranch2 = 0.0f;
independenceRipple = 0.0f;
shimmerRipple = 0.0f;
windIndependence = 0.0f;
treeExtentX = 0.0f;
treeExtentY = 0.0f;
treeExtentZ = 0.0f;
doShared = 0 /*false */;
doBranch1 = 0 /*false */;
doBranch2 = 0 /*false */;
doRipple = 0 /*false */;
doShimmer = 0 /*false */;
lodFade = 0 /*false */;
importScale = 1.0f;
}
public readonly bool IsWindEnabled => (doShared != 0 || doBranch1 != 0 || doBranch2 != 0 || doRipple != 0);
static public byte[] Serialize(SpeedTreeWindConfig9 config)
{
int size = Marshal.SizeOf(config);
byte[] data = new byte[size];
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
try
{
IntPtr ptr = handle.AddrOfPinnedObject();
Marshal.StructureToPtr(config, ptr, false);
}
finally
{
handle.Free();
}
return data;
}
};
[NativeHeader("Modules/Terrain/Public/SpeedTreeWind.h")]
[ExcludeFromPreset] // ?
public partial class SpeedTreeWindAsset : Object
{
extern public int Version { get; set; }
internal SpeedTreeWindAsset(int version, SpeedTreeWindConfig9 config)
{
Internal_Create(this, version, SpeedTreeWindConfig9.Serialize(config));
}
[NativeThrows]
static extern void Internal_Create([Writable] SpeedTreeWindAsset notSelf, int version, byte[] data);
}
}