Esempio n. 1
0
        public void TestTexture()
        {
            Texture texture = new Texture();

            texture.AddTexture(TypeOfTexture.IDLE, "path_idle");
            texture.AddTexture(TypeOfTexture.ATTACK, "path_attack");
            texture.AddTexture(TypeOfTexture.WALK, "path_walk");
            texture.AddTexture(TypeOfTexture.JUMP, "path_jump");
            texture.AddTexture(TypeOfTexture.DEAD, "path_dead");

            string value;

            if (texture.getTextureMap().TryGetValue(TypeOfTexture.IDLE, out value))
            {
                Assert.Equal("path_idle", value);
            }
            else
            {
                Assert.True(false, "Can't get IDLE TEXTURE ​​from the map");
            }
            if (texture.getTextureMap().TryGetValue(TypeOfTexture.ATTACK, out value))
            {
                Assert.Equal("path_attack", value);
            }
            else
            {
                Assert.True(false, "Can't get ATTACK TEXTURE ​​from the map");
            }
            if (texture.getTextureMap().TryGetValue(TypeOfTexture.WALK, out value))
            {
                Assert.Equal("path_walk", value);
            }
            else
            {
                Assert.True(false, "Can't get WALK TEXTURE ​​from the map");
            }
            if (texture.getTextureMap().TryGetValue(TypeOfTexture.JUMP, out value))
            {
                Assert.Equal("path_jump", value);
            }
            else
            {
                Assert.True(false, "Can't get JUMP TEXTURE ​​from the map");
            }
            if (texture.getTextureMap().TryGetValue(TypeOfTexture.DEAD, out value))
            {
                Assert.Equal("path_dead", value);
            }
            else
            {
                Assert.True(false, "Can't get DEAD TEXTURE ​​from the map");
            }
        }
