/// <summary> /// ID's all of SpatialMappingObserver's store meshes as visible or not, updates class metadata. /// Renders mesh bounds if VisualizeBounds. /// </summary> public List <bool> UpdateVertices(Intersector.Frustum SensorView) { Density = observer.Density; // Adjust Sensor.FOV by specified factor... FOV = new Intersector.ViewVector(FOVFactor * SensorView.FOV.Phi, FOVFactor * SensorView.FOV.Phi); SensorView.FOV = FOV; // create fresh lists, metadata List <bool> visiblilty = new List <bool>(); List <Visualizer.Content> toRender = new List <Visualizer.Content>(); TotalMeshCount = 0; TotalTriangleCount = 0; TotalVertexCount = 0; MeshesInView = 0; TrianglesInView = 0; VerticesInView = 0; // add colors if necessary while (VB && BoundColors.Count < observer.SurfaceObjects.Count) { BoundColors.Add(Visualizer.RandomColor(BoundsColor1, BoundsColor2)); } // check meshes for visiblity for (int i = 0; i < observer.ExtraData.Count; i++) { SurfacePoints extras = observer.ExtraData[i]; bool isVisible = MeshInter.AnyInView(extras.IntersectPts, SensorView); visiblilty.Add(isVisible); if (isVisible) { // update metadata MeshesInView++; TrianglesInView += extras.TriangleCount; VerticesInView += extras.Wvertices.Count; // setup bounding box visualization if (VB) { toRender.AddRange(Visualizer.CreateMarkers(extras.IntersectPts, MarkerSize, BoundColors[i])); toRender.AddRange(Visualizer.CreateBoundingLines(extras.BoundsBox, LineSize, BoundColors[i])); } } // update metadata totals TotalMeshCount++; TotalTriangleCount += extras.TriangleCount; TotalVertexCount += extras.Wvertices.Count; } if (VB) { BoundsVis.Visualize(toRender); } return(visiblilty); }
/// <summary> /// ID's all of SpatialMappingObserver's store meshes as visible or not, updates class metadata. /// Renders mesh bounds if VisualizeBounds. /// </summary> public List <bool> UpdateVertices(Intersector.Frustum SensorView) { Density = observer.Density; // Adjust Sensor.FOV by specified factor... FOV = new Intersector.ViewVector(FOVFactor * SensorView.FOV.Phi, FOVFactor * SensorView.FOV.Phi); SensorView.FOV = FOV; // create fresh lists, metadata List <bool> visiblilty = new List <bool>(); TotalMeshCount = 0; TotalTriangleCount = 0; TotalVertexCount = 0; MeshesInView = 0; TrianglesInView = 0; VerticesInView = 0; // check meshes for visiblity for (int i = 0; i < observer.ExtraData.Count; i++) { SurfacePoints extras = observer.ExtraData[i]; bool isVisible = MeshInter.AnyInView(extras.IntersectPts, SensorView); visiblilty.Add(isVisible); if (isVisible) { // update metadata MeshesInView++; TrianglesInView += extras.TriangleCount; VerticesInView += extras.Wvertices.Count; } // update metadata totals TotalMeshCount++; TotalTriangleCount += extras.TriangleCount; TotalVertexCount += extras.Wvertices.Count; } return(visiblilty); }
/// <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); }