Exemple #1
0
 public void Awake()
 {
     meshRenderer = GetComponent <MeshRenderer>();
     if (!shape)
     {
         shape = new ShapeSettings();
     }
     terrainLayer = LayerMask.NameToLayer("Terrain");
     colourGenerator.UpdateSettings(coloursSettings);
     colourGenerator.UpdateColours();
 }
    void Initialize()
    {
        shapeGenerator.UpdateSettings(shapeSettings);
        colourGenerator.UpdateSettings(colourSettings);

        //if (meshFilters == null || meshFilters.Length == 0 || meshFilters.Length < 6*divisions)
        //{
        var children = new List <GameObject>();

        foreach (Transform child in gameObject.transform)
        {
            children.Add(child.gameObject);
        }
        children.ForEach(child => DestroyImmediate(child));
        meshFilters = new MeshFilter[6 * divisions * divisions];
        //}
        terrainFaces = new TerrainFace[6 * divisions * divisions];

        Vector3[] directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };

        for (int i = 0; i < 6 * divisions * divisions; i++)
        {
            if (meshFilters[i] == null)
            {
                GameObject meshObj = new GameObject("mesh" + i);
                meshObj.transform.parent        = transform;
                meshObj.transform.localPosition = Vector3.zero;
                meshObj.transform.localScale    = Vector3.one;
                meshObj.layer = meshObj.transform.parent.gameObject.layer;

                meshObj.AddComponent <MeshRenderer>();
                meshFilters[i]            = meshObj.AddComponent <MeshFilter>();
                meshFilters[i].sharedMesh = new Mesh();
            }
            meshFilters[i].GetComponent <MeshRenderer>().sharedMaterial    = colourSettings.planetMaterial;
            meshFilters[i].GetComponent <MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            meshFilters[i].GetComponent <MeshRenderer>().receiveShadows    = false;
            genFace    = new bool[6 * divisions * divisions];
            genFace[i] = faceRenderMask == FaceRenderMask.All || (int)faceRenderMask - 2 == i / (divisions * divisions) || maskException == i;
            if (genFace[i])
            {
                terrainFaces[i] = new TerrainFace(shapeGenerator, meshFilters[i].sharedMesh, resolution, divisions, directions[i / (divisions * divisions)]);
            }
            else
            {
                terrainFaces[i] = null;
            }
            bool renderFace = faceRenderMask == FaceRenderMask.All || (int)faceRenderMask - 2 == i / (divisions * divisions) || maskException == i;
            //Debug.Log(renderFace);
            meshFilters[i].gameObject.SetActive(renderFace);
        }
    }
    public void Initialise()
    {
        shapeGenerator.UpdateSettings(shapeSettings);
        colourGenerator.UpdateSettings(colourSettings);
        if (meshFilters == null || meshFilters.Length == 0)
        {
            meshFilters = new MeshFilter[6];
        }
        terrainFaces = new TerrainFace[6];

        Vector3[] directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };
        for (int i = 0; i < 6; i++)
        {
            if (meshFilters[i] == null)
            {
                GameObject meshObj = new GameObject("mesh" + i);
                meshObj.transform.parent = transform;

                meshObj.AddComponent <MeshRenderer>();
                meshFilters[i]            = meshObj.AddComponent <MeshFilter>();
                meshFilters[i].sharedMesh = new Mesh();
            }
            meshFilters[i].GetComponent <MeshRenderer>().sharedMaterial = colourSettings.planetMaterial;

            terrainFaces[i] = new TerrainFace(shapeGenerator, meshFilters[i].sharedMesh, resolution, directions[i]);
            bool renderFace = faceRenderMask == FaceRenderMask.All || (int)faceRenderMask - 1 == i;
            meshFilters[i].gameObject.SetActive(renderFace);
        }
    }
Exemple #4
0
    /* function called when script is loaded or value is changed
     * private void OnValidate()
     * {
     *  GeneratePlanet();
     * }*/

    void Initialize()
    {
        shapeGenerator.UpdateSettings(shapeSetings);
        colourGenerator.UpdateSettings(colorSettings);

        if (meshFilter == null || meshFilter.Length == 0)
        {
            meshFilter = new MeshFilter[6];
        }
        terrainFaces = new TerrainFace[6];

        // array for direction to assign in localup variable of terrainface
        Vector3[] directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };

        for (int i = 0; i < 6; i++)
        {
            if (meshFilter[i] == null)
            {
                GameObject meshObj = new GameObject("mesh");
                meshObj.transform.parent = transform;

                meshObj.AddComponent <MeshRenderer>();
                meshFilter[i]            = meshObj.AddComponent <MeshFilter>();
                meshFilter[i].sharedMesh = new Mesh();
            }
            meshFilter[i].GetComponent <MeshRenderer>().sharedMaterial = colorSettings.planetMaterial; // add matrial to the object

            terrainFaces[i] = new TerrainFace(shapeGenerator, resolution, meshFilter[i].sharedMesh, directions[i]);

            bool renderFace = faceRenderMask == FaceRenderMask.All || (int)faceRenderMask - 1 == i; // see if face is selcted or not
            meshFilter[i].gameObject.SetActive(renderFace);
        }
    }