Esempio n. 2
0
        private static void WriteRS5Contents(Dictionary <string, RS5DirectoryEntry> directory, Dictionary <string, List <AnimationClip> > animclips)
        {
            Console.WriteLine("Writing raw files ... ");
            foreach (KeyValuePair <string, RS5DirectoryEntry> dirent in directory)
            {
                string filename = dirent.Value.Name + "." + (TypeExtensions.ContainsKey(dirent.Value.Type) ? TypeExtensions[dirent.Value.Type] : DefaultExtension);
                if (!File.Exists(filename))
                {
                    RS5Chunk data = dirent.Value.Data;
                    Console.Write("{0}   {1}   ", dirent.Value.Type, dirent.Value.Name);
                    string dir = Path.GetDirectoryName(filename);

                    if (dir != "" && !Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    using (Stream outfile = File.Create(filename))
                    {
                        data.ChunkData.CopyTo(outfile);
                    }

                    File.SetLastWriteTime(filename, dirent.Value.ModTime);
                    Console.WriteLine("{0}kiB", (data.ChunkData.Length + 1023) / 1024);
                }
            }

            Console.WriteLine("Processing Textures ... ");
            foreach (KeyValuePair <string, RS5DirectoryEntry> dirent in directory.Where(d => d.Value.Type == "IMAG"))
            {
                Texture texture = Texture.AddTexture(dirent.Value);
                if (!texture.TextureFileExists())
                {
                    Console.Write("Saving texture {0}", dirent.Key);

                    texture.SaveImage();
                    Console.WriteLine("{0}  ({1} x {2})  {3}kiB", Path.GetExtension(texture.Filename), texture.Width, texture.Height, (new FileInfo(texture.Filename).Length + 1023) / 1024);
                    if (texture.Image.FailureReason != null)
                    {
                        Console.WriteLine("  Reason: {0}", texture.Image.FailureReason);
                    }

                    if (texture.Image.IntensityFactor != 1.0)
                    {
                        Console.WriteLine("  Intensity: {0}", texture.Image.IntensityFactor);
                    }

                    if (!texture.IsLossless && Path.GetExtension(texture.Filename) != ".dds")
                    {
                        Console.Write("Saving DDS texture {0}", dirent.Key);
                        texture.SaveDDS();
                        Console.WriteLine(".dds  ({0} x {1})  {2}kiB", texture.Width, texture.Height, (new FileInfo(texture.DDSFilename).Length + 1023) / 1024);
                        Console.WriteLine("  Reason: DDS couldn't be faithfully converted", texture.Image.FourCC);
                    }
                }
            }

            Console.WriteLine("Processing Immobile Models ... ");
            foreach (KeyValuePair <string, RS5DirectoryEntry> dirent in directory.Where(d => d.Value.Type == "IMDL"))
            {
                Model            model              = new Model(dirent.Value);
                Collada.Exporter multimeshexporter  = model.CreateMultimeshExporter(false);
                Collada.Exporter unanimatedexporter = model.CreateUnanimatedExporter(false);
                if (!File.Exists(multimeshexporter.Filename) || !File.Exists(unanimatedexporter.Filename))
                {
                    Console.WriteLine("Processing immobile model {0} ... ", dirent.Key);

                    if (!model.HasGeometry)
                    {
                        Console.WriteLine("    no geometry");
                    }
                    else
                    {
                        Console.WriteLine("    {0} textures, {1} vertices, {2} triangles", model.Textures.Count(), model.Vertices.Count(), model.Triangles.Count());

                        unanimatedexporter.Save(() => Console.Write("  Saving unanimated ... "), () => Console.WriteLine("Done"));
                        multimeshexporter.Save(() => Console.Write("  Saving multimesh ... "), () => Console.WriteLine("Done"));
                    }
                }
            }

            Console.WriteLine("Processing Animated Models ... ");
            foreach (KeyValuePair <string, RS5DirectoryEntry> dirent in directory.Where(d => d.Value.Type == "AMDL"))
            {
                Model model = new Model(dirent.Value);
                List <Collada.Exporter> exporters = new List <Collada.Exporter>();
                List <Collada.Exporter <AnimationClip> > animexporters = new List <Collada.Exporter <AnimationClip> >();

                Collada.Exporter multimeshexporter  = model.CreateMultimeshExporter(false);
                Collada.Exporter unanimatedexporter = model.CreateUnanimatedExporter(false);
                Collada.Exporter animatedexporter   = model.CreateAnimatedExporter("ALL", false);

                exporters.Add(multimeshexporter);
                exporters.Add(unanimatedexporter);
                exporters.Add(animatedexporter);

                if (animclips.ContainsKey(model.Name))
                {
                    foreach (AnimationClip clip in animclips[model.Name])
                    {
                        Collada.Exporter <AnimationClip> exporter = model.CreateTrimmedAnimatedExporter(clip.Name, clip.StartFrame, clip.NumFrames, clip.FrameRate, false, clip);
                        exporters.Add(exporter);
                        animexporters.Add(exporter);
                    }
                }

                if (exporters.Select(e => File.Exists(e.Filename)).Any(v => !v))
                {
                    Console.WriteLine("Processing animated model {0} ... ", dirent.Key);

                    if (!model.HasGeometry)
                    {
                        Console.WriteLine("    no geometry");
                    }
                    else
                    {
                        Console.WriteLine("    {0} textures, {1} vertices, {2} triangles, {3} joints, {4} frames", model.Textures.Count(), model.Vertices.Count(), model.Triangles.Count(), model.Joints.Count(), model.NumAnimationFrames);

                        unanimatedexporter.Save(() => Console.Write("  Saving unanimated ... "), () => Console.WriteLine("Done"));
                        multimeshexporter.Save(() => Console.Write("  Saving multimesh ... "), () => Console.WriteLine("Done"));
                        animatedexporter.Save(() => Console.Write("  Saving all animations ({0} frames @ 24 fps) ... ", model.NumAnimationFrames), () => Console.WriteLine("Done"));

                        if (animclips.ContainsKey(model.Name))
                        {
                            foreach (Collada.Exporter <AnimationClip> exporter in animexporters)
                            {
                                exporter.Save((clip) => Console.Write("  Saving animation {0} ({1} frames @ {2} fps) ... ", clip.Name, clip.NumFrames, clip.FrameRate), (clip) => Console.WriteLine("Done"));
                            }
                        }
                        else
                        {
                            Console.WriteLine("  model clip start and end frames not in environment");
                        }
                    }
                }
            }

            Console.WriteLine("Export complete");
        }