This repository has been 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
/
Copy pathPQSMod_VertexHeightNoise.cs
72 lines (66 loc) · 2.14 KB
/
PQSMod_VertexHeightNoise.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
/**
* libpqsmods - A standalone implementation of KSP's PQSMods
* Copyright (c) Thomas P. 2016
* Licensed under the terms of the MIT license
*/
using LibNoise;
using LibNoise.Generator;
using System;
using ProceduralQuadSphere.Unity;
namespace ProceduralQuadSphere
{
/// <summary>
/// PQSMod that applies height based on a noise generator
/// </summary>
/// <seealso cref="PQSMod" />
public class PQSMod_VertexHeightNoise : PQSMod
{
public enum NoiseType
{
Perlin,
RiggedMultifractal,
Billow
}
/// <summary>
/// The type of the noise that gets used.
/// </summary>
public NoiseType noiseType;
#region Noise Values
public Single deformity;
public Int32 seed;
public Single frequency;
public Single lacunarity;
public Single persistance;
public Int32 octaves;
public QualityMode mode;
private ModuleBase noiseMap;
#endregion
/// <summary>
/// Initializes the base mod
/// </summary>
public override void OnSetup()
{
switch (noiseType)
{
case NoiseType.Perlin:
noiseMap = new Perlin(frequency, lacunarity, persistance, octaves, seed, mode);
break;
case NoiseType.Billow:
noiseMap = new Billow(frequency, lacunarity, persistance, octaves, seed, mode);
break;
case NoiseType.RiggedMultifractal:
noiseMap = new RidgedMultifractal(frequency, lacunarity, octaves, seed, mode);
break;
default:
throw new ArgumentException("Noise Type seems to be something undefineable. You are a scrub.", nameof(noiseType));
}
}
/// <summary>
/// Called when the parent sphere builds it's height
/// </summary>
public override void OnVertexBuildHeight(VertexBuildData data)
{
data.vertHeight += noiseMap.GetValue(data.directionFromCenter) * deformity;
}
}
}