Exemple #5
0
    // ********************************************************************** //

    void Initialize(bool reset = false)
    {
        shapeGenerator.UpdateSettings(shapeSettings, reset, shapeSampleStats);
        colourGenerator.UpdateSettings(colourSettings, reset, colourSampleStats);
        tintColor   = colourGenerator.GetTintColor();
        colourLevel = colourGenerator.GetColourLevel();
        saturation  = colourGenerator.GetSaturation();
        particleLauncher.UpdateSettings(tintColor, reset, particleSampleStats);

        // only create new meshFilters when you need them
        if (meshFilters == null || meshFilters.Length == 0)
        {
            meshFilters = new MeshFilter[cubeFaces];
        }
        terrainFaces = new TerrainFace[cubeFaces];

        Vector3[] directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };  // one for each of the cube faces

        for (int i = 0; i < cubeFaces; i++)
        {
            if (meshFilters[i] == null)
            {
                GameObject meshObj = new GameObject("mesh");
                meshObj.transform.parent = transform;

                meshObj.AddComponent <MeshRenderer>();
                meshFilters[i]            = meshObj.AddComponent <MeshFilter>();
                meshFilters[i].sharedMesh = new Mesh();
            }

            meshFilters[i].GetComponent <MeshRenderer>().sharedMaterial = colourSettings.planetMaterial;

            terrainFaces[i] = new TerrainFace(shapeGenerator, meshFilters[i].sharedMesh, resolution, directions[i]);
        }
    }
Exemple #6
0
    private void Initialize()
    {
        _divisions = (int)Mathf.Pow(4, Subdivisions);

        _shapeGenerator.UpdateSettings(ShapeSettings);
        _colourGenerator.UpdateSettings(ColourSettings);
        if (_meshFilters == null || _meshFilters.Length == 0 || _subdivisions != Subdivisions)
        {
            _meshFilters = new MeshFilter[6, _divisions];
        }

        _meshColliders = new MeshCollider[6, _divisions];

        _subdivisions = Subdivisions;

        _terrainFaces = new TerrainFace[6, _divisions];

        Vector3[] directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };
        Vector2[] offsets    =
        {
            new Vector2(1, 1),
            new Vector2(0, 1),
            new Vector2(1, 0),
            new Vector2(0, 0)
        };

        for (int d = 0; d < 6; d++)
        {
            // Remember arrays count 0 as a index. That is why we subtract 1 from divisions.
            GenerateFaces(directions, offsets, d, _divisions - 1);
        }
    }
    void Initialize()
    {
        colourGenerator.UpdateSettings(colourSettings);
        shapeGenerator.UpdateSettings(shapeSettings);

        if (renderer == null)
        {
            renderer = GetComponent <MeshRenderer>();
        }

        renderer.sharedMaterial = colourSettings.planetMaterial;
    }
Exemple #8
0
    void Initialise()
    {
        shapeGenerator.UpdateSettings(shapeSettings);
        colourGenerator.UpdateSettings(colourSettings);
        if (meshFilters == null || meshFilters.Length == 0)
        {
            meshFilters = new MeshFilter[6];
        }

        terrainFaces = new TerrainFace[6];
        for (int i = 0; i < 6; i++) //Iterate over 6 faces of cube
        {
            if (meshFilters[i] == null)
            {
                GameObject meshObject = new GameObject("mesh");
                meshObject.transform.parent = transform; //Add the new meshobject to current transform

                meshObject.AddComponent <MeshRenderer>();
                meshObject.AddComponent <MeshCollider>();
                meshFilters[i]            = meshObject.AddComponent <MeshFilter>();
                meshFilters[i].sharedMesh = new Mesh();
                meshObject.GetComponent <MeshCollider>().sharedMesh = meshFilters[i].sharedMesh;
                meshObject.tag = "ground";
                meshObject.AddComponent <Rigidbody>();
                meshObject.GetComponent <Rigidbody>().isKinematic = true;
                meshObject.GetComponent <Rigidbody>().useGravity  = false;
                Debug.Log(meshObject.GetComponent <Rigidbody>());
            }
            if (meshFilters[i].sharedMesh == null)
            {
                meshFilters[i].sharedMesh = new Mesh();
            }
            meshFilters[i].GetComponent <MeshRenderer>().sharedMaterial = colourSettings.planetMaterial;

            terrainFaces[i] = new TerrainFace(shapeGenerator, meshFilters[i].sharedMesh, resolution, directions[i]);
            bool renderFace = faceRenderMask == FaceRenderMask.All || (int)faceRenderMask - 1 == i;
            meshFilters[i].gameObject.SetActive(renderFace);
            // Debug.Log(meshFilters[i].gameObject);
            //meshColliders[i] = meshFilters[i].gameObject.AddComponent<MeshCollider>() as MeshCollider;
            // meshColliders[i].sharedMesh = meshFilters[i].mesh;
        }
    }
