Exemple #1
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);
    }
Exemple #2
0
    Texture2DArray LoadTextureArray(WorldAtlas atlas, string channel)
    {
        var path = atlas.GetAssetFolderPath();

        path = path + "/TextureArrays/" + atlas.name + "_" + channel + "TextureArray.asset";
        return(AssetDatabase.LoadAssetAtPath <Texture2DArray>(path));
    }
Exemple #3
0
    void LoadTextureChannel(WorldAtlas atlas, TextureBundle[] bundles, Func <WorldAtlasMaterialTextures, WorldAtlasMaterialTextures.TextureSet> getTexSetChannel, Func <TextureBundle, TextureSet, TextureBundle> setBundleChannel, string channelName)
    {
        List <Texture2D>  textures;
        List <TextureSet> indices;

        LoadTextureList(atlas, out textures, out indices, getTexSetChannel, channelName);
        TextureBundle.CopyChannelTextureSet(bundles, indices, setBundleChannel);
    }
Exemple #4
0
 void LoadTerrainTextures(WorldAtlas atlas, WorldAtlasClientData clientData)
 {
     LoadTextureArrayChannel(atlas, clientData, (cd, arr) => cd.albedo.textureArray  = arr, "Albedo");
     LoadTextureArrayChannel(atlas, clientData, (cd, arr) => cd.normals.textureArray = arr, "Normals");
     //LoadTextureArrayChannel(atlas, clientData, (cd, arr) => cd.roughness.textureArray = arr, "Roughness");
     //LoadTextureArrayChannel(atlas, clientData, (cd, arr) => cd.ao.textureArray = arr, "AO");
     //LoadTextureArrayChannel(atlas, clientData, (cd, arr) => cd.height.textureArray = arr, "Height");
     LoadTextureArrayChannel(atlas, clientData, (cd, arr) => cd.rho.textureArray = arr, "RHO");
 }
Exemple #5
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);
    }
Exemple #6
0
    void LoadTextureArrayChannel(WorldAtlas atlas, WorldAtlasClientData clientData, Action <WorldAtlasClientData, Texture2DArray> set, string channelName)
    {
        var arr = LoadTextureArray(atlas, channelName);

        if (arr == null)
        {
            RebuildTextureArray();
            arr = LoadTextureArray(atlas, channelName);
            if (arr == null)
            {
                ThrowAssetException(atlas, "Unable to load " + channelName + " texture array!");
            }
        }
        set(clientData, arr);
    }
Exemple #7
0
    void SaveTextureArray(WorldAtlas atlas, Texture2DArray array, string channel)
    {
        var folder   = atlas.GetAssetFolderPath();
        var path     = folder + "/TextureArrays/" + atlas.name + "_" + channel + "TextureArray.asset";
        var existing = AssetDatabase.LoadAssetAtPath <Texture2DArray>(path);

        if (existing != null)
        {
            EditorUtility.CopySerialized(array, existing);
            EditorUtility.SetDirty(existing);
        }
        else
        {
            Utils.CreateAssetFolder(folder, "TextureArrays");
            AssetDatabase.CreateAsset(array, path);
        }
    }
Exemple #8
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);
    }
Exemple #9
0
    WorldAtlasClientData SaveAtlasClientData(WorldAtlas atlas, WorldAtlasClientData clientData)
    {
        var folder   = atlas.GetAssetFolderPath();
        var path     = folder + "/Resources/" + atlas.name + "_AtlasClientData.asset";
        var existing = AssetDatabase.LoadAssetAtPath <WorldAtlasClientData>(path);

        if (existing != null)
        {
            EditorUtility.CopySerialized(clientData, existing);
            EditorUtility.SetDirty(existing);
            clientData = existing;
        }
        else
        {
            Utils.CreateAssetFolder(folder, "Resources");
            AssetDatabase.CreateAsset(clientData, path);
            clientData = AssetDatabase.LoadAssetAtPath <WorldAtlasClientData>(path);
        }
        return(clientData);
    }
Exemple #10
0
    WorldAtlasData SaveAtlasData(WorldAtlas atlas, WorldAtlasData atlasData)
    {
        var path = atlas.GetAssetFolderPath();

        path = path + "/" + atlas.name + "_AtlasData.asset";
        var existing = AssetDatabase.LoadAssetAtPath <WorldAtlasData>(path);

        if (existing != null)
        {
            EditorUtility.CopySerialized(atlasData, existing);
            EditorUtility.SetDirty(existing);
            atlasData = existing;
        }
        else
        {
            AssetDatabase.CreateAsset(atlasData, path);
            atlasData = AssetDatabase.LoadAssetAtPath <WorldAtlasData>(path);
        }
        return(atlasData);
    }
Exemple #11
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);
        }
    }
