Пример #1
0
 public void Load(AtlasPage page, String path)
 {
     Texture2D texture = Util.LoadTexture(device, path);
     page.texture = texture;
     page.width = texture.Width;
     page.height = texture.Height;
 }
Пример #2
0
 public void Load(AtlasPage page, String path)
 {
     Texture texture = new Texture(path, false);
     page.rendererObject = texture;
     page.width = texture.Width;
     page.height = texture.Height;
 }
Пример #3
0
	public void Load (AtlasPage page, String path) {
		String name = Path.GetFileNameWithoutExtension(path);
		Material material = null;
		foreach (Material other in atlasAsset.materials) {
			if (other.mainTexture == null) {
				Debug.LogError("Material is missing texture: " + other.name, other);
				return;
			}
			if (other.mainTexture.name == name) {
				material = other;
				break;
			}
		}
		if (material == null) {
			Debug.LogError("Material with texture name \"" + name + "\" not found for atlas asset: " + atlasAsset.name, atlasAsset);
			return;
		}
		page.rendererObject = material;

		// Very old atlas files expected the texture's actual size to be used at runtime.
		if (page.width == 0 || page.height == 0) {
			page.width = material.mainTexture.width;
			page.height = material.mainTexture.height;
		}
	}
		public void Load (AtlasPage page, String path) {

            texture = Util.LoadTexture(device, path);
            page.rendererObject = texture;
            page.width = texture.Width;
            page.height = texture.Height;
		}
 /// <summary>
 /// Loads the specified page.
 /// </summary>
 /// <param name="page">The page.</param>
 /// <param name="path">The path.</param>
 public void Load(AtlasPage page, string path)
 {
     path = Path.ChangeExtension(path, ".wpk");
     Texture2D texture = this.assets.LoadAsset<Texture2D>(path);
     page.rendererObject = texture;
     page.width = texture.Width;
     page.height = texture.Height;
 }
Пример #6
0
 public static void AtlasPageCreateTexture(ref AtlasPage self, string path)
 {
     CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(path);
     CCTextureAtlas textureAtlas = CCTextureAtlas.Create(texture, 128);
     //textureAtlas. ->retain();
     self.rendererObject = textureAtlas;
     self.width = texture.PixelsWide;
     self.height = texture.PixelsHigh;
 }
		public void Load (AtlasPage page, String path) 
		{
			var ccTexture = CCTextureCache.SharedTextureCache.AddImage(path);
            texture = ccTexture;

            page.rendererObject = texture;
            page.width = (int)texture.ContentSizeInPixels.Width;
            page.height = (int)texture.ContentSizeInPixels.Height;
		}
Пример #8
0
        public void Load(Spine.AtlasPage page, string path)
        {
            Debug.Log("load page:" + page.name);
            var mat = new Material(Shader.Find("Spine/Skeleton"));

            mat.mainTexture     = texs[page.name];
            page.rendererObject = mat;
            page.width          = mat.mainTexture.width;
            page.height         = mat.mainTexture.height;
        }
Пример #9
0
		public void Load(AtlasPage page, String path)
		{
			var image = ContentLoader.Load<Image>(Path.GetFileNameWithoutExtension(path));
			var shader =
				ContentLoader.Create<Shader>(new ShaderCreationData(ShaderFlags.Position2DColoredTextured));
			var material = new Material(shader, image);
			page.rendererObject = material;
			Size size = material.DiffuseMap.PixelSize;
			page.width = (int)size.Width;
			page.height = (int)size.Height;
		}
Пример #10
0
        void _spAtlasPage_createTexture(AtlasPage self, string path)
        {
            CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(path);
            CCTextureAtlas textureAtlas = new CCTextureAtlas();
            textureAtlas.InitWithTexture(texture, 128);

            textureAtlas.DrawQuads(); //retain();

            self.rendererObject = textureAtlas;
            self.width = texture.PixelsWide;
            self.height = texture.PixelsHigh;
        }
Пример #11
0
    public void Load(Spine.AtlasPage page, string path)
    {
        Debug.Log("load page:" + page.name);
        var mat   = new Material(Shader.Find("Spine/Skeleton"));
        int right = path.LastIndexOf('.');

        path = path.Substring(0, right);
        string file = System.IO.Path.Combine(basepath, path);

        Debug.Log("Load pic:" + file + "," + path);
        mat.mainTexture     = Resources.Load(file) as Texture2D;
        page.rendererObject = mat;
        page.width          = mat.mainTexture.width;
        page.height         = mat.mainTexture.height;
    }
		public void Load (AtlasPage page, String path) 
		{
			var ccTexture = CCTextureCache.SharedTextureCache.AddImage(path);

            if (texture == null)
                using (Stream stream = CCFileUtils.GetFileStream(path))
                {
                    texture = Util.LoadTexture(CCDrawManager.GraphicsDevice, stream);
                }
            else
                texture = ccTexture.XNATexture;

            page.rendererObject = texture;
            page.width = texture.Width;
            page.height = texture.Height;
		}
