Esempio n. 1
0
        private int[] ReadShortArray(SkeletonDataStream input)
        {
            int n = SkeletonDataStream.sp_readVarint(input.ptr, 1);

            int[] array = new int[n];
            for (int i = 0; i < n; i++)
            {
                array[i] = (input.ReadByte() << 8) | input.ReadByte();
            }
            return(array);
        }
Esempio n. 2
0
        void ReadSlotAnimation(ref ExposedList <Timeline> timelines, SkeletonDataStream input, ref float duration, float scale)
        {
            // Slot timelines.
            for (int i = 0, n = SkeletonDataStream.sp_readVarint(input.ptr, 1); i < n; i++)
            {
                int slotIndex = SkeletonDataStream.sp_readVarint(input.ptr, 1);
                for (int ii = 0, nn = SkeletonDataStream.sp_readVarint(input.ptr, 1); ii < nn; ii++)
                {
                    int timelineType = input.ReadByte();
                    int frameCount   = SkeletonDataStream.sp_readVarint(input.ptr, 1);
                    switch (timelineType)
                    {
                    case SLOT_COLOR: {
                        ColorTimeline timeline = new ColorTimeline(frameCount);
                        timeline.slotIndex = slotIndex;
                        for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
                        {
                            float time  = SkeletonDataStream.sp_readFloat(input.ptr);
                            int   color = input.ReadInt();
                            float r     = ((color & 0xff000000) >> 24) / 255f;
                            float g     = ((color & 0x00ff0000) >> 16) / 255f;
                            float b     = ((color & 0x0000ff00) >> 8) / 255f;
                            float a     = ((color & 0x000000ff)) / 255f;
                            timeline.SetFrame(frameIndex, time, r, g, b, a);
                            if (frameIndex < frameCount - 1)
                            {
                                SkeletonDataStream.sp_readCurve(input.ptr, frameIndex, timeline.curves);
                            }
                        }
                        timelines.Add(timeline);
                        duration = Math.Max(duration, timeline.frames[(timeline.FrameCount - 1) * ColorTimeline.ENTRIES]);
                        break;
                    }

                    case SLOT_ATTACHMENT: {
                        AttachmentTimeline timeline = new AttachmentTimeline(frameCount);
                        timeline.slotIndex = slotIndex;
                        for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
                        {
                            timeline.SetFrame(frameIndex, SkeletonDataStream.sp_readFloat(input.ptr), input.ReadString());
                        }
                        timelines.Add(timeline);
                        duration = Math.Max(duration, timeline.frames[frameCount - 1]);
                        break;
                    }
                    }
                }
            }
        }
