Package com.badlogic.gdx.utils

Examples of com.badlogic.gdx.utils.JsonValue


    if (file == null) throw new IllegalArgumentException("file cannot be null.");

    SkeletonData skeletonData = new SkeletonData();
    skeletonData.setName(file.nameWithoutExtension());

    JsonValue root = new JsonReader().parse(file);

    // Bones.
    for (JsonValue boneMap = root.getChild("bones"); boneMap != null; boneMap = boneMap.next()) {
      BoneData parent = null;
      String parentName = boneMap.getString("parent", null);
      if (parentName != null) {
        parent = skeletonData.findBone(parentName);
        if (parent == null) throw new SerializationException("Parent bone not found: " + parentName);
      }
      BoneData boneData = new BoneData(boneMap.getString("name"), parent);
      boneData.length = boneMap.getFloat("length", 0) * scale;
      boneData.x = boneMap.getFloat("x", 0) * scale;
      boneData.y = boneMap.getFloat("y", 0) * scale;
      boneData.rotation = boneMap.getFloat("rotation", 0);
      boneData.scaleX = boneMap.getFloat("scaleX", 1);
      boneData.scaleY = boneMap.getFloat("scaleY", 1);
      boneData.inheritScale = boneMap.getBoolean("inheritScale", true);
      boneData.inheritRotation = boneMap.getBoolean("inheritRotation", true);
      skeletonData.addBone(boneData);
    }

    // Slots.
    for (JsonValue slotMap = root.getChild("slots"); slotMap != null; slotMap = slotMap.next()) {
      String slotName = slotMap.getString("name");
      String boneName = slotMap.getString("bone");
      BoneData boneData = skeletonData.findBone(boneName);
      if (boneData == null) throw new SerializationException("Slot bone not found: " + boneName);
      SlotData slotData = new SlotData(slotName, boneData);

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

      slotData.setAttachmentName(slotMap.getString("attachment", null));

      slotData.additiveBlending = slotMap.getBoolean("additive", false);

      skeletonData.addSlot(slotData);
    }

    // Skins.
    for (JsonValue skinMap = root.getChild("skins"); skinMap != null; skinMap = skinMap.next()) {
      Skin skin = new Skin(skinMap.name());
      for (JsonValue slotEntry = skinMap.child(); slotEntry != null; slotEntry = slotEntry.next()) {
        int slotIndex = skeletonData.findSlotIndex(slotEntry.name());
        for (JsonValue entry = slotEntry.child(); entry != null; entry = entry.next()) {
          Attachment attachment = readAttachment(skin, entry.name(), entry);
          if (attachment != null) skin.addAttachment(slotIndex, entry.name(), attachment);
        }
      }
      skeletonData.addSkin(skin);
      if (skin.name.equals("default")) skeletonData.setDefaultSkin(skin);
    }

    // Animations.
    for (JsonValue animationMap = root.getChild("animations"); animationMap != null; animationMap = animationMap.next())
      readAnimation(animationMap.name(), animationMap, skeletonData);

    skeletonData.bones.shrink();
    skeletonData.slots.shrink();
    skeletonData.skins.shrink();
View Full Code Here


    timelines.shrink();
    skeletonData.addAnimation(new Animation(name, timelines, duration));
  }

  private void readCurve (CurveTimeline timeline, int frameIndex, JsonValue valueMap) {
    JsonValue curve = valueMap.get("curve");
    if (curve == null) return;
    if (curve.isString() && curve.asString().equals("stepped"))
      timeline.setStepped(frameIndex);
    else if (curve.isArray()) {
      timeline.setCurve(frameIndex, curve.getFloat(0), curve.getFloat(1), curve.getFloat(2), curve.getFloat(3));
    }
  }
View Full Code Here

    float scale = this.scale;

    SkeletonData skeletonData = new SkeletonData();
    skeletonData.name = file.nameWithoutExtension();

    JsonValue root = new JsonReader().parse(file);

    // Skeleton.
    JsonValue skeletonMap = root.get("skeleton");
    if (skeletonMap != null) {
      skeletonData.hash = skeletonMap.getString("hash", null);
      skeletonData.version = skeletonMap.getString("spine", null);
      skeletonData.width = skeletonMap.getFloat("width", 0);
      skeletonData.height = skeletonMap.getFloat("height", 0);
      skeletonData.imagesPath = skeletonMap.getString("images", null);
    }

    // Bones.
    for (JsonValue boneMap = root.getChild("bones"); boneMap != null; boneMap = boneMap.next) {
      BoneData parent = null;
View Full Code Here

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

    timelines.shrink();
    skeletonData.animations.add(new Animation(name, timelines, duration));
  }

  void readCurve (CurveTimeline timeline, int frameIndex, JsonValue valueMap) {
    JsonValue curve = valueMap.get("curve");
    if (curve == null) return;
    if (curve.isString() && curve.asString().equals("stepped"))
      timeline.setStepped(frameIndex);
    else if (curve.isArray()) {
      timeline.setCurve(frameIndex, curve.getFloat(0), curve.getFloat(1), curve.getFloat(2), curve.getFloat(3));
    }
  }
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.utils.JsonValue

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.