コード例 #1
0
            public void Flush(Stream outputStream)
            {
                HeaderWriter.Flush();
                HeaderStream.Position = 0;
                HeaderStream.CopyTo(outputStream);

                ContentWriter.Flush();
                ConentStream.Position = 0;
                ConentStream.CopyTo(outputStream);
            }
コード例 #2
0
        static void Main(string[] args)
        {
            log4net.Config.BasicConfigurator.Configure(new log4net.Appender.DebugAppender());

            _opaqueData["TextureType"] = TextureType.Texture2D;
            if (!ParseCommandLine(args))
            {
                return;
            }

            if (string.IsNullOrEmpty(_outputName))
            {
                _outputName = string.Format("{0}.meb", Path.GetFileNameWithoutExtension(_imageName));
            }



            //GetTypeWriters();
            ProcessAssemblies();

            string ext = Path.GetExtension(_imageName).ToLower();
            var    imp = _importers.FirstOrDefault(i => i.attribue.FileExtensions.Contains(ext));

            if (imp.type == null)
            {
                Console.WriteLine("file format is not handled by TextureImporter.");
                return;
            }

            ContentManager           manager = new ContentManager(_log);
            ContentTypeWriterManager contentTypeWriterManager = new ContentTypeWriterManager();

            contentTypeWriterManager.RegisterTypeWriter <Texture2DContent>(new Texture2DWriter());

            IContentImporter importer = CreateImporter(imp.type, _opaqueData);

            var content = importer.Import(_imageName, manager);

            IContentProcessor processor = CreateProcessor(FindDefaultProcessor(importer.GetType()), _opaqueData);

            object processedContent = processor.Process(content, new ContentProcessorContext());

            ContentTypeWriter typeWriter = GetTypeWriter(processedContent.GetType());

            using (FileStream stream = new FileStream(_outputName, FileMode.OpenOrCreate))
            {
                ContentWriter writer = manager.CreateWriter(contentTypeWriterManager, stream);
                writer.WriteObject(processedContent, typeWriter);
                writer.Flush();
            }
        }
コード例 #3
0
 protected override void Write(ContentWriter output, GifAnimationContent value)
 {
     output.Write(value.Frames.Length);
     for (int i = 0; i < value.Frames.Length; i++)
     {
         output.Write((int)value.Frames[i].__1__SurfaceFormat);
         output.Write(value.Frames[i].__2__Width);
         output.Write(value.Frames[i].__3__Height);
         output.Write(value.Frames[i].__4__Levels);
         output.Write(value.Frames[i].Data.Length);
         output.Write(value.Frames[i].Data);
         output.Flush();
     }
 }
コード例 #4
0
ファイル: ContentCompiler.cs プロジェクト: TyrelBaux/Gibbo2D
 /// <summary>
 /// Write the content to a XNB file.
 /// </summary>
 /// <param name="stream">The stream to write the XNB file to.</param>
 /// <param name="content">The content to write to the XNB file.</param>
 /// <param name="targetPlatform">The platform the XNB is intended for.</param>
 /// <param name="targetProfile">The graphics profile of the target.</param>
 /// <param name="compress">True if the content should be compressed.</param>
 /// <param name="rootDirectory">The root directory of the content.</param>
 /// <param name="referenceRelocationPath">The path of the XNB file, used to calculate relative paths for external references.</param>
 public void Compile(Stream stream, object content, TargetPlatform targetPlatform, GraphicsProfile targetProfile, bool compressContent, string rootDirectory, string referenceRelocationPath)
 {
     using (var writer = new ContentWriter(this, stream, targetPlatform, targetProfile, compressContent, rootDirectory, referenceRelocationPath))
     {
         writer.WriteObject(content);
         writer.Flush();
     }
 }
コード例 #5
0
        private List<byte[]> WriteSharedResourcesData(out byte[] sharedResourcesCountData)
        {
            List<byte[]> shareResourcesData = new List<byte[]>();

            using (MemoryStream stream = new MemoryStream())
            {
                using (ContentWriter writer = new ContentWriter(stream, this))
                {
                    writer.WriteEncodedInt32(sharedResources.Count);
                    writer.Flush();

                    stream.Flush();
                    sharedResourcesCountData = stream.GetBuffer().Take((int)stream.Length).ToArray();
                }
            }

            // TODO: Support shared resources
            return shareResourcesData;
        }
