Пример #1
0
    // Updates overlay surface mesh. Returns true on success, false if the surface needs to be deleted
    private bool UpdateOverlaySurface(OverlaySurfaceUpdater overlaySurface, DetectedPlane trackedSurface)
    {
        // check for validity
        if (overlaySurface == null || trackedSurface == null)
        {
            return(false);
        }
        else if (trackedSurface.SubsumedBy != null)
        {
            return(false);
        }
        else if (trackedSurface.TrackingState != TrackingState.Tracking)
        {
            overlaySurface.SetEnabled(false);
            return(true);
        }

        // enable the surface
        overlaySurface.SetEnabled(true);

        // estimate mesh vertices
        List <Vector3> meshVertices = new List <Vector3>();

        // GetBoundaryPolygon returns points in clockwise order.
        trackedSurface.GetBoundaryPolygon(meshVertices);
        int verticeLength = meshVertices.Count;

        // surface position & rotation
        Vector3    surfacePos = trackedSurface.CenterPose.position;       // Vector3.zero; //
        Quaternion surfaceRot = trackedSurface.CenterPose.rotation;       // Quaternion.identity; //

        // estimate vertices relative to the center
        Quaternion invRot = Quaternion.Inverse(surfaceRot);

        for (int v = verticeLength - 1; v >= 0; v--)
        {
            meshVertices[v] -= surfacePos;
            meshVertices[v]  = invRot * meshVertices[v];

            if (Mathf.Abs(meshVertices[v].y) > 0.1f)
            {
                meshVertices.RemoveAt(v);
            }
        }

        // estimate mesh indices
        List <int> meshIndices = MultiARInterop.GetMeshIndices(meshVertices.Count);

        // update the surface mesh
        overlaySurface.UpdateSurfaceMesh(surfacePos, surfaceRot, meshVertices, meshIndices);

        return(true);
    }
    // Updates overlay surface mesh. Returns true on success, false if the surface needs to be deleted
    private bool UpdateOverlaySurface(OverlaySurfaceUpdater overlaySurface, ARPlaneAnchor arPlaneAnchor)
    {
        // check for validity
        if (overlaySurface == null)
        {
            return(false);
        }

        // estimate mesh vertices & indices
        overlaySurface.SetEnabled(true);

        List <Vector3> meshVertices = new List <Vector3>();

        // surface position & rotation
        Vector3    surfacePos = UnityARMatrixOps.GetPosition(arPlaneAnchor.transform);       // Vector3.zero; //
        Quaternion surfaceRot = UnityARMatrixOps.GetRotation(arPlaneAnchor.transform);       // Quaternion.identity; //

        // add the center offset
        Vector3 centerPos = arPlaneAnchor.center;

        centerPos.z = -centerPos.z;

        centerPos   = surfaceRot * centerPos;
        surfacePos += centerPos;

//		Vector3 planeHalf = arPlaneAnchor.extent * 0.5f;
//		meshVertices.Add(new Vector3(-planeHalf.x, planeHalf.y, planeHalf.z));
//		meshVertices.Add(new Vector3(planeHalf.x, planeHalf.y, planeHalf.z));
//		meshVertices.Add(new Vector3(planeHalf.x, planeHalf.y, -planeHalf.z));
//		meshVertices.Add(new Vector3(-planeHalf.x, planeHalf.y, -planeHalf.z));
//
//		// estimate mesh indices
//		List<int> meshIndices = MultiARInterop.GetMeshIndices(meshVertices.Count);

        meshVertices.AddRange(arPlaneAnchor.planeGeometry.vertices);
        List <int> meshIndices = new List <int>(arPlaneAnchor.planeGeometry.triangleIndices);

        // update the surface mesh
        overlaySurface.UpdateSurfaceMesh(surfacePos, surfaceRot, meshVertices, meshIndices);

        return(true);
    }