Log in or register to post comments

Shapes Combined from Trackers Unity3D Vuforia

August 24, 2017 - 12:40am #1

https://www.youtube.com/watch?v=Tk31uGo7xHo

Hello

I tried to create a code by watching the video of the link.

However, it is not drawn like a Youtube, and it is drawn much higher.

I would be pleased if you could help.

I Attach the code.

======================================================================================

            GameObject.Find("Field").GetComponent<lineRenderer_Shtud>().myarr.Add(mTrackableBehaviour.TrackableName);

            GameObject.Find("Field").GetComponent<lineRenderer_Shtud>().ImageCount++;

======================================================================================

public class lineRenderer_Shtud : MonoBehaviour {

    public int ImageCount;

    public GameObject[] Shapes;

    public string[] ShapesStr = new string[4];

    public ArrayList myarr = new ArrayList();

    private LineRenderer lineRenderer;

    private Vector2[] go_points;

    private MeshFilter filter;

private void draw()

    {

        // Create Vector2 vertices

        Vector2[] vertices2D = go_points;

       

        // Use the triangulator to get indices for creating triangles

        Triangulator tr = new Triangulator(vertices2D);

        int[] indices = tr.Triangulate();

        // Create the Vector3 vertices

        Vector3[] vertices = new Vector3[vertices2D.Length];

        for (int i = 0; i < vertices.Length; i++)

        {

            GameObject TT = GameObject.Find(myarr[i].ToString());

            vertices[i] = new Vector3(TT.transform.position.x, TT.transform.position.y, TT.transform.position.z);

        }

        // Create the mesh

        Mesh msh = new Mesh();

        msh.vertices = vertices;

        msh.triangles = indices;

        msh.RecalculateNormals();

        msh.RecalculateBounds();

        // Set up game object with mesh;

        filter.mesh = msh;

    }

    private double distance(float x1, float y1, float x2, float y2)

    {

        float a = Math.Abs(x1 - x2);

        float b = Math.Abs(y1 - y2);

        double c = Math.Sqrt(a * a + b * b);

        return c;

    }

}

======================================================================================

The difference from video is that the video pre-defined the object and draws a line.

When I recognize the image, I add the name to myarr in the drawing script, find the object with the name contained in myarr in the line drawing script, and draw the line.

 

I would appreciate any help.

thank you.

By SEONHO

AttachmentSize
Image icon Nodelete.png144.22 KB
Log in or register to post comments