I created a project that uses data from MediaPipe via a UDP source to capture points of the palm of the hand and finally create a procedural mesh to create a palm surface. This surface is meant to interact with objects in the scene, but even though I added a collider, to the mesh, it does not interact with the objects. I found multiple threads regarding colliders and meshes, but none have solved my problem. Does it have to do with baking it?
See code below:
using UnityEngine;
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer), typeof(MeshCollider))]
public class ProceduralPalm : MonoBehaviour
{
public UDPReceive udpReceive;
Mesh mesh;
MeshCollider collide;
Vector3[] vertices;
int[] triangles;
public HandTracking handTracking;
void Start()
{
mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;
collide = GetComponent<MeshCollider>();
collide.sharedMesh = null;
collide.sharedMesh = mesh;
mesh.RecalculateBounds();
CreateShape();
UpdateMesh();
}
// Creates shape from vectors provided by the UDP Data Stream
void CreateShape()
{
vertices = new Vector3[]
{
new Vector3 (handTracking.x17, handTracking.y17, handTracking.z17),
new Vector3 (handTracking.x13, handTracking.y13, handTracking.z13),
new Vector3 (handTracking.x0, handTracking.y0, handTracking.z0),
new Vector3 (handTracking.x1, handTracking.y1, handTracking.z1),
new Vector3 (handTracking.x2, handTracking.y2, handTracking.z2),
new Vector3 (handTracking.x9, handTracking.y9, handTracking.z9),
new Vector3 (handTracking.x5, handTracking.y5, handTracking.z5)
};
triangles = new int[]
{
0, 1, 2, 2, 1, 3, 3, 1, 4, 4, 1, 5, 4, 5, 6,
//Reverse side of Normals begins here
2, 1, 0, 3, 1, 2, 4, 1, 3, 5, 1, 4, 6, 5, 4
};
}
void UpdateMesh()
{
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
}
void Update()
{
CreateShape();
UpdateMesh();
}
}