Exemple #9
0
    // Initialize mesh
    void Initialize()
    {
        // Initialize shapeGenerator
        shapeGenerator.UpdateSettings(shapeSettings);

        // Initialize colourGenerator
        colourGenerator.UpdateSettings(colourSettings);

        // Reinitialise mesh filters if array is empty
        if (meshFilters == null ||  meshFilters.Length == 0)
        {
            meshFilters = new MeshFilter[6];
        }

        terrainFaces = new TerrainFace[6];

        Vector3[] directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };

        for (int i = 0; i < 6; i++)
        {
            if (meshFilters[i] == null)
            {
                GameObject meshObj = new GameObject("mesh");
                meshObj.transform.parent = transform;

                meshObj.AddComponent <MeshRenderer>(); // .sharedMaterial = new Material(Shader.Find("Standard")); // mesh renderer
                meshFilters[i]            = meshObj.AddComponent <MeshFilter>();
                meshFilters[i].sharedMesh = new Mesh();
            }

            // Set material
            meshFilters[i].GetComponent <MeshRenderer>().sharedMaterial = colourSettings.planetMaterial;

            terrainFaces[i] = new TerrainFace(shapeGenerator, meshFilters[i].sharedMesh, resolution, directions[i]);

            // Render face by face
            bool renderFace = faceRenderMask == FaceRenderMask.All || (int)faceRenderMask - 1 == i;
            meshFilters[i].gameObject.SetActive(renderFace);
        }
    }
Exemple #10
0
        void Initialize()
        {
            _shapeGenerator.UpdateSettings(_shapeSettings);
            _colourGenerator.UpdateSettings(_colourSettings);

            if (_meshFilters == null || _meshFilters.Length == 0)
            {
                _meshFilters = new MeshFilter[6];
                foreach (var mesh in _meshFilters)
                {
                    mesh.gameObject.AddComponent <MeshCollider>();
                }
            }

            _terrainFaces = new TerrainFace[6];

            Vector3[] directions =
            { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };

            for (int i = 0; i < 6; i++)
            {
                if (_meshFilters[i] == null)
                {
                    GameObject meshObj = new GameObject("mesh");
                    meshObj.transform.parent = transform;

                    meshObj.AddComponent <MeshRenderer>();
                    _meshFilters[i]            = meshObj.AddComponent <MeshFilter>();
                    _meshFilters[i].sharedMesh = new Mesh();
                }

                _meshFilters[i].GetComponent <MeshRenderer>().sharedMaterial = _colourSettings.PlanetMaterial;

                _terrainFaces[i] = new TerrainFace(_shapeGenerator, _meshFilters[i].sharedMesh, resolution, directions[i]);
                bool renderFace = _faceRenderMask == FaceRenderMask.All || (int)_faceRenderMask - 1 == i;
                _meshFilters[i].gameObject.SetActive(renderFace);
            }
        }