Esempio n. 3
0
        void ReadBoneAnimation(ref ExposedList <Timeline> timelines, SkeletonDataStream input, ref float duration, float scale)
        {
            // Bone timelines.
            for (int i = 0, n = SkeletonDataStream.sp_readVarint(input.ptr, 1); i < n; i++)
            {
                int boneIndex = SkeletonDataStream.sp_readVarint(input.ptr, 1);
                for (int ii = 0, nn = SkeletonDataStream.sp_readVarint(input.ptr, 1); ii < nn; ii++)
                {
                    int timelineType = input.ReadByte();
                    int frameCount   = SkeletonDataStream.sp_readVarint(input.ptr, 1);
                    switch (timelineType)
                    {
                    case BONE_ROTATE: {
                        RotateTimeline timeline = new RotateTimeline(frameCount);
                        timeline.boneIndex = boneIndex;
                        for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
                        {
                            timeline.SetFrame(frameIndex, SkeletonDataStream.sp_readFloat(input.ptr), SkeletonDataStream.sp_readFloat(input.ptr));
                            if (frameIndex < frameCount - 1)
                            {
                                SkeletonDataStream.sp_readCurve(input.ptr, frameIndex, timeline.curves);
                            }
                        }
                        timelines.Add(timeline);
                        duration = Math.Max(duration, timeline.frames[(frameCount - 1) * RotateTimeline.ENTRIES]);
                        break;
                    }

                    case BONE_TRANSLATE:
                    case BONE_SCALE:
                    case BONE_SHEAR: {
                        TranslateTimeline timeline;
                        float             timelineScale = 1;
                        if (timelineType == BONE_SCALE)
                        {
                            timeline = new ScaleTimeline(frameCount);
                        }
                        else if (timelineType == BONE_SHEAR)
                        {
                            timeline = new ShearTimeline(frameCount);
                        }
                        else
                        {
                            timeline      = new TranslateTimeline(frameCount);
                            timelineScale = scale;
                        }
                        timeline.boneIndex = boneIndex;
                        for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
                        {
                            timeline.SetFrame(frameIndex, SkeletonDataStream.sp_readFloat(input.ptr), SkeletonDataStream.sp_readFloat(input.ptr) * timelineScale, SkeletonDataStream.sp_readFloat(input.ptr)
                                              * timelineScale);
                            if (frameIndex < frameCount - 1)
                            {
                                SkeletonDataStream.sp_readCurve(input.ptr, frameIndex, timeline.curves);
                            }
                        }
                        timelines.Add(timeline);
                        duration = Math.Max(duration, timeline.frames[(frameCount - 1) * TranslateTimeline.ENTRIES]);
                        break;
                    }
                    }
                }
            }
        }
