Beispiel #1
0
    public static void createQuad(float i, float j, float quadSize, Algorithm2 algorithm, TriangleList meshData, Transform transform)
    {
        // North
        Vertex a = new Vertex(i, 0, j);
        Vertex b = new Vertex(i, 0, j + quadSize);
        Vertex c = new Vertex(i + quadSize, 0, j + quadSize);
        Vertex d = new Vertex(i + quadSize, 0, j);

        // Apply terrain features based on the algorithm

        /*a.position = transform.TransformPoint(a.position);
         * b.position = transform.TransformPoint(b.position);
         * c.position = transform.TransformPoint(c.position);
         * d.position = transform.TransformPoint(d.position);
         * a.position = transform.InverseTransformPoint(a.position.normalized * algorithm.getHeight(a.position));
         * b.position = transform.InverseTransformPoint(b.position.normalized * algorithm.getHeight(b.position));
         * c.position = transform.InverseTransformPoint(c.position.normalized * algorithm.getHeight(c.position));
         * d.position = transform.InverseTransformPoint(d.position.normalized * algorithm.getHeight(d.position));*/

        // Texture coordinates
        a.uv = calcUV(a.position);
        b.uv = calcUV(b.position);
        c.uv = calcUV(c.position);
        d.uv = calcUV(d.position);

        // Add to geometry
        meshData.Add(new Triangle(a, b, c));
        meshData.Add(new Triangle(c, d, a));
    }
Beispiel #2
0
    public void CreatePlane(float width, float depth, int subdivisionSteps)
    {
        this.sizeX            = width;
        this.sizeZ            = depth;
        this.subdivisionSteps = subdivisionSteps;
        // Clear lists
        Points    = new PointList();
        Triangles = new TriangleList();


        // Vertices
        // XZ plane
        addVertex(new Point(sizeX / 2.0f, 0, -sizeZ / 2.0f));
        addVertex(new Point(sizeX / 2.0f, 0, sizeZ / 2.0f));
        addVertex(new Point(-sizeX / 2.0f, 0, -sizeZ / 2.0f));
        addVertex(new Point(-sizeX / 2.0f, 0, sizeZ / 2.0f));

        // Triangles
        Triangles.Add(new Triangle(1, 0, 2));
        Triangles.Add(new Triangle(3, 1, 2));

        Subdivide(subdivisionSteps);

        Debug.Log("Triangle count " + Triangles.Count + " Vertex count " + Points.Count);
    }
Beispiel #3
0
 public static void AddToCollision(Form_AreaEditor @base, VertexList vlist, Vertex[] vs, TriangleList tlist, Triangle[] ts)
 {
     foreach (Vertex v in vs)
     {
         vlist.Add(v);
     }
     foreach (Triangle t in ts)
     {
         tlist.Add(t);
     }
     @base.maps.ReloadCollisionInOpenGL();
 }
Beispiel #4
0
    private void Subdivide(int subdivisionSteps)
    {
        middlePointIndexCache = new Dictionary <Int64, int>();

        for (int i = 0; i < subdivisionSteps; i++)
        {
            var triangles2 = new TriangleList();
            foreach (var tri in Triangles)
            {
                // replace triangle by 4 triangles
                int a = GetMiddlePoint(tri.v1, tri.v2);
                int b = GetMiddlePoint(tri.v2, tri.v3);
                int c = GetMiddlePoint(tri.v3, tri.v1);

                triangles2.Add(new Triangle(tri.v1, a, c));
                triangles2.Add(new Triangle(tri.v2, b, a));
                triangles2.Add(new Triangle(tri.v3, c, b));
                triangles2.Add(new Triangle(a, b, c));
            }
            Triangles = triangles2;
        }
    }
Beispiel #5
0
        /**
         * Add new Triangle
         */
        private void AddTriangle(BSTriangle triangle, bool bCheckHalfEdge = true)
        {
            // see if it's same vertices
            for (int i = 0; i < TriangleList.Count; ++i)
            {
                if (triangle == TriangleList[i])
                {
                    return;
                }

                if (bCheckHalfEdge && triangle.HasSameHalfEdge(TriangleList[i]))
                {
                    return;
                }
            }

            TriangleList.Add(new BSTriangle(triangle.Vertices[0], triangle.Vertices[1], triangle.Vertices[2]));
        }
Beispiel #6
0
    public void CreateIcosphere(float radius, int subdivisionSteps)
    {
        this.radius           = radius;
        this.subdivisionSteps = subdivisionSteps;
        // Clear lists
        Points    = new PointList();
        Triangles = new TriangleList();

        var t = (1.0f + Mathf.Sqrt(5.0f)) / 2.0f;

        // Vertices
        // XY plane
        addVertex(new Point(-1, t, 0));
        addVertex(new Point(1, t, 0));
        addVertex(new Point(-1, -t, 0));
        addVertex(new Point(1, -t, 0));
        // YZ plane
        addVertex(new Point(0, -1, t));
        addVertex(new Point(0, 1, t));
        addVertex(new Point(0, -1, -t));
        addVertex(new Point(0, 1, -t));
        // XZ plane
        addVertex(new Point(t, 0, -1));
        addVertex(new Point(t, 0, 1));
        addVertex(new Point(-t, 0, -1));
        addVertex(new Point(-t, 0, 1));

        // Triangles
        Triangles.Add(new Triangle(0, 11, 5));
        Triangles.Add(new Triangle(0, 5, 1));
        Triangles.Add(new Triangle(0, 1, 7));
        Triangles.Add(new Triangle(0, 7, 10));
        Triangles.Add(new Triangle(0, 10, 11));

        // 5 adjacent triangles
        Triangles.Add(new Triangle(1, 5, 9));
        Triangles.Add(new Triangle(5, 11, 4));
        Triangles.Add(new Triangle(11, 10, 2));
        Triangles.Add(new Triangle(10, 7, 6));
        Triangles.Add(new Triangle(7, 1, 8));

        // 5 triangles around point 3
        Triangles.Add(new Triangle(3, 9, 4));
        Triangles.Add(new Triangle(3, 4, 2));
        Triangles.Add(new Triangle(3, 2, 6));
        Triangles.Add(new Triangle(3, 6, 8));
        Triangles.Add(new Triangle(3, 8, 9));

        // 5 adjacent triangles
        Triangles.Add(new Triangle(4, 9, 5));
        Triangles.Add(new Triangle(2, 4, 11));
        Triangles.Add(new Triangle(6, 2, 10));
        Triangles.Add(new Triangle(8, 6, 7));
        Triangles.Add(new Triangle(9, 8, 1));


        Subdivide(subdivisionSteps);

        Debug.Log("Triangle count " + Triangles.Count + " Vertex count " + Points.Count);
    }