コード例 #1
0
ファイル: Planet.cs プロジェクト: JLWard-90/Asteroid-Mining
    void GenerateMesh()
    {
        for (int i = 0; i < 6; i++)
        {
            if (meshFilters[i].gameObject.activeSelf)
            {
                terrainFaces[i].ConstructMesh();
            }
            GameObject meshObject = meshFilters[i].gameObject;
            if (meshObject.GetComponent <MeshCollider>() == null)
            {
                meshObject.AddComponent <MeshCollider>();
            }
            meshObject.GetComponent <MeshCollider>().sharedMesh = meshFilters[i].sharedMesh;
            meshObject.tag = "ground";
            if (meshObject.GetComponent <Rigidbody>() == null)
            {
                meshObject.AddComponent <Rigidbody>();
            }
            meshObject.GetComponent <Rigidbody>().isKinematic = true;
            meshObject.GetComponent <Rigidbody>().useGravity  = false;
            Debug.Log(meshObject.GetComponent <Rigidbody>());
        }

        colourGenerator.UpdateElevation(shapeGenerator.elevationMinMax);
    }
コード例 #2
0
ファイル: Planet.cs プロジェクト: AsylumRunner479/Planet-Game
 void GenerateMesh()
 {
     foreach (TerrainFace face in terrainFaces)
     {
         face.ConstructMesh();
     }
     colorGenerator.UpdateElevation(shapeGenerator.elevationMinMax);
 }
コード例 #3
0
    private void GenerateMesh()
    {
        foreach (TerrainFace face in _terrainFaces)
        {
            face.ConstructMesh(transform);
        }

        _colourGenerator.UpdateElevation(_shapeGenerator.ElevationMinMax);
    }
コード例 #4
0
    // ********************************************************************** //

    void GenerateMesh()
    {
        // Just generate the mesh for every face of the terrain
        foreach (TerrainFace face in terrainFaces)
        {
            face.ConstructMesh();
        }

        colourGenerator.UpdateElevation(shapeGenerator.elevationMinMax);
    }
コード例 #5
0
 public void GenerateTerrain()
 {
     for (int i = 0; i < 6; i++)
     {
         if (terrainFilters[i].gameObject.activeSelf)
         {
             terrainFaces[i].ConstructTerrain();
         }
     }
     colourGenerator.UpdateElevation(shapeGenerator.elevationMinMax);
 }
コード例 #6
0
    void GenerateMesh()
    {
        for (int i = 0; i < 6; i++)
        {
            if (meshFilter[i].gameObject.activeSelf)
            {   // only construct selected face
                terrainFaces[i].ConstructMesh();
            }
        }

        colourGenerator.UpdateElevation(shapeGenerator.elevationMinMax);
    }
コード例 #7
0
ファイル: Planet.cs プロジェクト: JoshH-H/Other-Dimension
        void GenerateMesh()
        {
            for (int i = 0; i < 6; i++)
            {
                if (_meshFilters[i].gameObject.activeSelf)
                {
                    _terrainFaces[i].ConstructMesh();
                }
            }

            _colourGenerator.UpdateElevation(_shapeGenerator.ElevationMinMax);
        }
コード例 #8
0
ファイル: Planet.cs プロジェクト: MaxAndreassen/Galaxies
    void GenerateMesh()
    {
        for (var i = 0; i < 6; i++)
        {
            if (meshFilters[i].gameObject.activeSelf)
            {
                terrainFaces[i].ConstructMesh();
            }
        }

        colourGenerator.UpdateElevation(shapeGenerator.elevationMinMax);
    }
コード例 #9
0
    void SetupMesh()
    {
        for (int i = 0; i < 6; i++)
        {
            PlanetFace face     = faces[i];
            bool       renderIt = toRender.HasFlag((Faces)(1 << i));
            face.meshFilter.sharedMesh   = renderIt ? GenerateFaceMesh(directions[i], nbSegments) : null;
            face.meshCollider.sharedMesh = renderIt && !designMode?GenerateFaceMesh(directions[i], Mathf.CeilToInt(colliderPrecision *nbSegments)) : null;

            face.GetComponent <MeshRenderer>().sharedMaterial = coloursSettings.planetMaterial;
            colourGenerator.UpdateElevation(elevationMinMax);
        }
    }
