Skip to content

Commit

Permalink
Dialog for terrain creation (#89)
Browse files Browse the repository at this point in the history
* Add support for exporting terrains as .obj for navmesh

* Implement Add Terrain Dialog

* Ability to customize terrain splat map size

* Update tooltip

* Update comment

* Update comment

* Fix after merge
  • Loading branch information
JamesTKhan authored Aug 17, 2022
1 parent f2a480f commit b88bef4
Show file tree
Hide file tree
Showing 19 changed files with 443 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.badlogic.gdx.utils.JsonReader;
import com.badlogic.gdx.utils.JsonValue;
import com.mbrlabs.mundus.commons.assets.AssetType;
import com.mbrlabs.mundus.commons.terrain.SplatMapResolution;
import com.mbrlabs.mundus.commons.terrain.Terrain;

/**
Expand Down Expand Up @@ -58,6 +59,7 @@ private void parseTerrain(Meta meta, JsonValue jsonTerrain) {

final MetaTerrain terrain = new MetaTerrain();
terrain.setSize(jsonTerrain.getInt(MetaTerrain.JSON_SIZE));
terrain.setSplatMapResolution(jsonTerrain.getInt(MetaTerrain.JSON_SPLATMAP_RESOLUTION, SplatMapResolution.DEFAULT_RESOLUTION.getResolutionValues()));
terrain.setUv(jsonTerrain.getFloat(MetaTerrain.JSON_UV_SCALE, Terrain.DEFAULT_UV_SCALE));
terrain.setSplatmap(jsonTerrain.getString(MetaTerrain.JSON_SPLATMAP, null));
terrain.setSplatBase64(jsonTerrain.getString(MetaTerrain.JSON_SPLAT_BASE64, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class MetaTerrain {

public static final String JSON_SIZE = "size";
public static final String JSON_SPLATMAP = "map";
public static final String JSON_SPLATMAP_RESOLUTION = "mapRes";
public static final String JSON_SPLAT_BASE = "base";
public static final String JSON_SPLAT_BASE64 = "base64";
public static final String JSON_SPLAT_R = "r";
Expand All @@ -39,6 +40,7 @@ public class MetaTerrain {
public static final String JSON_UV_SCALE= "uv";

private int size;
private int splatMapResolution;
private float uv;
private String splatmap;
private String splatBase;
Expand Down Expand Up @@ -117,6 +119,14 @@ public void setSize(int size) {
this.size = size;
}

public int getSplatMapResolution() {
return splatMapResolution;
}

public void setSplatMapResolution(int splatMapResolution) {
this.splatMapResolution = splatMapResolution;
}

public float getUv() {
return uv;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
*/
public class SplatMap {

public static final int DEFAULT_SIZE = 512;

private int width;
private int height;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.mbrlabs.mundus.commons.terrain;

/**
* @author JamesTKhan
* @version July 23, 2022
*/
public enum SplatMapResolution {
_512("512x512"),
_1024("1024x1024"),
_2048("2048x2048");

public static final SplatMapResolution DEFAULT_RESOLUTION = _512;
private final String value;

SplatMapResolution(String value) {
this.value = value;
}

public String getValue() {
return value;
}

public int getResolutionValues() {
if (this == _512) {
return 512;
}
if (this == _1024) {
return 1024;
}
if (this == _2048) {
return 2048;
}

return 512;
}

public static SplatMapResolution valueFromString(String string) {
for (SplatMapResolution res : values()) {
if (res.value.equals(string)) {
return res;
}
}

return DEFAULT_RESOLUTION;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ public void setTerrainTexture(TerrainTexture terrainTexture) {
material.set(new TerrainTextureAttribute(TerrainTextureAttribute.ATTRIBUTE_SPLAT0, this.terrainTexture));
}

public float[] getVertices() {
return vertices;
}

public void update() {
buildVertices();

Expand Down
24 changes: 24 additions & 0 deletions commons/src/main/com/mbrlabs/mundus/commons/utils/ModelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.mbrlabs.mundus.commons.utils;

import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.Renderable;
Expand Down Expand Up @@ -97,4 +98,27 @@ public static boolean isVisible(final Camera cam, final ModelInstance modelInsta
tmpVec0.add(center);
return cam.frustum.boundsInFrustum(tmpVec0, dimensions);
}

/**
* Get Vertices count of a Model
*/
public static int getVerticesCount(Model model) {
int vertices = 0;
for (Mesh mesh : model.meshes) {
vertices += mesh.getNumVertices();
}
return vertices;
}

/**
* Get Indices count of a Model
*/
public static float getIndicesCount(Model model) {
int indices = 0;
for (Mesh mesh : model.meshes) {
indices += mesh.getNumIndices();
}
return indices;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,16 @@ class EditorAssetManager(assetsRoot: FileHandle) : AssetManager(assetsRoot) {
* @throws IOException
*/
@Throws(IOException::class, AssetAlreadyExistsException::class)
fun createTerraAsset(name: String, vertexResolution: Int, size: Int): TerrainAsset {
val terraFilename = name + ".terra"
val metaFilename = terraFilename + ".meta"
fun createTerraAsset(name: String, vertexResolution: Int, size: Int, splatMapResolution: Int): TerrainAsset {
val terraFilename = "$name.terra"
val metaFilename = "$terraFilename.meta"

// create meta file
val metaPath = FilenameUtils.concat(rootFolder.path(), metaFilename)
val meta = createNewMetaFile(FileHandle(metaPath), AssetType.TERRAIN)
meta.terrain = MetaTerrain()
meta.terrain.size = size
meta.terrain.splatMapResolution = splatMapResolution
meta.terrain.uv = 60f
metaSaver.save(meta)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class MetaSaver {

json.writeObjectStart(Meta.JSON_TERRAIN)
json.writeValue(MetaTerrain.JSON_SIZE, terrain.size)
json.writeValue(MetaTerrain.JSON_SPLATMAP_RESOLUTION, terrain.splatMapResolution)
json.writeValue(MetaTerrain.JSON_UV_SCALE, terrain.uv)
json.writeValue(MetaTerrain.JSON_SPLAT_BASE64, terrain.splatBase64)
if (terrain.splatmap != null) json.writeValue(MetaTerrain.JSON_SPLATMAP, terrain.splatmap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public enum BrushMode {
RAISE_LOWER,
/** Sets all vertices of the selection to a specified height. */
FLATTEN,
/** TBD */
/** Smooths terrain based on average height within radius */
SMOOTH,
/** Paints on the splatmap of the terrainAsset. */
PAINT
Expand Down
2 changes: 2 additions & 0 deletions editor/src/main/com/mbrlabs/mundus/editor/ui/UI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.mbrlabs.mundus.editor.ui.modules.MundusToolbar
import com.mbrlabs.mundus.editor.ui.modules.outline.Outline
import com.mbrlabs.mundus.editor.ui.modules.StatusBar
import com.mbrlabs.mundus.editor.ui.modules.dialogs.AddComponentDialog
import com.mbrlabs.mundus.editor.ui.modules.dialogs.AddTerrainDialog
import com.mbrlabs.mundus.editor.ui.modules.dialogs.AmbientLightDialog
import com.mbrlabs.mundus.editor.ui.modules.dialogs.DirectionalLightsDialog
import com.mbrlabs.mundus.editor.ui.modules.dialogs.ExitDialog
Expand Down Expand Up @@ -105,6 +106,7 @@ object UI : Stage(ScreenViewport()) {
var directionalLightDialog: DirectionalLightsDialog = DirectionalLightsDialog()
var shadowSettingsDialog: ShadowSettingsDialog = ShadowSettingsDialog()
var addComponentDialog: AddComponentDialog = AddComponentDialog()
var addTerrainDialog: AddTerrainDialog = AddTerrainDialog()
val versionDialog: VersionDialog = VersionDialog()
val keyboardShortcuts: KeyboardShortcutsDialog = KeyboardShortcutsDialog()
val debugRenderDialog: DebugRenderDialog = DebugRenderDialog()
Expand Down

This file was deleted.

Loading

0 comments on commit b88bef4

Please sign in to comment.