Example #1
0
        public TextureBlock(TexturedMesh texturedmesh)

        {
            Texturename = texturedmesh.TextureName;
            texture     = texturedmesh.texture;
            width       = texturedmesh.texture.width;
            height      = texturedmesh.texture.height;
            pixels      = texturedmesh.texture.GetPixels(0, 0, width, height);

            meshes = new List <Mesh>();
            meshes.Add(texturedmesh.mesh);
        }
Example #2
0
        private static TexturedMesh createTexturedMesh(List <Shelf> shelfs)
        {
            int size        = 2048;
            int totalheight = 0;

            foreach (Shelf shelf in shelfs)
            {
                totalheight += shelf.height;
            }
            Texture2D TotaalTexture = new Texture2D(size, totalheight, TextureFormat.RGBA32, false);
            int       baseheight    = 0;

            List <CombineInstance> submeshes = new List <CombineInstance>();

            //create the combined texture
            foreach (Shelf shelf in shelfs)
            {
                Color[] shelfpixels = shelf.ShelfTexture.GetPixels(0, 0, size, shelf.height, 0);
                TotaalTexture.SetPixels(0, baseheight, size, shelf.height, shelfpixels, 0);
                TotaalTexture.Apply(true);
                shelf.baseheight = baseheight;
                baseheight      += shelf.height;
            }
            foreach (Shelf shelf in shelfs)
            {
                List <CombineInstance> shelfmeshes = shelf.ReturnMeshes(baseheight);
                foreach (CombineInstance item in shelfmeshes)
                {
                    submeshes.Add(item);
                }
            }
            TexturedMesh output    = new TexturedMesh();
            Mesh         totalMesh = new Mesh();

            totalMesh.CombineMeshes(submeshes.ToArray(), true, false);
            foreach (var meshHolder in submeshes)
            {
                Destroy(meshHolder.mesh);
            }
            output.mesh    = totalMesh;
            output.texture = TotaalTexture;

            return(output);
        }
Example #3
0
        public static TexturedMesh CombineMeshes(List <TexturedMesh> Texturedmeshes)
        {
            double totalArea = 0;
            double widest    = 0;
            double highest   = 0;

            foreach (TexturedMesh item in Texturedmeshes)
            {
                totalArea += item.texture.width * item.texture.height;
                if (item.texture.width > widest)
                {
                    widest = item.texture.width;
                }
                if (item.texture.height > highest)
                {
                    highest = item.texture.height;
                }
            }
            int size = GetMinimumSize(totalArea, widest, highest);

            if (size == (int)totalArea)
            {
                Debug.Log("afbeeldingen te groot"); return(null);
            }


            List <TextureBlock> TextureBlocks = new List <TextureBlock>();

            // add meshes to textureblocks
            foreach (TexturedMesh item in Texturedmeshes)
            {
                bool placed = false;
                foreach (TextureBlock tb in TextureBlocks)
                {
                    if (tb.Texturename == item.TextureName)
                    {
                        tb.meshes.Add(item.mesh);
                        placed = true;
                    }
                }

                if (placed == false)
                {
                    TextureBlocks.Add(new TextureBlock(item));
                }
            }

            TextureBlocks = SortTextures(TextureBlocks);

            List <Shelf> shelfs = new List <Shelf>();

            shelfs.Add(new Shelf(size));

            bool blockplaced = false;

            foreach (TextureBlock texblock in TextureBlocks)
            {
                foreach (Shelf shelf in shelfs)
                {
                    blockplaced = false;
                    blockplaced = shelf.AddTexture(texblock);
                }
                if (blockplaced == false)
                {
                    Shelf shelf = new Shelf(size);
                    shelf.AddTexture(texblock);
                    shelfs.Add(shelf);
                }
            }
            int totalheight = 0;

            foreach (Shelf shelf in shelfs)
            {
                totalheight += shelf.height;
            }
            Texture2D TotaalTexture = new Texture2D(size, totalheight);
            int       baseheight    = 0;

            List <CombineInstance> submeshes = new List <CombineInstance>();

            //create the combined texture
            foreach (Shelf shelf in shelfs)
            {
                Color[] shelfpixels = shelf.ShelfTexture.GetPixels(0, 0, size, shelf.height, 0);
                TotaalTexture.SetPixels(0, baseheight, size, shelf.height, shelfpixels, 0);
                TotaalTexture.Apply(true);
                shelf.baseheight = baseheight;
                baseheight      += shelf.height;
            }
            foreach (Shelf shelf in shelfs)
            {
                List <CombineInstance> shelfmeshes = shelf.ReturnMeshes(baseheight);
                foreach (CombineInstance item in shelfmeshes)
                {
                    submeshes.Add(item);
                }
            }
            TexturedMesh output    = new TexturedMesh();
            Mesh         totalMesh = new Mesh();

            totalMesh.CombineMeshes(submeshes.ToArray(), true, false);
            foreach (var meshHolder in submeshes)
            {
                Destroy(meshHolder.mesh);
            }
            output.mesh    = totalMesh;
            output.texture = TotaalTexture;

            return(output);
        }