Beispiel #1
0
        public static void UpdateSourceCache(TerrainCombinerSource source)
        {
            Terrain     targetTerrain     = source.GetComponent <Terrain>();
            TerrainData targetTerrainData = targetTerrain.terrainData;

            // TODO: reuse/scale textures ?
            // TODO: release?

            int size = targetTerrainData.heightmapResolution;

            source.CachedHeightmapTexture = TCGraphicsHelper.CreateTexture(size);
            TCGraphicsHelper.LoadTextureData(targetTerrainData.GetHeights(0, 0, size, size), ref source.CachedHeightmapTexture);
        }
Beispiel #2
0
        public override void OnInspectorGUI()
        {
            TerrainCombinerSource source = (TerrainCombinerSource)target;
            Terrain terrain = source.GetComponent <Terrain>();

            source.GroundLevelFraction = EditorGUILayout.FloatField("HeightDataGround", source.GroundLevelFraction);

            source.alphaMaterial = (Texture2D)EditorGUILayout.ObjectField("AlphaMaterial", source.alphaMaterial, typeof(Texture2D), false);                 // TODO find better name to alphamaterial

            if (GUILayout.Button("Calculate ground level"))
            {
                source.GroundLevelFraction = FindGroundLevel(terrain.terrainData);
            }

            source.CacheDirty = true;
        }
Beispiel #3
0
        public static void UpdateSourceCache(TerrainCombinerSource source)
        {
            TerrainData sourceTerrainData = source.GetComponent <Terrain>().terrainData;

            // TODO: reuse/scale textures ?
            // TODO: release?

            source.CachedMaterialTextures.Clear();

            int size = sourceTerrainData.alphamapResolution;

            float[,,] alphaMaps = sourceTerrainData.GetAlphamaps(0, 0, size, size);
            for (int layer = 0; layer < sourceTerrainData.alphamapLayers; layer++)
            {
                Texture2D texture = TCGraphicsHelper.CreateTexture(size);
                TCGraphicsHelper.LoadTextureData(alphaMaps, layer, ref texture);
                source.CachedMaterialTextures.Add(texture);
            }
        }
Beispiel #4
0
        private static void UpdateCaches(TerrainCombiner terrainCombiner)
        {
            // Update source caches
            for (int i = 0; i < terrainCombiner.Instances.Length; i++)
            {
                TerrainCombinerSource source = terrainCombiner.Instances[i].source;
                if (source != null && source.CacheDirty)
                {
                    TCHeightmapHelper.UpdateSourceCache(source);
                    TCMaterialHelper.UpdateSourceCache(source);

                    source.CacheDirty = false;
                }
            }

            // Update target caches
            if (terrainCombiner.CacheDirty)
            {
                TCHeightmapHelper.UpdateCombinerCache(terrainCombiner);
                TCMaterialHelper.UpdateCombinerCache(terrainCombiner);

                terrainCombiner.CacheDirty = false;
            }
        }