Search in sources :

Example 6 with ObjectMap

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);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ObjectMap(com.badlogic.gdx.utils.ObjectMap) FileHandle(com.badlogic.gdx.files.FileHandle) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) IOException(java.io.IOException)

Example 7 with ObjectMap

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;
}
Also used : AssetLoader(com.badlogic.gdx.assets.loaders.AssetLoader) ObjectMap(com.badlogic.gdx.utils.ObjectMap)

Example 8 with ObjectMap

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;
}
Also used : BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) ObjectMap(com.badlogic.gdx.utils.ObjectMap) ModelMaterial(com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial) FloatAttribute(com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute) TextureDescriptor(com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) ModelTexture(com.badlogic.gdx.graphics.g3d.model.data.ModelTexture) Texture(com.badlogic.gdx.graphics.Texture) ModelTexture(com.badlogic.gdx.graphics.g3d.model.data.ModelTexture) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)

Example 9 with ObjectMap

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);
            }
        }
    }
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) Node(com.badlogic.gdx.graphics.g3d.model.Node) NodeAnimation(com.badlogic.gdx.graphics.g3d.model.NodeAnimation)

Example 10 with ObjectMap

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);
    }
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) Region(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region) Page(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Page) Texture(com.badlogic.gdx.graphics.Texture)

Aggregations

ObjectMap (com.badlogic.gdx.utils.ObjectMap)15 Texture (com.badlogic.gdx.graphics.Texture)7 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)4 FileHandle (com.badlogic.gdx.files.FileHandle)3 IOException (java.io.IOException)3 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 DirectImageResolver (com.badlogic.gdx.maps.ImageResolver.DirectImageResolver)2 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)2 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)2 Array (com.badlogic.gdx.utils.Array)2 ArrayList (java.util.ArrayList)2 AssetLoader (com.badlogic.gdx.assets.loaders.AssetLoader)1 SkinLoader (com.badlogic.gdx.assets.loaders.SkinLoader)1 Color (com.badlogic.gdx.graphics.Color)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 Page (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Page)1 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1