Пример #1
0
        /// <summary>
        /// Move edge vertices
        /// </summary>
        protected void UpdateEdgeVertex()
        {
            foreach (int index in _groundMesh.indexes.edgeVertexIndex)
            {
                foreach (Cell fneighbor in _neighbors)
                {
                    foreach (int fIndex in fneighbor.Indexes.edgeVertexIndex)
                    {
                        Vector3 nVertex1 = _groundMesh.smoothVertex[index].normalized;
                        Vector3 nVertex2 = fneighbor.GroundMesh.smoothVertex[fIndex].normalized;

                        if (nVertex1 == nVertex2)
                        {
                            List <int> myLinkedInternIndex = GetLinkedInternVertexIndexes(_groundMesh, index);
                            List <int> linkedInternIndex   = GetLinkedInternVertexIndexes(fneighbor.GroundMesh, fIndex);

                            Vector3 internVertex         = GetNearestTypedVertex(_groundMesh.indexes.internVertexIndex, nVertex1, _groundMesh);
                            Vector3 internNeighborVertex = GetNearestTypedVertex(fneighbor.GroundMesh.indexes.internVertexIndex, nVertex2, fneighbor.GroundMesh);

                            Vector3[] cloudOfPoint = new Vector3[] { internVertex, internNeighborVertex };
                            Vector3   G            = MathCustom.GetBarycenter(cloudOfPoint);

                            _groundMesh.smoothVertex[index] = G;
                            fneighbor.UpdateVertexPos(fIndex, G);
                        }
                    }
                }
            }
        }
Пример #2
0
    private Vector3 GetRosacePosition(float deltaTime)
    {
        for (int i = 0; i < angularSpeeds.Count; i++)
        {
            Vector3 nVector;
            nVector    = MathCustom.RotateDirectionAround(vectors[i], deltaTime * angularSpeeds[i], Vector3.forward);
            nVector    = nVector.normalized * nTime * 2f;
            vectors[i] = nVector;
            nVector.z  = 0f;
            activeVectors.Add(nVector);
        }
        Vector3 pos = MathCustom.GetBarycenter(activeVectors.ToArray());

        activeVectors.Clear();
        return(pos);
    }
Пример #3
0
        /// <summary>
        /// Move corner vertices
        /// </summary>
        protected void UpdateCornerHeight()
        {
            foreach (int myindex in _groundMesh.indexes.cornerVertexIndex)
            {
                int    iterator            = 0;
                int[]  internVertexIndexes = new int[2];
                int[]  cornerVertexIndexes = new int[2];
                Cell[] linkedCells         = new Cell[2];

                foreach (Cell fneighbor in _neighbors)
                {
                    foreach (int index in fneighbor.Indexes.cornerVertexIndex)
                    {
                        Vector3 nVertex1 = _groundMesh.smoothVertex[myindex].normalized;
                        Vector3 nVertex2 = fneighbor.GroundMesh.smoothVertex[index].normalized;

                        if (nVertex1 == nVertex2)
                        {
                            List <int> internVertexIndex = GetLinkedInternVertexIndexes(fneighbor.GroundMesh, index);
                            linkedCells[iterator]         = fneighbor;
                            internVertexIndexes[iterator] = internVertexIndex[0];
                            cornerVertexIndexes[iterator] = index;
                            iterator++;
                        }
                    }
                }

                if (iterator == 2)
                {
                    List <int> myInternVertexIndex = GetLinkedInternVertexIndexes(_groundMesh, myindex);

                    Vector3[] cloudOfPoint = new Vector3[3]
                    {
                        _groundMesh.smoothVertex[myInternVertexIndex[0]],
                        linkedCells[0].GroundMesh.smoothVertex[internVertexIndexes[0]],
                        linkedCells[1].GroundMesh.smoothVertex[internVertexIndexes[1]]
                    };

                    Vector3 G = MathCustom.GetBarycenter(cloudOfPoint);
                    _groundMesh.smoothVertex[myindex] = G;

                    linkedCells[0].UpdateVertexPos(cornerVertexIndexes[0], G);
                    linkedCells[1].UpdateVertexPos(cornerVertexIndexes[1], G);
                }
            }
        }
Пример #4
0
        protected void AddRoadPart(RoadEdge startEdge, RoadEdge targetEdge)
        {
            SortPoints(startEdge, targetEdge);

            List <Vector3[]> preTris = new List <Vector3[]>();

            preTris.Add(new Vector3[3] {
                startEdge.meshPoints[1], startEdge.meshPoints[0], targetEdge.meshPoints[0]
            });
            preTris.Add(new Vector3[3] {
                targetEdge.meshPoints[0], targetEdge.meshPoints[1], startEdge.meshPoints[1]
            });

            for (int i = 0; i < 2; i++)
            {
                if (Vector3.Angle(MathCustom.GetFaceNormalVector(preTris[i][0], preTris[i][1], preTris[i][2]).normalized, MathCustom.GetBarycenter(preTris[i]).normalized) < 90f)
                {
                    roadVertice.AddTriangle(new Vector3[3] {
                        preTris[i][2], preTris[i][1], preTris[i][0]
                    });
                }
                else
                {
                    roadVertice.AddTriangle(preTris[i]);
                }
            }
            preTris.Clear();

            int[] lTriangles = new int[roadVertice.triangles.Count * 3];
            for (int i = 0; i < lTriangles.Length / 3; i++)
            {
                lTriangles[i * 3]       = roadVertice.triangles[i].verticesindex[0];
                lTriangles[(i * 3) + 1] = roadVertice.triangles[i].verticesindex[1];
                lTriangles[(i * 3) + 2] = roadVertice.triangles[i].verticesindex[2];
            }

            roadMeshObject.mesh.vertices  = roadVertice.vertex.ToArray();
            roadMeshObject.mesh.triangles = lTriangles;
            roadMeshObject.mesh.normals   = roadVertice.normals.ToArray();

            SetUV();
            roadMeshObject.mesh.uv      = roadVertice.UV.ToArray();
            roadMeshCollider.sharedMesh = roadMeshObject.mesh;
        }