コード例 #10
0
ファイル: Planet.cs プロジェクト: ahernot/testSolarSystem
    // Generate mesh
    void GenerateMesh()
    {
        // Run through all 6 faces
        for (int i = 0; i < 6; i++)
        {
            if (meshFilters[i].gameObject.activeSelf)
            {
                terrainFaces[i].ConstructMesh(); //face.ConstructMesh();
            }
        }

        // Update colours
        colourGenerator.UpdateElevation(shapeGenerator.elevationMinMax);
    }
コード例 #11
0
    void GeraMesh()
    {
        /* foreach(TerrainFace face in terrainFaces)
         * {
         *  face.ConstroiMesh();
         * } */
        for (int i = 0; i < 6; i++)
        {
            if (meshFilters[i].gameObject.activeSelf)
            {
                terrainFaces[i].ConstroiMesh();
            }
        }

        colourGenerator.UpdateElevation(geraShape.elevationMinMax);
    }
コード例 #12
0
    //Se genera el terreno y se actualiza la elevacion para la generacion del color
    void GenerateMesh()
    {
        for (int i = 0; i < 6; i++)
        {
            if (meshFilters[i].gameObject.activeSelf)
            {
                terrainFaces[i].CreateMesh();
                if (!meshFilters[i].gameObject.GetComponent <MeshCollider>())
                {
                    meshFilters[i].gameObject.AddComponent <MeshCollider>();
                }
            }
        }

        colourGenerator.UpdateElevation(shapeGenerator.elevationMinMax);
    }
コード例 #13
0
 void GenerateMesh()
 {
     for (int i = 0; i < 6; i++)
     {
         for (int y = 0; y < divisions; y++)
         {
             for (int x = 0; x < divisions; x++)
             {
                 if (meshFilters[i * divisions * divisions + y * divisions + x].gameObject.activeSelf)
                 {
                     terrainFaces[i * divisions * divisions + y * divisions + x].ConstructMesh(x, y, divisions, transform.position);
                 }
             }
         }
     }
     colourGenerator.UpdateElevation(shapeGenerator.elevationMinMax);
 }
