use of com.badlogic.gdx.utils.ObjectMap in project libgdx by libgdx.
the class AtlasTmxMapLoader method load.
public TiledMap load(String fileName, AtlasTiledMapLoaderParameters parameter) {
try {
if (parameter != null) {
convertObjectToTileSpace = parameter.convertObjectToTileSpace;
flipY = parameter.flipY;
} else {
convertObjectToTileSpace = false;
flipY = true;
}
FileHandle tmxFile = resolve(fileName);
root = xml.parse(tmxFile);
ObjectMap<String, TextureAtlas> atlases = new ObjectMap<String, TextureAtlas>();
FileHandle atlasFile = loadAtlas(root, tmxFile);
if (atlasFile == null) {
throw new GdxRuntimeException("Couldn't load atlas");
}
TextureAtlas atlas = new TextureAtlas(atlasFile);
atlases.put(atlasFile.path(), atlas);
AtlasResolver.DirectAtlasResolver atlasResolver = new AtlasResolver.DirectAtlasResolver(atlases);
TiledMap map = loadMap(root, tmxFile, atlasResolver);
map.setOwnedResources(atlases.values().toArray());
setTextureFilters(parameter.textureMinFilter, parameter.textureMagFilter);
return map;
} catch (IOException e) {
throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
}
}
use of com.badlogic.gdx.utils.ObjectMap in project libgdx by libgdx.
the class AssetManager method getLoader.
/** Returns the loader for the given type and the specified filename. If no loader exists for the specific filename, the default
* loader for that type is returned.
* @param type The type of the loader to get
* @param fileName The filename of the asset to get a loader for, or null to get the default loader
* @return The loader capable of loading the type and filename, or null if none exists */
public <T> AssetLoader getLoader(final Class<T> type, final String fileName) {
final ObjectMap<String, AssetLoader> loaders = this.loaders.get(type);
if (loaders == null || loaders.size < 1)
return null;
if (fileName == null)
return loaders.get("");
AssetLoader result = null;
int l = -1;
for (ObjectMap.Entry<String, AssetLoader> entry : loaders.entries()) {
if (entry.key.length() > l && fileName.endsWith(entry.key)) {
result = entry.value;
l = entry.key.length();
}
}
return result;
}
use of com.badlogic.gdx.utils.ObjectMap in project libgdx by libgdx.
the class Model method convertMaterial.
protected Material convertMaterial(ModelMaterial mtl, TextureProvider textureProvider) {
Material result = new Material();
result.id = mtl.id;
if (mtl.ambient != null)
result.set(new ColorAttribute(ColorAttribute.Ambient, mtl.ambient));
if (mtl.diffuse != null)
result.set(new ColorAttribute(ColorAttribute.Diffuse, mtl.diffuse));
if (mtl.specular != null)
result.set(new ColorAttribute(ColorAttribute.Specular, mtl.specular));
if (mtl.emissive != null)
result.set(new ColorAttribute(ColorAttribute.Emissive, mtl.emissive));
if (mtl.reflection != null)
result.set(new ColorAttribute(ColorAttribute.Reflection, mtl.reflection));
if (mtl.shininess > 0f)
result.set(new FloatAttribute(FloatAttribute.Shininess, mtl.shininess));
if (mtl.opacity != 1.f)
result.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, mtl.opacity));
ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
// FIXME uvScaling/uvTranslation totally ignored
if (mtl.textures != null) {
for (ModelTexture tex : mtl.textures) {
Texture texture;
if (textures.containsKey(tex.fileName)) {
texture = textures.get(tex.fileName);
} else {
texture = textureProvider.load(tex.fileName);
textures.put(tex.fileName, texture);
disposables.add(texture);
}
TextureDescriptor descriptor = new TextureDescriptor(texture);
descriptor.minFilter = texture.getMinFilter();
descriptor.magFilter = texture.getMagFilter();
descriptor.uWrap = texture.getUWrap();
descriptor.vWrap = texture.getVWrap();
float offsetU = tex.uvTranslation == null ? 0f : tex.uvTranslation.x;
float offsetV = tex.uvTranslation == null ? 0f : tex.uvTranslation.y;
float scaleU = tex.uvScaling == null ? 1f : tex.uvScaling.x;
float scaleV = tex.uvScaling == null ? 1f : tex.uvScaling.y;
switch(tex.usage) {
case ModelTexture.USAGE_DIFFUSE:
result.set(new TextureAttribute(TextureAttribute.Diffuse, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
case ModelTexture.USAGE_SPECULAR:
result.set(new TextureAttribute(TextureAttribute.Specular, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
case ModelTexture.USAGE_BUMP:
result.set(new TextureAttribute(TextureAttribute.Bump, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
case ModelTexture.USAGE_NORMAL:
result.set(new TextureAttribute(TextureAttribute.Normal, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
case ModelTexture.USAGE_AMBIENT:
result.set(new TextureAttribute(TextureAttribute.Ambient, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
case ModelTexture.USAGE_EMISSIVE:
result.set(new TextureAttribute(TextureAttribute.Emissive, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
case ModelTexture.USAGE_REFLECTION:
result.set(new TextureAttribute(TextureAttribute.Reflection, descriptor, offsetU, offsetV, scaleU, scaleV));
break;
}
}
}
return result;
}
use of com.badlogic.gdx.utils.ObjectMap in project libgdx by libgdx.
the class BaseAnimationController method applyAnimation.
/** Helper method to apply one animation to either an objectmap for blending or directly to the bones. */
protected static void applyAnimation(final ObjectMap<Node, Transform> out, final Pool<Transform> pool, final float alpha, final Animation animation, final float time) {
if (out == null) {
for (final NodeAnimation nodeAnim : animation.nodeAnimations) applyNodeAnimationDirectly(nodeAnim, time);
} else {
for (final Node node : out.keys()) node.isAnimated = false;
for (final NodeAnimation nodeAnim : animation.nodeAnimations) applyNodeAnimationBlending(nodeAnim, out, pool, alpha, time);
for (final ObjectMap.Entry<Node, Transform> e : out.entries()) {
if (!e.key.isAnimated) {
e.key.isAnimated = true;
e.value.lerp(e.key.translation, e.key.rotation, e.key.scale, alpha);
}
}
}
}
use of com.badlogic.gdx.utils.ObjectMap in project libgdx by libgdx.
the class TextureAtlas method load.
private void load(TextureAtlasData data) {
ObjectMap<Page, Texture> pageToTexture = new ObjectMap<Page, Texture>();
for (Page page : data.pages) {
Texture texture = null;
if (page.texture == null) {
texture = new Texture(page.textureFile, page.format, page.useMipMaps);
texture.setFilter(page.minFilter, page.magFilter);
texture.setWrap(page.uWrap, page.vWrap);
} else {
texture = page.texture;
texture.setFilter(page.minFilter, page.magFilter);
texture.setWrap(page.uWrap, page.vWrap);
}
textures.add(texture);
pageToTexture.put(page, texture);
}
for (Region region : data.regions) {
int width = region.width;
int height = region.height;
AtlasRegion atlasRegion = new AtlasRegion(pageToTexture.get(region.page), region.left, region.top, region.rotate ? height : width, region.rotate ? width : height);
atlasRegion.index = region.index;
atlasRegion.name = region.name;
atlasRegion.offsetX = region.offsetX;
atlasRegion.offsetY = region.offsetY;
atlasRegion.originalHeight = region.originalHeight;
atlasRegion.originalWidth = region.originalWidth;
atlasRegion.rotate = region.rotate;
atlasRegion.splits = region.splits;
atlasRegion.pads = region.pads;
if (region.flip)
atlasRegion.flip(false, true);
regions.add(atlasRegion);
}
}
Aggregations