// Called when the GameObject is first created.
        protected override void Awake()
        {
            base.Awake();

            surfaceObserver = gameObject.GetComponent <SpatialMappingObserver>();
            Source          = surfaceObserver;
        }
Esempio n. 2
0
        // Called when the GameObject is first created.
        protected override void Awake()
        {
            base.Awake();

            // Add debug text logger
            logger = Canvas.GetComponent <LogStates>();

            surfaceObserver = gameObject.GetComponent <SpatialMappingObserver>();
            Source          = surfaceObserver;
        }
Esempio n. 3
0
    /// <summary>
    /// Updates parameter list of cached vertices, updates class metadata.
    /// Renders mesh bounds if VisualizeBounds.
    /// </summary>
    public List <Vector3> UpdateVertices(Intersector.Frustum SensorView)
    {
        // can only call GetComponent in Start() or Awake() but this is not a MonoBehaiour Script
        // SpatialMappingObserver is not a Singleton, cannot use Instance.
        observer = GetComponent <HoloToolkit.Unity.SpatialMapping.SpatialMappingObserver>();
        Density  = observer.TrianglesPerCubicMeter;
        // Adjust Sensor.FOV by specified factor
        SensorView.FOV.Theta = FOVFactor * SensorView.FOV.Theta;
        SensorView.FOV.Phi   = FOVFactor * SensorView.FOV.Phi;

        // create fresh lists, metadata
        List <Vector3>      vertices      = new List <Vector3>();
        List <MeshFilter>   MeshFilters   = observer.GetMeshFilters();
        List <MeshRenderer> MeshRenderers = observer.GetMeshRenderers();
        List <Intersector.PointValue <byte> > BoundPoints = new List <Intersector.PointValue <byte> >();
        List <Visualizer.Content>             toRender    = new List <Visualizer.Content>();

        TotalMeshCount     = 0;
        TotalTriangleCount = 0;
        TotalVertexCount   = 0;
        VerticesInView     = 0;
        TrianglesInView    = 0;
        MeshesInView       = 0;

        if (MeshFilters.Count != MeshRenderers.Count)
        {
            Debug.Log(string.Format("SpatialMappingObserver's returned MeshFilters count does not match " +
                                    "returned MeshRenderers count: {0} vs. {1}",
                                    MeshFilters.Count, MeshRenderers.Count));
        }

        // add colors if necessary
        while (VB && BoundColors.Count < MeshFilters.Count)
        {
            BoundColors.Add(Visualizer.RandomColor(BoundsColor1, BoundsColor2));
        }

        for (int i = 0; i < MeshFilters.Count; i++)
        {
            MeshRenderer tmpRenderer  = MeshRenderers[i];
            Transform    tmpTransform = tmpRenderer.transform;

            List <Vector3> ThisBoundPoints = MBounds(tmpRenderer.bounds);
            foreach (Vector3 point in ThisBoundPoints)
            {
                BoundPoints.Add(new Intersector.PointValue <byte>(point, default(byte)));
            }

            // check if mesh is visible
            if (MeshInter.AnyInView(ThisBoundPoints, SensorView))
            {
                Mesh           tmpMesh     = MeshFilters[i].sharedMesh;
                List <Vector3> tmpVertices = tmpMesh.vertices.ToList();

                // update metadata visibles
                MeshesInView++;
                TrianglesInView += tmpMesh.triangles.ToList().Count();
                VerticesInView  += tmpMesh.vertices.ToList().Count();

                for (int j = 0; j < tmpVertices.Count; j++)
                {
                    vertices.Add(tmpTransform.TransformPoint(tmpVertices[j]));
                }

                if (VB)
                {
                    // setup bounding box visualization
                    toRender.AddRange(Visualizer.CreateMarkers(ThisBoundPoints,
                                                               MarkerSize, BoundColors[i]));
                    toRender.AddRange(Visualizer.CreateBoundingLines(tmpRenderer.bounds,
                                                                     LineSize, BoundColors[i]));
                }
            }

            // update metadata totals
            TotalMeshCount++;
            TotalTriangleCount += MeshFilters[i].sharedMesh.triangles.ToList().Count();
            TotalVertexCount   += MeshFilters[i].sharedMesh.vertices.ToList().Count();
        }

        /*
         * // test code
         * BoundColors.Add(Visualizer.RandomColor(BoundsColor1, BoundsColor2));
         * Bounds dummyBounds1 = new Bounds(new Vector3(1, 1, 1), new Vector3(1, 1, 1));
         * toRender.AddRange(Visualizer.CreateMarkers(MBounds(dummyBounds1), MarkerSize, BoundColors[0]));
         * toRender.AddRange(Visualizer.CreateBoundingLines(dummyBounds1, LineSize, BoundColors[0]));
         *
         * BoundColors.Add(Visualizer.RandomColor(BoundsColor1, BoundsColor2));
         * Bounds dummyBounds2 = new Bounds(new Vector3(-1, 1, 1), new Vector3(1, 1, 1));
         * toRender.AddRange(Visualizer.CreateMarkers(MBounds(dummyBounds2), MarkerSize, BoundColors[1]));
         * toRender.AddRange(Visualizer.CreateBoundingLines(dummyBounds2, LineSize, BoundColors[1]));
         */

        if (VB)
        {
            BoundsVis.Visualize(toRender);
        }

        return(vertices);
    }