コード例 #1
0
        private static TransformConstraintTimeline GetFillerTimeline(TransformConstraintTimeline timeline, SkeletonData skeletonData)
        {
            TransformConstraintTimeline timeline2 = new TransformConstraintTimeline(1);
            TransformConstraintData     data      = skeletonData.transformConstraints.Items[timeline.transformConstraintIndex];

            timeline2.SetFrame(0, 0f, data.rotateMix, data.translateMix, data.scaleMix, data.shearMix);
            return(timeline2);
        }
コード例 #2
0
        public override void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha, MixPose pose, MixDirection direction)
        {
            TransformConstraint transformConstraint = skeleton.transformConstraints.Items[transformConstraintIndex];

            float[] array = frames;
            if (time < array[0])
            {
                TransformConstraintData data = transformConstraint.data;
                switch (pose)
                {
                case MixPose.Setup:
                    transformConstraint.rotateMix    = data.rotateMix;
                    transformConstraint.translateMix = data.translateMix;
                    transformConstraint.scaleMix     = data.scaleMix;
                    transformConstraint.shearMix     = data.shearMix;
                    break;

                case MixPose.Current:
                    transformConstraint.rotateMix    += (data.rotateMix - transformConstraint.rotateMix) * alpha;
                    transformConstraint.translateMix += (data.translateMix - transformConstraint.translateMix) * alpha;
                    transformConstraint.scaleMix     += (data.scaleMix - transformConstraint.scaleMix) * alpha;
                    transformConstraint.shearMix     += (data.shearMix - transformConstraint.shearMix) * alpha;
                    break;
                }
                return;
            }
            float num2;
            float num3;
            float num4;
            float num5;

            if (time >= array[array.Length - 5])
            {
                int num = array.Length;
                num2 = array[num + -4];
                num3 = array[num + -3];
                num4 = array[num + -2];
                num5 = array[num + -1];
            }
            else
            {
                int num6 = Animation.BinarySearch(array, time, 5);
                num2 = array[num6 + -4];
                num3 = array[num6 + -3];
                num4 = array[num6 + -2];
                num5 = array[num6 + -1];
                float num7         = array[num6];
                float curvePercent = GetCurvePercent(num6 / 5 - 1, 1f - (time - num7) / (array[num6 + -5] - num7));
                num2 += (array[num6 + 1] - num2) * curvePercent;
                num3 += (array[num6 + 2] - num3) * curvePercent;
                num4 += (array[num6 + 3] - num4) * curvePercent;
                num5 += (array[num6 + 4] - num5) * curvePercent;
            }
            if (pose == MixPose.Setup)
            {
                TransformConstraintData data2 = transformConstraint.data;
                transformConstraint.rotateMix    = data2.rotateMix + (num2 - data2.rotateMix) * alpha;
                transformConstraint.translateMix = data2.translateMix + (num3 - data2.translateMix) * alpha;
                transformConstraint.scaleMix     = data2.scaleMix + (num4 - data2.scaleMix) * alpha;
                transformConstraint.shearMix     = data2.shearMix + (num5 - data2.shearMix) * alpha;
            }
            else
            {
                transformConstraint.rotateMix    += (num2 - transformConstraint.rotateMix) * alpha;
                transformConstraint.translateMix += (num3 - transformConstraint.translateMix) * alpha;
                transformConstraint.scaleMix     += (num4 - transformConstraint.scaleMix) * alpha;
                transformConstraint.shearMix     += (num5 - transformConstraint.shearMix) * alpha;
            }
        }