Пример #13
0
        /// <summary>
        /// Loads the specified page.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="path">The path.</param>
        public void Load(AtlasPage page, string path)
        {
            var material = new StandardMaterial()
            {
                LightingEnabled = false,
                DiffusePath = path,
                VertexColorEnable = true
            };

            material.Initialize(this.assets);

            var texture = material.Diffuse;
            page.rendererObject = material;
            page.width = texture.Width;
            page.height = texture.Height;
        }
Пример #14
0
        public void Load(AtlasPage page, string path)
        {
            Bitmap     b  = new Bitmap(path);
            BitmapData bd = b.LockBits(new Rectangle(0, 0, b.Width, b.Height),
                                       ImageLockMode.ReadOnly, b.PixelFormat);
            // convert format from ARGB to PARGB without modifying the actual data
            Bitmap     pb  = new Bitmap(b.Width, b.Height, PixelFormat.Format32bppPArgb);
            BitmapData pbd = pb.LockBits(new Rectangle(0, 0, pb.Width, pb.Height),
                                         ImageLockMode.ReadWrite, pb.PixelFormat);
            IntPtr ptr   = bd.Scan0;
            int    bytes = Math.Abs(bd.Stride) * b.Height;

            byte[] argbValues = new byte[bytes];
            System.Runtime.InteropServices.Marshal.Copy(ptr, argbValues, 0, bytes);
            System.Runtime.InteropServices.Marshal.Copy(argbValues, 0, pbd.Scan0, bytes);
            pb.UnlockBits(pbd);

            pb.SetResolution(96, 96);
            page.rendererObject = pb;
        }
Пример #15
0
        public void Load(AtlasPage page, String path)
        {
            Texture2D texture = Util.LoadTexture(device, path);

            page.width  = texture.Width;
            page.height = texture.Height;

            if (textureLayerSuffixes == null)
            {
                page.rendererObject = texture;
            }
            else
            {
                Texture2D[] textureLayersArray = new Texture2D[textureLayerSuffixes.Length];
                textureLayersArray[0] = texture;
                for (int layer = 1; layer < textureLayersArray.Length; ++layer)
                {
                    string layerPath = GetLayerName(path, textureLayerSuffixes[0], textureLayerSuffixes[layer]);
                    textureLayersArray[layer] = Util.LoadTexture(device, layerPath);
                }
                page.rendererObject = textureLayersArray;
            }
        }
        public void Load(AtlasPage page, String path)
        {
            Bitmap texture = new Bitmap(path);

            BitmapData texturedata = texture.LockBits(new Rectangle(0, 0, texture.Width, texture.Height),
                ImageLockMode.ReadOnly, PixelFormatMap.GetPixelFormat(page.format));

            int tex = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, tex);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureFilterMap.GetMagFilter(page.magFilter));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureFilterMap.GetMinFilter(page.minFilter));

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelFormatMap.GetInternalFormat(page.format), texture.Width, texture.Height, 0,
                PixelFormatMap.GetOpenGLPixelFormat(page.format), PixelType.UnsignedByte, texturedata.Scan0);

            GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

            texture.UnlockBits(texturedata);

            page.rendererObject = tex;
            page.width = texture.Width;
            page.height = texture.Height;
        }
Пример #17
0
    public RegionAttachment NewRegionAttachment(Skin skin, string name, string path)
    {
        RegionAttachment attachment = new RegionAttachment(name);

        Texture2D tex = sprite.texture;
        int instanceId = tex.GetInstanceID();
        AtlasRegion atlasRegion;

        //check cache first
        if (atlasTable.ContainsKey(instanceId)) {
            atlasRegion = atlasTable[instanceId];
        } else {
            //Setup new material
            Material mat = new Material(shader);
            if (sprite.packed)
                mat.name = "Unity Packed Sprite Material";
            else
                mat.name = sprite.name + " Sprite Material";
            mat.mainTexture = tex;

            //create faux-region to play nice with SkeletonRenderer
            atlasRegion = new AtlasRegion();
            AtlasPage page = new AtlasPage();
            page.rendererObject = mat;
            atlasRegion.page = page;

            //cache it
            atlasTable[instanceId] = atlasRegion;
        }

        Rect texRect = sprite.textureRect;

        //normalize rect to UV space of packed atlas
        texRect.x = Mathf.InverseLerp(0, tex.width, texRect.x);
        texRect.y = Mathf.InverseLerp(0, tex.height, texRect.y);
        texRect.width = Mathf.InverseLerp(0, tex.width, texRect.width);
        texRect.height = Mathf.InverseLerp(0, tex.height, texRect.height);

        Bounds bounds = sprite.bounds;
        Vector3 size = bounds.size;

        //TODO: make sure this rotation thing actually works
        bool rotated = false;
        if (sprite.packed)
            rotated = sprite.packingRotation == SpritePackingRotation.Any;

        //do some math and assign UVs and sizes
        attachment.SetUVs(texRect.xMin, texRect.yMax, texRect.xMax, texRect.yMin, rotated);
        attachment.RendererObject = atlasRegion;
        attachment.SetColor(Color.white);
        attachment.ScaleX = 1;
        attachment.ScaleY = 1;
        attachment.RegionOffsetX = sprite.rect.width * (0.5f - Mathf.InverseLerp(bounds.min.x, bounds.max.x, 0)) / sprite.pixelsPerUnit;
        attachment.RegionOffsetY = sprite.rect.height * (0.5f - Mathf.InverseLerp(bounds.min.y, bounds.max.y, 0)) / sprite.pixelsPerUnit;
        attachment.Width = size.x;
        attachment.Height = size.y;
        attachment.RegionWidth = size.x;
        attachment.RegionHeight = size.y;
        attachment.RegionOriginalWidth = size.x;
        attachment.RegionOriginalHeight = size.y;
        attachment.UpdateOffset();

        return attachment;
    }