Esempio n. 4
0
        private Attachment ReadAttachment(SkeletonDataStream input, Skin skin, int slotIndex, String attachmentName, bool nonessential)
        {
            float scale = Scale;

            String name = input.ReadString();

            if (name == null)
            {
                name = attachmentName;
            }

            AttachmentType type = (AttachmentType)input.ReadByte();

            switch (type)
            {
            case AttachmentType.Region: {
                String path     = input.ReadString();
                float  rotation = SkeletonDataStream.sp_readFloat(input.ptr);
                float  x        = SkeletonDataStream.sp_readFloat(input.ptr);
                float  y        = SkeletonDataStream.sp_readFloat(input.ptr);
                float  scaleX   = SkeletonDataStream.sp_readFloat(input.ptr);
                float  scaleY   = SkeletonDataStream.sp_readFloat(input.ptr);
                float  width    = SkeletonDataStream.sp_readFloat(input.ptr);
                float  height   = SkeletonDataStream.sp_readFloat(input.ptr);
                int    color    = input.ReadInt();

                if (path == null)
                {
                    path = name;
                }
                RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, name, path);
                if (region == null)
                {
                    return(null);
                }
                region.Path     = path;
                region.x        = x * scale;
                region.y        = y * scale;
                region.scaleX   = scaleX;
                region.scaleY   = scaleY;
                region.rotation = rotation;
                region.width    = width * scale;
                region.height   = height * scale;
                region.r        = ((color & 0xff000000) >> 24) / 255f;
                region.g        = ((color & 0x00ff0000) >> 16) / 255f;
                region.b        = ((color & 0x0000ff00) >> 8) / 255f;
                region.a        = ((color & 0x000000ff)) / 255f;
                region.UpdateOffset();
                return(region);
            }

            case AttachmentType.Boundingbox: {
                int      vertexCount = SkeletonDataStream.sp_readVarint(input.ptr, 1);
                Vertices vertices    = ReadVertices(input, vertexCount);
                if (nonessential)
                {
                    input.ReadInt();                                       //int color = nonessential ? input.ReadInt() : 0; // Avoid unused local warning.
                }
                BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, name);
                if (box == null)
                {
                    return(null);
                }
                box.worldVerticesLength = vertexCount << 1;
                box.vertices            = vertices.vertices;
                box.bones = vertices.bones;
                return(box);
            }

            case AttachmentType.Mesh: {
                String   path = input.ReadString();
                int      color = input.ReadInt();
                int      vertexCount = SkeletonDataStream.sp_readVarint(input.ptr, 1);
                float[]  uvs = ReadFloatArray(input, vertexCount << 1, 1);
                int[]    triangles = ReadShortArray(input);
                Vertices vertices = ReadVertices(input, vertexCount);
                int      hullLength = SkeletonDataStream.sp_readVarint(input.ptr, 1);
                int[]    edges = null;
                float    width = 0, height = 0;
                if (nonessential)
                {
                    edges  = ReadShortArray(input);
                    width  = SkeletonDataStream.sp_readFloat(input.ptr);
                    height = SkeletonDataStream.sp_readFloat(input.ptr);
                }

                if (path == null)
                {
                    path = name;
                }
                MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path);
                if (mesh == null)
                {
                    return(null);
                }
                mesh.Path                = path;
                mesh.r                   = ((color & 0xff000000) >> 24) / 255f;
                mesh.g                   = ((color & 0x00ff0000) >> 16) / 255f;
                mesh.b                   = ((color & 0x0000ff00) >> 8) / 255f;
                mesh.a                   = ((color & 0x000000ff)) / 255f;
                mesh.bones               = vertices.bones;
                mesh.vertices            = vertices.vertices;
                mesh.WorldVerticesLength = vertexCount << 1;
                mesh.triangles           = triangles;
                mesh.regionUVs           = uvs;
                mesh.UpdateUVs();
                mesh.HullLength = hullLength << 1;
                if (nonessential)
                {
                    mesh.Edges  = edges;
                    mesh.Width  = width * scale;
                    mesh.Height = height * scale;
                }
                return(mesh);
            }

            case AttachmentType.Linkedmesh: {
                String path = input.ReadString();
                int    color = input.ReadInt();
                String skinName = input.ReadString();
                String parent = input.ReadString();
                bool   inheritDeform = input.ReadBoolean();
                float  width = 0, height = 0;
                if (nonessential)
                {
                    width  = SkeletonDataStream.sp_readFloat(input.ptr);
                    height = SkeletonDataStream.sp_readFloat(input.ptr);
                }

                if (path == null)
                {
                    path = name;
                }
                MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path);
                if (mesh == null)
                {
                    return(null);
                }
                mesh.Path          = path;
                mesh.r             = ((color & 0xff000000) >> 24) / 255f;
                mesh.g             = ((color & 0x00ff0000) >> 16) / 255f;
                mesh.b             = ((color & 0x0000ff00) >> 8) / 255f;
                mesh.a             = ((color & 0x000000ff)) / 255f;
                mesh.inheritDeform = inheritDeform;
                if (nonessential)
                {
                    mesh.Width  = width * scale;
                    mesh.Height = height * scale;
                }
                linkedMeshes.Add(new SkeletonJson.LinkedMesh(mesh, skinName, slotIndex, parent));
                return(mesh);
            }

            case AttachmentType.Path: {
                bool     closed        = input.ReadBoolean();
                bool     constantSpeed = input.ReadBoolean();
                int      vertexCount   = SkeletonDataStream.sp_readVarint(input.ptr, 1);
                Vertices vertices      = ReadVertices(input, vertexCount);
                float[]  lengths       = new float[vertexCount / 3];
                for (int i = 0, n = lengths.Length; i < n; i++)
                {
                    lengths[i] = SkeletonDataStream.sp_readFloat(input.ptr) * scale;
                }
                if (nonessential)
                {
                    input.ReadInt();                                       //int color = nonessential ? input.ReadInt() : 0; // Avoid unused local warning.
                }
                PathAttachment path = attachmentLoader.NewPathAttachment(skin, name);
                if (path == null)
                {
                    return(null);
                }
                path.closed              = closed;
                path.constantSpeed       = constantSpeed;
                path.worldVerticesLength = vertexCount << 1;
                path.vertices            = vertices.vertices;
                path.bones   = vertices.bones;
                path.lengths = lengths;
                return(path);
            }
            }
            return(null);
        }