protected internal override void Serialize(IntermediateWriter output, NamedValueDictionary <T> value, ContentSerializerAttribute format)
        {
            var valueSerializer = output.Serializer.GetTypeSerializer(value.DefaultSerializerType);

            foreach (var kvp in value)
            {
                output.Xml.WriteStartElement(format.CollectionItemName);

                output.WriteObject(kvp.Key, _keyFormat, _keySerializer);
                output.WriteObject(kvp.Value, _valueFormat, valueSerializer);

                output.Xml.WriteEndElement();
            }
        }
예제 #2
0
        /// <summary>
        /// Imports Acclaim AFS (motion capture skeleton).
        /// Stores dof spec (degrees of freedom) as string in OpaqueData for each bone.
        /// </summary>
        public override BoneContent Import(string filename, ContentImporterContext context)
        {
            this.context = context;
            contentId    = new ContentIdentity(filename);
            BoneContent root = new BoneContent();

            root.Name      = "root";
            root.Identity  = cId;
            root.Transform = Matrix.Identity;
            bones          = new NamedValueDictionary <BoneContent>();
            bones.Add("root", root);
            if (!File.Exists(filename))
            {
                throw new InvalidContentException("file " + filename + " not found");
            }
            reader = new StreamReader(filename);
            String line;

            while ((line = readLine()) != ":bonedata")
            {
                if (line == null)
                {
                    throw new InvalidContentException("no bone data found", cId);
                }
            }
            BoneContent bone;

            while ((bone = importBone()) != null)
            {
                bones.Add(bone.Name, bone);
            }
            importHierarchy();
            foreach (BoneContent b in bones.Values)
            {
                if (b.Name != "root" && b.Parent == null)
                {
                    throw new InvalidContentException("incomplete hierarchy - bone " + b + " has no parent", cId);
                }
            }
            return(root);
        }
        protected internal override NamedValueDictionary <T> Deserialize(IntermediateReader input, ContentSerializerAttribute format, NamedValueDictionary <T> existingInstance)
        {
            var result = existingInstance ?? new NamedValueDictionary <T>();

            var valueSerializer = input.Serializer.GetTypeSerializer(result.DefaultSerializerType);

            while (input.MoveToElement(format.CollectionItemName))
            {
                input.Xml.ReadStartElement();

                var key   = input.ReadObject <string>(_keyFormat, _keySerializer);
                var value = input.ReadObject <T>(_valueFormat, valueSerializer);
                result.Add(key, value);

                input.Xml.ReadEndElement();
            }

            return(result);
        }
 protected internal override void ScanChildren(IntermediateSerializer serializer, ChildCallback callback, NamedValueDictionary <T> value)
 {
     foreach (var kvp in value)
     {
         callback(serializer.GetTypeSerializer(typeof(T)), kvp.Value);
     }
 }
 public override bool ObjectIsEmpty(NamedValueDictionary <T> value)
 {
     return(value.Count == 0);
 }
예제 #6
0
        /// <summary>
        /// Imports Acclaim AMC (motion capture data).
        /// For a foo_bar.amc, expects skeleton in a file named foo.asf.
        /// Returns a skeleton with Animations in root bone.
        /// </summary>
        public override BoneContent Import(string filename, ContentImporterContext context)
        {
            this.context = context;
            contentId    = new ContentIdentity(filename, GetType().ToString());
            reader       = new StreamReader(filename);

            AnimationContent animation = new AnimationContent();

            animation.Name     = Path.GetFileNameWithoutExtension(filename);
            animation.Identity = contentId;

            string dir         = Path.GetDirectoryName(filename);
            string asfFilename = animation.Name + ".asf";

            if (animation.Name.Contains("_"))
            {
                //asfFilename = animation.Name.Split('_')[0] + ".asf";
            }
            asfFilename = dir + @"\" + asfFilename;
            context.Logger.LogWarning("", contentId, "using skeleton from {0}", asfFilename);
            AsfImporter asfImporter = new AsfImporter();
            BoneContent root        = asfImporter.Import(asfFilename, context);

            bones = asfImporter.Bones;

            int    frameNumber    = 1;
            int    maxFrameNumber = 0;
            string line;

            animation.Channels.Add("root", new AnimationChannel());
            while ((line = readLine()) != null)
            {
                if (line[0] != '#' && line[0] != ':')
                {
                    int fn = 0;
                    if (int.TryParse(line, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out fn))
                    {
                        ++frameNumber;// = int.Parse(line, NumberStyles.Int, CultureInfo.InvariantCulture.NumberFormat);
                        maxFrameNumber = Math.Max(frameNumber, maxFrameNumber);
                        TimeSpan time = TimeSpan.FromTicks(frameNumber * ticksPerFrame);
                        animation.Channels["root"].Add(new AnimationKeyframe(time, Matrix.Identity));
                    }
                    else
                    {
                        string[] s    = line.Split(' ');
                        string   bone = s[0];
                        if (!animation.Channels.ContainsKey(bone))
                        {
                            animation.Channels.Add(bone, new AnimationChannel());
                        }
                        AnimationChannel  channel  = animation.Channels[bone];
                        AnimationKeyframe keyframe = importKeyframe(s, frameNumber);
                        if (keyframe != null)
                        {
                            channel.Add(keyframe);
                        }
                    }
                }
            }
            animation.Duration = TimeSpan.FromTicks(maxFrameNumber * ticksPerFrame);
            context.Logger.LogImportantMessage("imported {0} animation frames for {1} bones",
                                               maxFrameNumber, animation.Channels.Count);
            root.Animations.Add(animation.Name, animation);
            return(root);
        }