Пример #18
0
        private void Load(TextReader reader, string imagesDir, TextureLoader textureLoader)
        {
            if (textureLoader == null)
            {
                throw new ArgumentNullException("textureLoader", "textureLoader cannot be null.");
            }
            this.textureLoader = textureLoader;

            string[]  tuple = new string[4];
            AtlasPage page  = null;

            while (true)
            {
                string line = reader.ReadLine();
                if (line == null)
                {
                    break;
                }
                if (line.Trim().Length == 0)
                {
                    page = null;
                }
                else if (page == null)
                {
                    page      = new AtlasPage();
                    page.name = line;

                    if (ReadTuple(reader, tuple) == 2)                       // size is only optional for an atlas packed with an old TexturePacker.
                    {
                        page.width  = int.Parse(tuple[0]);
                        page.height = int.Parse(tuple[1]);
                        ReadTuple(reader, tuple);
                    }
                    page.format = (Format)Enum.Parse(typeof(Format), tuple[0], false);

                    ReadTuple(reader, tuple);
                    page.minFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[0], false);
                    page.magFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[1], false);

                    string direction = ReadValue(reader);
                    page.uWrap = TextureWrap.ClampToEdge;
                    page.vWrap = TextureWrap.ClampToEdge;
                    if (direction == "x")
                    {
                        page.uWrap = TextureWrap.Repeat;
                    }
                    else if (direction == "y")
                    {
                        page.vWrap = TextureWrap.Repeat;
                    }
                    else if (direction == "xy")
                    {
                        page.uWrap = page.vWrap = TextureWrap.Repeat;
                    }

                    textureLoader.Load(page, Path.Combine(imagesDir, line));

                    pages.Add(page);
                }
                else
                {
                    AtlasRegion region = new AtlasRegion();
                    region.name = line;
                    region.page = page;

                    string rotateValue = ReadValue(reader);
                    if (rotateValue == "true")
                    {
                        region.degrees = 90;
                    }
                    else if (rotateValue == "false")
                    {
                        region.degrees = 0;
                    }
                    else
                    {
                        region.degrees = int.Parse(rotateValue);
                    }
                    region.rotate = region.degrees == 90;

                    ReadTuple(reader, tuple);
                    int x = int.Parse(tuple[0]);
                    int y = int.Parse(tuple[1]);

                    ReadTuple(reader, tuple);
                    int width  = int.Parse(tuple[0]);
                    int height = int.Parse(tuple[1]);

                    region.u = x / (float)page.width;
                    region.v = y / (float)page.height;
                    if (region.rotate)
                    {
                        region.u2 = (x + height) / (float)page.width;
                        region.v2 = (y + width) / (float)page.height;
                    }
                    else
                    {
                        region.u2 = (x + width) / (float)page.width;
                        region.v2 = (y + height) / (float)page.height;
                    }
                    region.x      = x;
                    region.y      = y;
                    region.width  = Math.Abs(width);
                    region.height = Math.Abs(height);

                    if (ReadTuple(reader, tuple) == 4)                       // split is optional
                    {
                        region.splits = new [] { int.Parse(tuple[0]), int.Parse(tuple[1]),
                                                 int.Parse(tuple[2]), int.Parse(tuple[3]) };

                        if (ReadTuple(reader, tuple) == 4)                           // pad is optional, but only present with splits
                        {
                            region.pads = new [] { int.Parse(tuple[0]), int.Parse(tuple[1]),
                                                   int.Parse(tuple[2]), int.Parse(tuple[3]) };

                            ReadTuple(reader, tuple);
                        }
                    }

                    region.originalWidth  = int.Parse(tuple[0]);
                    region.originalHeight = int.Parse(tuple[1]);

                    ReadTuple(reader, tuple);
                    region.offsetX = int.Parse(tuple[0]);
                    region.offsetY = int.Parse(tuple[1]);

                    region.index = int.Parse(ReadValue(reader));

                    regions.Add(region);
                }
            }
        }
