Example #1
0
    public LightingUnit(Vector3 p, PlaneTypes t, GameObject b, float r, int h, string n)
    {
        position  = p;
        planeType = t;
        bulb      = b;
        maxRange  = r;
        hits      = h;
        unitType  = n;

        if (unitType == "Type A")
        {
            lux        = 4;
            durability = 3;
            watt       = 100;
        }
        else if (unitType == "Type B")
        {
            lux        = 3;
            durability = 4;
            watt       = 70;
        }
        else
        {
            lux        = 1;
            durability = 6;
            watt       = 10;
        }
    }
        /// <summary>
        /// Gets all active planes of the specified type(s).
        /// </summary>
        /// <param name="planeTypes">A flag which includes all plane type(s) that should be returned.</param>
        /// <returns>A collection of planes that match the expected type(s).</returns>
        public List <GameObject> GetActivePlanes(PlaneTypes planeTypes)
        {
            List <GameObject> typePlanes = new List <GameObject>();

            foreach (GameObject plane in ActivePlanes)
            {
                SurfacePlane surfacePlane = plane.GetComponent <SurfacePlane>();

                if (surfacePlane != null)
                {
                    if ((planeTypes & surfacePlane.PlaneType) == surfacePlane.PlaneType)
                    {
                        if (surfacePlane.PlaneType == PlaneTypes.Table)
                        {
                            plane.tag = "Table";
                        }
                        if (surfacePlane.PlaneType == PlaneTypes.Ceiling)
                        {
                            plane.tag = "Ceiling";
                        }
                        if (surfacePlane.PlaneType == PlaneTypes.Wall)
                        {
                            plane.tag = "Wall";
                        }
                        if (surfacePlane.PlaneType == PlaneTypes.Floor)
                        {
                            plane.tag = "Floor";
                        }
                        typePlanes.Add(plane);
                    }
                }
            }

            return(typePlanes);
        }
 public async void DeletePlaneType()
 {
     if (await service.DeleteEntity(SelectedPlaneType.Id))
     {
         PlaneTypes.Remove(PlaneTypes.FirstOrDefault(c => c.Id == SelectedPlaneType.Id));
     }
 }
        private async void FillPlaneTypesCollection()
        {
            var temp = await service.GetEntities();

            foreach (var item in temp)
            {
                PlaneTypes.Add(item);
            }
        }
Example #5
0
        private async void Create()
        {
            var created = await airportConnector.PlaneTypeEndpoint.Create(newPlaneType);

            PlaneTypes.Add(created);
            newPlaneType = new PlaneType();
            RaisePropertyChanged(() => PlaneTypes);
            RaisePropertyChanged(() => NewPlaneType);
        }
Example #6
0
        /// <summary>
        /// Checks the list of passed in planes for one that might match the passed in bounding plane.
        /// </summary>
        /// <param name="planes"></param>
        /// <param name="plane"></param>
        /// <returns></returns>
        private SurfacePlane CheckForExistingPlane(List <SurfacePlane> planes, BoundedPlane plane)
        {
            SurfacePlane bestMatch       = null;
            float        bestAreaDiff    = float.MaxValue;
            float        bestDistance    = float.MaxValue;
            float        bestDistPercent = float.MaxValue;

            PlaneTypes type = GetPossibleType(plane, m_UpNormalThreshold);

            foreach (SurfacePlane possiblePlane in planes)
            {
                if ((possiblePlane.PlaneType & type) == 0)
                {
                    //Skip this one.
                    continue;
                }

                //What is the area difference?
                float areaDiff        = Mathf.Abs(possiblePlane.Plane.Area - plane.Area);
                float areaDiffPercent = areaDiff / ((possiblePlane.Plane.Area + plane.Area) / 2);

                //What is the distance difference?
                float distDiff          = (possiblePlane.Plane.Bounds.Center - plane.Bounds.Center).sqrMagnitude;
                float distChangePercent = distDiff / (possiblePlane.Plane.Bounds.Center.sqrMagnitude + plane.Bounds.Center.sqrMagnitude) / 2;

                if (areaDiffPercent >= m_MaxAreaDiffPercent || distDiff > m_MaxDistChange)
                {
                    //The difference in these planes are to different so we can ignore this one.
                    continue;
                }
                else if (areaDiffPercent < bestAreaDiff && distDiff < bestDistance)
                {
                    bestMatch       = possiblePlane;
                    bestAreaDiff    = areaDiffPercent;
                    bestDistPercent = distChangePercent;
                    distDiff        = bestDistance;
                }
                else if (areaDiffPercent < bestAreaDiff && areaDiffPercent <= bestDistPercent)
                {
                    bestMatch       = possiblePlane;
                    bestAreaDiff    = areaDiffPercent;
                    bestDistPercent = distChangePercent;
                    distDiff        = bestDistance;
                }
                else if (distDiff < bestDistance && distChangePercent <= areaDiffPercent)
                {
                    bestMatch       = possiblePlane;
                    bestAreaDiff    = areaDiffPercent;
                    bestDistPercent = distChangePercent;
                    distDiff        = bestDistance;
                }
            }

            return(bestMatch);
        }
