Examples of FfdTimeline


Examples of com.esotericsoftware.spine.Animation.FfdTimeline

        for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) {
          int slotIndex = input.readInt(true);
          for (int iii = 0, nnn = input.readInt(true); iii < nnn; iii++) {
            Attachment attachment = skin.getAttachment(slotIndex, input.readString());
            int frameCount = input.readInt(true);
            FfdTimeline timeline = new FfdTimeline(frameCount);
            timeline.slotIndex = slotIndex;
            timeline.attachment = attachment;
            for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
              float time = input.readFloat();

              float[] vertices;
              int vertexCount;
              if (attachment instanceof MeshAttachment)
                vertexCount = ((MeshAttachment)attachment).getVertices().length;
              else
                vertexCount = ((SkinnedMeshAttachment)attachment).getWeights().length / 3 * 2;

              int end = input.readInt(true);
              if (end == 0) {
                if (attachment instanceof MeshAttachment)
                  vertices = ((MeshAttachment)attachment).getVertices();
                else
                  vertices = new float[vertexCount];
              } else {
                vertices = new float[vertexCount];
                int start = input.readInt(true);
                end += start;
                if (scale == 1) {
                  for (int v = start; v < end; v++)
                    vertices[v] = input.readFloat();
                } else {
                  for (int v = start; v < end; v++)
                    vertices[v] = input.readFloat() * scale;
                }
                if (attachment instanceof MeshAttachment) {
                  float[] meshVertices = ((MeshAttachment)attachment).getVertices();
                  for (int v = 0, vn = vertices.length; v < vn; v++)
                    vertices[v] += meshVertices[v];
                }
              }

              timeline.setFrame(frameIndex, time, vertices);
              if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline);
            }
            timelines.add(timeline);
            duration = Math.max(duration, timeline.getFrames()[frameCount - 1]);
          }
        }
      }

      // Draw order timeline.
      int drawOrderCount = input.readInt(true);
      if (drawOrderCount > 0) {
        DrawOrderTimeline timeline = new DrawOrderTimeline(drawOrderCount);
        int slotCount = skeletonData.slots.size;
        for (int i = 0; i < drawOrderCount; i++) {
          int offsetCount = input.readInt(true);
          int[] drawOrder = new int[slotCount];
          for (int ii = slotCount - 1; ii >= 0; ii--)
            drawOrder[ii] = -1;
          int[] unchanged = new int[slotCount - offsetCount];
          int originalIndex = 0, unchangedIndex = 0;
          for (int ii = 0; ii < offsetCount; ii++) {
            int slotIndex = input.readInt(true);
            // Collect unchanged items.
            while (originalIndex != slotIndex)
              unchanged[unchangedIndex++] = originalIndex++;
            // Set changed items.
            drawOrder[originalIndex + input.readInt(true)] = originalIndex++;
          }
          // Collect remaining unchanged items.
          while (originalIndex < slotCount)
            unchanged[unchangedIndex++] = originalIndex++;
          // Fill in unchanged items.
          for (int ii = slotCount - 1; ii >= 0; ii--)
            if (drawOrder[ii] == -1) drawOrder[ii] = unchanged[--unchangedIndex];
          timeline.setFrame(i, input.readFloat(), drawOrder);
        }
        timelines.add(timeline);
        duration = Math.max(duration, timeline.getFrames()[drawOrderCount - 1]);
      }

      // Event timeline.
      int eventCount = input.readInt(true);
      if (eventCount > 0) {
        EventTimeline timeline = new EventTimeline(eventCount);
        for (int i = 0; i < eventCount; i++) {
          float time = input.readFloat();
          EventData eventData = skeletonData.events.get(input.readInt(true));
          Event event = new Event(eventData);
          event.intValue = input.readInt(false);
          event.floatValue = input.readFloat();
          event.stringValue = input.readBoolean() ? input.readString() : eventData.stringValue;
          timeline.setFrame(i, time, event);
        }
        timelines.add(timeline);
        duration = Math.max(duration, timeline.getFrames()[eventCount - 1]);
      }
    } catch (IOException ex) {
      throw new SerializationException("Error reading skeleton file.", ex);
    }

View Full Code Here

