1
\$\begingroup\$

I want to get all the vertices of an 3D object.

I'm using this:

public List<Vector3> getVertices()
{
    MeshFilter meshFilter = GetComponent<MeshFilter>();
    List<Vector3> lst = new List<Vector3>();

    if (meshFilter != null)
    {
        Mesh mesh = meshFilter.sharedMesh;
    
        // Get the vertices of the mesh and transform to world space
        foreach (Vector3 vertex in mesh.vertices)
        {
            Vector3 trnsvertex = transform.TransformPoint(vertex);
            lst.Add(trnsvertex);
        }
        
        // Now add points within the volume of the balloon
        Bounds bounds = mesh.bounds;
        Vector3 center = bounds.center;
        Vector3 extents = bounds.extents;
        int pointsInside = 1; // Adjust this to change the number of internal points
        
        // Scaling factors to map unit sphere points to the balloon ellipsoid
        Vector3 scale = extents;
        
        for (int i = 0; i < pointsInside; i++)
        {
            // Generate a random point inside a unit sphere
            Vector3 randomPointInSphere = Random.insideUnitSphere;
        
            // Scale to the balloon's ellipsoid dimensions
            Vector3 randomPointInEllipsoid = new Vector3(
                randomPointInSphere.x * scale.x,
                randomPointInSphere.y * scale.y,
                randomPointInSphere.z * scale.z
            );
        
            // Transform to world space
            Vector3 worldPoint = transform.TransformPoint(randomPointInEllipsoid + center);
            lst.Add(worldPoint);
        }
    }

    return lst;
}

It works fine, but the problem is it's giving me only the vertices of what we can see (only from outside),

I also want to get the vertices of what's inside this object. In other words, I want to get all the vertices that the objects cover.

How do I do that?

\$\endgroup\$

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.