aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Barnett <noreply@jamesbarnett.xyz>2019-12-31 15:10:27 +0000
committerJames Barnett <noreply@jamesbarnett.xyz>2019-12-31 15:10:27 +0000
commit89e6b7e1fa7f27dcc6cd1b8e3b11fc445b73606a (patch)
tree82ba52cfcd02f149e18b9332a5dcc159b3ac324c
parent4bff7e3c56e2e7f1f769d560c8712be224682760 (diff)
downloadterrain-89e6b7e1fa7f27dcc6cd1b8e3b11fc445b73606a.tar.xz
terrain-89e6b7e1fa7f27dcc6cd1b8e3b11fc445b73606a.zip
Remove scaling type. Auto rotate camera
-rw-r--r--src/main/kotlin/GenerateOptions.kt2
-rw-r--r--src/main/kotlin/Terrain.kt69
-rw-r--r--src/main/resources/presets.json6
3 files changed, 28 insertions, 49 deletions
diff --git a/src/main/kotlin/GenerateOptions.kt b/src/main/kotlin/GenerateOptions.kt
index c97e9f4..0c3b44a 100644
--- a/src/main/kotlin/GenerateOptions.kt
+++ b/src/main/kotlin/GenerateOptions.kt
@@ -1,8 +1,6 @@
data class GenerateOptions (
var zoomFactor: Int,
var scalingFactor: Double,
- var scalingType: String,
- var autoRotate: Boolean,
var waterHeight: Int,
var snowHeightThreshold: Int,
var showWireframe: Boolean
diff --git a/src/main/kotlin/Terrain.kt b/src/main/kotlin/Terrain.kt
index 7d172ea..2568202 100644
--- a/src/main/kotlin/Terrain.kt
+++ b/src/main/kotlin/Terrain.kt
@@ -45,15 +45,9 @@ class Terrain {
private val size: Int = 256
- enum class ScalingType {
- LINEAR, EXPONENTIAL
- }
-
var options = GenerateOptions(
80,
2.9,
- ScalingType.EXPONENTIAL.name,
- false,
4,
16,
false)
@@ -109,15 +103,6 @@ class Terrain {
regenerateTerrain()
}
- private fun regenerateTerrain() {
- document.getElementById("loading-overlay")?.removeClass("hidden")
- // without the setTimeout the loading overlay is never rendered
- window.setTimeout({
- generateTerrain()
- document.getElementById("loading-overlay")?.addClass("hidden")
- }, 10)
- }
-
private fun generateTerrain() {
val genStart = window.performance.now()
@@ -140,15 +125,9 @@ class Terrain {
var noise = simplexNoise.noise2D(x / options.zoomFactor.toDouble(), y / options.zoomFactor.toDouble())
// add some fine noise
noise += (0.03 * simplexNoise.noise2D(x/15.toDouble(), y/15.toDouble()))
- noise += 1
-
- // have to toString here for JS interop
- if (options.scalingType == ScalingType.LINEAR.toString()) {
- noise *= options.scalingFactor
- } else {
- noise += 1
- noise = noise.pow(options.scalingFactor)
- }
+ noise += 2
+
+ noise = noise.pow(options.scalingFactor)
terrainGeometry.vertices[x + (y * size)].setZ(noise)
}
@@ -183,17 +162,13 @@ class Terrain {
generateWater()
}
- private fun applyHeightMapColour(planeGeometry: PlaneGeometry) {
- planeGeometry.faces.forEach { face ->
- val vertexes = listOf(planeGeometry.vertices[face.a].z, planeGeometry.vertices[face.b].z, planeGeometry.vertices[face.c].z)
- val min = vertexes.min()!!
-
- if (min < options.snowHeightThreshold) {
- face.color?.set(ColorConstants.forestgreen)
- } else if (min >= options.snowHeightThreshold) {
- face.color?.set(ColorConstants.floralwhite)
- }
- }
+ private fun regenerateTerrain() {
+ document.getElementById("loading-overlay")?.removeClass("hidden")
+ // without the setTimeout the loading overlay is never rendered
+ window.setTimeout({
+ generateTerrain()
+ document.getElementById("loading-overlay")?.addClass("hidden")
+ }, 10)
}
private fun generateWater() {
@@ -232,6 +207,19 @@ class Terrain {
js("waterMeshJsVar.material.uniforms.size.value = 7")
}
+ private fun applyHeightMapColour(planeGeometry: PlaneGeometry) {
+ planeGeometry.faces.forEach { face ->
+ val vertexes = listOf(planeGeometry.vertices[face.a].z, planeGeometry.vertices[face.b].z, planeGeometry.vertices[face.c].z)
+ val min = vertexes.min()!!
+
+ if (min < options.snowHeightThreshold) {
+ face.color?.set(ColorConstants.forestgreen)
+ } else if (min >= options.snowHeightThreshold) {
+ face.color?.set(ColorConstants.floralwhite)
+ }
+ }
+ }
+
@Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE")
fun initGui() {
@@ -275,12 +263,10 @@ class Terrain {
.step(1)
.onFinishChange { regenerateTerrain() }
}
- it.add(this.options, "scalingType", Terrain.ScalingType.values()).onChange {
- regenerateTerrain()
- }
+
it.add(this, "reseedNoise")
it.add(this.options, "showWireframe").onChange { regenerateTerrain() }
- it.add(this.options, "autoRotate")
+ it.add(controls, "autoRotate")
}
}
@@ -293,9 +279,8 @@ class Terrain {
window.setTimeout({
window.requestAnimationFrame {
- if (options.autoRotate) {
- terrainMesh.rotation.z += 0.005
- waterMesh.rotation.z += 0.005
+ if (controls.autoRotate) {
+ controls.update()
// println("x:${camera.position.x} y: ${camera.position.y} z:${camera.position.z}")
}
var waterMeshJsVar = waterMesh
diff --git a/src/main/resources/presets.json b/src/main/resources/presets.json
index c824fa3..bf5ceab 100644
--- a/src/main/resources/presets.json
+++ b/src/main/resources/presets.json
@@ -5,7 +5,6 @@
"0": {
"zoomFactor": 80,
"scalingFactor": 2.9,
- "scalingType": "EXPONENTIAL",
"autoRotate": false,
"waterHeight": 5,
"snowHeightThreshold": 16,
@@ -16,7 +15,6 @@
"0": {
"zoomFactor": 100,
"scalingFactor": 2.5,
- "scalingType": "EXPONENTIAL",
"autoRotate": false,
"waterHeight": 3,
"snowHeightThreshold": 15,
@@ -27,7 +25,6 @@
"0": {
"zoomFactor": 45,
"scalingFactor": 2.8,
- "scalingType": "EXPONENTIAL",
"autoRotate": false,
"waterHeight": 6,
"snowHeightThreshold": 15,
@@ -37,8 +34,7 @@
"Marsh": {
"0": {
"zoomFactor": 55,
- "scalingFactor": 2.5,
- "scalingType": "LINEAR",
+ "scalingFactor": 1.5,
"autoRotate": false,
"waterHeight": 3,
"snowHeightThreshold": 15,