Search in sources :

Example 51 with Array

use of com.badlogic.gdx.utils.Array in project libgdx by libgdx.

the class MaxRectsPacker method packAtSize.

/** @param fully If true, the only results that pack all rects will be considered. If false, all results are considered, not
	 *           all rects may be packed. */
private Page packAtSize(boolean fully, int width, int height, Array<Rect> inputRects) {
    Page bestResult = null;
    for (int i = 0, n = methods.length; i < n; i++) {
        maxRects.init(width, height);
        Page result;
        if (!settings.fast) {
            result = maxRects.pack(inputRects, methods[i]);
        } else {
            Array<Rect> remaining = new Array();
            for (int ii = 0, nn = inputRects.size; ii < nn; ii++) {
                Rect rect = inputRects.get(ii);
                if (maxRects.insert(rect, methods[i]) == null) {
                    while (ii < nn) remaining.add(inputRects.get(ii++));
                }
            }
            result = maxRects.getResult();
            result.remainingRects = remaining;
        }
        if (fully && result.remainingRects.size > 0)
            continue;
        if (result.outputRects.size == 0)
            continue;
        bestResult = getBest(bestResult, result);
    }
    return bestResult;
}
Also used : Array(com.badlogic.gdx.utils.Array) Rect(com.badlogic.gdx.tools.texturepacker.TexturePacker.Rect) Page(com.badlogic.gdx.tools.texturepacker.TexturePacker.Page)

Example 52 with Array

use of com.badlogic.gdx.utils.Array in project libgdx by libgdx.

the class MaxRectsPacker method pack.

public Array<Page> pack(Array<Rect> inputRects) {
    for (int i = 0, nn = inputRects.size; i < nn; i++) {
        Rect rect = inputRects.get(i);
        rect.width += settings.paddingX;
        rect.height += settings.paddingY;
    }
    if (settings.fast) {
        if (settings.rotation) {
            // Sort by longest side if rotation is enabled.
            sort.sort(inputRects, new Comparator<Rect>() {

                public int compare(Rect o1, Rect o2) {
                    int n1 = o1.width > o1.height ? o1.width : o1.height;
                    int n2 = o2.width > o2.height ? o2.width : o2.height;
                    return n2 - n1;
                }
            });
        } else {
            // Sort only by width (largest to smallest) if rotation is disabled.
            sort.sort(inputRects, new Comparator<Rect>() {

                public int compare(Rect o1, Rect o2) {
                    return o2.width - o1.width;
                }
            });
        }
    }
    Array<Page> pages = new Array();
    while (inputRects.size > 0) {
        Page result = packPage(inputRects);
        pages.add(result);
        inputRects = result.remainingRects;
    }
    return pages;
}
Also used : Array(com.badlogic.gdx.utils.Array) Rect(com.badlogic.gdx.tools.texturepacker.TexturePacker.Rect) Page(com.badlogic.gdx.tools.texturepacker.TexturePacker.Page)

Example 53 with Array

use of com.badlogic.gdx.utils.Array in project libgdx by libgdx.

the class ModelLoader method getDependencies.

@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, P parameters) {
    final Array<AssetDescriptor> deps = new Array();
    ModelData data = loadModelData(file, parameters);
    if (data == null)
        return deps;
    ObjectMap.Entry<String, ModelData> item = new ObjectMap.Entry<String, ModelData>();
    item.key = fileName;
    item.value = data;
    synchronized (items) {
        items.add(item);
    }
    TextureLoader.TextureParameter textureParameter = (parameters != null) ? parameters.textureParameter : defaultParameters.textureParameter;
    for (final ModelMaterial modelMaterial : data.materials) {
        if (modelMaterial.textures != null) {
            for (final ModelTexture modelTexture : modelMaterial.textures) deps.add(new AssetDescriptor(modelTexture.fileName, Texture.class, textureParameter));
        }
    }
    return deps;
}
Also used : Array(com.badlogic.gdx.utils.Array) ModelData(com.badlogic.gdx.graphics.g3d.model.data.ModelData) ObjectMap(com.badlogic.gdx.utils.ObjectMap) ModelMaterial(com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor) ModelTexture(com.badlogic.gdx.graphics.g3d.model.data.ModelTexture)

Example 54 with Array

use of com.badlogic.gdx.utils.Array in project libgdx by libgdx.

the class ParticleEffectLoader method getDependencies.

@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, ParticleEffectParameter param) {
    Array<AssetDescriptor> deps = null;
    if (param != null && param.atlasFile != null) {
        deps = new Array();
        deps.add(new AssetDescriptor<TextureAtlas>(param.atlasFile, TextureAtlas.class));
    }
    return deps;
}
Also used : Array(com.badlogic.gdx.utils.Array) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

Example 55 with Array

use of com.badlogic.gdx.utils.Array in project libgdx by libgdx.

the class TextureAtlasLoader method getDependencies.

@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle atlasFile, TextureAtlasParameter parameter) {
    FileHandle imgDir = atlasFile.parent();
    if (parameter != null)
        data = new TextureAtlasData(atlasFile, imgDir, parameter.flip);
    else {
        data = new TextureAtlasData(atlasFile, imgDir, false);
    }
    Array<AssetDescriptor> dependencies = new Array();
    for (Page page : data.getPages()) {
        TextureParameter params = new TextureParameter();
        params.format = page.format;
        params.genMipMaps = page.useMipMaps;
        params.minFilter = page.minFilter;
        params.magFilter = page.magFilter;
        dependencies.add(new AssetDescriptor(page.textureFile, Texture.class, params));
    }
    return dependencies;
}
Also used : Array(com.badlogic.gdx.utils.Array) TextureAtlasData(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData) FileHandle(com.badlogic.gdx.files.FileHandle) Page(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Page) TextureParameter(com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter) Texture(com.badlogic.gdx.graphics.Texture) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

Aggregations

Array (com.badlogic.gdx.utils.Array)67 FileHandle (com.badlogic.gdx.files.FileHandle)18 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)16 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)9 Texture (com.badlogic.gdx.graphics.Texture)8 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)7 IntArray (com.badlogic.gdx.utils.IntArray)7 Element (com.badlogic.gdx.utils.XmlReader.Element)7 IOException (java.io.IOException)7 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)5 JsonValue (com.badlogic.gdx.utils.JsonValue)5 ObjectMap (com.badlogic.gdx.utils.ObjectMap)5 Color (com.badlogic.gdx.graphics.Color)4 ModelMaterial (com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial)4 Page (com.badlogic.gdx.tools.texturepacker.TexturePacker.Page)4 Rect (com.badlogic.gdx.tools.texturepacker.TexturePacker.Rect)4 Json (com.badlogic.gdx.utils.Json)4 TextureParameter (com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter)3 GwtFileHandle (com.badlogic.gdx.backends.gwt.GwtFileHandle)3