-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShapeGenerator.cs
49 lines (42 loc) · 1.46 KB
/
ShapeGenerator.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShapeGenerator {
ShapeSettings settings;
INoiseFilter[] noiseFilters;
public MinMax elevationMinMax;
public void UpdateSettings(ShapeSettings settings)
{
this.settings = settings;
noiseFilters = new INoiseFilter[settings.noiseLayers.Length];
for (int i = 0; i < noiseFilters.Length; i++)
{
noiseFilters[i] = NoiseFilterFactory.CreateNoiseFilter(settings.noiseLayers[i].noiseSettings);
}
elevationMinMax = new MinMax();
}
public Vector3 CalculatePointOnPlanet(Vector3 pointOnUnitSphere)
{
float firstLayerValue = 0;
float elevation = 0;
if (noiseFilters.Length > 0)
{
firstLayerValue = noiseFilters[0].Evaluate(pointOnUnitSphere);
if (settings.noiseLayers[0].enabled)
{
elevation = firstLayerValue;
}
}
for (int i = 1; i < noiseFilters.Length; i++)
{
if (settings.noiseLayers[i].enabled)
{
float mask = (settings.noiseLayers[i].useFirstLayerAsMask) ? firstLayerValue : 1;
elevation += noiseFilters[i].Evaluate(pointOnUnitSphere) * mask;
}
}
elevation = settings.planetRadius * (1 + elevation);
elevationMinMax.AddValue(elevation);
return pointOnUnitSphere * elevation;
}
}