Example #7
0
 public SurfacePlane(PlaneTypes type, Plane plane, OrientedBoundingBox bounds, TextMeshPro tag, Transform parent)
 {
     Type     = type;
     Plane    = plane;
     Bounds   = bounds;
     Area     = ((bounds.Extents.x * 2) * (bounds.Extents.y * 2));
     Tag      = GameObject.Instantiate(tag, parent);
     Tag.text = Type.ToString();
     Tag.transform.localPosition = bounds.Center;
     Tag.transform.eulerAngles   = new Vector3(bounds.Rotation.eulerAngles.x, bounds.Rotation.eulerAngles.y, 0);
 }
 public async void UpdatePlaneType()
 {
     if (await service.UpdateEntity(SelectedPlaneType.Id, SelectedPlaneType))
     {
         var tempPlaneType = PlaneTypes.FirstOrDefault(c => c.Id == SelectedPlaneType.Id);
         tempPlaneType.Model         = SelectedPlaneType.Model;
         tempPlaneType.MaxHeight     = SelectedPlaneType.MaxHeight;
         tempPlaneType.MaxMass       = SelectedPlaneType.MaxMass;
         tempPlaneType.Places        = SelectedPlaneType.Places;
         tempPlaneType.Speed         = SelectedPlaneType.Speed;
         tempPlaneType.FleightLength = SelectedPlaneType.FleightLength;
     }
 }
Example #9
0
        private async void Delete()
        {
            if (selectedPlaneType == null)
            {
                return;
            }

            await airportConnector.PlaneTypeEndpoint.Delete(selectedPlaneType.Id);

            PlaneTypes.Remove(selectedPlaneType);
            selectedPlaneType = null;
            RaisePropertyChanged(() => PlaneTypes);
            RaisePropertyChanged(() => SelectedPlaneType);
        }
Example #10
0
        /// <summary>
        /// Gets all active planes of the specified type(s).
        /// </summary>
        /// <param name="planeTypes">A flag which includes all plane type(s) that should be returned.</param>
        /// <returns>A collection of planes that match the expected type(s).</returns>
        public List <SurfacePlane> GetActivePlanes(PlaneTypes planeTypes)
        {
            List <SurfacePlane> typePlanes = new List <SurfacePlane>();

            foreach (SurfacePlane plane in m_ActivePlanes)
            {
                if ((planeTypes & plane.PlaneType) == plane.PlaneType)
                {
                    typePlanes.Add(plane);
                }
            }

            return(typePlanes);
        }
