Beispiel #1
0
    void buildMesh()
    {
        HE_Mesh mesh = new HE_Mesh();

        mesh = container.get();

        meshes.Add(mesh);
        centers.Add(new PVector());
    }
Beispiel #2
0
    public override void mousePressed()
    {
        PVector        O          = new PVector(random(-S, S), random(-S, S), random(-S, S));
        Plane          P          = new Plane(O, new PVector(random(-1, 1), random(-1, 1), random(-1, 1)));
        List <HE_Mesh> newMeshes  = new List <HE_Mesh> ();
        List <PVector> newCenters = new List <PVector> ();

        for (int i = 0; i < meshes.Count; i++)
        {
            HE_Mesh mesh  = (HE_Mesh)meshes [i];
            HE_Mesh mesh2 = mesh.get();
            mesh.cutMesh(P, new PVector());
            mesh2.cutMesh(P, new PVector(2 * O.x, 2 * O.y, 2 * O.z));
            newMeshes.Add(mesh);
            newMeshes.Add(mesh2);

            PVector center = new PVector();
            for (int j = 0; j < mesh.vertices.Count; j++)
            {
                HE_Vertex v = (HE_Vertex)mesh.vertices [j];
                center.add(v);
            }
            center.div(mesh.vertices.Count);
            newCenters.Add(center);

            center = new PVector();
            for (int j = 0; j < mesh2.vertices.Count; j++)
            {
                HE_Vertex v = (HE_Vertex)mesh2.vertices [j];
                center.add(v);
            }
            center.div(mesh2.vertices.Count);
            newCenters.Add(center);
        }
        meshes  = newMeshes;
        centers = newCenters;

        //
        drawMesh();
    }
Beispiel #3
0
    // A hack-n-slash approach to voronoi, literally. The individual cells are created by iteratively splitting
    // the container mesh by the bisector planes of all other points. (Bisector plane = plane perpendicular to line
    // between two points, positioned halfway between the points)

    void buildVoronoi()
    {
        for (int i = 0; i < numPoints; i++)
        {
            // each Voronoi cell starts as the entire container
            voronoiCells [i] = container.get();
        }
        for (int i = 0; i < numPoints; i++)
        {
            for (int j = 0; j < numPoints; j++)
            {
                if (i != j)
                {
                    PVector N = PVector.sub(points [j], points [i]);                      // plane normal=normalized vector pinting from point i to point j
                    N.normalize();
                    PVector O = PVector.add(points [j], points [i]);                      // plane origin=point halfway between point i and point j
                    O.mult(0.5f);

                    O.x += N.x * offset_size;
                    O.y += N.y * offset_size;
                    O.z += N.z * offset_size;

                    P = new Plane(O, N);
                    voronoiCells [i].cutMesh(P, points [i]);
                }
            }
        }

        for (int i = 0; i < numPoints; i++)
        {
            centers [i] = new PVector();
            for (int j = 0; j < voronoiCells[i].vertices.Count; j++)
            {
                HE_Vertex v = (HE_Vertex)voronoiCells [i].vertices [j];
                centers [i].add(v);
            }
            centers [i].div(voronoiCells [i].vertices.Count);
        }
    }