Пример #1
0
	void GenerateWater () {
		// setting up the gameobject
		g_water = Instantiate (spherePrefabToUse) as GameObject;
		g_water.name = "Water";
		g_water.transform.parent = g_parent.transform;
		g_water.transform.localScale = Vector3.one;
		g_water.transform.rotation = Random.rotation;

		// rotation
		_WorldRotate wr =  g_water.AddComponent <_WorldRotate> ();
		wr.r = Vector3.up * 1.5f + Vector3.right * 0.5f;

		// setting up mesh
		Mesh m = g_water.GetComponent<MeshFilter> ().mesh;
		int points = m.vertexCount;

		// setting up vertices
		List<Vector3> vs = new List<Vector3>();
		foreach (Vector3 v in m.vertices) {
			vs.Add(v * 100); // multiplying by 100 for scale
		}
		//noise offset
		for (int i = 0; i < points; i++) {
			vs[i] += Perlin3D(vs[i])*0.15f;
			vs[i] = Vector3.Normalize(vs[i]) * 1.0f;
		}
		// final vertices set
		m.SetVertices (vs);
		m.RecalculateNormals ();

		// setting material
		g_water.GetComponent<Renderer> ().material = SeaMat;
	}
Пример #2
0
	void GenerateLand () {
		// setting up the gameobject
		g_land = Instantiate (spherePrefabToUse) as GameObject;
		g_land.name = "Land";
		g_land.transform.parent = g_parent.transform;
		g_land.transform.localScale = Vector3.one;
		g_land.transform.eulerAngles = Vector3.zero;

		// rotation
		_WorldRotate wr =  g_land.AddComponent <_WorldRotate> ();
		wr.r = Vector3.up * 2f;

		// setting up mesh
		Mesh m = g_land.GetComponent<MeshFilter> ().mesh;
		int points = m.vertexCount;

		// setting up vertices
		List<Vector3> vs = new List<Vector3>();
		foreach (Vector3 v in m.vertices) {
			vs.Add(v * 100); // multiplying by 100 for scale
		}
		//noise offset
		for (int i = 0; i < points; i++) {
			vs[i] += Perlin3D(vs[i])*0.15f;
		}
		// final vertices set
		m.SetVertices (vs);
		m.RecalculateNormals ();

		// setting material
		g_land.GetComponent<Renderer> ().material = LandMat;
	}
Пример #3
0
    void GenerateMoons()
    {
        g_moons = new GameObject("Moons");
        g_moons.transform.parent = g_parent.transform;
        int moonsAmt = Random.Range(0, 7);

        moonScale = moonsAmt <= 2 ? 0.2f : moonsAmt <= 4 ? 0.1f : 0.05f;
        Material[] ms = moonsAmt <= 2 ? MoonMatSet1 : moonsAmt <= 4 ? MoonMatSet2 : MoonMatSet3;
        for (int i = 0; i < moonsAmt; i++)
        {
            GameObject mp = new GameObject("moonRotator");
            mp.transform.parent = g_moons.transform;
            _WorldRotate wr = mp.AddComponent <_WorldRotate> ();
            wr.r = Vector3.up * (Random.value - 0.5f) * 20 + Vector3.right * (Random.value - 0.5f) * 2;
            GameObject m = Instantiate(moons_prefabs [Random.Range(0, moons_prefabs.Length)]);
            m.transform.localScale = Vector3.one * moonScale * 100;
            m.transform.parent     = mp.transform;
            m.transform.rotation   = Random.rotation;
            m.transform.Translate(Vector3.forward * Random.Range(1.5f, 2f));
            m.transform.rotation = Random.rotation;
            m.GetComponent <Renderer> ().material = ms [Random.Range(0, ms.Length)];
            wr   = m.AddComponent <_WorldRotate> ();
            wr.r = Vector3.up * (Random.value - 0.5f) * 20 + Vector3.right * (Random.value - 0.5f) * 2;

            moonsPlaceholders.Add(m.transform);
        }
    }
Пример #4
0
	void GenerateClouds() {
		// setting up the gameobject
		//g_clouds = Instantiate (spherePrefabToUse) as GameObject;
		g_clouds = Instantiate (spherePrefabs[scale+1]) as GameObject;
		g_clouds.name = "Clouds";
		g_clouds.transform.parent = g_parent.transform;
		g_clouds.transform.localScale = Vector3.one;
		g_clouds.transform.rotation = Random.rotation;

		// rotation
		_WorldRotate wr =  g_clouds.AddComponent <_WorldRotate> ();
		wr.r = Vector3.up * -3f + Vector3.right * -2f;

		// setting up mesh
		Mesh m = g_clouds.GetComponent<MeshFilter> ().mesh;
		int points = m.vertexCount;
		int tris = m.triangles.Length / 3;
		int[] triarray = m.triangles;

		// setting up vertices
		List<Vector3> vs = new List<Vector3>();
		float cloudSize = 1.3f - 0.1f * scale;
		foreach (Vector3 v in m.vertices) {
			vs.Add(v * 100 * cloudSize); // multiplying by 100 for scale
		}
		// add them a second time for two sided
		foreach (Vector3 v in m.vertices) {
			vs.Add(v * 100 * cloudSize); 
		}

		// setting up triangles. going through noise to get cloud density
		List<int> ts = new List<int> ();
		float cloudsRatio = 0.25f;
		for (int i = 0; i < tris; i++) {
			Vector3 refPoint = vs [triarray [i * 3]];
			refPoint = Vector3.Scale(refPoint, new Vector3 (1, 2, 1));
			refPoint = (Perlin3D (refPoint) + Vector3.one) * 0.5f;
			if (refPoint.y < cloudsRatio) {
				ts.Add (triarray [i * 3]);
				ts.Add (triarray [i * 3]+1);
				ts.Add (triarray [i * 3]+2);
				ts.Add (triarray [i * 3] + points);
				ts.Add (triarray [i * 3]+2 + points);
				ts.Add (triarray [i * 3]+1 + points);
			}
		}

		// final vertices set
		m.SetVertices (vs);
		m.SetTriangles (ts, 0);
		m.RecalculateNormals ();

		// setting material
		g_clouds.GetComponent<Renderer> ().material = CloudMat;
	}
Пример #5
0
	void RandomizeRingBits(){
		g_rBits.transform.eulerAngles = Vector3.right * Random.value * 30f;
		_WorldRotate wr = g_rBits.AddComponent<_WorldRotate> ();
		wr.r = Vector3.up * 1.2f + Vector3.right * -0.5f;
		foreach (Transform b in ringBits) {
			b.localScale = Vector3.zero;
			b.rotation = Random.rotation;
			b.position += b.forward * (Random.value * 2 - 1) * 2;
			_WorldRotate wr2 = b.gameObject.AddComponent<_WorldRotate> ();
			wr2.r = Random.rotation.eulerAngles * 0.05f;
			b.gameObject.GetComponent<Renderer> ().material = MoonMatSet1 [Random.Range (0, MoonMatSet1.Length)];
		}
	}
Пример #6
0
	void RandomizePlanetBits(){
		g_pBits.transform.rotation = Random.rotation;
		_WorldRotate wr = g_pBits.AddComponent<_WorldRotate> ();
		wr.r = Vector3.up * -1.2f + Vector3.right * 0.5f;
		foreach (Transform b in planetBits) {
			b.localScale = Vector3.zero;
			b.rotation = Random.rotation;
			b.position *= 2;
			_WorldRotate wr2 = b.gameObject.AddComponent<_WorldRotate> ();
			wr2.r = Random.rotation.eulerAngles * 0.01f;
			b.gameObject.GetComponent<Renderer> ().material = MoonMatSet1 [Random.Range (0, MoonMatSet1.Length)];
		}
	}