Example #11
0
        public static float CalculateArea(GameObject plane)
        {
            Collider   collider   = plane.GetComponent <Collider>();
            PlaneTypes planeTypes = plane.GetComponent <SurfacePlane>().PlaneType;

            if ((planeTypes & (PlaneTypes.Ceiling | PlaneTypes.Floor | PlaneTypes.Table)) > 0)
            {
                return(collider.bounds.size.x * collider.bounds.size.z);
            }
            else if ((planeTypes & (PlaneTypes.Wall)) > 0)
            {
                return(collider.bounds.size.x * collider.bounds.size.y);
            }

            return(0);
        }
        protected void SearchAsync()
        {
            List <PlaneType> temp = PlaneTypes.ToList();

            PlaneTypes.Clear();
            if (string.IsNullOrWhiteSpace(SearchFilter))
            {
                temp.Clear();
                UpdateDataAsync();
            }
            else
            {
                PlaneTypes = new ObservableCollection <PlaneType>(temp.Where(s => s.Model.StartsWith(SearchFilter, StringComparison.CurrentCultureIgnoreCase)).ToList());
            }
            RaisePropertyChanged(nameof(PlaneTypes));
        }
        /// <summary>
        /// Classifies the surface as a floor, wall, ceiling, table, etc.
        /// </summary>
        private void SetPlaneType()
        {
            SurfaceNormal = plane.Plane.normal;
            float floorYPosition   = SurfaceMeshesToPlanes.Instance.FloorYPosition;
            float ceilingYPosition = SurfaceMeshesToPlanes.Instance.CeilingYPosition;

            // Determine what type of plane this is.
            // Use the upNormalThreshold to help determine if we have a horizontal or vertical surface.
            if (SurfaceNormal.y >= UpNormalThreshold)
            {
                // If we have a horizontal surface with a normal pointing up, classify it as a floor.
                PlaneType      = PlaneTypes.Floor;
                gameObject.tag = "Floor";

                if (gameObject.transform.position.y > (floorYPosition + FloorBuffer))
                {
                    // If the plane is too high to be considered part of the floor, classify it as a table.
                    PlaneType      = PlaneTypes.Table;
                    gameObject.tag = "Table";
                }
            }
            else if (SurfaceNormal.y <= -(UpNormalThreshold))
            {
                // If we have a horizontal surface with a normal pointing down, classify it as a ceiling.
                PlaneType      = PlaneTypes.Ceiling;
                gameObject.tag = "Ceiling";

                if (gameObject.transform.position.y < (ceilingYPosition - CeilingBuffer))
                {
                    // If the plane is not high enough to be considered part of the ceiling, classify it as a table.
                    PlaneType      = PlaneTypes.Table;
                    gameObject.tag = "Table";
                }
            }
            else if (Mathf.Abs(SurfaceNormal.y) <= (1 - UpNormalThreshold))
            {
                // If the plane is vertical, then classify it as a wall.
                PlaneType      = PlaneTypes.Wall;
                gameObject.tag = "Wall";
            }
            else
            {
                // The plane has a strange angle, classify it as 'unknown'.
                PlaneType      = PlaneTypes.Unknown;
                gameObject.tag = "Unknown";
            }
        }
Example #14
0
        public static Plane CreatePlane(PlaneTypes planeType)
        {
            switch (planeType)
            {
            case PlaneTypes.AirbusA340:
                return(new AirbusA340Plane());

            case PlaneTypes.Boeing747:
                return(new Boeing747Plane());

            case PlaneTypes.Boeing757:
                return(new Boeing757Plane());

            default:
                return(new Boeing747Plane());
            }
        }
Example #15
0
    /// <summary>
    /// Returns either the largest floor or ceiling based on its type.
    /// </summary>
    /// <param name="planeTypes">Specified surface type.</param>
    /// <returns>The largest surfaceplane if several exist.</returns>
    public SurfacePlane GetFloorOrCeiling(PlaneTypes planeTypes)
    {
        List <SurfacePlane> detectedFloorsOrCeilings = detectedSurfacePlanes.FindAll(p => p.Type == planeTypes);

        // Return first if only one exist
        if (detectedFloorsOrCeilings.Count == 1)
        {
            return(detectedFloorsOrCeilings[0]);
        } // Return empty if none exist
        else if (detectedFloorsOrCeilings.Count == 0)
        {
            return(new SurfacePlane());
        } // Return surface plane with largest area if several exist
        else
        {
            return(detectedFloorsOrCeilings.OrderByDescending(c => c.Area).First());
        }
    }