Exemple #11
0
    void Initialize()
    {
        //Si es la primera vez y hay variables a null se instancian
        if (shapeGenerator == null)
        {
            shapeGenerator  = new ShapeGenerator();
            colourGenerator = new ColourGenerator();
            floraGenerator  = new FloraGenerator();

            faces = new GameObject[6];
        }

        //Actualizamos las opciones
        shapeGenerator.UpdateSettings(shapeSettings);
        colourGenerator.UpdateSettings(colourSettings);

        if (floraSettings.generateFlora)
        {
            floraGenerator.UpdateSettings(floraSettings, transform);
        }

        //Si no hay mallas para cada cara se crean
        if (meshFilters == null || meshFilters.Length == 0)
        {
            meshFilters = new MeshFilter[6];
        }
        terrainFaces = new TerrainFace[6];

        Vector3[] directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };

        //Por cada cara creamos una malla y la colocamos en su posicion
        for (int i = 0; i < 6; i++)
        {
            if (meshFilters[i] == null)
            {
                faces[i] = new GameObject("face");

                if (i != 0)
                {
                    if (i != 1)
                    {
                        faces[i].transform.Rotate(Vector3.Cross(Vector3.up, directions[i]), 90);
                    }
                    else
                    {
                        faces[i].transform.Rotate(Vector3.Cross(Vector3.up, Vector3.right), 180);
                    }
                }
                faces[i].transform.parent = transform;

                GameObject meshObj = new GameObject("mesh");
                meshObj.transform.parent = faces[i].transform;
                if (transform.gameObject.layer == 0)
                {
                    meshObj.layer = 8;
                }
                else
                {
                    meshObj.layer = transform.gameObject.layer;
                }

                meshObj.AddComponent <MeshRenderer>();
                meshFilters[i]            = meshObj.AddComponent <MeshFilter>();
                meshFilters[i].sharedMesh = new Mesh();
            }

            meshFilters[i].GetComponent <MeshRenderer>().sharedMaterial = colourSettings.planetMaterial;

            terrainFaces[i] = new TerrainFace(shapeGenerator, meshFilters[i].sharedMesh, resolution, directions[i]);
            bool renderFace = faceRenderMask == FaceRenderMask.All || (int)faceRenderMask - 1 == i;
            meshFilters[i].gameObject.SetActive(renderFace);
        }
    }
Exemple #12
0
    public void Initialize()
    {
        shapeGenerator.UpdateSettings(shapeSettings);
        colourGenerator.UpdateSettings(colourSettings);

        if (terrainMeshes == null)
        {
            terrainMeshes = new GameObject("TerrainFaces");
        }
        terrainMeshes.transform.parent        = transform;
        terrainMeshes.transform.localPosition = Vector3.zero;

        if (atmosphereMeshes == null)
        {
            atmosphereMeshes = new GameObject("AtmosphereFaces");
        }
        atmosphereMeshes.transform.parent        = transform;
        atmosphereMeshes.transform.localPosition = Vector3.zero;

        if (terrainFilters == null || terrainFilters.Length == 0)
        {
            terrainFilters = new MeshFilter[6];
        }
        terrainFaces = new TerrainFace[6];

        if (atmosphereFilters == null || atmosphereFilters.Length == 0)
        {
            atmosphereFilters = new MeshFilter[6];
        }
        atmosphereFaces = new TerrainFace[6];

        Vector3[] directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back, };

        for (int i = 0; i < 6; i++)
        {
            if (terrainFilters[i] == null)
            {
                GameObject meshTerrain = new GameObject("Terrain");
                meshTerrain.transform.parent   = terrainMeshes.transform;
                meshTerrain.transform.position = terrainMeshes.transform.position;

                meshTerrain.AddComponent <MeshRenderer>();
                terrainFilters[i]            = meshTerrain.AddComponent <MeshFilter>();
                terrainFilters[i].sharedMesh = new Mesh();
            }
            terrainFilters[i].GetComponent <MeshRenderer>().sharedMaterial = colourSettings.planetMaterial;

            terrainFaces[i] = new TerrainFace(shapeGenerator, terrainFilters[i].sharedMesh, resolution, directions[i]);
            bool renderFace = faceRenderMask == FaceRenderMask.All || (int)faceRenderMask - 1 == i;
            terrainFilters[i].gameObject.SetActive(renderFace);

            if (atmosphereFilters[i] == null)
            {
                GameObject meshAtmosphere = new GameObject("Atmosphere");
                meshAtmosphere.transform.parent   = atmosphereMeshes.transform;
                meshAtmosphere.transform.position = atmosphereMeshes.transform.position;

                meshAtmosphere.AddComponent <MeshRenderer>();
                atmosphereFilters[i]            = meshAtmosphere.AddComponent <MeshFilter>();
                atmosphereFilters[i].sharedMesh = new Mesh();
            }
            atmosphereFilters[i].GetComponent <MeshRenderer>().sharedMaterial = colourSettings.atmosphereMaterial;

            atmosphereFaces[i] = new TerrainFace(shapeGenerator, atmosphereFilters[i].sharedMesh, resolution, directions[i]);
            atmosphereFilters[i].gameObject.SetActive(true);
        }
    }