Ejemplo n.º 1
0
    void GenerateInOneFrame()
    {
        Texture2D texture = new Texture2D(width, height);

        GetComponent <Renderer>().material.mainTexture = texture;

        ModuleBase     combinedTerrain = TerrainPresets.GetPreset(preset);
        SMappingRanges ranges          = new SMappingRanges();


        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                double p = (double)x / (double)width;
                double q = (double)y / (double)height;
                double nx, ny = 0.0;
                nx = ranges.mapx0 + p * (ranges.mapx1 - ranges.mapx0);
                ny = ranges.mapy0 + q * (ranges.mapy1 - ranges.mapy0);

                double val = combinedTerrain.Get(nx * 3, ny * 3);
                if (val == 0)
                {
                    texture.SetPixel(x, y, Color.black);
                }
                else
                {
                    texture.SetPixel(x, y, Color.white);
                }
            }
        }

        texture.Apply();
    }
Ejemplo n.º 2
0
    public TerrainPresets getTPR()
    {
        TerrainPresets outPut = new TerrainPresets();

        outPut = ConvertTPR(this);
        return(outPut);
    }
	IEnumerator GenerateStream(){
		Texture2D texture = new Texture2D(width,height);
		GetComponent<Renderer>().material.mainTexture = texture;

		ModuleBase combinedTerrain = TerrainPresets.GetPreset(preset);
		SMappingRanges ranges = new SMappingRanges();

		yield return null;

		for (int x = 0; x < width; x++){
			yield return null;

			for(int y = 0; y < height; y++){
				double p = (double)x / (double)width;
				double q = (double)y / (double)height;
				double nx, ny = 0.0;
				nx = ranges.mapx0 + p * (ranges.mapx1 - ranges.mapx0);
				ny = ranges.mapy0 + q * (ranges.mapy1 - ranges.mapy0);

				float val = (float) combinedTerrain.Get(nx * scale, ny * scale);
				texture.SetPixel(x,y,new Color(val,val,val));
			}
			texture.Apply();
		}		

	}
Ejemplo n.º 4
0
    public TerrainPresets ConvertTPR(TerrainType Source)
    {
        TerrainPresets outPut = new TerrainPresets
        {
            name   = Source.name,
            height = Source.height,
            r      = Source.color.r,
            g      = Source.color.g,
            b      = Source.color.b,
            a      = Source.color.a
        };

        return(outPut);
    }
Ejemplo n.º 5
0
    public void SaveTerrain(TerrainType[] savedPresets, string destpath)//saves the map to a given string location.
    {
        TerrainPresets[] presetsToSave = new TerrainPresets[savedPresets.Length];
        for (int i = 0; i < savedPresets.Length; i++)
        {
            presetsToSave[i] = savedPresets[i].getTPR();
        }

        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(destpath);

        bf.Serialize(file, presetsToSave);
        file.Close();
    }
    public static ModuleBase GetPreset(PresetType preset)
    {
        switch (preset)
        {
        case PresetType.mountains: return(TerrainPresets.Mountains());

        case PresetType.caves: return(TerrainPresets.Caves());

        case PresetType.cavesAndMountains: return(TerrainPresets.CavesAndMountains());

        case PresetType.fractal: return(TerrainPresets.FractalExample());
        }
        return(TerrainPresets.CavesAndMountains());
    }
Ejemplo n.º 7
0
    IEnumerator GenerateStream()
    {
        float scale = duplicateObj.transform.localScale.x;

        ModuleBase     combinedTerrain = TerrainPresets.GetPreset(preset);
        SMappingRanges ranges          = new SMappingRanges();


        Camera.main.transform.position = new Vector3(width / 2.0f * scale, height / 2.0f * scale, -15.0f);


        yield return(null);

        for (int x = 0; x < width; x++)
        {
            yield return(null);

            for (int y = 0; y < height; y++)
            {
                double p = (double)x / (double)width;
                double q = (double)y / (double)height;
                double nx, ny = 0.0;
                nx = ranges.mapx0 + p * (ranges.mapx1 - ranges.mapx0);
                ny = ranges.mapy0 + q * (ranges.mapy1 - ranges.mapy0);

                double val = combinedTerrain.Get(nx * 3, ny * 3);

                if (val > threshold)
                {
                    Vector3    pos = new Vector3(x, height - y, 0) * scale;
                    GameObject g   = GameObject.Instantiate(duplicateObj, pos, Quaternion.identity) as GameObject;
                    g.name = "cube-" + x + "-" + y;
                }
            }
        }
    }
Ejemplo n.º 8
0
    public TerrainType ConvertTPR(TerrainPresets Source)
    {
        TerrainType outPut = new TerrainType(Source);

        return(outPut);
    }
Ejemplo n.º 9
0
 public TerrainType(TerrainPresets sourcePresets)
 {
     name   = sourcePresets.name;
     height = sourcePresets.height;
     color  = new Color(sourcePresets.r, sourcePresets.g, sourcePresets.g, sourcePresets.a);
 }