Ejemplo n.º 1
0
    void CheckTextureSizeAndFormatAndThrow(ref int w, ref int h, ref int mm, ImportSettings_t settings, Texture2D channel, string channelName)
    {
        if (w == -1)
        {
            w = channel.width;
        }
        else if (w != channel.width)
        {
            ThrowAssetException(channel, channelName + " channel width mismatch.");
        }
        if (h == -1)
        {
            h = channel.height;
        }
        else if (h != channel.height)
        {
            ThrowAssetException(channel, channelName + " channel height mismatch.");
        }

        SetTextureImporterSettings(channel, settings);

        if (mm == -1)
        {
            mm = channel.mipmapCount;
        }
        else if (mm != channel.mipmapCount)
        {
            ThrowAssetException(channel, channelName + " channel mipmaps mismatch.");
        }
    }
Ejemplo n.º 2
0
    void SetTextureImporterSettings(Texture2D t, ImportSettings_t settings)
    {
        bool changed = false;

        {
            var s = t.GetImporterSettings();
            if (settings.Apply(s))
            {
                t.SetImporterSettings(s);
                changed = true;
            }
        }

        {
            var s = t.GetImporterPlatformSettings("Standalone");
            if (settings.Apply(s))
            {
                t.SetImporterPlatformSettings(s);
                changed = true;
            }
        }

        if (changed)
        {
            t.ReimportAsset();
        }
    }
Ejemplo n.º 3
0
    void CreateNormalsChannelTextureArray(WorldAtlas atlas, Func <WorldAtlasMaterialTextures, WorldAtlasMaterialTextures.TextureSet> f, string channelName)
    {
        List <Texture2D>  textures;
        List <TextureSet> indices;

        LoadTextureList(atlas, out textures, out indices, f, channelName);

        if (textures.Count < 1)
        {
            throw new Exception("No textures defined in atlas!");
        }

        var settings = new ImportSettings_t()
        {
            alphaSource         = TextureImporterAlphaSource.FromInput,
            alphaIsTransparency = false,
            aniso      = 16,
            filterMode = FilterMode.Trilinear,
            mipmap     = true,
            readable   = true,
            type       = TextureImporterType.NormalMap,
            format     = NORMALS_TEXTURE_FORMAT
        };

        CreateTextureArray(atlas, settings, textures, channelName);
    }
Ejemplo n.º 4
0
    void CreateTextureArray(WorldAtlas atlas, ImportSettings_t settings, List <Texture2D> textures, string channelName)
    {
        int w  = -1;
        int h  = -1;
        int mm = -1;

        for (int i = 0; i < textures.Count; ++i)
        {
            CheckTextureSizeAndFormatAndThrow(ref w, ref h, ref mm, settings, textures[i], channelName);
        }

        UncheckedCreateTextureArray(atlas, settings, textures, channelName);
    }
Ejemplo n.º 5
0
    void UncheckedCreateTextureArray(WorldAtlas atlas, ImportSettings_t settings, List <Texture2D> textures, string channelName)
    {
        var arr = new Texture2DArray(textures[0].width, textures[0].height, textures.Count, (TextureFormat)settings.format, true, false);

        arr.Apply(false, true);
        arr.wrapMode = TextureWrapMode.Repeat;

        for (int i = 0; i < textures.Count; ++i)
        {
            var t = textures[i];
            for (int mipNum = 0; mipNum < t.mipmapCount; ++mipNum)
            {
                Graphics.CopyTexture(t, 0, mipNum, arr, i, mipNum);
            }
        }

        SaveTextureArray(atlas, arr, channelName);
    }
Ejemplo n.º 6
0
    void CreateRHOTextureArray(WorldAtlas atlas)
    {
        var table = LoadRHOTextureTable(atlas);         // this sets the incoming texture formats to Alpha8

        if (table.textures.Count < 1)
        {
            throw new Exception("No textures defined in atlas!");
        }

        var textureList = new List <Texture2D>(table.textures.Count);

        foreach (var t in table.textures)
        {
            var joined = JoinTextures(table, t, RHO_TEXTURE_FORMAT);
            textureList.Add(joined);
        }

        var settings = new ImportSettings_t()
        {
            alphaSource         = TextureImporterAlphaSource.FromInput,
            alphaIsTransparency = false,
            aniso      = 16,
            filterMode = FilterMode.Trilinear,
            mipmap     = true,
            readable   = true,
            type       = TextureImporterType.Default,
            format     = RHO_TEXTURE_FORMAT
        };

        UncheckedCreateTextureArray(atlas, settings, textureList, "RHO");

        foreach (var t in textureList)
        {
            DestroyImmediate(t);
        }
    }
Ejemplo n.º 7
0
    RHOTextureTable LoadRHOTextureTable(WorldAtlas atlas)
    {
        var table = new RHOTextureTable();

        for (int i = 0; i < atlas.materials.Length; ++i)
        {
            var m = atlas.materials[i];

            if (m == null)
            {
                ThrowAssetException(atlas, "Material for terrain type '" + ((EVoxelBlockType)(i + 1)).ToString() + "' is not set!");
            }

            if (m.textures != null)
            {
                var set = new RHOTextureSet()
                {
                    roughness = m.textures.roughness,
                    height    = m.textures.height,
                    ao        = m.textures.ao
                };
                AddTextureSet(m, table, set);
            }
            else
            {
                ThrowAssetException(m, "Missing textures for atlas material.");
            }
        }

        int w  = -1;
        int h  = -1;
        int mm = -1;

        var settings = new ImportSettings_t()
        {
            alphaSource         = TextureImporterAlphaSource.FromGrayScale,
            alphaIsTransparency = false,
            aniso      = 16,
            filterMode = FilterMode.Trilinear,
            mipmap     = false,
            readable   = true,
            type       = TextureImporterType.Default,
            format     = TextureImporterFormat.Alpha8
        };

        foreach (var t in table.roughness)
        {
            CheckTextureSizeAndFormatAndThrow(ref w, ref h, ref mm, settings, t, "Roughness");
        }

        foreach (var t in table.height)
        {
            CheckTextureSizeAndFormatAndThrow(ref w, ref h, ref mm, settings, t, "Height");
        }

        foreach (var t in table.ao)
        {
            CheckTextureSizeAndFormatAndThrow(ref w, ref h, ref mm, settings, t, "AO");
        }

        return(table);
    }