Package com.esotericsoftware.spine.attachments

Examples of com.esotericsoftware.spine.attachments.MeshAttachment


        vertices = region.getWorldVertices();
        triangles = quadTriangles;
        texture = region.getRegion().getTexture();

      } else if (attachment instanceof MeshAttachment) {
        MeshAttachment mesh = (MeshAttachment)attachment;
        mesh.updateWorldVertices(slot, true);
        vertices = mesh.getWorldVertices();
        triangles = mesh.getTriangles();
        texture = mesh.getRegion().getTexture();

      } else if (attachment instanceof SkinnedMeshAttachment) {
        SkinnedMeshAttachment mesh = (SkinnedMeshAttachment)attachment;
        mesh.updateWorldVertices(slot, true);
        vertices = mesh.getWorldVertices();
        triangles = mesh.getTriangles();
        texture = mesh.getRegion().getTexture();

      } else if (attachment instanceof SkeletonAttachment) {
        Skeleton attachmentSkeleton = ((SkeletonAttachment)attachment).getSkeleton();
        if (attachmentSkeleton == null) continue;
        Bone bone = slot.getBone();
View Full Code Here


      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;
View Full Code Here

      }
      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;
View Full Code Here

        Attachment attachment = slot.attachment;
        float[] vertices = null;
        short[] triangles = null;
        int hullLength = 0;
        if (attachment instanceof MeshAttachment) {
          MeshAttachment mesh = (MeshAttachment)attachment;
          mesh.updateWorldVertices(slot, false);
          vertices = mesh.getWorldVertices();
          triangles = mesh.getTriangles();
          hullLength = mesh.getHullLength();
        } else if (attachment instanceof SkinnedMeshAttachment) {
          SkinnedMeshAttachment mesh = (SkinnedMeshAttachment)attachment;
          mesh.updateWorldVertices(slot, false);
          vertices = mesh.getWorldVertices();
          triangles = mesh.getTriangles();
          hullLength = mesh.getHullLength();
        }
        if (vertices == null || triangles == null) continue;
        if (drawMeshTriangles) {
          shapes.setColor(triangleLineColor);
          for (int ii = 0, nn = triangles.length; ii < nn; ii += 3) {
View Full Code Here

TOP

Related Classes of com.esotericsoftware.spine.attachments.MeshAttachment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.