Exemple #12
0
    void LoadTextureList(WorldAtlas atlas, out List <Texture2D> arr, out List <TextureSet> indices, Func <WorldAtlasMaterialTextures, WorldAtlasMaterialTextures.TextureSet> f, string channelName)
    {
        arr     = new List <Texture2D>();
        indices = new List <TextureSet>();

        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)
            {
                AddTextureSet(m, arr, indices, f(m.textures), channelName);
            }
            else
            {
                ThrowAssetException(m, "Missing textures for atlas material.");
            }
        }
    }
Exemple #13
0
    void LoadRHOTextureChannel(WorldAtlas atlas, TextureBundle[] bundles, WorldAtlasClientData clientData)
    {
        var table = LoadRHOTextureTable(atlas);

        TextureBundle.CopyChannelTextureSet(bundles, table.indices, (b, s) => { b.rho = s; return(b); });
    }
Exemple #14
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);
    }
Exemple #15
0
 // Use this for initialization
 void Start()
 {
     current = this;
     GenerateDebugData();
 }
Exemple #16
0
    private bool CheckWorldDataUpToDate(WorldData worldData)
    {
        WorldData.VersionData versionData = worldData.VersionDatas;
        if (worldData.VersionDatas == null)
        {
            versionData         = new WorldData.VersionData();
            versionData.Version = 0;
        }
        IGameService    service             = Amplitude.Unity.Framework.Services.GetService <IGameService>();
        global::Game    game                = service.Game as global::Game;
        WorldAtlas      atlas               = game.World.Atlas;
        GridMap <byte>  gridMap             = atlas.GetMap(WorldAtlas.Maps.Anomalies) as GridMap <byte>;
        GridMap <byte>  gridMap2            = atlas.GetMap(WorldAtlas.Maps.Terrain) as GridMap <byte>;
        GridMap <sbyte> gridMap3            = atlas.GetMap(WorldAtlas.Maps.Height) as GridMap <sbyte>;
        Map <PointOfInterestDefinition> map = atlas.GetMap(WorldAtlas.Tables.PointOfInterestDefinitions) as Map <PointOfInterestDefinition>;
        Map <WorldRiver> map2               = atlas.GetMap(WorldAtlas.Tables.Rivers) as Map <WorldRiver>;
        int            num      = 0;
        GridMap <bool> gridMap4 = atlas.GetMap(WorldAtlas.Maps.Ridges) as GridMap <bool>;

        if (gridMap4 != null)
        {
            num = gridMap4.Version;
        }
        if (versionData.Version != WorldData.VersionData.CurrentVersion)
        {
            Diagnostics.Log("Geometry is not uptodate : {0} : {1}, current version = {2}", new object[]
            {
                "Version",
                versionData.Version,
                WorldData.VersionData.CurrentVersion
            });
            return(false);
        }
        if (versionData.TerrainTypeVersion != gridMap2.Version)
        {
            Diagnostics.Log("Geometry is not uptodate : {0} = {1}, atlas version = {2}", new object[]
            {
                "TerrainTypeVersion",
                versionData.TerrainTypeVersion,
                gridMap2.Version
            });
            return(false);
        }
        if (versionData.AnomalyVersion != gridMap.Version)
        {
            Diagnostics.Log("Geometry is not uptodate : {0} = {1}, atlas version = {2}", new object[]
            {
                "AnomalyVersion",
                versionData.AnomalyVersion,
                gridMap.Version
            });
            return(false);
        }
        if (versionData.TerrainHeightVersion != gridMap3.Version)
        {
            Diagnostics.Log("Geometry is not uptodate : {0} = {1}, atlas version = {2}", new object[]
            {
                "TerrainHeightVersion",
                versionData.TerrainHeightVersion,
                gridMap3.Version
            });
            return(false);
        }
        if (versionData.POIVersion != map.Version)
        {
            Diagnostics.Log("Geometry is not uptodate : {0} = {1}, atlas version = {2}", new object[]
            {
                "POIVersion",
                versionData.POIVersion,
                map.Version
            });
            return(false);
        }
        if (versionData.RidgeVersion != num && versionData.RidgeVersion > 0)
        {
            Diagnostics.Log("Geometry is not uptodate : {0} = {1}, atlas version = {2}", new object[]
            {
                "RidgeVersion",
                versionData.RidgeVersion,
                num
            });
            return(false);
        }
        if (versionData.RiverVersion != map2.Version)
        {
            Diagnostics.Log("Geometry is not uptodate : {0} = {1}, atlas version = {2}", new object[]
            {
                "RiverVersion",
                versionData.RiverVersion,
                map2.Version
            });
            return(false);
        }
        return(true);
    }
 // Use this for initialization
 void Start()
 {
     DontDestroyOnLoad(transform.parent.gameObject);
     cg.alpha = 0;
     WorldAtlas.RegisterSceneListener(this);
 }