Пример #1
0
        public AttributeAnimation(XmlElement elem)
        {
            name_          = elem.GetAttribute("name");
            speed_         = float.Parse(elem.GetAttribute("speed"));
            splineTension_ = float.Parse(elem.GetAttribute("splinetension"));
            string interp   = elem.GetAttribute("interpolation").ToLowerInvariant();
            string wrapmode = elem.GetAttribute("wrapmode").ToLowerInvariant();

            if (interp.Equals("linear"))
            {
                interp_ = InterpolationMethod.Linear;
            }
            else if (interp.Equals("linear"))
            {
                interp_ = InterpolationMethod.Spline;
            }
            if (wrapmode.Equals("clamp"))
            {
                wrap_ = AnimWrapMode.Clamp;
            }
            else if (wrapmode.Equals("loop"))
            {
                wrap_ = AnimWrapMode.Loop;
            }
            else if (wrapmode.Equals("once"))
            {
                wrap_ = AnimWrapMode.Once;
            }

            foreach (XmlElement keyelem in elem.GetElementsByTagName("keyframe"))
            {
                Keyframes.Add(new Keyframe(keyelem));
            }
        }
Пример #2
0
 public SerializableUniform(string uniformName, IEnumerable <KeyValuePair <float, float> > uniformKeyFrames) : this(uniformName)
 {
     foreach (var kf in uniformKeyFrames)
     {
         Keyframes.Add(new Keyframe(kf.Key, kf.Value));
     }
 }
Пример #3
0
 private void RebuildKeyframeViewModels()
 {
     foreach (var key in timeline.Keys)
     {
         KeyframeViewModel keyVM = new KeyframeViewModel(key.Key);
         Keyframes.Add(keyVM);
     }
 }
            public virtual void ReadChildData(BinaryReader reader)
            {
                int x = 0;

                for (x = 0; (x < _keyframes.Count); x = (x + 1))
                {
                    Keyframes.Add(new ScreenAnimationKeyframeReferenceBlockBlock());
                    Keyframes[x].Read(reader);
                }
                for (x = 0; (x < _keyframes.Count); x = (x + 1))
                {
                    Keyframes[x].ReadChildData(reader);
                }
            }
Пример #5
0
    void ImportKeyframe(XmlElement parent, Keyframes keyframes)
    {
        Timecode position = ChildTimecode(parent, "Position");
        Keyframe keyframe = null;

        if (0 == position.Nanos)
        {
            keyframe = (Keyframe)keyframes[0];
        }
        else
        {
            keyframe = new Keyframe(position);
            keyframes.Add(keyframe);
        }
        try { keyframe.Type = ChildVideoKeyframeType(parent, "Type"); } catch {}
    }
Пример #6
0
        /// <summary> Adds a new HitboxKeyfram at the a specified time. </summary>
        /// <param name="time"> the time to add the keyframe at </param>
        /// <param name="defaultType"> the default type to use for every hitbox if no keyframes are currently present </param>
        /// <returns> the created keyframe </returns>
        /// <exception cref="ArgumentNullException"> </exception>
        public HitboxKeyframe AddKeyframe(float time = 0f, Hitbox.Type defaultType = Hitbox.Type.Inactive)
        {
            time = Mathf.Clamp01(time);
#if UNITY_EDITOR
            Undo.RecordObject(this, "Add Keyframe");
#endif
            HitboxKeyframe prevKeyframe = PrevKeyframe(time);
            var            keyframe     = new HitboxKeyframe {
                Time = time,
            };
            if (prevKeyframe != null)
            {
                keyframe.States = new List <Hitbox.Type>(prevKeyframe.States);
            }
            else
            {
                keyframe.States = Enumerable.Repeat(defaultType, IDs.Count).ToList();
            }
            Keyframes.Add(keyframe);
            InternalOnChange();
            return(keyframe);
        }
Пример #7
0
 /// <summary>
 /// Public constructor. Builds animation keyframe list.
 /// </summary>
 public CHenNormalAnimation()
 {
     fileName = "hen";
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_4"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_4"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_4"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_4"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_5"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_6"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_7"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_8"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_9"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_10"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_9"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_8"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_7"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_6"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_5"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_4"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_4"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_4"));
     Keyframes.Add(Game1.Inst.Content.Load <Model>("Models/hen_4"));
 }
