This repository was archived by the owner on Aug 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPQSMod_VertexHeightMapStep.cs
More file actions
76 lines (66 loc) · 2.22 KB
/
PQSMod_VertexHeightMapStep.cs
File metadata and controls
76 lines (66 loc) · 2.22 KB
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
/**
* libpqsmods - A standalone implementation of KSP's PQSMods
* Copyright (c) Thomas P. 2016
* Licensed under the terms of the MIT license
*/
using System;
using ProceduralQuadSphere.Unity;
using ProceduralQuadSphere.KSP;
namespace ProceduralQuadSphere
{
/// <summary>
/// The heightmap PQSMod. Gets the pixel data from a binary texture wrapper and returns it. (Costal Step)
/// </summary>
public class PQSMod_VertexHeightMapStep : PQSMod
{
/// <summary>
/// The height map for the mod
/// </summary>
public MapSO heightMap;
/// <summary>
/// How much should the calculated height get deformed
/// </summary>
public Double heightMapDeformity;
/// <summary>
/// A static offset that gets applied to all values
/// </summary>
public Double heightMapOffset;
/// <summary>
/// Whether the radius should influence the deformity parameter
/// </summary>
public Boolean scaleDeformityByRadius;
/// <summary>
/// A storage value for the final deformity
/// </summary>
private Double heightDeformity;
/// <summary>
/// The coast height
/// </summary>
public Double coastHeight;
/// <summary>
/// Initializes the base mod
/// </summary>
public override void OnSetup()
{
// Calculate the deformity
if (scaleDeformityByRadius)
heightDeformity = sphere.radius * heightMapDeformity;
else
heightDeformity = heightMapDeformity;
// Check whether the HeightMap exists
if (heightMap == null)
throw new ArgumentNullException(nameof(heightMap));
}
/// <summary>
/// Called when the parent sphere builds it's height
/// </summary>
public override void OnVertexBuildHeight(VertexBuildData data)
{
Double h = heightMap.GetPixelColor(data.u, data.v).grayscale;
if (h < coastHeight)
data.vertHeight += heightMapOffset;
else
data.vertHeight += heightMapOffset + h * heightDeformity;
}
}
}