remove MaterialTileMapping and update references. it is now part of gdx-toolbox itself (always in a public field within a TextureAtlas)
This commit is contained in:
parent
ac66820997
commit
e38c6f3434
|
@ -1,17 +0,0 @@
|
|||
package ca.blarg.gdx.tilemap3d.assets.tilemesh;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class JsonMaterialMapping {
|
||||
public class Material {
|
||||
public String name;
|
||||
public int tile;
|
||||
public float minU;
|
||||
public float maxU;
|
||||
public float minV;
|
||||
public float maxV;
|
||||
}
|
||||
|
||||
public String textureAtlas;
|
||||
public ArrayList<Material> materials;
|
||||
}
|
|
@ -22,7 +22,6 @@ public class JsonTileMesh {
|
|||
public Vector3 positionOffset;
|
||||
}
|
||||
|
||||
public String materials;
|
||||
public String textureAtlas;
|
||||
public boolean cube;
|
||||
public CubeTextures textures;
|
||||
|
|
|
@ -4,6 +4,5 @@ import java.util.ArrayList;
|
|||
|
||||
public class JsonTileMeshCollection {
|
||||
public String textureAtlas;
|
||||
public String materials;
|
||||
public ArrayList<String> tiles;
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package ca.blarg.gdx.tilemap3d.assets.tilemesh;
|
||||
|
||||
import ca.blarg.gdx.assets.AssetLoadingException;
|
||||
import ca.blarg.gdx.graphics.atlas.TextureAtlas;
|
||||
import ca.blarg.gdx.tilemap3d.tilemesh.MaterialTileMapping;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
|
||||
class MaterialTileMappingJsonLoader {
|
||||
public static JsonMaterialMapping load(FileHandle file) {
|
||||
Json json = new Json();
|
||||
return json.fromJson(JsonMaterialMapping.class, file);
|
||||
}
|
||||
|
||||
public static MaterialTileMapping create(FileHandle file, JsonMaterialMapping definition, AssetManager assetManager) {
|
||||
if (definition.materials == null || definition.materials.size() == 0)
|
||||
throw new AssetLoadingException(file.path(), "No material mappings defined.");
|
||||
if (definition.textureAtlas == null)
|
||||
throw new AssetLoadingException(file.path(), "No texture atlas specified.");
|
||||
|
||||
TextureAtlas atlas = assetManager.get(definition.textureAtlas, TextureAtlas.class);
|
||||
|
||||
MaterialTileMapping materialMapping = new MaterialTileMapping();
|
||||
for (int i = 0; i < definition.materials.size(); ++i) {
|
||||
JsonMaterialMapping.Material mapping = definition.materials.get(i);
|
||||
materialMapping.add(
|
||||
mapping.name, atlas.get(mapping.tile),
|
||||
mapping.minU, mapping.maxU, mapping.minV, mapping.maxV
|
||||
);
|
||||
}
|
||||
|
||||
return materialMapping;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package ca.blarg.gdx.tilemap3d.assets.tilemesh;
|
||||
|
||||
import ca.blarg.gdx.graphics.atlas.TextureAtlas;
|
||||
import ca.blarg.gdx.tilemap3d.tilemesh.MaterialTileMapping;
|
||||
import com.badlogic.gdx.assets.AssetDescriptor;
|
||||
import com.badlogic.gdx.assets.AssetLoaderParameters;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.assets.loaders.AsynchronousAssetLoader;
|
||||
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MaterialTileMappingLoader extends AsynchronousAssetLoader<MaterialTileMapping, MaterialTileMappingLoader.MaterialTileMappingParameters> {
|
||||
public static class MaterialTileMappingParameters extends AssetLoaderParameters<MaterialTileMapping> {
|
||||
}
|
||||
|
||||
public MaterialTileMappingLoader(FileHandleResolver resolver) {
|
||||
super(resolver);
|
||||
}
|
||||
|
||||
JsonMaterialMapping definition;
|
||||
MaterialTileMapping mapping;
|
||||
|
||||
@Override
|
||||
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, MaterialTileMappingParameters parameter) {
|
||||
definition = MaterialTileMappingJsonLoader.load(file);
|
||||
Array<AssetDescriptor> deps = new Array<AssetDescriptor>();
|
||||
deps.add(new AssetDescriptor(definition.textureAtlas, TextureAtlas.class));
|
||||
return deps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAsync(AssetManager manager, String fileName, FileHandle file, MaterialTileMappingParameters parameter) {
|
||||
mapping = MaterialTileMappingJsonLoader.create(file, definition, manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialTileMapping loadSync(AssetManager manager, String fileName, FileHandle file, MaterialTileMappingParameters parameter) {
|
||||
return mapping;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package ca.blarg.gdx.tilemap3d.assets.tilemesh;
|
||||
|
||||
import ca.blarg.gdx.graphics.atlas.TextureAtlas;
|
||||
import ca.blarg.gdx.tilemap3d.tilemesh.MaterialTileMapping;
|
||||
import ca.blarg.gdx.tilemap3d.tilemesh.TileMesh;
|
||||
import ca.blarg.gdx.tilemap3d.tilemesh.TileMeshCollection;
|
||||
import com.badlogic.gdx.assets.AssetDescriptor;
|
||||
|
@ -29,8 +28,6 @@ public class TileMeshCollectionLoader extends AsynchronousAssetLoader<TileMeshCo
|
|||
definition = TileMeshCollectionJsonLoader.load(file);
|
||||
Array<AssetDescriptor> deps = new Array<AssetDescriptor>();
|
||||
|
||||
if (definition.materials != null)
|
||||
deps.add(new AssetDescriptor(definition.materials, MaterialTileMapping.class));
|
||||
if (definition.textureAtlas != null)
|
||||
deps.add(new AssetDescriptor(definition.textureAtlas, TextureAtlas.class));
|
||||
|
||||
|
|
|
@ -20,20 +20,18 @@ class TileMeshJsonLoader {
|
|||
public static TileMesh create(JsonTileMesh definition, AssetManager assetManager) {
|
||||
if (!definition.cube && definition.model == null && definition.models == null)
|
||||
throw new RuntimeException("One of cube, model or models must be specified for each tile.");
|
||||
if (definition.materials != null && definition.textureAtlas != null)
|
||||
throw new RuntimeException("materials and textureAtlas cannot both be set.");
|
||||
if (definition.model != null && definition.materials == null)
|
||||
throw new RuntimeException("Missing materials section but using models to define tiles. When using models, a materials section to map model textures to texture atlas regions is required.");
|
||||
if (definition.textureAtlas == null)
|
||||
throw new RuntimeException("A texture atlas must be specified.");
|
||||
if (definition.collisionModel != null && definition.collisionShape != null)
|
||||
throw new RuntimeException("collisionModel and collisionShape cannot both be set.");
|
||||
|
||||
MaterialTileMapping materials = null;
|
||||
TextureAtlas atlas = null;
|
||||
if (definition.materials != null)
|
||||
materials = assetManager.get(definition.materials, MaterialTileMapping.class);
|
||||
else if (definition.textureAtlas != null)
|
||||
if (definition.textureAtlas != null)
|
||||
atlas = assetManager.get(definition.textureAtlas, TextureAtlas.class);
|
||||
|
||||
if (!atlas.materialTileMapping.hasMappings() && !definition.cube)
|
||||
throw new RuntimeException("No material mappings defined for non-cube tile mesh. Material mappings needed to map from source model(s) textures to texture atlas tiles.");
|
||||
|
||||
boolean isCube = definition.cube;
|
||||
TextureRegion texture = null;
|
||||
TextureRegion topTexture = null;
|
||||
|
@ -142,7 +140,7 @@ class TileMeshJsonLoader {
|
|||
throw new RuntimeException("collisionShape not recognized.");
|
||||
}
|
||||
|
||||
return new ModelTileMesh(model, collisionModel, materials, opaqueSides, lightValue, alpha, translucency, color, scaleToSize, positionOffset, collisionPositionOffset);
|
||||
return new ModelTileMesh(model, collisionModel, atlas.materialTileMapping, opaqueSides, lightValue, alpha, translucency, color, scaleToSize, positionOffset, collisionPositionOffset);
|
||||
|
||||
} else if (definition.models != null) {
|
||||
int numModels = definition.models.size();
|
||||
|
@ -176,7 +174,7 @@ class TileMeshJsonLoader {
|
|||
throw new RuntimeException("collisionShape not recognized.");
|
||||
}
|
||||
|
||||
return new MultiModelTileMesh(submodels, colors, scaleToSizes, positionOffsets, collisionModel, materials, opaqueSides, lightValue, alpha, translucency, color, scaleToSize, positionOffset, collisionPositionOffset);
|
||||
return new MultiModelTileMesh(submodels, colors, scaleToSizes, positionOffsets, collisionModel, atlas.materialTileMapping, opaqueSides, lightValue, alpha, translucency, color, scaleToSize, positionOffset, collisionPositionOffset);
|
||||
|
||||
} else
|
||||
throw new RuntimeException("Unrecognized tile mesh type.");
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package ca.blarg.gdx.tilemap3d.assets.tilemesh;
|
||||
|
||||
import ca.blarg.gdx.graphics.atlas.TextureAtlas;
|
||||
import ca.blarg.gdx.tilemap3d.tilemesh.MaterialTileMapping;
|
||||
import ca.blarg.gdx.tilemap3d.tilemesh.TileMesh;
|
||||
import com.badlogic.gdx.assets.AssetDescriptor;
|
||||
import com.badlogic.gdx.assets.AssetLoaderParameters;
|
||||
|
@ -29,8 +28,6 @@ public class TileMeshLoader extends AsynchronousAssetLoader<TileMesh, TileMeshLo
|
|||
definition = TileMeshJsonLoader.load(file);
|
||||
Array<AssetDescriptor> deps = new Array<AssetDescriptor>();
|
||||
|
||||
if (definition.materials != null)
|
||||
deps.add(new AssetDescriptor(definition.materials, MaterialTileMapping.class));
|
||||
if (definition.textureAtlas != null)
|
||||
deps.add(new AssetDescriptor(definition.textureAtlas, TextureAtlas.class));
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package ca.blarg.gdx.tilemap3d.tilemesh;
|
||||
|
||||
import ca.blarg.gdx.graphics.Vertices;
|
||||
import ca.blarg.gdx.graphics.atlas.MaterialTileMapping;
|
||||
import ca.blarg.gdx.graphics.atlas.TextureAtlas;
|
||||
import ca.blarg.gdx.math.MathHelpers;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.VertexAttributes;
|
||||
import com.badlogic.gdx.graphics.g3d.Model;
|
||||
|
@ -11,9 +15,6 @@ import com.badlogic.gdx.math.Vector2;
|
|||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.math.collision.BoundingBox;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import ca.blarg.gdx.graphics.Vertices;
|
||||
import ca.blarg.gdx.graphics.atlas.TextureAtlas;
|
||||
import ca.blarg.gdx.math.MathHelpers;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
package ca.blarg.gdx.tilemap3d.tilemesh;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import ca.blarg.gdx.graphics.atlas.TextureAtlas;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MaterialTileMapping {
|
||||
public class TileTexture {
|
||||
public TextureRegion region;
|
||||
public float materialMinU = 0.0f;
|
||||
public float materialMaxU = 1.0f;
|
||||
public float materialMinV = 0.0f;
|
||||
public float materialMaxV = 1.0f;
|
||||
}
|
||||
|
||||
private Map<String, TileTexture> mappings;
|
||||
|
||||
public MaterialTileMapping() {
|
||||
mappings = new HashMap<String, TileTexture>();
|
||||
}
|
||||
|
||||
public MaterialTileMapping add(String materialName, TextureRegion region) {
|
||||
TileTexture tileTexture = new TileTexture();
|
||||
tileTexture.region = region;
|
||||
mappings.put(materialName, tileTexture);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MaterialTileMapping add(String materialName, TextureRegion region, float materialMinU, float materialMaxU, float materialMinV, float materialMaxV) {
|
||||
TileTexture tileTexture = new TileTexture();
|
||||
tileTexture.region = region;
|
||||
tileTexture.materialMinU = materialMinU;
|
||||
tileTexture.materialMaxU = materialMaxU;
|
||||
tileTexture.materialMinV = materialMinV;
|
||||
tileTexture.materialMaxV = materialMaxV;
|
||||
mappings.put(materialName, tileTexture);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TileTexture get(String materialName) {
|
||||
return mappings.get(materialName);
|
||||
}
|
||||
|
||||
public void scaleUV(String materialName, Vector2 srcTexCoord, Vector2 out) {
|
||||
TileTexture tileTexture = mappings.get(materialName);
|
||||
if (tileTexture == null)
|
||||
throw new IllegalArgumentException("No matching material.");
|
||||
|
||||
out.x = TextureAtlas.scaleTexCoordU(srcTexCoord.x, tileTexture.materialMinU, tileTexture.materialMaxU, tileTexture.region);
|
||||
out.y = TextureAtlas.scaleTexCoordV(srcTexCoord.y, tileTexture.materialMinV, tileTexture.materialMaxV, tileTexture.region);
|
||||
}
|
||||
|
||||
public void scaleUV(String materialName, float srcU, float srcV, Vector2 out) {
|
||||
TileTexture tileTexture = mappings.get(materialName);
|
||||
if (tileTexture == null)
|
||||
throw new IllegalArgumentException("No matching material.");
|
||||
|
||||
out.x = TextureAtlas.scaleTexCoordU(srcU, tileTexture.materialMinU, tileTexture.materialMaxU, tileTexture.region);
|
||||
out.y = TextureAtlas.scaleTexCoordV(srcV, tileTexture.materialMinV, tileTexture.materialMaxV, tileTexture.region);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
mappings.clear();
|
||||
}
|
||||
}
|
|
@ -1,13 +1,14 @@
|
|||
package ca.blarg.gdx.tilemap3d.tilemesh;
|
||||
|
||||
import ca.blarg.gdx.graphics.Vertices;
|
||||
import ca.blarg.gdx.graphics.atlas.MaterialTileMapping;
|
||||
import ca.blarg.gdx.math.MathHelpers;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.VertexAttribute;
|
||||
import com.badlogic.gdx.graphics.g3d.Model;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.math.collision.BoundingBox;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import ca.blarg.gdx.graphics.Vertices;
|
||||
import ca.blarg.gdx.math.MathHelpers;
|
||||
|
||||
public class ModelTileMesh extends BaseModelTileMesh {
|
||||
static final Vector3 tmpPosition = new Vector3();
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package ca.blarg.gdx.tilemap3d.tilemesh;
|
||||
|
||||
import ca.blarg.gdx.graphics.Vertices;
|
||||
import ca.blarg.gdx.graphics.atlas.MaterialTileMapping;
|
||||
import ca.blarg.gdx.math.MathHelpers;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.VertexAttribute;
|
||||
import com.badlogic.gdx.graphics.g3d.Model;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.math.collision.BoundingBox;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import ca.blarg.gdx.graphics.Vertices;
|
||||
import ca.blarg.gdx.math.MathHelpers;
|
||||
|
||||
public class MultiModelTileMesh extends BaseModelTileMesh {
|
||||
BoundingBox bounds;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ca.blarg.gdx.tilemap3d.tilemesh;
|
||||
|
||||
import ca.blarg.gdx.Bitfield;
|
||||
import ca.blarg.gdx.graphics.atlas.MaterialTileMapping;
|
||||
import ca.blarg.gdx.graphics.atlas.TextureAtlas;
|
||||
import ca.blarg.gdx.tilemap3d.Tile;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
|
|
Loading…
Reference in a new issue