Example #1
0
 public static void Serialize(this SerializingContainer2 sc, ref AlphaMap map)
 {
     if (sc.IsLoading)
     {
         map = new AlphaMap();
     }
     sc.Serialize(ref map.Data, Serialize);
 }
Example #2
0
    private static void Restore()
    {
        if (!HasValidTerrain())
        {
            return;
        }

        Debug.Log("Script reload detected. Attempting to restore texture data...");

        string path = Path.Combine(Application.dataPath, "splat.bytes");

        if (File.Exists(path))
        {
            TerrainMap <byte> byteMap = new TerrainMap <byte>(File.ReadAllBytes(path), 8);
            Splat = new SplatMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Splat Maps");
        }

        path = Path.Combine(Application.dataPath, "biome.bytes");
        if (File.Exists(path))
        {
            TerrainMap <byte> byteMap = new TerrainMap <byte>(File.ReadAllBytes(path), 4);
            Biome = new BiomeMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Biome Maps");
        }

        path = Path.Combine(Application.dataPath, "alpha.bytes");
        if (File.Exists(path))
        {
            TerrainMap <byte> byteMap = new TerrainMap <byte>(File.ReadAllBytes(path), 1);
            Alpha = new AlphaMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Alpha Maps");
        }

        path = Path.Combine(Application.dataPath, "topology.bytes");
        if (File.Exists(path))
        {
            TerrainMap <int> byteMap = new TerrainMap <int>(File.ReadAllBytes(path), 1);
            Topology = new TopologyMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Topology Maps");
        }

        path = Path.Combine(Application.dataPath, "water.bytes");
        if (File.Exists(path))
        {
            TerrainMap <short> byteMap = new TerrainMap <short>(File.ReadAllBytes(path), 1);
            Water = new WaterMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Water Maps");
        }
    }
Example #3
0
    public static AlphaMap Load(Sprite sprite)
    {
        cache = cache ?? new Dictionary<string, AlphaMap>();

        if (cache.ContainsKey(sprite.name))
            return cache[sprite.name];

        var map = new AlphaMap(sprite);
        cache.Add(sprite.name, map);
        return map;
    }
    public void createTerrainObject()
    {
        this.BaseTerrainObj = new GameObject("TerrainIsle");
        this.BaseTerrainObj.transform.parent   = terr.transform;
        terr.BaseTerrainData.baseMapResolution = 1024;
        int baseResolution = (int)Math.Pow(2, 8 + terr.terrainScalingFactor) + 1;

        terr.BaseTerrainData.SetDetailResolution(baseResolution, 16);
        terr.BaseTerrainData.heightmapResolution = baseResolution;
        terr.BaseTerrainData.alphamapResolution  = baseResolution;

        terr.BaseTerrainData.size = new Vector3(baseResolution, 600, baseResolution);

        this.BaseTerrainCollider             = this.BaseTerrainObj.AddComponent <TerrainCollider>();
        this.BaseTerrainCollider.terrainData = terr.BaseTerrainData;

        this.terrain             = BaseTerrainObj.AddComponent <Terrain>();
        this.terrain.terrainData = terr.BaseTerrainData;

        // get the terrain component
        //this.terrain = BaseTerrain;

        // get the generated standard data
        this.tData = terrain.terrainData;

        // get the terrain resolution
        this.xTerrainRes        = tData.heightmapWidth;
        this.yTerrainRes        = tData.heightmapHeight;
        this.terrainWidthScale  = tData.size.x;
        this.terrainLengthScale = tData.size.z;
        this.terrainHeightScale = tData.size.y;

        // transform terrain to middle point of global coordinates system
        this.terrain.transform.position = new Vector3(-terrainWidthScale / 2, 0, -terrainLengthScale / 2);

        // get the texture resolution
        this.xTextureRes = tData.alphamapWidth;
        this.yTextureRes = tData.alphamapHeight;

        this.alphaMap   = new AlphaMap(new float[this.xTextureRes, this.yTextureRes, 6]);
        this.biomeMap   = new int[this.xTextureRes, this.yTextureRes];
        this.MountMap   = new MountMap(this);
        this.DetailsMap = new DetailsMap(this);
        this.TreeMap    = new TreeMap(this);


        tData.SetAlphamaps(0, 0, this.alphaMap.aMap);
        tData.SetDetailLayer(0, 0, 0, this.DetailsMap.dMap);
        tData.SetHeights(0, 0, this.MountMap.heightMap);
        tData.treeInstances = new List <TreeInstance>().ToArray();

        //print("Width: " + xTerrainRes + " / " + xTextureRes + " / " + terrainWidthScale + " / " + tData.alphamapResolution);
        //print("Length: " + yTerrainRes + " / " + yTextureRes + " / " + terrainLengthScale + " / " + tData.detailResolution);
    }