Example #16
0
        /// <summary>
        /// Gets all active planes of the specified type(s).
        /// </summary>
        /// <param name="planeTypes">A flag which includes all plane type(s) that should be returned.</param>
        /// <returns>A collection of planes that match the expected type(s).</returns>
        public List <GameObject> GetActivePlanes(PlaneTypes planeTypes)
        {
            List <GameObject> typePlanes = new List <GameObject>();

            foreach (GameObject plane in ActivePlanes)
            {
                SurfacePlane surfacePlane = plane.GetComponent <SurfacePlane>();

                if (surfacePlane != null)
                {
                    if ((planeTypes & surfacePlane.PlaneType) == surfacePlane.PlaneType)
                    {
                        typePlanes.Add(plane);
                    }
                }
            }

            return(typePlanes);
        }
Example #17
0
        /// <summary>
        /// Classifies the surface as a floor, wall, ceiling, table, etc.
        /// </summary>
        public PlaneTypes GetPlaneType(BoundedPlane plane)
        {
            Vector3    surfaceNormal = plane.Plane.normal;
            PlaneTypes planeType     = PlaneTypes.Unknown;

            // Determine what type of plane this is.
            // Use the upNormalThreshold to help determine if we have a horizontal or vertical surface.
            if (surfaceNormal.y >= UpNormalThreshold)
            {
                // If we have a horizontal surface with a normal pointing up, classify it as a floor.
                planeType = PlaneTypes.Floor;

                if (plane.Bounds.Center.y > (FloorYPosition + m_FloorBuffer))
                {
                    // If the plane is too high to be considered part of the floor, classify it as a table.
                    planeType = PlaneTypes.Table;
                }
            }
            else if (surfaceNormal.y <= -(UpNormalThreshold))
            {
                // If we have a horizontal surface with a normal pointing down, classify it as a ceiling.
                planeType = PlaneTypes.Ceiling;

                if (plane.Bounds.Center.y < (CeilingYPosition - m_CeilingBuffer))
                {
                    // If the plane is not high enough to be considered part of the ceiling, classify it as a table.
                    planeType = PlaneTypes.Table;
                }
            }
            else if (Mathf.Abs(surfaceNormal.y) <= (1 - UpNormalThreshold))
            {
                // If the plane is vertical, then classify it as a wall.
                planeType = PlaneTypes.Wall;
            }
            else
            {
                // The plane has a strange angle, classify it as 'unknown'.
                planeType = PlaneTypes.Unknown;
            }

            return(planeType);
        }
Example #18
0
    //sets the theme and saves it
    public void SetPlane(string newType)
    {
        switch (newType)
        {
        case "Blue": planeType = PlaneTypes.BluePlane;
            PlayerPrefs.SetString("PlaneColor", "Blue");
            break;

        case "Red": planeType = PlaneTypes.RedPlane;
            PlayerPrefs.SetString("PlaneColor", "Red");
            break;

        case "Green": planeType = PlaneTypes.GreenPlane;
            PlayerPrefs.SetString("PlaneColor", "Green");
            break;

        case "Yellow": planeType = PlaneTypes.YellowPlane;
            PlayerPrefs.SetString("PlaneColor", "Yellow");
            break;
        }
    }
Example #19
0
    public List <GameObject> GetTables()
    {
        PlaneTypes        desired_types = PlaneTypes.Table;
        List <GameObject> planes        = new List <GameObject>();

        foreach (GameObject plane in SurfaceMeshesToPlanes.Instance.ActivePlanes)
        {
            SurfacePlane surfacePlane = plane.GetComponent <SurfacePlane>();
            // Only tables below eye level. SurfacePlane has the unfortunate problem
            // that it creates tables with planes oriented downwards. We ignore these
            // (but maybe we should rotate?).
            if ((surfacePlane.PlaneType & desired_types) == surfacePlane.PlaneType)
            {
                Debug.Log("Found: " + surfacePlane.transform.position.ToString() + ", " + surfacePlane.Plane.Plane.normal.ToString("F2"));
            }
            if ((surfacePlane.PlaneType & desired_types) == surfacePlane.PlaneType && surfacePlane.transform.position.y < 0 && surfacePlane.Plane.Plane.normal.y > 0)
            {
                planes.Add(plane);
            }
        }
        return(planes);
    }
