Esempio n. 1
0
            private void RaycastEntity(HaE_Entity entity)
            {
                Vector3D   extrapolatedPosition = TrackingUtils.GetPredictedEntityLocation(entity);
                HaE_Entity detectedEntity       = RaycastPosition(extrapolatedPosition);

                if (detectedEntity == null)
                {
                    if (!AttemptReScan(entity))
                    {
                        return;
                    }
                }

                OnEntityDetected?.Invoke(detectedEntity);
            }
Esempio n. 2
0
            private bool AttemptReScan(HaE_Entity entity)
            {
                Vector3D Direction = entity.entityInfo.Position - reference.GetPosition();
                double   distance  = Direction.Normalize();

                for (int i = 0; i < MaxReScanAmount; i++)
                {
                    Vector3D   scanDir  = TrackingUtils.GenerateShotgunVector(random, Direction, ReScanConeAngle);
                    HaE_Entity detected = RaycastDirection(Direction, distance * ReScanMultiplier);

                    if (detected != null)
                    {
                        OnEntityDetected?.Invoke(detected);
                        return(true);
                    }
                }

                return(false);
            }
Esempio n. 3
0
    public void Update()
    {
        // Fill in the data to draw the point cloud.
        if (Frame.PointCloud.IsUpdatedThisFrame)
        {
            // Copy the point cloud points for mesh verticies.
            for (int i = 0; i < Frame.PointCloud.PointCount; i++)
            {
                // Updates points from arcore to sturfee so that it can be visible from XrCamera
                _points[i] = TrackingUtils.TrackingPosToSturfeePos(Frame.PointCloud.GetPointAsStruct(i));
            }

            // Update the mesh indicies array.
            int[] indices = new int[Frame.PointCloud.PointCount];
            for (int i = 0; i < Frame.PointCloud.PointCount; i++)
            {
                indices[i] = i;
            }

            _mesh.Clear();
            _mesh.vertices = _points;
            _mesh.SetIndices(indices, MeshTopology.Points, 0);
        }
    }
Esempio n. 4
0
    /// <summary>
    /// Update mesh with a list of Vector3 and plane's center position.
    /// </summary>
    private void _UpdateMeshIfNeeded()
    {
        m_DetectedPlane.GetBoundaryPolygon(m_MeshVertices);

        if (_AreVerticesListsEqual(m_PreviousFrameMeshVertices, m_MeshVertices))
        {
            return;
        }

        m_PreviousFrameMeshVertices.Clear();
        m_PreviousFrameMeshVertices.AddRange(m_MeshVertices);

        m_PlaneCenter = m_DetectedPlane.CenterPose.position;

        Vector3 planeNormal = m_DetectedPlane.CenterPose.rotation * Vector3.up;

        m_MeshRenderer.material.SetVector("_PlaneNormal", planeNormal);

        int planePolygonCount = m_MeshVertices.Count;

        // The following code converts a polygon to a mesh with two polygons, inner
        // polygon renders with 100% opacity and fade out to outter polygon with opacity 0%, as shown below.
        // The indices shown in the diagram are used in comments below.
        // _______________     0_______________1
        // |             |      |4___________5|
        // |             |      | |         | |
        // |             | =>   | |         | |
        // |             |      | |         | |
        // |             |      |7-----------6|
        // ---------------     3---------------2
        m_MeshColors.Clear();

        // Fill transparent color to vertices 0 to 3.
        for (int i = 0; i < planePolygonCount; ++i)
        {
            m_MeshColors.Add(Color.clear);
        }

        // Feather distance 0.2 meters.
        const float featherLength = 0.2f;

        // Feather scale over the distance between plane center and vertices.
        const float featherScale = 0.2f;

        // Add vertex 4 to 7.
        for (int i = 0; i < planePolygonCount; ++i)
        {
            Vector3 v = m_MeshVertices[i];

            // Vector from plane center to current point
            Vector3 d = v - m_PlaneCenter;

            float scale = 1.0f - Mathf.Min(featherLength / d.magnitude, featherScale);
            m_MeshVertices.Add((scale * d) + m_PlaneCenter);

            m_MeshColors.Add(Color.white);
        }

        m_MeshIndices.Clear();
        int firstOuterVertex = 0;
        int firstInnerVertex = planePolygonCount;

        // Generate triangle (4, 5, 6) and (4, 6, 7).
        for (int i = 0; i < planePolygonCount - 2; ++i)
        {
            m_MeshIndices.Add(firstInnerVertex);
            m_MeshIndices.Add(firstInnerVertex + i + 1);
            m_MeshIndices.Add(firstInnerVertex + i + 2);
        }

        // Generate triangle (0, 1, 4), (4, 1, 5), (5, 1, 2), (5, 2, 6), (6, 2, 3), (6, 3, 7)
        // (7, 3, 0), (7, 0, 4)
        for (int i = 0; i < planePolygonCount; ++i)
        {
            int outerVertex1 = firstOuterVertex + i;
            int outerVertex2 = firstOuterVertex + ((i + 1) % planePolygonCount);
            int innerVertex1 = firstInnerVertex + i;
            int innerVertex2 = firstInnerVertex + ((i + 1) % planePolygonCount);

            m_MeshIndices.Add(outerVertex1);
            m_MeshIndices.Add(outerVertex2);
            m_MeshIndices.Add(innerVertex1);

            m_MeshIndices.Add(innerVertex1);
            m_MeshIndices.Add(outerVertex2);
            m_MeshIndices.Add(innerVertex2);
        }


        for (int i = 0; i < m_MeshVertices.Count; i++)
        {
            m_MeshVertices[i] = TrackingUtils.TrackingPosToSturfeePos(m_MeshVertices[i]);
        }

        m_Mesh.Clear();
        m_Mesh.SetVertices(m_MeshVertices);
        m_Mesh.SetIndices(m_MeshIndices.ToArray(), MeshTopology.Triangles, 0);
        m_Mesh.SetColors(m_MeshColors);
    }