Example usage for com.badlogic.gdx.utils FloatArray toArray

List of usage examples for com.badlogic.gdx.utils FloatArray toArray

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils FloatArray toArray.

Prototype

public float[] toArray() 

Source Link

Usage

From source file:com.company.minery.utils.spine.SkeletonBinary.java

License:Open Source License

private Attachment readAttachment(DataInput input, Skin skin, String attachmentName, boolean nonessential)
        throws IOException {
    float scale = this.scale;

    String name = input.readString();
    if (name == null)
        name = attachmentName;/*from  ww w  .  j  av  a 2  s . c  om*/

    switch (AttachmentType.values()[input.readByte()]) {
    case region: {
        String path = input.readString();
        if (path == null)
            path = name;
        RegionAttachment region = attachmentLoader.newRegionAttachment(skin, name, path);
        if (region == null)
            return null;
        region.setPath(path);
        region.setX(input.readFloat() * scale);
        region.setY(input.readFloat() * scale);
        region.setScaleX(input.readFloat());
        region.setScaleY(input.readFloat());
        region.setRotation(input.readFloat());
        region.setWidth(input.readFloat() * scale);
        region.setHeight(input.readFloat() * scale);
        Color.rgba8888ToColor(region.getColor(), input.readInt());
        region.updateOffset();
        return region;
    }
    case boundingbox: {
        BoundingBoxAttachment box = attachmentLoader.newBoundingBoxAttachment(skin, name);
        if (box == null)
            return null;
        box.setVertices(readFloatArray(input, scale));
        return box;
    }
    case mesh: {
        String path = input.readString();
        if (path == null)
            path = name;
        MeshAttachment mesh = attachmentLoader.newMeshAttachment(skin, name, path);
        if (mesh == null)
            return null;
        mesh.setPath(path);
        float[] uvs = readFloatArray(input, 1);
        short[] triangles = readShortArray(input);
        float[] vertices = readFloatArray(input, scale);
        mesh.setVertices(vertices);
        mesh.setTriangles(triangles);
        mesh.setRegionUVs(uvs);
        mesh.updateUVs();
        Color.rgba8888ToColor(mesh.getColor(), input.readInt());
        mesh.setHullLength(input.readInt(true) * 2);
        if (nonessential) {
            mesh.setEdges(readIntArray(input));
            mesh.setWidth(input.readFloat() * scale);
            mesh.setHeight(input.readFloat() * scale);
        }
        return mesh;
    }
    case skinnedmesh: {
        String path = input.readString();
        if (path == null)
            path = name;
        SkinnedMeshAttachment mesh = attachmentLoader.newSkinnedMeshAttachment(skin, name, path);
        if (mesh == null)
            return null;
        mesh.setPath(path);
        float[] uvs = readFloatArray(input, 1);
        short[] triangles = readShortArray(input);

        int vertexCount = input.readInt(true);
        FloatArray weights = new FloatArray(uvs.length * 3 * 3);
        IntArray bones = new IntArray(uvs.length * 3);
        for (int i = 0; i < vertexCount; i++) {
            int boneCount = (int) input.readFloat();
            bones.add(boneCount);
            for (int nn = i + boneCount * 4; i < nn; i += 4) {
                bones.add((int) input.readFloat());
                weights.add(input.readFloat() * scale);
                weights.add(input.readFloat() * scale);
                weights.add(input.readFloat());
            }
        }
        mesh.setBones(bones.toArray());
        mesh.setWeights(weights.toArray());
        mesh.setTriangles(triangles);
        mesh.setRegionUVs(uvs);
        mesh.updateUVs();
        Color.rgba8888ToColor(mesh.getColor(), input.readInt());
        mesh.setHullLength(input.readInt(true) * 2);
        if (nonessential) {
            mesh.setEdges(readIntArray(input));
            mesh.setWidth(input.readFloat() * scale);
            mesh.setHeight(input.readFloat() * scale);
        }
        return mesh;
    }
    }
    return null;
}

From source file:com.company.minery.utils.spine.SkeletonJson.java

License:Open Source License

