Ejemplo n.º 1
0
    public void Calculate(int index = 0)
    {
        Vertices.Clear();
        Triangles.Clear();
        UVs.Clear();

        var s = Size / 2f;

        Vector3[] p = new Vector3[] {
            new Vector3(-s, -s, -s) + Position,             // 0 0
            new Vector3(-s, s, -s) + Position,              // 1 1
            new Vector3(s, s, -s) + Position,               // 2 2
            new Vector3(s, -s, -s) + Position,              // 3 3

            new Vector3(-s, -s, s) + Position,              // 4 0
            new Vector3(-s, s, s) + Position,               // 5 1
            new Vector3(s, s, s) + Position,                // 6 2
            new Vector3(s, -s, s) + Position,               // 7 3
        };

        for (int i = 0; i < Faces.Length; i++)
        {
            if (Faces[i])
            {
                Triangles.AddRange(AddTriangles(index + Vertices.Count));
                UVs.AddRange(UVPacker.GetCubeUVs(i, CubeTypes[type]));

                switch (i)
                {
                case 0: Vertices.AddRange(new Vector3[] { p[0], p[1], p[2], p[3] }); break;

                case 1: Vertices.AddRange(new Vector3[] { p[3], p[2], p[6], p[7] }); break;

                case 2: Vertices.AddRange(new Vector3[] { p[7], p[6], p[5], p[4] }); break;

                case 3: Vertices.AddRange(new Vector3[] { p[4], p[5], p[1], p[0] }); break;

                case 4: Vertices.AddRange(new Vector3[] { p[1], p[5], p[6], p[2] }); break;

                case 5: Vertices.AddRange(new Vector3[] { p[4], p[0], p[3], p[7] }); break;

                default: break;
                }
            }
        }

        this.Calculated = true;
    }
Ejemplo n.º 2
0
    private void CalculateUVs(int subMesh, Vector3 direction)
    {
        int vertCount = (Triangles [subMesh].Count / 6) * 4;

        Vector2[] planeUVs = new Vector2[vertCount];

        for (int i = 0; i < vertCount; i++)
        {
            int     index = Vertices.Count - vertCount + i;
            Vector2 uv    = Vec3ToVec2(Vertices [index], direction);
            uv.x        *= tiling;
            uv.y        *= tiling;
            planeUVs [i] = uv;
        }
        UVs.AddRange(planeUVs);
    }
Ejemplo n.º 3
0
    public void AddTriangle(MeshTriangle _triangle)
    {
        int currentVerticeCount = vertices.Count;

        Vertices.AddRange(_triangle.Vertices);
        Normals.AddRange(_triangle.Normals);
        UVs.AddRange(_triangle.UVs);

        if (SubmeshIndices.Count < _triangle.SubmeshIndex + 1)
        {
            for (int i = submeshIndices.Count; i < (_triangle.SubmeshIndex + 1); i++)
            {
                SubmeshIndices.Add(new List <int>());
            }
        }

        for (int i = 0; i < 3; i++)
        {
            SubmeshIndices[_triangle.SubmeshIndex].Add(currentVerticeCount + i);
        }
    }