Пример #8
0
        internal override void Read(ResourceReader reader)
        {
            KeyframeType = ( KeyframeType )reader.ReadInt32();

            int keyframeCount = reader.ReadInt32();

            for (int i = 0; i < keyframeCount; i++)
            {
                KeyframeTimings.Add(reader.ReadSingle());
            }

            for (int i = 0; i < keyframeCount; i++)
            {
                Keyframe keyframe;

                switch (KeyframeType)
                {
                case KeyframeType.NodePR:
                case KeyframeType.NodePRS:
                case KeyframeType.NodePRHalf:
                case KeyframeType.NodePRSHalf:
                case KeyframeType.NodePRHalf_2:
                case KeyframeType.NodePHalf:
                case KeyframeType.NodeRHalf:
                case KeyframeType.NodeSHalf:
                    keyframe = new KeyframePRS(KeyframeType);
                    break;

                case KeyframeType.Vector3:
                case KeyframeType.Vector3_2:
                case KeyframeType.Vector3_3:
                case KeyframeType.Vector3_4:
                case KeyframeType.MaterialVector3_5:
                    keyframe = new KeyframeVector3(KeyframeType);
                    break;

                case KeyframeType.Quaternion:
                case KeyframeType.Quaternion_2:
                    keyframe = new KeyframeQuaternion(KeyframeType);
                    break;

                case KeyframeType.Single:
                case KeyframeType.Single_2:
                case KeyframeType.Single_3:
                case KeyframeType.MaterialSingle_4:
                case KeyframeType.Single_5:
                case KeyframeType.Single_6:
                case KeyframeType.Single_7:
                case KeyframeType.Single_8:
                case KeyframeType.SingleAlt_2:
                case KeyframeType.MaterialSingle_9:
                case KeyframeType.SingleAlt_3:
                    keyframe = new KeyframeSingle(KeyframeType);
                    break;

                case KeyframeType.Single5:
                case KeyframeType.Single5_2:
                case KeyframeType.Single5Alt:
                    keyframe = new KeyframeSingle5(KeyframeType);
                    break;

                case KeyframeType.PRSByte:
                    keyframe = new KeyframePRSByte();
                    break;

                case KeyframeType.Single4Byte:
                    keyframe = new KeyframeSingle4Byte();
                    break;

                case KeyframeType.SingleByte:
                    keyframe = new KeyframeSingleByte();
                    break;

                case KeyframeType.Type22:
                    keyframe = new KeyframeType22();
                    break;

                default:
                    throw new InvalidDataException($"Unknown/Invalid Key frame type: {KeyframeType}");
                }

                keyframe.Read(reader);
                Keyframes.Add(keyframe);
            }

            if (UsesScaleVectors())
            {
                PositionScale = reader.ReadVector3();
                ScaleScale    = reader.ReadVector3();
            }
        }
Пример #9
0
        /// <summary>
        /// Event for when a keyframe is added to the timeline
        /// </summary>
        /// <param name="key"></param>

        private void Timeline_KeyframeAdded(KeyContainer key)
        {
            KeyframeViewModel keyVM = new KeyframeViewModel(key.Time);

            Keyframes.Add(keyVM);
        }