Пример #19
0
		private void Load (TextReader reader, String imagesDir, TextureLoader textureLoader) {
			if (textureLoader == null) throw new ArgumentNullException("textureLoader cannot be null.");
			this.textureLoader = textureLoader;

			String[] tuple = new String[4];
			AtlasPage page = null;
			while (true) {
				String line = reader.ReadLine();
				if (line == null) break;
				if (line.Trim().Length == 0)
					page = null;
				else if (page == null) {
					page = new AtlasPage();
					page.name = line;

					if (readTuple(reader, tuple) == 2) { // size is only optional for an atlas packed with an old TexturePacker.
						page.width = int.Parse(tuple[0]);
						page.height = int.Parse(tuple[1]);
						readTuple(reader, tuple);
					}
					page.format = (Format)Enum.Parse(typeof(Format), tuple[0], false);

					readTuple(reader, tuple);
					page.minFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[0], false);
					page.magFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[1], false);

					String direction = readValue(reader);
					page.uWrap = TextureWrap.ClampToEdge;
					page.vWrap = TextureWrap.ClampToEdge;
					if (direction == "x")
						page.uWrap = TextureWrap.Repeat;
					else if (direction == "y")
						page.vWrap = TextureWrap.Repeat;
					else if (direction == "xy")
						page.uWrap = page.vWrap = TextureWrap.Repeat;

					textureLoader.Load(page, Path.Combine(imagesDir, line));

					pages.Add(page);

				} else {
					AtlasRegion region = new AtlasRegion();
					region.name = line;
					region.page = page;

					region.rotate = Boolean.Parse(readValue(reader));

					readTuple(reader, tuple);
					int x = int.Parse(tuple[0]);
					int y = int.Parse(tuple[1]);

					readTuple(reader, tuple);
					int width = int.Parse(tuple[0]);
					int height = int.Parse(tuple[1]);

					region.u = x / (float)page.width;
					region.v = y / (float)page.height;
					if (region.rotate) {
						region.u2 = (x + height) / (float)page.width;
						region.v2 = (y + width) / (float)page.height;
					} else {
						region.u2 = (x + width) / (float)page.width;
						region.v2 = (y + height) / (float)page.height;
					}
					region.x = x;
					region.y = y;
					region.width = Math.Abs(width);
					region.height = Math.Abs(height);

					if (readTuple(reader, tuple) == 4) { // split is optional
						region.splits = new int[] {int.Parse(tuple[0]), int.Parse(tuple[1]),
								int.Parse(tuple[2]), int.Parse(tuple[3])};

						if (readTuple(reader, tuple) == 4) { // pad is optional, but only present with splits
							region.pads = new int[] {int.Parse(tuple[0]), int.Parse(tuple[1]),
									int.Parse(tuple[2]), int.Parse(tuple[3])};

							readTuple(reader, tuple);
						}
					}

					region.originalWidth = int.Parse(tuple[0]);
					region.originalHeight = int.Parse(tuple[1]);

					readTuple(reader, tuple);
					region.offsetX = int.Parse(tuple[0]);
					region.offsetY = int.Parse(tuple[1]);

					region.index = int.Parse(readValue(reader));

					regions.Add(region);
				}
			}
		}
Пример #20
0
		public RegionAttachment NewRegionAttachment (Skin skin, string name, string path) {
			RegionAttachment attachment = new RegionAttachment(name);

			Texture2D tex = sprite.texture;
			int instanceId = tex.GetInstanceID();
			AtlasRegion atlasRegion;
			bool cachedMaterialExists = atlasTable.TryGetValue(instanceId, out atlasRegion);

			if (!cachedMaterialExists) {
				// Setup new material.
				var material = new Material(shader);
				if (sprite.packed)
					material.name = "Unity Packed Sprite Material";
				else
					material.name = sprite.name + " Sprite Material";
				material.mainTexture = tex;

				// Create faux-region to play nice with SkeletonRenderer.
				atlasRegion = new AtlasRegion();
				var page = new AtlasPage();
				page.rendererObject = material;
				atlasRegion.page = page;

				// Cache it.
				atlasTable[instanceId] = atlasRegion;
			}

			Rect texRect = sprite.textureRect;

			// Normalize rect to UV space of packed atlas
			texRect.x = Mathf.InverseLerp(0, tex.width, texRect.x);
			texRect.y = Mathf.InverseLerp(0, tex.height, texRect.y);
			texRect.width = Mathf.InverseLerp(0, tex.width, texRect.width);
			texRect.height = Mathf.InverseLerp(0, tex.height, texRect.height);

			Bounds bounds = sprite.bounds;
			Vector2 boundsMin = bounds.min, boundsMax = bounds.max;
			Vector2 size = bounds.size;
			float spriteUnitsPerPixel = 1f / sprite.pixelsPerUnit;

			bool rotated = false;
			if (sprite.packed)
				rotated = sprite.packingRotation == SpritePackingRotation.Any;

			attachment.SetUVs(texRect.xMin, texRect.yMax, texRect.xMax, texRect.yMin, rotated);
			attachment.RendererObject = atlasRegion;
			attachment.SetColor(Color.white);
			attachment.ScaleX = 1;
			attachment.ScaleY = 1;
			attachment.RegionOffsetX = sprite.rect.width * (0.5f - InverseLerp(boundsMin.x, boundsMax.x, 0)) * spriteUnitsPerPixel;
			attachment.RegionOffsetY = sprite.rect.height * (0.5f - InverseLerp(boundsMin.y, boundsMax.y, 0)) * spriteUnitsPerPixel;
			attachment.Width = size.x;
			attachment.Height = size.y;
			attachment.RegionWidth = size.x;
			attachment.RegionHeight = size.y;
			attachment.RegionOriginalWidth = size.x;
			attachment.RegionOriginalHeight = size.y;
			attachment.UpdateOffset();

			return attachment;
		}
