Пример #1
0
    void BuildAtlas(string name, TextureFormat format = TextureFormat.RGBA32, Color defaultColor = default(Color), bool linear = false)
    {
        textureList.Sort(CompareBySize);
        AtlasCreator.Atlas[] atlasList = AtlasCreator.CreateAtlas(name, textureList.ToArray(), null, format, defaultColor, linear);
        if ((atlasList.Length > 1) || (GameSettings.Instance.rendering.debugTextureAtlas))
        {
            for (int i = 0; i < atlasList.Length; i++)
            {
                AtlasCreator.SaveAtlas(atlasList[i], i + name);
            }
        }
        atlas = atlasList[0];
        textureList.Clear();

        texIndexToAtlasIndex = new Dictionary <int, int>();
        nameToAtlasIndex     = new Dictionary <string, int>();
        for (int i = 0; i < atlas.uvRects.Length; i++)
        {
            nameToAtlasIndex[atlas.uvRects[i].name] = i;
        }

        foreach (var item in texIndexToName)
        {
            if (nameToAtlasIndex.ContainsKey(item.Value))
            {
                texIndexToAtlasIndex[item.Key] = nameToAtlasIndex[item.Value];
            }
            else
            {
                Debug.LogError("What the f**k");
            }
        }

        //AtlasCreator.SaveAtlas(atlas, name);
    }
Пример #2
0
        static void Main(string[] args)
        {
            AtlasArguments arguments = new AtlasArguments();

            if (CommandLine.Parser.Default.ParseArguments(args, arguments))
            {
                AtlasCreator.AtlasFormat format = AtlasCreator.AtlasFormat.NONE;

                if (!Enum.TryParse <AtlasCreator.AtlasFormat>(arguments.format, true, out format))
                {
                    Console.WriteLine("Invalid Atlas format. See help -h for valid formats");
                    return;
                }

                if (!IsPowerOfTwo((ulong)arguments.Size))
                {
                    Console.WriteLine("Size is not a power of two");
                    return;
                }

                AtlasCreator.QuickCreate(arguments.InputPath, arguments.OutputPath, arguments.Size, arguments.Recursive, format);

                PromptForEnter();
            }
        }
Пример #3
0
        public void Test04_CustomIconsLoadingTest()
        {
            log.Write("Asserting to start the loading of mod textures");
            List <string> modIconsLocation = new List <string>()
            {
                UnitTestHelper.ResourcesFolder
            };
            CancellationToken token         = new CancellationToken();
            Task loadCustomContourIconsTask = AtlasCreator.LoadCustomContourIconsAsync(modIconsLocation, token);

            Assert.IsNotNull(loadCustomContourIconsTask);
            Assert.IsNotNull(AtlasUtils.AtlasLoaderLockObject);

            //wait
            loadCustomContourIconsTask.Wait();
            log.Write(string.Format("Task status: {0}", loadCustomContourIconsTask.Status.ToString()));
            Assert.IsTrue(loadCustomContourIconsTask.Status == TaskStatus.RanToCompletion);

            log.Write("Asserting each texture start point is (0,0) and width, height = image width, height");
            Assert.IsNotNull(AtlasCreator.CustomContourIconImages);
            foreach (Texture texture in AtlasCreator.CustomContourIconImages)
            {
                Assert.IsNotNull(texture.AtlasImage);
                Assert.IsTrue(texture.X == 0);
                Assert.IsTrue(texture.Y == 0);
                Assert.IsTrue(texture.Width == texture.AtlasImage.Width);
                Assert.IsTrue(texture.Height == texture.AtlasImage.Height);
            }

            //dispose of the mod contour icons
            AtlasCreator.DisposeParsedCustomTextures();
        }
Пример #4
0
    public void BuildAtlas(string name, TextureFormat format = TextureFormat.RGBA32, Color defaultColor = default(Color), bool linear = false)
    {
        AtlasCreator.Atlas[] atlasList = AtlasCreator.CreateAtlas(name, textureList.ToArray(), null, format, defaultColor, linear);
        atlas = atlasList[0];
        textureList.Clear();

        texIndexToAtlasIndex = new Dictionary <int, int>();
        nameToAtlasIndex     = new Dictionary <string, int>();
        for (int i = 0; i < atlas.uvRects.Length; i++)
        {
            nameToAtlasIndex[atlas.uvRects[i].name] = i;
        }

        foreach (var item in texIndexToName)
        {
            texIndexToAtlasIndex[item.Key] = nameToAtlasIndex[item.Value];
        }

        //AtlasCreator.SaveAtlas(atlas, name);
    }