Example #5
0
    void Start()
    {
        image = GetComponent<Image>();
        CanvasScaler scaler;
        Transform p = transform;
        do {
            p = p.parent;
            scaler = p.GetComponent<CanvasScaler>();
        } while(scaler == null);

        canvas = scaler.GetComponent<Canvas>();
        canvasWidth = (int)scaler.referenceResolution.x;
        canvasHeight = (int)scaler.referenceResolution.y;

        alphaMap = AlphaMap.Load(image.sprite);
    }
	public void generate(AlphaMap alphaMap, GraphVoronoi graphVoronoi){

		int alphaMapSize = alphaMap.mapSize;
		int heightMapSize = 512;

		float ratio = (float)heightMapSize / alphaMapSize;
			
			
		for(int x = 0; x < alphaMapSize; x++) 
		{
			for (int y = 0; y < alphaMapSize; y++) 
			{
				
				Center.BiomeTypes biome = graphVoronoi.getNearestCenter((int)(ratio* x), (int)(ratio*y)).biome;

				alphaMap.setAlpha(x,y,(int)biome);
			}
		}

		alphaMap.fillSplitMap ();
			
	}
Example #7
0
    public IEnumerator Load(World.Data world)
    {
        ActionProgressBar.UpdateProgress("Loading Terrain", 0f);
        yield return(null);

        yield return(null);

        Splat    = new SplatMap(world.splatMap);
        Alpha    = new AlphaMap(world.alphaMap);
        Biome    = new BiomeMap(world.biomeMap);
        Topology = new TopologyMap(world.topologyMap);
        Water    = new WaterMap(world.waterMap);

        TerrainData terrainData = new TerrainData();

        terrainData.alphamapResolution  = Mathf.Clamp(Mathf.NextPowerOfTwo((int)(world.size.x * 0.50f)), 16, 2048);
        terrainData.baseMapResolution   = Mathf.NextPowerOfTwo((int)((float)(world.size.x) * 0.01f));
        terrainData.heightmapResolution = Mathf.NextPowerOfTwo((int)((float)(world.size.x) * 0.5f)) + 1;

        terrainData.size = world.size;

        terrainData.SetHeights(0, 0, world.landHeightMap);

        Terrain = Terrain.CreateTerrainGameObject(terrainData).GetComponent <Terrain>();

        Terrain.name = Terrain.tag = "Terrain";

        Terrain.gameObject.layer = 8;

        Terrain.transform.position = -0.5f * terrainData.size;

        Terrain.gameObject.AddComponent <PositionLock>();

        SetSplatMaps(PaintType.Splat);

        CreateWaterPlane(world.size.x);
    }
	private void fillAlphaMap(){
		Debug.Log (textures.Length);
		p_alphaMap = new AlphaMap (alphaMapSize, textures.Length);
		p_alphaMap.terrainSize = p_terrainSize;
		
		AlphaMapGeneratorBiomes alphaMapGenerator = new AlphaMapGeneratorBiomes ();
		
		alphaMapGenerator.generate (p_alphaMap, p_graphVoronoi);

		p_terrain.terrainData.SetAlphamaps (0, 0, p_alphaMap.splitMap); 	
		
	}
Example #9
0
 private unsafe void Construct()
 {
     Map = new AlphaMap(this);
 }