Пример #21
0
 public void Load(AtlasPage page, String path)
 {
     String name = Path.GetFileNameWithoutExtension(path);
     Material material = null;
     foreach (Material other in atlasAsset.materials) {
         if (other.mainTexture.name == name) {
             material = other;
             break;
         }
     }
     if (material == null) {
         Debug.LogWarning("Material with texture name \"" + name + "\" not found for atlas asset: " + atlasAsset.name, atlasAsset);
         return;
     }
     page.rendererObject = material;
     page.width = material.mainTexture.width;
     page.height = material.mainTexture.height;
 }
Пример #22
0
        public Atlas(TextReader reader, string imagesDir, TextureLoader textureLoader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader", "reader cannot be null.");
            }
            if (imagesDir == null)
            {
                throw new ArgumentNullException("imagesDir", "imagesDir cannot be null.");
            }
            if (textureLoader == null)
            {
                throw new ArgumentNullException("textureLoader", "textureLoader cannot be null.");
            }
            this.textureLoader = textureLoader;

            string[]    entry  = new string[5];
            AtlasPage   page   = null;
            AtlasRegion region = null;

            var pageFields = new Dictionary <string, Action>(5);

            pageFields.Add("size", () => {
                page.width  = int.Parse(entry[1], CultureInfo.InvariantCulture);
                page.height = int.Parse(entry[2], CultureInfo.InvariantCulture);
            });
            pageFields.Add("format", () => {
                page.format = (Format)Enum.Parse(typeof(Format), entry[1], false);
            });
            pageFields.Add("filter", () => {
                page.minFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), entry[1], false);
                page.magFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), entry[2], false);
            });
            pageFields.Add("repeat", () => {
                if (entry[1].IndexOf('x') != -1)
                {
                    page.uWrap = TextureWrap.Repeat;
                }
                if (entry[1].IndexOf('y') != -1)
                {
                    page.vWrap = TextureWrap.Repeat;
                }
            });
            pageFields.Add("pma", () => {
                page.pma = entry[1] == "true";
            });

            var regionFields = new Dictionary <string, Action>(8);

            regionFields.Add("xy", () => {             // Deprecated, use bounds.
                region.x = int.Parse(entry[1], CultureInfo.InvariantCulture);
                region.y = int.Parse(entry[2], CultureInfo.InvariantCulture);
            });
            regionFields.Add("size", () => {             // Deprecated, use bounds.
                region.width  = int.Parse(entry[1], CultureInfo.InvariantCulture);
                region.height = int.Parse(entry[2], CultureInfo.InvariantCulture);
            });
            regionFields.Add("bounds", () => {
                region.x      = int.Parse(entry[1], CultureInfo.InvariantCulture);
                region.y      = int.Parse(entry[2], CultureInfo.InvariantCulture);
                region.width  = int.Parse(entry[3], CultureInfo.InvariantCulture);
                region.height = int.Parse(entry[4], CultureInfo.InvariantCulture);
            });
            regionFields.Add("offset", () => {             // Deprecated, use offsets.
                region.offsetX = int.Parse(entry[1], CultureInfo.InvariantCulture);
                region.offsetY = int.Parse(entry[2], CultureInfo.InvariantCulture);
            });
            regionFields.Add("orig", () => {             // Deprecated, use offsets.
                region.originalWidth  = int.Parse(entry[1], CultureInfo.InvariantCulture);
                region.originalHeight = int.Parse(entry[2], CultureInfo.InvariantCulture);
            });
            regionFields.Add("offsets", () => {
                region.offsetX        = int.Parse(entry[1], CultureInfo.InvariantCulture);
                region.offsetY        = int.Parse(entry[2], CultureInfo.InvariantCulture);
                region.originalWidth  = int.Parse(entry[3], CultureInfo.InvariantCulture);
                region.originalHeight = int.Parse(entry[4], CultureInfo.InvariantCulture);
            });
            regionFields.Add("rotate", () => {
                string value = entry[1];
                if (value == "true")
                {
                    region.degrees = 90;
                }
                else if (value != "false")
                {
                    region.degrees = int.Parse(value, CultureInfo.InvariantCulture);
                }
            });
            regionFields.Add("index", () => {
                region.index = int.Parse(entry[1], CultureInfo.InvariantCulture);
            });

            string line = reader.ReadLine();

            // Ignore empty lines before first entry.
            while (line != null && line.Trim().Length == 0)
            {
                line = reader.ReadLine();
            }
            // Header entries.
            while (true)
            {
                if (line == null || line.Trim().Length == 0)
                {
                    break;
                }
                if (ReadEntry(entry, line) == 0)
                {
                    break;                                              // Silently ignore all header fields.
                }
                line = reader.ReadLine();
            }
            // Page and region entries.
            List <string> names  = null;
            List <int[]>  values = null;

            while (true)
            {
                if (line == null)
                {
                    break;
                }
                if (line.Trim().Length == 0)
                {
                    page = null;
                    line = reader.ReadLine();
                }
                else if (page == null)
                {
                    page      = new AtlasPage();
                    page.name = line.Trim();
                    while (true)
                    {
                        if (ReadEntry(entry, line = reader.ReadLine()) == 0)
                        {
                            break;
                        }
                        Action field;
                        if (pageFields.TryGetValue(entry[0], out field))
                        {
                            field();                                                                      // Silently ignore unknown page fields.
                        }
                    }
                    textureLoader.Load(page, Path.Combine(imagesDir, page.name));
                    pages.Add(page);
                }
                else
                {
                    region      = new AtlasRegion();
                    region.page = page;
                    region.name = line;
                    while (true)
                    {
                        int count = ReadEntry(entry, line = reader.ReadLine());
                        if (count == 0)
                        {
                            break;
                        }
                        Action field;
                        if (regionFields.TryGetValue(entry[0], out field))
                        {
                            field();
                        }
                        else
                        {
                            if (names == null)
                            {
                                names  = new List <string>(8);
                                values = new List <int[]>(8);
                            }
                            names.Add(entry[0]);
                            int[] entryValues = new int[count];
                            for (int i = 0; i < count; i++)
                            {
                                int.TryParse(entry[i + 1], NumberStyles.Any, CultureInfo.InvariantCulture, out entryValues[i]);                                 // Silently ignore non-integer values.
                            }
                            values.Add(entryValues);
                        }
                    }
                    if (region.originalWidth == 0 && region.originalHeight == 0)
                    {
                        region.originalWidth  = region.width;
                        region.originalHeight = region.height;
                    }
                    if (names != null && names.Count > 0)
                    {
                        region.names  = names.ToArray();
                        region.values = values.ToArray();
                        names.Clear();
                        values.Clear();
                    }
                    region.u = region.x / (float)page.width;
                    region.v = region.y / (float)page.height;
                    if (region.degrees == 90)
                    {
                        region.u2 = (region.x + region.height) / (float)page.width;
                        region.v2 = (region.y + region.width) / (float)page.height;
                    }
                    else
                    {
                        region.u2 = (region.x + region.width) / (float)page.width;
                        region.v2 = (region.y + region.height) / (float)page.height;
                    }
                    regions.Add(region);
                }
            }
        }
