private void Start() { IPackImage[] imgs = new IPackImage[_textures.Length]; for (int i = 0; i < _textures.Length; i++) { imgs[i] = new PackImage(_textures[i]); } // Create dummy images. // // int min = 10; // int max = 50; // int count = 955; // IPackImage[] imgs = new IPackImage[count]; // for (int i = 0; i < imgs.Length; i++) // { // imgs[i] = new DummyPackImage(Random.Range(min, max), Random.Range(min, max), Random.ColorHSV()); // }; _packer = new Packer(_material); _packerService = new PackService(_packer); _infos = _packerService.PackImages(imgs); // Show a packed texture as preview. _tex = _packerService.GetPackedImage(); _targetMaterial = _target.GetComponent <Renderer>().material; _targetMaterial.mainTexture = _tex; ShowTex(0); }
private bool CheckFitPerfectly(IPackImage image) { bool isSameBoth = (image.Width == Rectangle.width) && (image.Height == Rectangle.height); return(isSameBoth); }
private bool CheckFitInRect(IPackImage image) { bool isInRect = (image.Width <= Rectangle.width) && (image.Height <= Rectangle.height); return(isInRect); }
private void Pack(IPackImage image, Rect rect) { Vector4 scaleAndOffset = GetScaleAndOffset(rect); _material.SetVector("_ScaleAndOffset", scaleAndOffset); _material.SetTexture("_PackTex", image.Texture); Graphics.Blit(_current, _next, _material); SwapBuffer(); }
public Node Insert(IPackImage image) { if (!_isLeafNode) { Node newNode = Child[0].Insert(image); if (newNode != null) { return(newNode); } return(Child[1].Insert(image)); } else { if (_imageID != -1) { return(null); } if (!CheckFitInRect(image)) { return(null); } if (CheckFitPerfectly(image)) { return(this); } _isLeafNode = false; Child[0] = new Node(); Child[1] = new Node(); float dw = Rectangle.width - image.Width; float dh = Rectangle.height - image.Height; if (dw > dh) { Child[0].Rectangle = new Rect(Rectangle.x, Rectangle.y, image.Width, Rectangle.height); Child[1].Rectangle = new Rect(Rectangle.x + image.Width + 1, Rectangle.y, Rectangle.width - image.Width - 1, Rectangle.height); } else { Child[0].Rectangle = new Rect(Rectangle.x, Rectangle.y, Rectangle.width, image.Height); Child[1].Rectangle = new Rect(Rectangle.x, Rectangle.y + image.Height + 1, Rectangle.width, Rectangle.height - image.Height - 1); } return(Child[0].Insert(image)); } }
private bool TryPack(IPackImage image, out PackedInfo info) { Node node = _rootNode.Insert(image); if (node == null) { info = null; return(false); } int imageID = _count++; node.SetImageID(imageID); info = new PackedInfo(imageID, node.Rectangle); return(true); }