Example #20
0
    private List <GameObject> GetSurfacePlanes(PlaneTypes desiredTypes, SurfacePlaneConstraint ExtraConstraints, SortOrder sortOrder)
    {
        List <GameObject> planes = new List <GameObject>();

        foreach (GameObject plane in SurfaceMeshesToPlanes.Instance.ActivePlanes)
        {
            SurfacePlane surfacePlane = plane.GetComponent <SurfacePlane>();
            if ((surfacePlane.PlaneType & desiredTypes) == surfacePlane.PlaneType && ExtraConstraints(surfacePlane))
            {
                planes.Add(plane);
            }
        }
        planes.Sort((plane1, plane2) =>
        {
            BoundedPlane bp1 = plane1.GetComponent <SurfacePlane>().Plane;
            BoundedPlane bp2 = plane2.GetComponent <SurfacePlane>().Plane;
            // Sort descending
            int result = 0;
            switch (sortOrder)
            {
            case SortOrder.None:
                result = 0;
                break;

            case SortOrder.Descending:
                result = bp2.Area.CompareTo(bp1.Area);
                break;

            case SortOrder.Ascending:
                result = bp1.Area.CompareTo(bp2.Area);
                break;
            }
            return(result);
        });
        return(planes);
    }
Example #21
0
 List <GameObject> GetPlanesForPlaneTypes(PlaneTypes planeTypes)
 {
     return(SurfaceMeshesToPlanes.Instance.GetActivePlanes(planeTypes));
 }
Example #22
0
 /// <summary>
 /// Returns all detected surface planes of a specific type.
 /// </summary>
 /// <param name="planeTypes">Specified surface type.</param>
 /// <returns>List of surface planes of the specified type.</returns>
 public List <SurfacePlane> GetDetectedSurfacePlanesByType(PlaneTypes planeTypes)
 {
     return(detectedSurfacePlanes.FindAll(p => p.Type == planeTypes));
 }
Example #23
0
    IEnumerator FindPlacesForBoundsCoroutine(Bounds bounds, float minDistanceFromUser, float maxDistanceFromUser, PlaneTypes planeTypes, int numberOfPlacesToFind)
    {
        List <GameObject> planes = GetPlanesForPlaneTypes(planeTypes);

        foreach (GameObject plane in planes)
        {
            FindPlacesOnPlane(bounds, minDistanceFromUser, maxDistanceFromUser, plane, numberOfPlacesToFind, foundPlaces);
            yield return(null);
        }

        IsSearching = false;

        OnPlaceSearchComplete(foundPlaces);
    }
        /// <summary>
        /// Classifies the surface as a floor, wall, ceiling, table, etc.
        /// </summary>
        private void SetPlaneType()
        {
            SurfaceNormal = plane.Plane.normal;
            float floorYPosition = SurfaceMeshesToPlanes.Instance.FloorYPosition;
            float ceilingYPosition = SurfaceMeshesToPlanes.Instance.CeilingYPosition;

            // Determine what type of plane this is.
            // Use the upNormalThreshold to help determine if we have a horizontal or vertical surface.
            if (SurfaceNormal.y >= UpNormalThreshold)
            {
                // If we have a horizontal surface with a normal pointing up, classify it as a floor.
                PlaneType = PlaneTypes.Floor;

                if (gameObject.transform.position.y > (floorYPosition + FloorBuffer))
                {
                    // If the plane is too high to be considered part of the floor, classify it as a table.
                    PlaneType = PlaneTypes.Table;
                }
            }
            else if (SurfaceNormal.y <= -(UpNormalThreshold))
            {
                // If we have a horizontal surface with a normal pointing down, classify it as a ceiling.
                PlaneType = PlaneTypes.Ceiling;

                if (gameObject.transform.position.y < (ceilingYPosition - CeilingBuffer))
                {
                    // If the plane is not high enough to be considered part of the ceiling, classify it as a table.
                    PlaneType = PlaneTypes.Table;
                }
            }
            else if (Mathf.Abs(SurfaceNormal.y) <= (1 - UpNormalThreshold))
            {
                // If the plane is vertical, then classify it as a wall.
                PlaneType = PlaneTypes.Wall;
            }
            else
            {
                // The plane has a strange angle, classify it as 'unknown'.
                PlaneType = PlaneTypes.Unknown;
            }
        }