Пример #5
0
    void OnGUI()
    {
        if (addToAtlas)
        {
            GUILayout.BeginVertical();

            int width = Screen.width / 100;

            GUILayout.Space(15.0f);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label("<size=30>Select images to add to atlas</size>");
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            scrollView = GUILayout.BeginScrollView(scrollView);
            GUILayout.BeginHorizontal();
            for (int i = 0; i < eligable.Count; ++i)
            {
                if (i % width == 0)
                {
                    GUILayout.EndHorizontal();
                }
                if (i % width == 0)
                {
                    GUILayout.BeginHorizontal();
                }
                if (!selected[i])
                {
                    if (GUILayout.Button(eligable[i], GUILayout.Width(100), GUILayout.Height(100)))
                    {
                        selected[i] = true;
                    }
                }
                else
                {
                    GUILayout.Label(eligable[i], GUILayout.Width(100), GUILayout.Height(100));
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.EndScrollView();

            GUILayout.Space(25.0f);
            bool madeSelection = false;
            foreach (bool b in selected)
            {
                if (b)
                {
                    madeSelection = true;
                    break;
                }
            }

            if (madeSelection)
            {
                if (GUILayout.Button("Add Selected Images To Atlas", GUILayout.Height(75.0f), GUILayout.Width(Screen.width)))
                {
                    building = new List <Texture2D>();

                    for (int i = eligable.Count - 1; i >= 0; --i)
                    {
                        if (selected[i])
                        {
                            building.Add(eligable[i]);
                            eligable.RemoveAt(i);
                            selected.RemoveAt(i);
                        }
                    }

                    AtlasCreator.Atlas[] newAtlases = AtlasCreator.CreateAtlas("test", building.ToArray(), atlases == null || atlases.Count == 0? null : atlases[atlases.Count - 1]);
                    foreach (AtlasCreator.Atlas newAtlas in newAtlases)
                    {
                        if (!atlases.Contains(newAtlas))
                        {
                            atlases.Add(newAtlas);
                        }
                    }
                    addToAtlas = false;
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Label("<size=30>Select a few images to continue</size>");
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
        }
        else if (atlases != null && atlases.Count >= 1)
        {
            GUILayout.BeginVertical();

            GUILayout.Space(15.0f);
            GUILayout.BeginHorizontal();
            if (atlases.Count > 1)
            {
                if (GUILayout.Button("<<", GUILayout.Height(50.0f)))
                {
                    selectedAtlas -= 1;
                    if (selectedAtlas < 0)
                    {
                        selectedAtlas = atlases.Count - 1;
                    }
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.Label("<size=30>Atlas" + (selectedAtlas + 1) + " of " + atlases.Count + "</size>");
            GUILayout.FlexibleSpace();
            if (atlases.Count > 1)
            {
                if (GUILayout.Button(">>", GUILayout.Height(50.0f)))
                {
                    selectedAtlas += 1;
                    if (selectedAtlas >= atlases.Count)
                    {
                        selectedAtlas = 0;
                    }
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label(atlases[selectedAtlas].texture, GUILayout.Height(Screen.height - 150));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            if (eligable.Count > 0)
            {
                if (GUILayout.Button("Add More Sprites To Atlas", GUILayout.Height(75.0f)))
                {
                    addToAtlas = true;
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Label("<size=30>No More Images To Add</size>");
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
        }
    }
Пример #6
0
        protected override void OnLoad()
        {
            Directory.CreateDirectory("fantasia");
            Logger.Init();
            Bind.KeyboardState = KeyboardState;
            VSync = VSyncMode.Off;

            _renderer       = new MainRenderer(Size.X, Size.Y);
            RenderFrequency = _framesPerSec;
            UpdateFrequency = _ticksPerSec;

            try
            {
                //Steamworks.SteamClient.Init(1363820);
            }
            catch (Exception e)
            {
                Logger.LogError(e);
                _quit = true;
            }

            Block.RegisterBlocks();

            AddonSystem.Init();
            AddonSystem.LoadAddonBlocks();

            _renderer.State = RendererState.InGame;

            Panel pan = new Panel(.5, .5);

            pan.Width  = .1;
            pan.Height = .1;

            _renderer.GUIRenderer.GUIElements.Add(pan);

            //List<string> files = Directory.GetFiles("fantasia/textures/", "*.png", SearchOption.AllDirectories).ToList();
            //files.AddRange(Directory.GetFiles("fantasia/addons/Minecraft/textures/", "*.png", SearchOption.AllDirectories).ToList());
            //AtlasCreator.GenAtlas(files.ToList());

            AtlasCreator.GetTexturesAndGenAtlas();
            _renderer.WorldRenderer.BlockAtlas = Texture.LoadAtlas();

            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
            GL.Enable(EnableCap.DepthTest);
            GL.ClearColor(.702f, .827f, .871f, 1.0f);

            LocalPlayer = new LocalPlayer();

            //Test Server
            _server = new IntegratedServer(1, LocalPlayer);
            //Set Active World
            _renderer.WorldRenderer.ActiveWorld = _server.World;

            Bind.TryBindKey(Keys.W, "forward");
            Bind.TryBindKey(Keys.S, "backward");
            Bind.TryBindKey(Keys.A, "left");
            Bind.TryBindKey(Keys.D, "right");
            Bind.TryBindKey(Keys.Space, "jump");

            CursorGrabbed = true;

            base.OnLoad();
        }
        public void Test05_FullAtlasTest()
        {
            Logfile log = UnitTestHelper.CreateLogfile();

            Assert.IsNotNull(log);
            Assert.IsTrue(log.CanWrite);

            //make sure atlas packer's relhax temp folder exists
            if (!Directory.Exists(ApplicationConstants.RelhaxTempFolderPath))
            {
                Directory.CreateDirectory(ApplicationConstants.RelhaxTempFolderPath);
            }
            AtlasCreator atlasCreator = null;

            foreach (string atlasPrefix in AtlasFiles)
            {
                using (atlasCreator = new AtlasCreator())
                {
                    string testAtlasOut = Path.Combine(UnitTestHelper.ResourcesFolder, "atlas_out", string.Format("{0}.dds", atlasPrefix));
                    string testMapOut   = Path.Combine(UnitTestHelper.ResourcesFolder, "atlas_out", string.Format("{0}.xml", atlasPrefix));
                    string testMapIn    = Path.Combine(UnitTestHelper.ResourcesFolder, string.Format("{0}.xml", atlasPrefix));

                    atlasCreator.Atlas = new Atlas()
                    {
                        AtlasFile          = "battleAtlas.dds",              //changed later
                        AtlasHeight        = 0,                              //auto-size
                        AtlasWidth         = 0,                              //auto-size
                        AtlasSaveDirectory = Path.GetDirectoryName(testAtlasOut),
                        DirectoryInArchive = UnitTestHelper.ResourcesFolder, //set the full path without filename when it's a copy
                        FastImagePacker    = true,                           //don't change this
                        PowOf2             = true,                           //changed later
                        Square             = true,                           //changed later
                        Padding            = 1,                              //also don't change this
                        Pkg = string.Empty,                                  //set this to do a file copy rather then unpack
                    };

                    foreach (PackerSettings settings in PackerSettingsToTest)
                    {
                        if (Directory.Exists(atlasCreator.Atlas.AtlasSaveDirectory))
                        {
                            Directory.Delete(atlasCreator.Atlas.AtlasSaveDirectory, true);
                        }
                        Directory.CreateDirectory(atlasCreator.Atlas.AtlasSaveDirectory);

                        log.Write("Asserting to start the loading of mod textures");
                        List <string> modIconsLocation = new List <string>()
                        {
                            UnitTestHelper.ResourcesFolder
                        };
                        CancellationToken token = new CancellationToken();
                        AtlasCreator.LoadCustomContourIconsAsync(modIconsLocation, token);

                        log.Write(string.Format("Asserting to create the atlas '{0}' using the following settings:", atlasPrefix));
                        log.Write(string.Format("{0}={1}, {2}={3}", "powerTwo", settings.PowerTwo, "squareImage", settings.SquareImage));
                        atlasCreator.Atlas.PowOf2          = settings.PowerTwo;
                        atlasCreator.Atlas.Square          = settings.SquareImage;
                        atlasCreator.Atlas.FastImagePacker = true;
                        atlasCreator.Atlas.AtlasFile       = Path.GetFileName(testAtlasOut);

                        //actually run the packer
                        FailCode code = atlasCreator.CreateAtlas();
                        log.Write(string.Format("Packer fail code: {0}", code.ToString()));
                        Assert.AreEqual(FailCode.None, code);
                        Assert.IsTrue(File.Exists(testAtlasOut));
                        Assert.IsTrue(File.Exists(testMapOut));

                        //check the number of texture elements. should not have changed
                        log.Write("Asserting created map file has correct number of textures");
                        XmlDocument textureDocument = new XmlDocument();
                        textureDocument.Load(testMapIn);
                        int numSubTexturesIn = textureDocument.SelectNodes("//SubTexture").Count;

                        textureDocument = new XmlDocument();
                        textureDocument.Load(testMapOut);
                        int numSubTexturesOut = textureDocument.SelectNodes("//SubTexture").Count;
                        log.Write(string.Format("Expected node textures: {0}, actual {1}", numSubTexturesIn, numSubTexturesOut));
                        Assert.AreEqual(numSubTexturesIn, numSubTexturesOut);

                        //dispose of the mod contour icons
                        AtlasCreator.DisposeParsedCustomTextures();
                    }
                }
            }

            Directory.Delete(atlasCreator.Atlas.AtlasSaveDirectory, true);

            UnitTestHelper.DestroyLogfile(ref log, false);
            Assert.IsNull(log);
        }