private Attachment readAttachment(Skin skin, String name, JsonValue map) {
    float scale = this.scale;
    name = map.getString("name", name);
    String path = map.getString("path", name);

    switch (AttachmentType.valueOf(map.getString("type", AttachmentType.region.name()))) {
    case region: {
        RegionAttachment region = attachmentLoader.newRegionAttachment(skin, name, path);
        if (region == null)
            return null;
        region.setPath(path);/*from  w ww .  j a v a 2 s. co m*/
        region.setX(map.getFloat("x", 0) * scale);
        region.setY(map.getFloat("y", 0) * scale);
        region.setScaleX(map.getFloat("scaleX", 1));
        region.setScaleY(map.getFloat("scaleY", 1));
        region.setRotation(map.getFloat("rotation", 0));
        region.setWidth(map.getFloat("width") * scale);
        region.setHeight(map.getFloat("height") * scale);

        String color = map.getString("color", null);
        if (color != null)
            region.getColor().set(Color.valueOf(color));

        region.updateOffset();
        return region;
    }
    case boundingbox: {
        BoundingBoxAttachment box = attachmentLoader.newBoundingBoxAttachment(skin, name);
        if (box == null)
            return null;
        float[] vertices = map.require("vertices").asFloatArray();
        if (scale != 1) {
            for (int i = 0, n = vertices.length; i < n; i++)
                vertices[i] *= scale;
        }
        box.setVertices(vertices);
        return box;
    }
    case mesh: {
        MeshAttachment mesh = attachmentLoader.newMeshAttachment(skin, name, path);
        if (mesh == null)
            return null;
        mesh.setPath(path);
        float[] vertices = map.require("vertices").asFloatArray();
        if (scale != 1) {
            for (int i = 0, n = vertices.length; i < n; i++)
                vertices[i] *= scale;
        }
        mesh.setVertices(vertices);
        mesh.setTriangles(map.require("triangles").asShortArray());
        mesh.setRegionUVs(map.require("uvs").asFloatArray());
        mesh.updateUVs();

        String color = map.getString("color", null);
        if (color != null)
            mesh.getColor().set(Color.valueOf(color));

        if (map.has("hull"))
            mesh.setHullLength(map.require("hull").asInt() * 2);
        if (map.has("edges"))
            mesh.setEdges(map.require("edges").asIntArray());
        mesh.setWidth(map.getFloat("width", 0) * scale);
        mesh.setHeight(map.getFloat("height", 0) * scale);
        return mesh;
    }
    case skinnedmesh: {
        SkinnedMeshAttachment mesh = attachmentLoader.newSkinnedMeshAttachment(skin, name, path);
        if (mesh == null)
            return null;
        mesh.setPath(path);
        float[] uvs = map.require("uvs").asFloatArray();
        float[] vertices = map.require("vertices").asFloatArray();
        FloatArray weights = new FloatArray(uvs.length * 3 * 3);
        IntArray bones = new IntArray(uvs.length * 3);
        for (int i = 0, n = vertices.length; i < n;) {
            int boneCount = (int) vertices[i++];
            bones.add(boneCount);
            for (int nn = i + boneCount * 4; i < nn;) {
                bones.add((int) vertices[i]);
                weights.add(vertices[i + 1] * scale);
                weights.add(vertices[i + 2] * scale);
                weights.add(vertices[i + 3]);
                i += 4;
            }
        }
        mesh.setBones(bones.toArray());
        mesh.setWeights(weights.toArray());
        mesh.setTriangles(map.require("triangles").asShortArray());
        mesh.setRegionUVs(uvs);
        mesh.updateUVs();

        String color = map.getString("color", null);
        if (color != null)
            mesh.getColor().set(Color.valueOf(color));

        if (map.has("hull"))
            mesh.setHullLength(map.require("hull").asInt() * 2);
        if (map.has("edges"))
            mesh.setEdges(map.require("edges").asIntArray());
        mesh.setWidth(map.getFloat("width", 0) * scale);
        mesh.setHeight(map.getFloat("height", 0) * scale);
        return mesh;
    }
    }

    // RegionSequenceAttachment regionSequenceAttachment = (RegionSequenceAttachment)attachment;
    //
    // float fps = map.getFloat("fps");
    // regionSequenceAttachment.setFrameTime(fps);
    //
    // String modeString = map.getString("mode");
    // regionSequenceAttachment.setMode(modeString == null ? Mode.forward : Mode.valueOf(modeString));

    return null;
}

From source file:com.mbrlabs.mundus.commons.assets.TerrainAsset.java

License:Apache License