Пример #10
0
    int FixTargetMotions(List <CellTarget> cellTargets, double stepSize)
    {
        double time   = 0;
        int    groups = cellTargets[0].ProgramTargets.Count;

        for (int i = 0; i < cellTargets.Count; i++)
        {
            var cellTarget = cellTargets[i];
            //int errorIndex = -1;

            // first target
            if (i == 0)
            {
                var firstKinematics = _robotSystem.Kinematics(cellTargets[0].ProgramTargets.Select(x => x.Target));
                cellTargets[0].SetTargetKinematics(firstKinematics, _program.Errors, _program.Warnings);
                CheckUndefined(cellTarget, cellTargets);
                Keyframes.Add(cellTargets[0].ShallowClone());
            }
            else
            {
                var prevTarget = cellTargets[i - 1];
                var prevJoints = prevTarget.ProgramTargets.Select(x => x.Kinematics.Joints);

                // no interpolation
                {
                    var kineTargets = cellTarget.ProgramTargets.MapToList(x => x.Target.ShallowClone());

                    for (int j = 0; j < kineTargets.Count; j++)
                    {
                        if (kineTargets[j] is CartesianTarget target && target.Motion == Motions.Linear)
                        {
                            target.Configuration = prevTarget.ProgramTargets[j].Kinematics.Configuration;
                        }
                    }

                    var kinematics = _robotSystem.Kinematics(kineTargets, prevJoints);
                    cellTarget.SetTargetKinematics(kinematics, _program.Errors, _program.Warnings, prevTarget);
                    CheckUndefined(cellTarget, cellTargets);
                }

                double divisions     = 1;
                var    linearTargets = cellTarget.ProgramTargets.Where(x => !x.IsJointMotion);
                //   if (linearTargets.Count() > 0) program.Errors.Clear();

                foreach (var target in linearTargets)
                {
                    var    prevPlane     = target.GetPrevPlane(prevTarget.ProgramTargets[target.Group]);
                    double distance      = prevPlane.Origin.DistanceTo(target.Plane.Origin);
                    double divisionsTemp = Ceiling(distance / stepSize);
                    if (divisionsTemp > divisions)
                    {
                        divisions = divisionsTemp;
                    }
                }

                var prevInterTarget = prevTarget.ShallowClone();
                prevInterTarget.DeltaTime = 0;
                prevInterTarget.TotalTime = 0;
                prevInterTarget.MinTime   = 0;

                double totalDeltaTime     = 0;
                double lastDeltaTime      = 0;
                double deltaTimeSinceLast = 0;
                double totalMinTime       = 0;
                double minTimeSinceLast   = 0;

                for (double j = 1; j <= divisions; j++)
                {
                    double t           = j / divisions;
                    var    interTarget = cellTarget.ShallowClone();
                    var    kineTargets = cellTarget.Lerp(prevTarget, _robotSystem, t, 0.0, 1.0);
                    var    kinematics  = _program.RobotSystem.Kinematics(kineTargets, prevJoints);
                    interTarget.SetTargetKinematics(kinematics, _program.Errors, null, prevInterTarget);

                    // Set speed

                    double slowestDelta   = 0;
                    double slowestMinTime = 0;
                    foreach (var target in interTarget.ProgramTargets)
                    {
                        var speeds = GetSpeeds(target, prevInterTarget.ProgramTargets[target.Group]);
                        slowestDelta        = Max(slowestDelta, speeds.Item1);
                        slowestMinTime      = Max(slowestMinTime, speeds.Item2);
                        target.LeadingJoint = speeds.Item3;
                    }

                    if ((j > 1) && (Abs(slowestDelta - lastDeltaTime) > 1e-09))
                    {
                        Keyframes.Add(prevInterTarget.ShallowClone());
                        deltaTimeSinceLast = 0;
                        minTimeSinceLast   = 0;
                    }

                    lastDeltaTime       = slowestDelta;
                    time               += slowestDelta;
                    totalDeltaTime     += slowestDelta;
                    deltaTimeSinceLast += slowestDelta;
                    totalMinTime       += slowestMinTime;
                    minTimeSinceLast   += slowestMinTime;

                    interTarget.DeltaTime = deltaTimeSinceLast;
                    interTarget.MinTime   = minTimeSinceLast;
                    interTarget.TotalTime = time;

                    prevInterTarget = interTarget;
                }

                Keyframes.Add(prevInterTarget.ShallowClone());

                if (_program.Errors.Count == 0)
                {
                    double longestWaitTime = 0;
                    foreach (var target in cellTarget.ProgramTargets)
                    {
                        double waitTime = target.Commands.OfType <Commands.Wait>().Select(x => x.Seconds).Sum();
                        if (waitTime > longestWaitTime)
                        {
                            longestWaitTime = waitTime;
                        }
                    }

                    if (longestWaitTime > TimeTol)
                    {
                        time           += longestWaitTime;
                        totalDeltaTime += longestWaitTime;

                        prevInterTarget.TotalTime  = time;
                        prevInterTarget.DeltaTime += longestWaitTime;
                        Keyframes.Add(prevInterTarget.ShallowClone());
                    }
                }

                // set target kinematics

                cellTarget.TotalTime = time;
                cellTarget.DeltaTime = totalDeltaTime;
                cellTarget.MinTime   = totalMinTime;

                foreach (var programTarget in cellTarget.ProgramTargets)
                {
                    int group = programTarget.Group;
                    programTarget.Kinematics           = prevInterTarget.ProgramTargets[group].Kinematics;
                    programTarget.ChangesConfiguration = prevInterTarget.ProgramTargets[group].ChangesConfiguration;
                    programTarget.LeadingJoint         = prevInterTarget.ProgramTargets[group].LeadingJoint;
                }
            }

            if (_program.Errors.Count > 0)
            {
                _program.Duration = time;
                return(i);
            }

            //   if (errorIndex != -1) return errorIndex;
        }

        _program.Duration = time;
        return(-1);
    }
Пример #11
0
 /// <inheritdoc/>
 internal override void AddKeyframe(AnimationKeyframeBase keyframe)
 {
     Keyframes.Add((AnimationKeyframe <T>)keyframe);
 }