Пример #23
0
 public void Load(AtlasPage page, String path)
 {
     page.width = material.mainTexture.width;
     page.height = material.mainTexture.height;
 }
Пример #24
0
        private void Load(TextReader reader, string imagesDir, TextureLoader textureLoader)
        {
            if (textureLoader == null)
            {
                throw new ArgumentNullException("textureLoader", "textureLoader cannot be null.");
            }
            this.textureLoader = textureLoader;
            string[]  tuple = new string[4];
            AtlasPage page  = null;

            while (true)
            {
                string str = reader.ReadLine();
                if (str == null)
                {
                    return;
                }
                if (str.Trim().Length == 0)
                {
                    page = null;
                }
                else if (page == null)
                {
                    page = new AtlasPage {
                        name = str
                    };
                    if (ReadTuple(reader, tuple) == 2)
                    {
                        page.width  = int.Parse(tuple[0]);
                        page.height = int.Parse(tuple[1]);
                        ReadTuple(reader, tuple);
                    }
                    page.format = (Format)Enum.Parse(typeof(Format), tuple[0], false);
                    ReadTuple(reader, tuple);
                    page.minFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[0], false);
                    page.magFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[1], false);
                    string str2 = ReadValue(reader);
                    page.uWrap = TextureWrap.ClampToEdge;
                    page.vWrap = TextureWrap.ClampToEdge;
                    switch (str2)
                    {
                    case "x":
                        page.uWrap = TextureWrap.Repeat;
                        break;

                    case "y":
                        page.vWrap = TextureWrap.Repeat;
                        break;

                    case "xy":
                        page.uWrap = page.vWrap = TextureWrap.Repeat;
                        break;
                    }
                    textureLoader.Load(page, Path.Combine(imagesDir, str));
                    this.pages.Add(page);
                }
                else
                {
                    AtlasRegion item = new AtlasRegion {
                        name   = str,
                        page   = page,
                        rotate = bool.Parse(ReadValue(reader))
                    };
                    ReadTuple(reader, tuple);
                    int num  = int.Parse(tuple[0]);
                    int num2 = int.Parse(tuple[1]);
                    ReadTuple(reader, tuple);
                    int num3 = int.Parse(tuple[0]);
                    int num4 = int.Parse(tuple[1]);
                    item.u = ((float)num) / ((float)page.width);
                    item.v = ((float)num2) / ((float)page.height);
                    if (item.rotate)
                    {
                        item.u2 = ((float)(num + num4)) / ((float)page.width);
                        item.v2 = ((float)(num2 + num3)) / ((float)page.height);
                    }
                    else
                    {
                        item.u2 = ((float)(num + num3)) / ((float)page.width);
                        item.v2 = ((float)(num2 + num4)) / ((float)page.height);
                    }
                    item.x      = num;
                    item.y      = num2;
                    item.width  = Math.Abs(num3);
                    item.height = Math.Abs(num4);
                    if (ReadTuple(reader, tuple) == 4)
                    {
                        item.splits = new int[] { int.Parse(tuple[0]), int.Parse(tuple[1]), int.Parse(tuple[2]), int.Parse(tuple[3]) };
                        if (ReadTuple(reader, tuple) == 4)
                        {
                            item.pads = new int[] { int.Parse(tuple[0]), int.Parse(tuple[1]), int.Parse(tuple[2]), int.Parse(tuple[3]) };
                            ReadTuple(reader, tuple);
                        }
                    }
                    item.originalWidth  = int.Parse(tuple[0]);
                    item.originalHeight = int.Parse(tuple[1]);
                    ReadTuple(reader, tuple);
                    item.offsetX = int.Parse(tuple[0]);
                    item.offsetY = int.Parse(tuple[1]);
                    item.index   = int.Parse(ReadValue(reader));
                    this.regions.Add(item);
                }
            }
        }
