Пример #1
0
        public virtual KeyframeSequence RestoreKeyframes(TypedAttribSet attributes)
        {
            TypedAttribSet listAttribs = find_struct(attributes, IOStrings.KeyframeListStruct);

            if (listAttribs == null)
            {
                throw new Exception("SOFactory.RestoreKeyframes: Transform struct not found!");
            }

            KeyframeSequence keys = new KeyframeSequence();

            if (check_key_or_debug_print(listAttribs, IOStrings.ATimeRange))
            {
                Vector2f vRange = (Vector2f)listAttribs[IOStrings.ATimeRange];
                keys.SetValidRange(vRange[0], vRange[1]);
            }

            List <TypedAttribSet> frames = find_all_structs(listAttribs, IOStrings.KeyframeStruct);

            foreach (TypedAttribSet frameAttrib in frames)
            {
                double  time  = double.PositiveInfinity;
                Frame3f frame = Frame3f.Identity;
                if (check_key_or_debug_print(frameAttrib, IOStrings.ATime))
                {
                    time = (float)frameAttrib[IOStrings.ATime];
                }
                if (check_key_or_debug_print(frameAttrib, IOStrings.APosition))
                {
                    frame.Origin = (Vector3f)frameAttrib[IOStrings.APosition];
                }
                if (check_key_or_debug_print(frameAttrib, IOStrings.AOrientation))
                {
                    frame.Rotation = (Quaternionf)frameAttrib[IOStrings.AOrientation];
                }
                if (time != double.PositiveInfinity)
                {
                    keys.AddOrUpdateKey(new Keyframe(time, frame));
                }
            }

            return(keys);
        }
        /// <summary>
        /// Emit a keyframe sequence as a KeyframeListStruct
        /// </summary>
        public static void EmitKeyframes(this SceneSerializer s, KeyframeSequence seq, IOutputStream o)
        {
            o.BeginStruct(IOStrings.KeyframeListStruct);
            o.AddAttribute(IOStrings.ATimeRange, (Vector2f)seq.ValidRange);

            int i = 0;

            foreach (Keyframe k  in seq)
            {
                o.BeginStruct(IOStrings.KeyframeStruct, i.ToString());
                i++;
                o.AddAttribute(IOStrings.ATime, (float)k.Time, true);
                o.AddAttribute(IOStrings.APosition, k.Frame.Origin, true);
                o.AddAttribute(IOStrings.AOrientation, k.Frame.Rotation, true);
                o.EndStruct();
            }

            o.EndStruct();
        }