add json config support for cube tile meshes
This commit is contained in:
parent
4dd2724b47
commit
657d274f93
10
src/com/blarg/gdx/tilemap3d/tilemesh/JsonCubeTextures.java
Normal file
10
src/com/blarg/gdx/tilemap3d/tilemesh/JsonCubeTextures.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
package com.blarg.gdx.tilemap3d.tilemesh;
|
||||
|
||||
public class JsonCubeTextures {
|
||||
public int top;
|
||||
public int bottom;
|
||||
public int front;
|
||||
public int back;
|
||||
public int left;
|
||||
public int right;
|
||||
}
|
|
@ -6,6 +6,10 @@ import com.badlogic.gdx.math.Vector3;
|
|||
import java.util.ArrayList;
|
||||
|
||||
public class JsonTileDefinition {
|
||||
public boolean cube;
|
||||
public JsonCubeTextures textures;
|
||||
public int texture;
|
||||
public ArrayList<String> faces;
|
||||
public String model;
|
||||
public String collisionModel;
|
||||
public String collisionShape;
|
||||
|
|
|
@ -148,11 +148,22 @@ public class TileMeshCollection {
|
|||
for (int i = 0; i < config.tiles.size(); ++i) {
|
||||
JsonTileDefinition tileDef = config.tiles.get(i);
|
||||
|
||||
if (tileDef.cube && tileDef.model != null)
|
||||
throw new RuntimeException("cube and model cannot both be set.");
|
||||
if (tileDef.model != null && materialMapping == null)
|
||||
throw new RuntimeException("Missing materials section but using models to define tiles.");
|
||||
if (tileDef.collisionModel != null && tileDef.collisionShape != null)
|
||||
throw new RuntimeException("collisionModel and collisionShape cannot both be set.");
|
||||
|
||||
boolean isCube = tileDef.cube;
|
||||
TextureRegion texture = null;
|
||||
TextureRegion topTexture = null;
|
||||
TextureRegion bottomTexture = null;
|
||||
TextureRegion frontTexture = null;
|
||||
TextureRegion backTexture = null;
|
||||
TextureRegion leftTexture = null;
|
||||
TextureRegion rightTexture = null;
|
||||
byte faces = 0;
|
||||
Model model;
|
||||
Model collisionModel;
|
||||
byte opaqueSides = 0;
|
||||
|
@ -164,28 +175,6 @@ public class TileMeshCollection {
|
|||
Vector3 positionOffset = new Vector3(0.0f, 0.0f, 0.0f);
|
||||
Vector3 collisionPositionOffset = new Vector3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
|
||||
model = models.get(tileDef.model);
|
||||
if (model == null) {
|
||||
model = loader.loadModel(Gdx.files.internal(tileDef.model));
|
||||
models.put(tileDef.model, model);
|
||||
}
|
||||
|
||||
collisionModel = model; // default is to use the same model
|
||||
|
||||
if (tileDef.collisionModel != null) {
|
||||
//override with a specific collision model
|
||||
collisionModel = models.get(tileDef.collisionModel);
|
||||
if (collisionModel == null) {
|
||||
collisionModel = loader.loadModel(Gdx.files.internal(tileDef.collisionModel));
|
||||
models.put(tileDef.collisionModel, collisionModel);
|
||||
}
|
||||
}
|
||||
if (tileDef.collisionShape != null) {
|
||||
collisionModel = null; // using a shape instead!
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
if (tileDef.opaqueSides != null) {
|
||||
if (tileDef.opaqueSides.contains("ALL"))
|
||||
opaqueSides = TileMesh.SIDE_ALL;
|
||||
|
@ -217,7 +206,72 @@ public class TileMeshCollection {
|
|||
if (tileDef.collisionPositionOffset != null)
|
||||
collisionPositionOffset.set(tileDef.collisionPositionOffset);
|
||||
|
||||
add(model, collisionModel, materialMapping, opaqueSides, lightValue, alpha, translucency, color, scaleToSize, positionOffset, collisionPositionOffset);
|
||||
if (isCube) {
|
||||
if (tileDef.textures != null) {
|
||||
if (tileDef.textures.top >= 0)
|
||||
topTexture = atlas.get(tileDef.textures.top);
|
||||
if (tileDef.textures.bottom >= 0)
|
||||
bottomTexture = atlas.get(tileDef.textures.bottom);
|
||||
if (tileDef.textures.front >= 0)
|
||||
frontTexture = atlas.get(tileDef.textures.front);
|
||||
if (tileDef.textures.back >= 0)
|
||||
backTexture = atlas.get(tileDef.textures.back);
|
||||
if (tileDef.textures.left >= 0)
|
||||
leftTexture = atlas.get(tileDef.textures.left);
|
||||
if (tileDef.textures.right >= 0)
|
||||
rightTexture = atlas.get(tileDef.textures.right);
|
||||
} else if (tileDef.texture >= 0) {
|
||||
texture = atlas.get(tileDef.texture);
|
||||
if (tileDef.faces != null) {
|
||||
if (tileDef.faces.contains("ALL"))
|
||||
faces = TileMesh.SIDE_ALL;
|
||||
else {
|
||||
if (tileDef.faces.contains("TOP"))
|
||||
faces = Bitfield.set(TileMesh.SIDE_TOP, opaqueSides);
|
||||
if (tileDef.faces.contains("BOTTOM"))
|
||||
faces = Bitfield.set(TileMesh.SIDE_BOTTOM, opaqueSides);
|
||||
if (tileDef.faces.contains("FRONT"))
|
||||
faces = Bitfield.set(TileMesh.SIDE_FRONT, opaqueSides);
|
||||
if (tileDef.faces.contains("BACK"))
|
||||
faces = Bitfield.set(TileMesh.SIDE_BACK, opaqueSides);
|
||||
if (tileDef.faces.contains("LEFT"))
|
||||
faces = Bitfield.set(TileMesh.SIDE_LEFT, opaqueSides);
|
||||
if (tileDef.faces.contains("RIGHT"))
|
||||
faces = Bitfield.set(TileMesh.SIDE_RIGHT, opaqueSides);
|
||||
}
|
||||
}
|
||||
} else
|
||||
throw new RuntimeException("No cube texture specified.");
|
||||
|
||||
if (texture != null)
|
||||
addCube(texture, faces, opaqueSides, lightValue, alpha, translucency, color);
|
||||
else
|
||||
addCube(topTexture, bottomTexture, frontTexture, backTexture, leftTexture, rightTexture, opaqueSides, lightValue, alpha, translucency, color);
|
||||
|
||||
} else {
|
||||
model = models.get(tileDef.model);
|
||||
if (model == null) {
|
||||
model = loader.loadModel(Gdx.files.internal(tileDef.model));
|
||||
models.put(tileDef.model, model);
|
||||
}
|
||||
|
||||
collisionModel = model; // default is to use the same model
|
||||
|
||||
if (tileDef.collisionModel != null) {
|
||||
//override with a specific collision model
|
||||
collisionModel = models.get(tileDef.collisionModel);
|
||||
if (collisionModel == null) {
|
||||
collisionModel = loader.loadModel(Gdx.files.internal(tileDef.collisionModel));
|
||||
models.put(tileDef.collisionModel, collisionModel);
|
||||
}
|
||||
}
|
||||
if (tileDef.collisionShape != null) {
|
||||
collisionModel = null; // using a shape instead!
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
add(model, collisionModel, materialMapping, opaqueSides, lightValue, alpha, translucency, color, scaleToSize, positionOffset, collisionPositionOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue