Exemplo n.º 1
0
        public static void ApplyMaterial(GameObject sphere, PlanetProperties planetProps)
        {
            MeshRenderer renderer = sphere.GetComponent<MeshRenderer>();
            if (!renderer) {
                renderer = sphere.AddComponent<MeshRenderer>();
            }

            renderer.material = (Material) GameObject.Instantiate (planetProps.landMaterial);
            renderer.material.shader = (Shader) GameObject.Instantiate (planetProps.terrainShader);

            renderer.material.SetTexture ("_Side", planetProps.cliffTexture);
            renderer.material.SetFloat("_SideScale", (float) planetProps.landTextureScale);
            renderer.material.SetTexture ("_Top", planetProps.landTexture);
            renderer.material.SetFloat("_TopScale", (float) planetProps.landTextureScale);

            if (planetProps.landNormalMap != null) {
                //TODO:  If I ever add normals, will have to do them the tri-planar way instead.
                //renderer.material.SetTexture("Normalmap", planetProps.landNormalMap);
            }

            /*if (planetProps.multiTexture) {
                int newLen = renderer.materials.Length + 1;
                Material[] matList = new Material[newLen];
                renderer.materials.CopyTo(matList, 0);
                Material copiedMat = (Material) GameObject.Instantiate (planetProps.landMaterial);
                copiedMat.color = new Color(renderer.material.color.r, renderer.material.color.b, renderer.material.color.g, 0.33f);
                renderer.material.color = new Color(renderer.material.color.r, renderer.material.color.g, renderer.material.color.b, 0.66f);
                matList[newLen - 1] = copiedMat;
                matList[newLen - 1].mainTexture = planetProps.landTexture;
                if (planetProps.landTextureScale > 1) {
                    matList[newLen - 1].mainTextureScale = new Vector2(1f, 1f);
                } else {
                    matList[newLen - 1].mainTextureScale = new Vector2(4f, 4f);
                }

                renderer.materials = matList;
            }*/
        }
Exemplo n.º 2
0
        public static PlanetProperties GetRand(int seed)
        {
            System.Random rand = new System.Random(seed);
            UnityEngine.Random.seed = rand.Next ();

            PlanetProperties pp = new PlanetProperties("Shaders/TriPlanar",
                                                   PlanetProperties.RandLandTexture(rand.Next ()),
                                                   PlanetProperties.RandCliffTexture(rand.Next ()),
                                                   PlanetProperties.RandSnowTexture(rand.Next ()),
                                                   null,
                                                   null,
                                                   UnityEngine.Random.Range(0.6f, 1.5f),
                                                       UnityEngine.Random.Range (6, 8));
            pp.radius = UnityEngine.Random.Range (10f, 50f);
            return pp;
        }
Exemplo n.º 3
0
        public static Planet GeneratePlanet(string planetName, PlanetProperties planetProps, OceanProperties oceanProps = null)
        {
            SphereProperties sp = PlanetGen.defaultLandSphereProps.shallowClone();
            sp.radius = planetProps.radius;

            GameObject sphere = SphereGenerator.GenPrimitive (sp);
            Planet planet = sphere.AddComponent<Planet>();
            planet.SetLand (sphere);
            planet.SetName (planetName);

            if (oceanProps != null) {
                SphereProperties osp = PlanetGen.defaultOceanSphereProps.shallowClone();
                osp.radius = planetProps.radius;
                GameObject ocean = PlanetGen.CreateOcean (sphere, osp, oceanProps);
                planet.SetOcean (ocean);
            }

            PlanetGen.ApplyMaterial(sphere, planetProps);
            if (planetProps.applySubdivide) {
                SphereGenerator.Subdivide (sphere, planetProps.landSubTexture, 1);
            }
            if (planetProps.applyHeightmap) {
                SphereGenerator.ApplyHeightMap(sphere, planetProps.heightScaleFactor, planetProps.landHeightTexture);
            }

            return planet;
        }