Exemplo n.º 1
0
            private static DisposableDictionary <PackingType, WorkingTexture> CreateDefaultTextures()
            {
                DisposableDictionary <PackingType, WorkingTexture> textures = new DisposableDictionary <PackingType, WorkingTexture>();

                textures.Add(PackingType.White, CreateEmptyTexture(4, 4, Color.white, false));
                textures.Add(PackingType.Black, CreateEmptyTexture(4, 4, Color.black, false));
                textures.Add(PackingType.Normal, CreateEmptyTexture(4, 4, new Color(0.5f, 0.5f, 1.0f), true));

                return(textures);
            }
Exemplo n.º 2
0
            private void AddToCache(WorkingMaterial material)
            {
                string         inputName = m_textureInfoList[0].InputName;
                WorkingTexture texture   = material.GetTexture(inputName);

                if (texture == null)
                {
                    texture = m_defaultTextures[m_textureInfoList[0].Type];
                }

                TexturePacker.MaterialTexture materialTexture = new TexturePacker.MaterialTexture();

                if (m_enableTintColor)
                {
                    Color tintColor = material.GetColor(m_tintColorName);

                    texture = texture.Clone();
                    ApplyTintColor(texture, tintColor);
                    materialTexture.Add(texture);
                    texture.Dispose();
                }
                else
                {
                    materialTexture.Add(texture);
                }


                for (int ti = 1; ti < m_textureInfoList.Count; ++ti)
                {
                    string         input = m_textureInfoList[ti].InputName;
                    WorkingTexture tex   = material.GetTexture(input);

                    if (tex == null)
                    {
                        tex = m_defaultTextures[m_textureInfoList[ti].Type];
                    }

                    materialTexture.Add(tex);
                }

                m_textureCache.Add(material.Guid, materialTexture);
            }
Exemplo n.º 3
0
        private void PackingTexture(TexturePacker packer, DisposableList <HLODBuildInfo> targets, dynamic options, Action <float> onProgress)
        {
            List <TextureInfo> textureInfoList = options.TextureInfoList;

            using (MaterialTextureCache cache = new MaterialTextureCache(options))
            {
                for (int i = 0; i < targets.Count; ++i)
                {
                    var workingObjects = targets[i].WorkingObjects;
                    Dictionary <Guid, TexturePacker.MaterialTexture> textures =
                        new Dictionary <Guid, TexturePacker.MaterialTexture>();

                    for (int oi = 0; oi < workingObjects.Count; ++oi)
                    {
                        var materials = workingObjects[oi].Materials;

                        for (int m = 0; m < materials.Count; ++m)
                        {
                            var materialTextures = cache.GetMaterialTextures(materials[m]);
                            if (materialTextures == null)
                            {
                                continue;
                            }

                            if (textures.ContainsKey(materialTextures[0].GetGUID()) == true)
                            {
                                continue;
                            }

                            textures.Add(materialTextures[0].GetGUID(), materialTextures);
                        }
                    }


                    packer.AddTextureGroup(targets[i], textures.Values.ToList());


                    if (onProgress != null)
                    {
                        onProgress(((float)i / targets.Count) * 0.1f);
                    }
                }
            }

            packer.Pack(TextureFormat.RGBA32, options.PackTextureSize, options.LimitTextureSize, false);
            if (onProgress != null)
            {
                onProgress(0.3f);
            }

            int index   = 1;
            var atlases = packer.GetAllAtlases();

            foreach (var atlas in atlases)
            {
                Dictionary <string, WorkingTexture> textures = new Dictionary <string, WorkingTexture>();
                for (int i = 0; i < atlas.Textures.Count; ++i)
                {
                    WorkingTexture wt = atlas.Textures[i];
                    wt.Name = "CombinedTexture " + index + "_" + i;
                    if (textureInfoList[i].Type == PackingType.Normal)
                    {
                        wt.Linear = true;
                    }

                    textures.Add(textureInfoList[i].OutputName, wt);
                }

                WorkingMaterial mat = CreateMaterial(options.MaterialGUID, textures);
                mat.Name = "CombinedMaterial " + index;
                m_createdMaterials.Add(atlas, mat);
                index += 1;
            }
        }