コード例 #14
0
    void GenerateMesh()
    {
        //Debug.Log("Called Generate mesh, 88");

        if (mesh == null)
        {
            mesh = new Mesh();
        }

        List <Vector3>         vertList = new List <Vector3>();
        Dictionary <long, int> middlePointIndexCache = new Dictionary <long, int>();

        // create 12 vertices of a icosahedron
        float t = (1f + Mathf.Sqrt(5f)) / 2f;

        vertList.Add(new Vector3(-1f, t, 0f).normalized);
        vertList.Add(new Vector3(1f, t, 0f).normalized);
        vertList.Add(new Vector3(-1f, -t, 0f).normalized);
        vertList.Add(new Vector3(1f, -t, 0f).normalized);

        vertList.Add(new Vector3(0f, -1f, t).normalized);
        vertList.Add(new Vector3(0f, 1f, t).normalized);
        vertList.Add(new Vector3(0f, -1f, -t).normalized);
        vertList.Add(new Vector3(0f, 1f, -t).normalized);

        vertList.Add(new Vector3(t, 0f, -1f).normalized);
        vertList.Add(new Vector3(t, 0f, 1f).normalized);
        vertList.Add(new Vector3(-t, 0f, -1f).normalized);
        vertList.Add(new Vector3(-t, 0f, 1f).normalized);


        // create 20 triangles of the icosahedron
        List <TriangleIndices> faces = new List <TriangleIndices>();

        // 5 faces around point 0
        faces.Add(new TriangleIndices(0, 11, 5));
        faces.Add(new TriangleIndices(0, 5, 1));
        faces.Add(new TriangleIndices(0, 1, 7));
        faces.Add(new TriangleIndices(0, 7, 10));
        faces.Add(new TriangleIndices(0, 10, 11));

        // 5 adjacent faces
        faces.Add(new TriangleIndices(1, 5, 9));
        faces.Add(new TriangleIndices(5, 11, 4));
        faces.Add(new TriangleIndices(11, 10, 2));
        faces.Add(new TriangleIndices(10, 7, 6));
        faces.Add(new TriangleIndices(7, 1, 8));

        // 5 faces around point 3
        faces.Add(new TriangleIndices(3, 9, 4));
        faces.Add(new TriangleIndices(3, 4, 2));
        faces.Add(new TriangleIndices(3, 2, 6));
        faces.Add(new TriangleIndices(3, 6, 8));
        faces.Add(new TriangleIndices(3, 8, 9));

        // 5 adjacent faces
        faces.Add(new TriangleIndices(4, 9, 5));
        faces.Add(new TriangleIndices(2, 4, 11));
        faces.Add(new TriangleIndices(6, 2, 10));
        faces.Add(new TriangleIndices(8, 6, 7));
        faces.Add(new TriangleIndices(9, 8, 1));


        // refine triangles
        for (int i = 0; i < resolution; i++)
        {
            List <TriangleIndices> faces2 = new List <TriangleIndices>();
            foreach (var tri in faces)
            {
                // replace triangle by 4 triangles
                int a = GetMiddlePoint(tri.v1, tri.v2, ref vertList, ref middlePointIndexCache, 1f);
                int b = GetMiddlePoint(tri.v2, tri.v3, ref vertList, ref middlePointIndexCache, 1f);
                int c = GetMiddlePoint(tri.v3, tri.v1, ref vertList, ref middlePointIndexCache, 1f);

                faces2.Add(new TriangleIndices(tri.v1, a, c));
                faces2.Add(new TriangleIndices(tri.v2, b, a));
                faces2.Add(new TriangleIndices(tri.v3, c, b));
                faces2.Add(new TriangleIndices(a, b, c));
            }
            faces = faces2;
        }

        // add noise to surface
        for (int i = 0; i < vertList.Count; i++)
        {
            vertList[i] = shapeGenerator.CalculatePointOnPlanet(vertList[i]);
        }


        //Debug.Log("Defined vertices and triangles, 160");

        // update mesh
        mesh.Clear();
        mesh.vertices = vertList.ToArray();

        List <int> triList = new List <int>();

        for (int i = 0; i < faces.Count; i++)
        {
            triList.Add(faces[i].v1);
            triList.Add(faces[i].v2);
            triList.Add(faces[i].v3);
        }
        mesh.triangles = triList.ToArray();

        //Debug.Log("Updated Mesh, 175");

        /*
         * var nVertices = mesh.vertices;
         * Vector2[] UVs = new Vector2[nVertices.Length];
         *
         * for (var i = 0; i < nVertices.Length; i++)
         * {
         *  var unitVector = nVertices[i].normalized;
         *  Vector2 ICOuv = new Vector2(0, 0);
         *  ICOuv.x = (Mathf.Atan2(unitVector.x, unitVector.z) + Mathf.PI) / Mathf.PI / 2;
         *  ICOuv.y = (Mathf.Acos(unitVector.y) + Mathf.PI) / Mathf.PI - 1;
         *  UVs[i] = new Vector2(ICOuv.x, ICOuv.y);
         * }
         *
         * mesh.uv = UVs;
         *
         *
         * Vector3[] normales = new Vector3[vertList.Count];
         * for (int i = 0; i < normales.Length; i++)
         *  normales[i] = vertList[i].normalized;
         *
         * mesh.normals = normales;
         *
         */

        // extra code added
        mesh.RecalculateNormals();

        mesh.RecalculateBounds();
        mesh.Optimize();

        //Debug.Log("Optimesed Mesh, 207");


        if (meshFilter == null)
        {
            meshFilter = GetComponent <MeshFilter>();
        }

        meshFilter.sharedMesh = mesh;

        //Debug.Log("Apply to filter, 207");
        //mesh.RecalculateBounds();

        colourGenerator.UpdateElevation(shapeGenerator.elevationMinMax);
    }