Пример #7
0
	void Setup() {
		g_parent = new GameObject ("Planet");

		moons_prefabs = ShuffleGOList (moons_prefabs);
		nature_prefabs = ShuffleGOList (nature_prefabs);
		urban_prefabs = ShuffleGOList (urban_prefabs);

		spherePrefabToUse = spherePrefabs [scale];
		spherePlacement = spherePrefabs [scale + 2];

		ringType = Random.value < 0.5f ? 0 : Random.value < 0.5f ? 1 : Random.value < 0.5f ? 2 : 3;

		// generate water, clouds, land, and trees/urban here
		SetNoiseParameters ();
		GenerateLand();
		GenerateWater();
		SetNoiseParameters ();
		GenerateClouds();
		SetNoiseParameters ();
		GenerateTreesAndUrban();
		GenerateMoons ();

		// assign colors to materials and to particles
		Color[] colors= NewSet();

		Color Life1 = colors [0];
		Color Life2 = colors [1];
		Color Life3 = colors [2];

		Color Land1 = colors [3];
		Color Land2 = colors [4];
		Color Land3 = colors [5];

		Color Water1 = colors [6];
		Color Water2 = colors [7];
		Color Water3 = colors [8];

		LandMat.SetColor ("_Color", Land1);
		LandMat.SetColor ("_Color1", Land2);
		LandMat.SetColor ("_Color2", Land3);

		SeaMat.SetColor ("_Color", Water3);
		SeaMat.SetColor ("_Color1", Water2);
		SeaMat.SetColor ("_Color2", Water1);

		CloudMat.SetColor ("_Color", Water1);

		Color[] rc = { Land1, Land3, Water1, Water2, Water3, Life1, Life2, Life3 };
		Color r = rc [Random.Range (0, 8)];
		FlatRingMat.SetColor ("_Color", r);
		r = rc [Random.Range (0, 8)];
		FlatRingMat.SetColor ("_Color1", r);
		r = rc [Random.Range (0, 8)];
		FlatRingMat.SetColor ("_Color2", r);

		Life1M.color = Life1;
		Life2M.color = Life2;
		Life3M.color = Life3;
		MoonMatSet3 [0].color = Land1;
		MoonMatSet3 [1].color = Land3;
		MoonMatSet3 [5].color = Water1;
		MoonMatSet3 [6].color = Water2;
		MoonMatSet3 [7].color = Water3;
		//MoonMatSet3 [2].color = Life1;
		//MoonMatSet3 [3].color = Life2;
		MoonMatSet3 [4].color = Life3;

		rc = new Color[] { Land1, Land3, Life1, Life2, Life3 };
		ParticleSystem.MainModule m = g_spark.GetComponent<ParticleSystem> ().main;
		m.startColor = rc [Random.Range (2, 5)];
		m = g_dust.GetComponent<ParticleSystem> ().main;
		m.startColor = rc[Random.Range(0,3)];
		m = g_particleRing.GetComponent<ParticleSystem> ().main;
		m.startColor = rc[Random.Range(0,5)];

		//set every object to it's starting scale / coordinates
		foreach (GameObject g in new GameObject[]{g_land, g_water}){
			g.transform.localScale = Vector3.zero;
		}
		foreach (Transform g in planetBits){
			g.localScale = Vector3.zero;
		}
		foreach (Transform g in ringBits){
			g.localScale = Vector3.zero;
		}
		foreach (Transform g in moonsPlaceholders){
			g.localScale = Vector3.zero;
		}
		foreach (Transform g in treesBits){
			g.localScale *= 0.0001f;
		}
		foreach (Transform g in urbanBits){
			g.localScale *= 0.0001f;
		}
		RandomizeRingBits ();
		RandomizePlanetBits ();
		Color c = CloudMat.color;
		c.a = 0;
		CloudMat.color = c;
		if (ringType == 3) {
			g_particleRing.transform.Rotate (Vector3.right * Random.Range (-30, 30));
			_WorldRotate wrp = g_particleRing.AddComponent<_WorldRotate> ();
			wrp.r = Vector3.up * 4 * (Random.value - 0.5f) + Vector3.right * -1.5f;
		}
		if (ringType == 2) {
			targetFlatRingRot = (Vector3.forward * Random.Range (-30, 30)) + (Vector3.right * Random.Range (-5, 5));
			g_flatRing.transform.localScale = Vector3.one * 5;
			g_flatRing.transform.eulerAngles = Vector3.right * -90;
			_WorldRotate wrp = g_flatRing.AddComponent<_WorldRotate> ();
			wrp.r = Vector3.up * 4 * (Random.value - 0.5f) + Vector3.right * -1.5f;
			wrp.noInitRotate = true;
		} else {
			g_flatRing.transform.localScale = Vector3.zero;
		}

		// parenting everything to parent
		foreach (GameObject g in new GameObject[]{g_pBits, g_rBits, g_flatRing}){
			g.transform.parent = g_parent.transform;
		}

		// go
		step = -1;
		NextStep ();
	}