/// <summary>
            /// Computes positions for this Tile and caches
            /// them.
            /// </summary>
            public void ComputePositions()
            {
                Positions = new PositionsContainer[Pool.Placer.ObjectsToPlace.Count];

                for (int i = 0; i < Positions.Length; i++)
                {
                    ObjectPlacementData objectPlacementData = Pool.Placer.ObjectsToPlace[i];
                    Vector3[]           locations           = Pool.Placer.GetFilteredGrid(Tile, objectPlacementData, 1).ToArray();
                    Positions[i] = new PositionsContainer(locations, objectPlacementData);
                }
            }
        /// <summary>
        /// First creates a poisson grid based on the passed density.
        /// Positions are then filtered based on the passed object placement
        /// type taking into account height and angle constraints.
        /// </summary>
        /// <param name="m">Mesh to sample height and angle values from</param>
        /// <param name="objectPlacementData">object placement type to sample</param>
        /// <param name="density">How dense should the samples be</param>
        /// <returns>List of vectors within the grid and sample constraints</returns>
        public List <Vector3> GetFilteredGrid(Tile tile, ObjectPlacementData objectPlacementData, float density)
        {
            MeshFilter mf = tile.GetComponent <MeshFilter>();

            if (mf == null)
            {
                throw new ArgumentException("The passed Tile does not have an attached MeshFilter. Has a mesh been created?");
            }

            return(GetFilteredGrid(mf.sharedMesh, objectPlacementData));
        }
            /// <summary>
            /// Gets the container that holds the passed
            /// ObjectPlacementType
            /// </summary>
            /// <param name="objectPlacementData">type to search for</param>
            /// <returns>ObjectContainer, null if no matches were found</returns>
            ObjectContainer GetContainerForType(ObjectPlacementData objectPlacementData)
            {
                foreach (ObjectContainer c in Pool.Containers)
                {
                    if (c.ObjectPlacementData.Equals(objectPlacementData))
                    {
                        return(c);
                    }
                }

                return(null);
            }
        /// <summary>
        /// First creates a poisson grid based on the passed density.
        /// Positions are then filtered based on the passed object placement
        /// type taking into account height and angle constraints.
        ///
        /// Unlike the <c>GetFilteredGrid(ObjectPlacementType, float)</c> method
        /// this method samples from the passed Mesh rather than pulling
        /// mesh information from TerraSettings.
        /// </summary>
        /// <param name="m">Mesh to sample height and angle values from</param>
        /// <param name="objectPlacementData">object placement type to sample</param>
        /// <returns>List of vectors within the grid and sample constraints</returns>
        public List <Vector3> GetFilteredGrid(Mesh m, ObjectPlacementData objectPlacementData)
        {
            MeshSampler    sampler = /**new MeshSampler(m, Settings.Generator.MeshResolution);*/ new MeshSampler(m, 128);          //TODO Resolution from TerraSettings
            List <Vector2> grid    = GetPoissonGrid(objectPlacementData.Spread / 10);
            List <Vector3> toAdd   = new List <Vector3>();

            foreach (Vector2 pos in grid)
            {
                MeshSampler.MeshSample sample = sampler.SampleAt(pos.x, pos.y);

                if (objectPlacementData.ShouldPlaceAt(sample.Height, sample.Angle))
                {
                    Vector3 newPos = new Vector3(pos.x, sample.Height, pos.y);
                    toAdd.Add(newPos);
                }
            }

            return(toAdd);
        }
 public PositionsContainer(Vector3[] positions, ObjectPlacementData objectPlacementData)
 {
     Positions           = positions;
     ObjectPlacementData = objectPlacementData;
 }
 public ObjectContainer(ObjectPlacementData objectPlacementData)
 {
     ObjectPlacementData = objectPlacementData;
 }