コード例 #3
0
        private static Dictionary <string, object> fromAnimation(Animation animation, SkeletonData skeletonData)
        {
            Dictionary <string, object> anim = new Dictionary <string, object>();
            Dictionary <string, Dictionary <string, List <object> > > bones = new Dictionary <string, Dictionary <string, List <object> > >();
            Dictionary <string, List <object> > ik = new Dictionary <string, List <object> >();
            Dictionary <string, Dictionary <string, List <object> > > paths     = new Dictionary <string, Dictionary <string, List <object> > >();
            Dictionary <string, Dictionary <string, List <object> > > slots     = new Dictionary <string, Dictionary <string, List <object> > >();
            Dictionary <string, Dictionary <string, List <object> > > transform = new Dictionary <string, Dictionary <string, List <object> > >();
            Dictionary <string, Dictionary <string, List <object> > > events    = new Dictionary <string, Dictionary <string, List <object> > >();
            Dictionary <string, Dictionary <string, Dictionary <string, List <object> > > > deform = new Dictionary <string, Dictionary <string, Dictionary <string, List <object> > > >();
            List <Dictionary <string, object> > drawOrder = new List <Dictionary <string, object> >();



            List <object> tl;
            Dictionary <string, object> tmp;


            foreach (var timeline in animation.Timelines)
            {
                SlotData           sd;
                BoneData           bd;
                PathConstraintData pcd;

                int    count = 0;
                string name;
                int    length;
                switch (timeline)
                {
                case ColorTimeline ct:     //slots timeline
                    //TODO: add color timeline support
                    break;

                case AttachmentTimeline at:     //slots timeline
                    sd     = skeletonData.Slots.Items[at.SlotIndex];
                    name   = "attachment";
                    length = at.FrameCount;

                    tl = new List <object>();
                    for (int i = 0; i < length; i++)
                    {
                        tmp         = new Dictionary <string, object>();
                        tmp["time"] = at.Frames[i];
                        tmp["name"] = at.AttachmentNames[i];
                        tl.Add(tmp);
                    }
                    if (!slots.ContainsKey(sd.Name))
                    {
                        slots[sd.Name] = new Dictionary <string, List <object> >();
                    }
                    slots[sd.Name][name] = tl;
                    break;

                case RotateTimeline rt:     //bone timeline
                    name  = "rotate";
                    bd    = skeletonData.Bones.Items[rt.BoneIndex];
                    count = 0;
                    if (!bones.ContainsKey(bd.Name))
                    {
                        bones[bd.Name] = new Dictionary <string, List <object> >();
                    }
                    bones[bd.Name][name] = applyTimeline(rt.Frames, (f, d) => {
                        d["time"]  = f.pop();
                        d["angle"] = f.pop();
                        setCurve(d, rt, count++);
                    });
                    break;

                case TranslateTimeline tt:
                    float timelineScale = 1;
                    if (tt is ShearTimeline)
                    {
                        name = "shear";
                    }
                    else if (tt is ScaleTimeline)
                    {
                        name = "scale";
                    }
                    else
                    {
                        name = "translate";
                    }
                    bd    = skeletonData.Bones.Items[tt.BoneIndex];
                    count = 0;
                    if (!bones.ContainsKey(bd.Name))
                    {
                        bones[bd.Name] = new Dictionary <string, List <object> >();
                    }
                    bones[bd.Name][name] = applyTimeline(tt.Frames, (f, d) => {
                        d["time"] = f.pop();
                        d["x"]    = f.pop() / timelineScale;
                        d["y"]    = f.pop() / timelineScale;
                        setCurve(d, tt, count++);
                    });
                    break;

                case IkConstraintTimeline ikt:
                    IkConstraintData ikd = skeletonData.IkConstraints.Items[ikt.IkConstraintIndex];
                    count        = 0;
                    ik[ikd.Name] = applyTimeline(ikt.Frames, (f, d) => {
                        d["time"]         = f.pop();
                        d["mix"]          = f.pop();
                        d["bendPositive"] = f.pop();
                        setCurve(d, ikt, count++);
                    });

                    break;

                case TransformConstraintTimeline tft:
                    name = "transform";
                    TransformConstraintData tfd = skeletonData.TransformConstraints.Items[tft.TransformConstraintIndex];
                    count = 0;
                    if (!transform.ContainsKey(tfd.Name))
                    {
                        transform[tfd.Name] = new Dictionary <string, List <object> >();
                    }
                    transform[tfd.Name][name] = applyTimeline(tft.Frames, (f, d) => {
                        d["time"]         = f.pop();
                        d["rotateMix"]    = f.pop();
                        d["translateMix"] = f.pop();
                        d["scaleMix"]     = f.pop();
                        d["shearMix"]     = f.pop();
                        setCurve(d, tft, count++);
                    });
                    break;

                case PathConstraintPositionTimeline pcpt:
                    name = "position";
                    if (pcpt is PathConstraintSpacingTimeline)
                    {
                        name = "spacing";
                    }
                    pcd   = skeletonData.PathConstraints.Items[pcpt.PathConstraintIndex];
                    count = 0;
                    if (!paths.ContainsKey(pcd.Name))
                    {
                        paths[pcd.Name] = new Dictionary <string, List <object> >();
                    }
                    paths[pcd.Name][name] = applyTimeline(pcpt.Frames, (f, d) => {
                        d["time"] = f.pop();
                        d[name]   = f.pop();
                        setCurve(d, pcpt, count++);
                    });

                    break;

                case PathConstraintMixTimeline pcmt:
                    name = "mix";
                    //"time"], GetFloat(valueMap, "rotateMix", 1), GetFloat(valueMap, "translateMix",
                    pcd   = skeletonData.PathConstraints.Items[pcmt.PathConstraintIndex];
                    count = 0;
                    if (!paths.ContainsKey(pcd.Name))
                    {
                        paths[pcd.Name] = new Dictionary <string, List <object> >();
                    }
                    paths[pcd.Name][name] = applyTimeline(pcmt.Frames, (f, d) => {
                        d["time"]         = f.pop();
                        d["rotateMix"]    = f.pop();
                        d["translateMix"] = f.pop();
                        setCurve(d, pcmt, count++);
                    });
                    break;

                case DeformTimeline dt:
                    var att = dt.Attachment;

                    sd = skeletonData.Slots.Items[dt.SlotIndex];
                    string skinName = dt.skin.Name;
                    count = 0;
                    if (!deform.ContainsKey(skinName))
                    {
                        deform[skinName] = new Dictionary <string, Dictionary <string, List <object> > >();
                    }
                    if (!deform[skinName].ContainsKey(sd.Name))
                    {
                        deform[skinName][sd.Name] = new Dictionary <string, List <object> >();
                    }
                    string attName = att.Name;
                    if (attName.Contains('/'))
                    {
                        attName = attName.Substring(attName.LastIndexOf('/') + 1);
                    }
                    attName = attName.Replace('-', ' ');
                    deform[skinName][sd.Name][attName] = applyTimeline(dt.Frames, (f, d) => {
                        d["time"]   = f.pop();
                        d["offset"] = dt.offsets[count];
                        var verts   = dt.originalVerts[count];
                        if (verts != null)
                        {
                            d["vertices"] = dt.originalVerts[count];
                        }
                        setCurve(d, dt, count);
                        count++;
                    });


                    break;

                case DrawOrderTimeline dot:
                    //for each frame in the draw order
                    for (int i = 0; i < dot.FrameCount; i++)
                    {
                        //create new frame object -> order
                        Dictionary <string, object> order = new Dictionary <string, object>();
                        //each frame has a list of offset objects
                        List <object> list = new List <object>();
                        for (int k = 0; k < dot.offsetSet[i].Length; k++)
                        {
                            int offset = dot.offsetSet[i][k];
                            if (offset == 0)
                            {
                                continue;
                            }
                            Dictionary <string, object> temp = new Dictionary <string, object>();
                            sd             = skeletonData.Slots.Items[k];
                            temp["slot"]   = sd.Name;
                            temp["offset"] = offset;
                            list.Add(temp);
                        }
                        order["time"]    = dot.Frames[i];
                        order["offsets"] = list;
                        drawOrder.Add(order);
                    }
                    break;

                case EventTimeline et:
                    throw new Exception("Does not support Events to JSON");
                    break;
                }
            }

            if (bones.Count != 0)
            {
                anim["bones"] = bones;
            }
            if (ik.Count != 0)
            {
                anim["ik"] = ik;
            }
            if (paths.Count != 0)
            {
                anim["paths"] = paths;
            }
            if (slots.Count != 0)
            {
                anim["slots"] = slots;
            }
            if (transform.Count != 0)
            {
                anim["transform"] = transform;
            }
            if (drawOrder.Count != 0)
            {
                anim["drawOrder"] = drawOrder;
            }
            if (events.Count != 0)
            {
                anim["events"] = events;
            }
            if (deform.Count != 0)
            {
                anim["deform"] = deform;
            }

            return(anim);
        }