@Override
public void load() {
    // load height data from terra file
    final FloatArray floatArray = new FloatArray();

    DataInputStream is;/*from   w w w.  j ava 2 s  .  c o  m*/
    try {
        is = new DataInputStream(file.read());
        while (is.available() > 0) {
            floatArray.add(is.readFloat());
        }
        is.close();
    } catch (EOFException e) {
        // e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    data = floatArray.toArray();

    terrain = new Terrain(meta.getTerrain().getSize(), data);
    terrain.init();
    terrain.update();
}

From source file:com.mbrlabs.mundus.runtime.libgdx.TerraLoader.java

License:Apache License

public static float[] readTerraFile(FileHandle terra) {
    FloatArray floatArray = new FloatArray();

    DataInputStream is = null;//ww w.j av  a  2s.  c o  m
    try {
        is = new DataInputStream(new BufferedInputStream(new GZIPInputStream(terra.read())));
        while (is.available() > 0) {
            floatArray.add(is.readFloat());
        }
        is.close();
    } catch (EOFException e) {
        // e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return floatArray.toArray();
}

From source file:com.mbrlabs.mundus.utils.TerrainIO.java

License:Apache License

public static Terrain importTerrain(ProjectContext projectContext, Terrain terrain) {
    FloatArray floatArray = new FloatArray();

    String terraPath = FilenameUtils.concat(projectContext.path, terrain.terraPath);
    try (DataInputStream is = new DataInputStream(
            new BufferedInputStream(new GZIPInputStream(new FileInputStream(terraPath))))) {
        while (is.available() > 0) {
            floatArray.add(is.readFloat());
        }/*from  w w  w  .  j av a  2 s  . co  m*/
    } catch (EOFException e) {
        //e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    //Log.debug("Terrain import. floats: " + floatArray.size);

    terrain.heightData = floatArray.toArray();
    terrain.init();
    terrain.update();

    // set default terrain base texture if none is present
    TerrainTexture terrainTexture = terrain.getTerrainTexture();
    if (terrainTexture.getTexture(SplatTexture.Channel.BASE) == null) {
        MTexture base = new MTexture();
        base.setId(-1);
        base.texture = TextureUtils.loadMipmapTexture(Gdx.files.internal("textures/terrain/chess.png"), true);
        terrainTexture.setSplatTexture(new SplatTexture(SplatTexture.Channel.BASE, base));
    }

    // load splat map if available
    SplatMap splatmap = terrainTexture.getSplatmap();
    if (splatmap != null) {
        String splatPath = FilenameUtils.concat(projectContext.path, splatmap.getPath());
        splatmap.loadPNG(Gdx.files.absolute(splatPath));
    }

    return terrain;
}

From source file:es.eucm.ead.engine.collision.BoundingAreaBuilder.java

License:Open Source License

/**
 * Creates a minimum convex polygon that contains the given entity. The
 * algorithm takes into account renderers' colliders (if available), and
 * children. The algorithm gets different polygons coming from renderers,
 * children, etc. and uses {@link ConvexHull} to determine the minimum
 * convex polygon that contains all of them.
 * /*w ww  .  jav  a  2s .co  m*/
 * @param entity
 *            The entity to build a bounding polygon for.
 * @return The bounding convex polygon, in coordinates of the
 *         {@link Layer#SCENE_CONTENT} layer. May return {@code null} if
 *         this entity is not a descendant of {@link Layer#SCENE_CONTENT}.
 */
static Polygon getBoundingPolygon(EngineEntity entity) {
    Array<Vector2> points = new Array<Vector2>();
    int count = 0;
    Group sceneContentGroup = getSceneContentAncestor(entity).getGroup();
    if (sceneContentGroup == null) {
        return null;
    }

    Polygon polygon = getBoundingPolygon(entity, sceneContentGroup, entity.getGroup());
    if (polygon != null) {
        toVector2Array(polygon.getVertices(), points);
        count++;
    }

    for (Actor actor : entity.getGroup().getChildren()) {
        if (actor.getUserObject() != null && actor.getUserObject() instanceof EngineEntity) {
            EngineEntity child = (EngineEntity) actor.getUserObject();
            Polygon childPolygon = getBoundingPolygon(child);
            toVector2Array(childPolygon.getVertices(), points);
            count++;
        }
    }

    polygon = new Polygon();
    if (count > 1) {
        FloatArray polygonPoints = convexHull.computePolygon(toSimpleArray(points), false);
        // Remove last point (duplicate)
        polygonPoints.removeRange(polygonPoints.size - 2, polygonPoints.size - 1);
        polygon.setVertices(polygonPoints.toArray());
    } else {
        polygon.setVertices(toSimpleArray(points));
    }
    for (Vector2 point : points) {
        Pools.free(point);
    }
    return polygon;
}

From source file:es.eucm.ead.engine.collision.BoundingAreaBuilder.java

License:Open Source License

private static Polygon getBoundingPolygon(EngineEntity entity, Group sceneContentGroup, Group group) {
    SnapshotArray<Vector2> allPoints = new SnapshotArray<Vector2>();

    for (Polygon polygon : getColliders(entity)) {
        for (int i = 0; i < polygon.getVertices().length; i += 2) {
            Vector2 tmp = Pools.obtain(Vector2.class);
            tmp.set(polygon.getVertices()[i], polygon.getVertices()[i + 1]);
            group.localToAscendantCoordinates(sceneContentGroup, tmp);
            allPoints.add(tmp);//from  w  w  w.  j  a  va2 s  .c  o  m
        }
    }

    if (allPoints.size == 0) {
        return null;
    }

    // Remove duplicates, if any. Algorithm works better this way
    Object[] pointsToIterate = allPoints.begin();
    int size = allPoints.size;
    for (int i = 0; i < size; i++) {
        Vector2 pointA = (Vector2) pointsToIterate[i];
        for (int j = 0; j < size; j++) {
            Vector2 pointB = (Vector2) pointsToIterate[j];
            if (j != i && pointA.equals(pointB)) {
                allPoints.removeValue(pointB, true);
            }
        }
    }
    allPoints.end();

    // To array
    float[] points = toSimpleArray(allPoints);
    FloatArray floatArray = convexHull.computePolygon(points, false);
    // Remove the last point, since its the first one (duplicate)
    floatArray.removeRange(floatArray.size - 2, floatArray.size - 1);
    Polygon polygon = new Polygon();
    polygon.setVertices(floatArray.toArray());
    return polygon;
}

From source file:spine.SkeletonBinary.java

License:Open Source License

private Attachment readAttachment(DataInput input, Skin skin, String attachmentName, boolean nonessential)
        throws IOException {
    float scale = this.scale;

    String name = input.readString();
    if (name == null)
        name = attachmentName;/*from  w  w w.  j  a v  a2  s  . co  m*/

    switch (AttachmentType.values[input.readByte()]) {
    case region: {
        String path = input.readString();
        if (path == null)
            path = name;
        RegionAttachment region = attachmentLoader.newRegionAttachment(skin, name, path);
        if (region == null)
            return null;
        region.setPath(path);
        region.setX(input.readFloat() * scale);
        region.setY(input.readFloat() * scale);
        region.setScaleX(input.readFloat());
        region.setScaleY(input.readFloat());
        region.setRotation(input.readFloat());
        region.setWidth(input.readFloat() * scale);
        region.setHeight(input.readFloat() * scale);
        Color.rgba8888ToColor(region.getColor(), input.readInt());
        region.updateOffset();
        return region;
    }
    case boundingbox: {
        BoundingBoxAttachment box = attachmentLoader.newBoundingBoxAttachment(skin, name);
        if (box == null)
            return null;
        box.setVertices(readFloatArray(input, scale));
        return box;
    }
    case mesh: {
        String path = input.readString();
        if (path == null)
            path = name;
        MeshAttachment mesh = attachmentLoader.newMeshAttachment(skin, name, path);
        if (mesh == null)
            return null;
        mesh.setPath(path);
        float[] uvs = readFloatArray(input, 1);
        short[] triangles = readShortArray(input);
        float[] vertices = readFloatArray(input, scale);
        mesh.setVertices(vertices);
        mesh.setTriangles(triangles);
        mesh.setRegionUVs(uvs);
        mesh.updateUVs();
        Color.rgba8888ToColor(mesh.getColor(), input.readInt());
        mesh.setHullLength(input.readInt(true) * 2);
        if (nonessential) {
            mesh.setEdges(readIntArray(input));
            mesh.setWidth(input.readFloat() * scale);
            mesh.setHeight(input.readFloat() * scale);
        }
        return mesh;
    }
    case skinnedmesh: {
        String path = input.readString();
        if (path == null)
            path = name;
        SkinnedMeshAttachment mesh = attachmentLoader.newSkinnedMeshAttachment(skin, name, path);
        if (mesh == null)
            return null;
        mesh.setPath(path);
        float[] uvs = readFloatArray(input, 1);
        short[] triangles = readShortArray(input);

        int vertexCount = input.readInt(true);
        FloatArray weights = new FloatArray(uvs.length * 3 * 3);
        IntArray bones = new IntArray(uvs.length * 3);
        for (int i = 0; i < vertexCount; i++) {
            int boneCount = (int) input.readFloat();
            bones.add(boneCount);
            for (int nn = i + boneCount * 4; i < nn; i += 4) {
                bones.add((int) input.readFloat());
                weights.add(input.readFloat() * scale);
                weights.add(input.readFloat() * scale);
                weights.add(input.readFloat());
            }
        }
        mesh.setBones(bones.toArray());
        mesh.setWeights(weights.toArray());
        mesh.setTriangles(triangles);
        mesh.setRegionUVs(uvs);
        mesh.updateUVs();
        Color.rgba8888ToColor(mesh.getColor(), input.readInt());
        mesh.setHullLength(input.readInt(true) * 2);
        if (nonessential) {
            mesh.setEdges(readIntArray(input));
            mesh.setWidth(input.readFloat() * scale);
            mesh.setHeight(input.readFloat() * scale);
        }
        return mesh;
    }
    }
    return null;
}