Example #25
0
 public List <BoundedPlane> GetPlaneOfType(PlaneTypes _planeType)
 {
     return(m_mergedSemanticPlanes[_planeType]);
 }
Example #26
0
        /// <summary>
        /// Gets the closest plane to a provided world position of one of the types defined by validTypes
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="validTypes"></param>
        /// <returns></returns>
        public SurfacePlane GetClosestPlane(Vector3 pos, PlaneTypes validTypes)
        {
            SurfacePlane        closestPlane   = null;
            List <SurfacePlane> possiblePlanes = new List <SurfacePlane>();

            if ((validTypes & PlaneTypes.Ceiling) == PlaneTypes.Ceiling)
            {
                SurfacePlane possiblePlane  = null;
                BoundedPlane possibleBounds = new BoundedPlane();
                if (m_CeilingPlanes.FindClosestBoundedPlane(pos, out possibleBounds, out possiblePlane))
                {
                    possiblePlanes.Add(possiblePlane);
                }
            }

            if ((validTypes & PlaneTypes.Floor) == PlaneTypes.Floor)
            {
                SurfacePlane possiblePlane  = null;
                BoundedPlane possibleBounds = new BoundedPlane();
                if (m_FloorPlanes.FindClosestBoundedPlane(pos, out possibleBounds, out possiblePlane))
                {
                    possiblePlanes.Add(possiblePlane);
                }
            }

            if ((validTypes & PlaneTypes.Table) == PlaneTypes.Table)
            {
                SurfacePlane possiblePlane  = null;
                BoundedPlane possibleBounds = new BoundedPlane();
                if (m_TablePlanes.FindClosestBoundedPlane(pos, out possibleBounds, out possiblePlane))
                {
                    possiblePlanes.Add(possiblePlane);
                }
            }

            if ((validTypes & PlaneTypes.Wall) == PlaneTypes.Wall)
            {
                SurfacePlane possiblePlane  = null;
                BoundedPlane possibleBounds = new BoundedPlane();
                if (m_WallPlanes.FindClosestBoundedPlane(pos, out possibleBounds, out possiblePlane))
                {
                    possiblePlanes.Add(possiblePlane);
                }
            }


            float closestDist = float.MaxValue;

            //Of the possible planes figure out which is closest.
            foreach (SurfacePlane possiblePlane in possiblePlanes)
            {
                if ((possiblePlane.PlaneType & validTypes) == possiblePlane.PlaneType)
                {
                    float dist = possiblePlane.Plane.GetSqrDistance(pos);
                    if (closestPlane == null || dist < closestDist)
                    {
                        closestDist  = dist;
                        closestPlane = possiblePlane;
                    }
                }
            }

            if (closestPlane != null)
            {
                float   distanceToPlane = closestPlane.Plane.Plane.GetDistanceToPoint(pos);
                Vector3 worldPosOnPlane = pos - closestPlane.Plane.Plane.normal * distanceToPlane;

                Debug.DrawLine(pos, worldPosOnPlane, Color.red, 15);
                Debug.DrawLine(pos, closestPlane.Plane.GetClosestWorldPoint(pos), Color.green, 15);
            }

            return(closestPlane);
        }
Example #27
0
    public void FindPlacesForBounds(Bounds bounds, float minDistanceFromUser, float maxDistanceFromUser, PlaneTypes planeTypes, int numberOfPlacesToFind = 3)
    {
        IsSearching = true;

        StopAllCoroutines();

        foundPlaces.Clear();

        StartCoroutine(FindPlacesForBoundsCoroutine(bounds, minDistanceFromUser, maxDistanceFromUser, planeTypes, numberOfPlacesToFind));
    }