Package com.badlogic.gdx.utils

Examples of com.badlogic.gdx.utils.DataInput


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

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

    DataInput input = new DataInput(file.read(512));
    try {
      // Bones.
      for (int i = 0, n = input.readInt(true); i < n; i++) {
        String name = input.readString();
        BoneData parent = null;
        String parentName = input.readString();
        if (parentName != null) {
          parent = skeletonData.findBone(parentName);
          if (parent == null) throw new SerializationException("Parent bone not found: " + parentName);
        }
        BoneData boneData = new BoneData(name, parent);
        boneData.x = input.readFloat() * scale;
        boneData.y = input.readFloat() * scale;
        boneData.scaleX = input.readFloat();
        boneData.scaleY = input.readFloat();
        boneData.rotation = input.readFloat();
        boneData.length = input.readFloat() * scale;
        boneData.inheritScale = input.readByte() == 1;
        boneData.inheritRotation = input.readByte() == 1;
        skeletonData.addBone(boneData);
      }

      // Slots.
      for (int i = 0, n = input.readInt(true); i < n; i++) {
        String slotName = input.readString();
        String boneName = input.readString();
        BoneData boneData = skeletonData.findBone(boneName);
        if (boneData == null) throw new SerializationException("Bone not found: " + boneName);
        SlotData slotData = new SlotData(slotName, boneData);
        Color.rgba8888ToColor(slotData.getColor(), input.readInt());
        slotData.setAttachmentName(input.readString());
        slotData.additiveBlending = input.readByte() == 1;
        skeletonData.addSlot(slotData);
      }

      // Default skin.
      Skin defaultSkin = readSkin(input, "default");
      if (defaultSkin != null) {
        skeletonData.setDefaultSkin(defaultSkin);
        skeletonData.addSkin(defaultSkin);
      }

      // Skins.
      for (int i = 0, n = input.readInt(true); i < n; i++)
        skeletonData.addSkin(readSkin(input, input.readString()));

      // Animations.
      for (int i = 0, n = input.readInt(true); i < n; i++)
        readAnimation(input.readString(), input, skeletonData);

    } catch (IOException ex) {
      throw new SerializationException("Error reading skeleton file.", ex);
    } finally {
      try {
        input.close();
      } catch (IOException ignored) {
      }
    }

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


    float scale = this.scale;

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

    DataInput input = new DataInput(file.read(512));
    try {
      skeletonData.hash = input.readString();
      if (skeletonData.hash.isEmpty()) skeletonData.hash = null;
      skeletonData.version = input.readString();
      if (skeletonData.version.isEmpty()) skeletonData.version = null;
      skeletonData.width = input.readFloat();
      skeletonData.height = input.readFloat();

      boolean nonessential = input.readBoolean();

      if (nonessential) {
        skeletonData.imagesPath = input.readString();
        if (skeletonData.imagesPath.isEmpty()) skeletonData.imagesPath = null;
      }

      // Bones.
      for (int i = 0, n = input.readInt(true); i < n; i++) {
        String name = input.readString();
        BoneData parent = null;
        int parentIndex = input.readInt(true) - 1;
        if (parentIndex != -1) parent = skeletonData.bones.get(parentIndex);
        BoneData boneData = new BoneData(name, parent);
        boneData.x = input.readFloat() * scale;
        boneData.y = input.readFloat() * scale;
        boneData.scaleX = input.readFloat();
        boneData.scaleY = input.readFloat();
        boneData.rotation = input.readFloat();
        boneData.length = input.readFloat() * scale;
        boneData.flipX = input.readBoolean();
        boneData.flipY = input.readBoolean();
        boneData.inheritScale = input.readBoolean();
        boneData.inheritRotation = input.readBoolean();
        if (nonessential) Color.rgba8888ToColor(boneData.color, input.readInt());
        skeletonData.bones.add(boneData);
      }

      // IK constraints.
      for (int i = 0, n = input.readInt(true); i < n; i++) {
        IkConstraintData ikConstraintData = new IkConstraintData(input.readString());
        for (int ii = 0, nn = input.readInt(true); ii < nn; ii++)
          ikConstraintData.bones.add(skeletonData.bones.get(input.readInt(true)));
        ikConstraintData.target = skeletonData.bones.get(input.readInt(true));
        ikConstraintData.mix = input.readFloat();
        ikConstraintData.bendDirection = input.readByte();
        skeletonData.ikConstraints.add(ikConstraintData);
      }

      // Slots.
      for (int i = 0, n = input.readInt(true); i < n; i++) {
        String slotName = input.readString();
        BoneData boneData = skeletonData.bones.get(input.readInt(true));
        SlotData slotData = new SlotData(slotName, boneData);
        Color.rgba8888ToColor(slotData.color, input.readInt());
        slotData.attachmentName = input.readString();
        slotData.additiveBlending = input.readBoolean();
        skeletonData.slots.add(slotData);
      }

      // Default skin.
      Skin defaultSkin = readSkin(input, "default", nonessential);
      if (defaultSkin != null) {
        skeletonData.defaultSkin = defaultSkin;
        skeletonData.skins.add(defaultSkin);
      }

      // Skins.
      for (int i = 0, n = input.readInt(true); i < n; i++)
        skeletonData.skins.add(readSkin(input, input.readString(), nonessential));

      // Events.
      for (int i = 0, n = input.readInt(true); i < n; i++) {
        EventData eventData = new EventData(input.readString());
        eventData.intValue = input.readInt(false);
        eventData.floatValue = input.readFloat();
        eventData.stringValue = input.readString();
        skeletonData.events.add(eventData);
      }

      // Animations.
      for (int i = 0, n = input.readInt(true); i < n; i++)
        readAnimation(input.readString(), input, skeletonData);

    } catch (IOException ex) {
      throw new SerializationException("Error reading skeleton file.", ex);
    } finally {
      try {
        input.close();
      } catch (IOException ignored) {
      }
    }

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

TOP

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

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.