コード例 #6
0
        private byte[] WriteRootObjectData(object rootObject)
        {
            byte[] rootObjectData = null;

            using (MemoryStream stream = new MemoryStream())
            {
                using (ContentWriter writer = new ContentWriter(stream, this))
                {
                    writer.WriteObject<object>(rootObject);
                    writer.Flush();

                    stream.Flush();
                    rootObjectData = stream.GetBuffer().Take((int)stream.Length).ToArray();
                }
            }

            return rootObjectData;
        }
コード例 #7
0
        protected override void Write(ContentWriter output, AnimationData animData)
        {
            BinaryDataWriter data = new BinaryDataWriter();

            ContentBinaryWriter bw;

            #region BindPoseTag
            List <Matrix> bindPose = animData.BindPose;

            if (bindPose != null)
            {
                data.AddEntry(BindPoseCountTag, bindPose.Count);

                bw = data.AddEntry(BindPoseTag);
                for (int i = 0; i < bindPose.Count; i++)
                {
                    bw.Write(bindPose[i]);
                }
                bw.Close();
            }
            #endregion

            #region InvBindPoseTag
            List <Matrix> invBindPose = animData.InverseBindPose;
            if (invBindPose != null)
            {
                data.AddEntry(InvBindPoseCountTag, invBindPose.Count);

                bw = data.AddEntry(InvBindPoseTag);
                for (int i = 0; i < invBindPose.Count; i++)
                {
                    bw.Write(invBindPose[i]);
                }
                bw.Close();
            }

            #endregion

            #region AnimationClipTag

            var aclip = animData.ModelAnimationClips;

            if (aclip != null)
            {
                data.AddEntry(ModelAnimationClipCountTag, aclip.Count);

                bw = data.AddEntry(ModelAnimationClipTag);
                foreach (var e in aclip)
                {
                    bw.WriteStringUnicode(e.Key);

                    ModelAnimationClip clip = e.Value;
                    bw.Write(clip.Duration.TotalSeconds);

                    bw.Write(clip.Keyframes.Count);

                    for (int i = 0; i < clip.Keyframes.Count; i++)
                    {
                        bw.Write(clip.Keyframes[i].Bone);
                        bw.Write(clip.Keyframes[i].Time.TotalSeconds);
                        bw.Write(clip.Keyframes[i].Transform);
                    }
                }
                bw.Close();
            }


            #endregion

            #region RootAnimationClipTag
            aclip = animData.RootAnimationClips;

            if (aclip != null)
            {
                data.AddEntry(RootAnimationClipCountTag, aclip.Count);

                bw = data.AddEntry(RootAnimationClipTag);
                foreach (var e in aclip)
                {
                    bw.WriteStringUnicode(e.Key);

                    ModelAnimationClip clip = e.Value;
                    bw.Write(clip.Duration.TotalSeconds);

                    bw.Write(clip.Keyframes.Count);

                    for (int i = 0; i < clip.Keyframes.Count; i++)
                    {
                        bw.Write(clip.Keyframes[i].Bone);
                        bw.Write(clip.Keyframes[i].Time.TotalSeconds);
                        bw.Write(clip.Keyframes[i].Transform);
                    }
                }
                bw.Close();
            }

            #endregion

            #region BoneHierarchyTag

            List <int> bh = animData.SkeletonHierarchy;
            if (bh != null)
            {
                data.AddEntry(BoneHierarchyCountTag, bh.Count);

                bw = data.AddEntry(BoneHierarchyTag);
                for (int i = 0; i < bh.Count; i++)
                {
                    bw.Write(bh[i]);
                }
                bw.Close();
            }

            #endregion


            output.Write(0); //Õ¼¸öλÖÃ
            output.Flush();

            long start = output.BaseStream.Position;

            data.Save(new VirtualStream(output.BaseStream, output.BaseStream.Position));

            long end  = output.BaseStream.Position;
            int  size = (int)(end - start);

            output.BaseStream.Position = start - 4;
            output.Write(size);
            output.BaseStream.Position = end;
        }