Examples of com.esotericsoftware.spine.Animation.FfdTimeline

      if (skin == null) throw new SerializationException("Skin not found: " + ffdMap.name);
      for (JsonValue slotMap = ffdMap.child; slotMap != null; slotMap = slotMap.next) {
        int slotIndex = skeletonData.findSlotIndex(slotMap.name);
        if (slotIndex == -1) throw new SerializationException("Slot not found: " + slotMap.name);
        for (JsonValue meshMap = slotMap.child; meshMap != null; meshMap = meshMap.next) {
          FfdTimeline timeline = new FfdTimeline(meshMap.size);
          Attachment attachment = skin.getAttachment(slotIndex, meshMap.name);
          if (attachment == null) throw new SerializationException("FFD attachment not found: " + meshMap.name);
          timeline.slotIndex = slotIndex;
          timeline.attachment = attachment;

          int vertexCount;
          if (attachment instanceof MeshAttachment)
            vertexCount = ((MeshAttachment)attachment).getVertices().length;
          else
            vertexCount = ((SkinnedMeshAttachment)attachment).getWeights().length / 3 * 2;

          int frameIndex = 0;
          for (JsonValue valueMap = meshMap.child; valueMap != null; valueMap = valueMap.next) {
            float[] vertices;
            JsonValue verticesValue = valueMap.get("vertices");
            if (verticesValue == null) {
              if (attachment instanceof MeshAttachment)
                vertices = ((MeshAttachment)attachment).getVertices();
              else
                vertices = new float[vertexCount];
            } else {
              vertices = new float[vertexCount];
              int start = valueMap.getInt("offset", 0);
              System.arraycopy(verticesValue.asFloatArray(), 0, vertices, start, verticesValue.size);
              if (scale != 1) {
                for (int i = start, n = i + verticesValue.size; i < n; i++)
                  vertices[i] *= scale;
              }
              if (attachment instanceof MeshAttachment) {
                float[] meshVertices = ((MeshAttachment)attachment).getVertices();
                for (int i = 0; i < vertexCount; i++)
                  vertices[i] += meshVertices[i];
              }
            }

            timeline.setFrame(frameIndex, valueMap.getFloat("time"), vertices);
            readCurve(timeline, frameIndex, valueMap);
            frameIndex++;
          }
          timelines.add(timeline);
          duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
        }
      }
    }

    // Draw order timeline.
    JsonValue drawOrdersMap = map.get("drawOrder");
    if (drawOrdersMap == null) drawOrdersMap = map.get("draworder");
    if (drawOrdersMap != null) {
      DrawOrderTimeline timeline = new DrawOrderTimeline(drawOrdersMap.size);
      int slotCount = skeletonData.slots.size;
      int frameIndex = 0;
      for (JsonValue drawOrderMap = drawOrdersMap.child; drawOrderMap != null; drawOrderMap = drawOrderMap.next) {
        int[] drawOrder = null;
        JsonValue offsets = drawOrderMap.get("offsets");
        if (offsets != null) {
          drawOrder = new int[slotCount];
          for (int i = slotCount - 1; i >= 0; i--)
            drawOrder[i] = -1;
          int[] unchanged = new int[slotCount - offsets.size];
          int originalIndex = 0, unchangedIndex = 0;
          for (JsonValue offsetMap = offsets.child; offsetMap != null; offsetMap = offsetMap.next) {
            int slotIndex = skeletonData.findSlotIndex(offsetMap.getString("slot"));
            if (slotIndex == -1) throw new SerializationException("Slot not found: " + offsetMap.getString("slot"));
            // Collect unchanged items.
            while (originalIndex != slotIndex)
              unchanged[unchangedIndex++] = originalIndex++;
            // Set changed items.
            drawOrder[originalIndex + offsetMap.getInt("offset")] = originalIndex++;
          }
          // Collect remaining unchanged items.
          while (originalIndex < slotCount)
            unchanged[unchangedIndex++] = originalIndex++;
          // Fill in unchanged items.
          for (int i = slotCount - 1; i >= 0; i--)
            if (drawOrder[i] == -1) drawOrder[i] = unchanged[--unchangedIndex];
        }
        timeline.setFrame(frameIndex++, drawOrderMap.getFloat("time"), drawOrder);
      }
      timelines.add(timeline);
      duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
    }

    // Event timeline.
    JsonValue eventsMap = map.get("events");
    if (eventsMap != null) {
      EventTimeline timeline = new EventTimeline(eventsMap.size);
      int frameIndex = 0;
      for (JsonValue eventMap = eventsMap.child; eventMap != null; eventMap = eventMap.next) {
        EventData eventData = skeletonData.findEvent(eventMap.getString("name"));
        if (eventData == null) throw new SerializationException("Event not found: " + eventMap.getString("name"));
        Event event = new Event(eventData);
        event.intValue = eventMap.getInt("int", eventData.getInt());
        event.floatValue = eventMap.getFloat("float", eventData.getFloat());
        event.stringValue = eventMap.getString("string", eventData.getString());
        timeline.setFrame(frameIndex++, eventMap.getFloat("time"), event);
      }
      timelines.add(timeline);
      duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
    }

    timelines.shrink();
    skeletonData.animations.add(new Animation(name, timelines, duration));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.