Tuesday, November 15, 2022
HomeGame DevelopmentAttaching gameObjects to a shifting Mesh by place retrieved from triangle index

Attaching gameObjects to a shifting Mesh by place retrieved from triangle index


I’m attempting to connect GameObjects testAttach to triangle indices in trianglesToAttachTo on a mesh, name it goMesh. I’ve recognized the triangleIndices I need to connect to from retrieving by way of RaycastHit.triangleIndex however I appear to run into points like: IndexOutOfRangeException: Index was exterior the bounds of the array. I’ve tried eradicating the three multiplier, however that results in positions that don’t replicate the chosen triangle positions.

Tremendous fast check script:

public class AttachToFaceMeshEars : MonoBehaviour
{
    public GameObject[] testAttach;

    public int[] trianglesToAttachTo = { 1604, 1982 };

    public GameObject goMesh;
     
    void Replace()
    {
        Take a look at(goMesh);
    }

    void Take a look at(GameObject g)
    {
        for (int i = 0; i < testAttach.Size; i++) AttachTo(g,g.GetComponent<MeshFilter>().mesh, trianglesToAttachTo[i], testAttach[i]);
    }

    void AttachTo(GameObject goMesh,Mesh mesh,int triangle,GameObject go)
    {
        int[] tris = mesh.triangles;
        Vector3[] vertices = mesh.vertices;
        Vector3 p0 = vertices[ 3 * tris[triangle] ];

        go.remodel.place = goMesh.remodel.TransformPoint(p0);
    }

}

````

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments