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

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

Introduction

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

Prototype

public int[] 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;/* w w  w  . ja  v a 2s .  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  .  jav a2  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: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  ww.j  a v  a2 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;
}