Пример #1
0
    public void OnPlaneTracked(Wikitude.Plane trackedPlane)
    {
        GameObject renderPlane;

        if (_renderPlanes.TryGetValue(trackedPlane.ID, out renderPlane))
        {
            UpdateMesh(renderPlane, renderPlane.GetComponent <MeshFilter>().sharedMesh, trackedPlane);
        }
        else
        {
            Debug.LogError("Could not find tracked plane with ID: " + trackedPlane.ID);
        }
    }
Пример #2
0
    public void OnPlaneLost(Wikitude.Plane lostPlane)
    {
        GameObject renderPlane;

        if (_renderPlanes.TryGetValue(lostPlane.ID, out renderPlane))
        {
            _renderPlanes.Remove(lostPlane.ID);
            Destroy(renderPlane);
        }
        else
        {
            Debug.LogError("Could not find lost plane with ID: " + lostPlane.ID);
        }
    }
Пример #3
0
    public void OnPlaneRecognized(Wikitude.Plane recognizedPlane)
    {
        var renderPlane = new GameObject("Plane");

        renderPlane.transform.SetParent(recognizedPlane.Drawable.transform);

        var mesh = new Mesh();

        renderPlane.AddComponent <MeshFilter>().mesh       = mesh;
        renderPlane.AddComponent <MeshRenderer>().material = new Material(RenderPlaneMaterial);

        UpdateMesh(renderPlane, mesh, recognizedPlane);

        _renderPlanes.Add(recognizedPlane.ID, renderPlane);
    }
Пример #4
0
    private void UpdateMesh(GameObject renderPlane, Mesh mesh, Wikitude.Plane plane)
    {
        /* Convert the raw float array into a list of vectors, making it easier to work with. */
        int            vertexCount = plane.ConvexHull.Length / 2;
        List <Vector3> convexHull  = new List <Vector3>(vertexCount);

        for (int i = 0; i < vertexCount; ++i)
        {
            convexHull.Add(new Vector3(plane.ConvexHull[i * 2], 0.0f, plane.ConvexHull[i * 2 + 1]));
        }

        var inset = ComputeInset(convexHull);

        /* The sign of the fadeDistance decides which polygon is outside, and which one is inside. */
        if (FadeDistance > 0)
        {
            UpdateMeshGeometry(mesh, convexHull, inset);
        }
        else
        {
            UpdateMeshGeometry(mesh, inset, convexHull);
        }

        /* Select different colors based on the plane type. */
        Color32 color = Color.white;

        switch (plane.PlaneType)
        {
        case PlaneType.HorizontalUpward:
        case PlaneType.HorizontalDownward: {
            color = new Color32(0, 0, 255, 102);
            break;
        }

        case PlaneType.Vertical: {
            color = new Color32(237, 33, 200, 102);
            break;
        }

        case PlaneType.Arbitrary: {
            color = new Color32(64, 237, 33, 102);
            break;
        }
        }

        renderPlane.GetComponent <MeshRenderer>().sharedMaterial.SetColor("_Color", color);
    }