Пример #25
0
        public void load(StreamReader reader, String imagesDir)
        {
            String[]  tuple = new String[4];
            AtlasPage page  = null;

            while (true)
            {
                String line = reader.ReadLine();
                if (line == null)
                {
                    break;
                }
                if (line.Trim().Length == 0)
                {
                    page = null;
                }
                else if (page == null)
                {
                    page = NewAtlasPage(Path.Combine(imagesDir, line));

                    page.Format = (Format)Enum.Parse(typeof(Format), readValue(reader), false);

                    readTuple(reader, tuple);
                    page.MinFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[0]);
                    page.MagFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[1]);

                    String direction = readValue(reader);
                    page.UWrap = TextureWrap.ClampToEdge;
                    page.VWrap = TextureWrap.ClampToEdge;
                    if (direction == "x")
                    {
                        page.UWrap = TextureWrap.Repeat;
                    }
                    else if (direction == "y")
                    {
                        page.VWrap = TextureWrap.Repeat;
                    }
                    else if (direction == "xy")
                    {
                        page.UWrap = page.VWrap = TextureWrap.Repeat;
                    }

                    pages.Add(page);
                }
                else
                {
                    AtlasRegion region = new AtlasRegion();
                    region.Name = line;
                    region.Page = page;

                    region.Rotate = Boolean.Parse(readValue(reader));

                    readTuple(reader, tuple);
                    int x = int.Parse(tuple[0]);
                    int y = int.Parse(tuple[1]);

                    readTuple(reader, tuple);
                    int width  = int.Parse(tuple[0]);
                    int height = int.Parse(tuple[1]);

                    float invTexWidth  = 1f / page.GetTextureWidth();
                    float invTexHeight = 1f / page.GetTextureHeight();
                    region.U      = x * invTexWidth;
                    region.V      = y * invTexHeight;
                    region.U2     = (x + width) * invTexWidth;
                    region.V2     = (y + height) * invTexHeight;
                    region.Width  = Math.Abs(width);
                    region.Height = Math.Abs(height);

                    if (readTuple(reader, tuple) == 4)                       // split is optional
                    {
                        region.Splits = new int[] { int.Parse(tuple[0]), int.Parse(tuple[1]),
                                                    int.Parse(tuple[2]), int.Parse(tuple[3]) };

                        if (readTuple(reader, tuple) == 4)                           // pad is optional, but only present with splits
                        {
                            region.Pads = new int[] { int.Parse(tuple[0]), int.Parse(tuple[1]),
                                                      int.Parse(tuple[2]), int.Parse(tuple[3]) };

                            readTuple(reader, tuple);
                        }
                    }

                    region.OriginalWidth  = int.Parse(tuple[0]);
                    region.OriginalHeight = int.Parse(tuple[1]);

                    readTuple(reader, tuple);
                    region.OffsetX = int.Parse(tuple[0]);
                    region.OffsetY = int.Parse(tuple[1]);

                    region.Index = int.Parse(readValue(reader));

                    regions.Add(region);
                }
            }
        }
Пример #26
0
        private void Load(TextReader reader, string imagesDir, TextureLoader textureLoader)
        {
            if (textureLoader == null)
            {
                throw new ArgumentNullException("textureLoader", "textureLoader cannot be null.");
            }
            this.textureLoader = textureLoader;
            string[]  array     = new string[4];
            AtlasPage atlasPage = null;

            while (true)
            {
                string text = reader.ReadLine();
                if (text == null)
                {
                    break;
                }
                if (text.Trim().Length == 0)
                {
                    atlasPage = null;
                    continue;
                }
                if (atlasPage == null)
                {
                    atlasPage      = new AtlasPage();
                    atlasPage.name = text;
                    if (ReadTuple(reader, array) == 2)
                    {
                        atlasPage.width  = int.Parse(array[0]);
                        atlasPage.height = int.Parse(array[1]);
                        ReadTuple(reader, array);
                    }
                    atlasPage.format = (Format)Enum.Parse(typeof(Format), array[0], ignoreCase: false);
                    ReadTuple(reader, array);
                    atlasPage.minFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), array[0], ignoreCase: false);
                    atlasPage.magFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), array[1], ignoreCase: false);
                    string a = ReadValue(reader);
                    atlasPage.uWrap = TextureWrap.ClampToEdge;
                    atlasPage.vWrap = TextureWrap.ClampToEdge;
                    if (a == "x")
                    {
                        atlasPage.uWrap = TextureWrap.Repeat;
                    }
                    else if (a == "y")
                    {
                        atlasPage.vWrap = TextureWrap.Repeat;
                    }
                    else if (a == "xy")
                    {
                        atlasPage.uWrap = (atlasPage.vWrap = TextureWrap.Repeat);
                    }
                    textureLoader.Load(atlasPage, Path.Combine(imagesDir, text));
                    pages.Add(atlasPage);
                    continue;
                }
                AtlasRegion atlasRegion = new AtlasRegion();
                atlasRegion.name   = text;
                atlasRegion.page   = atlasPage;
                atlasRegion.rotate = bool.Parse(ReadValue(reader));
                ReadTuple(reader, array);
                int num  = int.Parse(array[0]);
                int num2 = int.Parse(array[1]);
                ReadTuple(reader, array);
                int num3 = int.Parse(array[0]);
                int num4 = int.Parse(array[1]);
                atlasRegion.u = (float)num / (float)atlasPage.width;
                atlasRegion.v = (float)num2 / (float)atlasPage.height;
                if (atlasRegion.rotate)
                {
                    atlasRegion.u2 = (float)(num + num4) / (float)atlasPage.width;
                    atlasRegion.v2 = (float)(num2 + num3) / (float)atlasPage.height;
                }
                else
                {
                    atlasRegion.u2 = (float)(num + num3) / (float)atlasPage.width;
                    atlasRegion.v2 = (float)(num2 + num4) / (float)atlasPage.height;
                }
                atlasRegion.x      = num;
                atlasRegion.y      = num2;
                atlasRegion.width  = Math.Abs(num3);
                atlasRegion.height = Math.Abs(num4);
                if (ReadTuple(reader, array) == 4)
                {
                    atlasRegion.splits = new int[4]
                    {
                        int.Parse(array[0]),
                        int.Parse(array[1]),
                        int.Parse(array[2]),
                        int.Parse(array[3])
                    };
                    if (ReadTuple(reader, array) == 4)
                    {
                        atlasRegion.pads = new int[4]
                        {
                            int.Parse(array[0]),
                            int.Parse(array[1]),
                            int.Parse(array[2]),
                            int.Parse(array[3])
                        };
                        ReadTuple(reader, array);
                    }
                }
                atlasRegion.originalWidth  = int.Parse(array[0]);
                atlasRegion.originalHeight = int.Parse(array[1]);
                ReadTuple(reader, array);
                atlasRegion.offsetX = int.Parse(array[0]);
                atlasRegion.offsetY = int.Parse(array[1]);
                atlasRegion.index   = int.Parse(ReadValue(reader));
                regions.Add(atlasRegion);
            }
        }
Пример #27
0
 void _spAtlasPage_disposeTexture(AtlasPage self)
 {
     ((CCTextureAtlas)self.rendererObject).RemoveAllQuads();//Release(); // =============> ?
 }