Exemplo n.º 1
0
        public void outputRoom()
        {
            foreach (Bounds b in propDict.Keys)
            {
                var obj = GameObject.Instantiate(propDict[b].prop);
                b.Encapsulate(b.min - Vector3.one / 2);
                b.Encapsulate(b.max + Vector3.one / 2);

                Aligner.AlignBoundingBoxFaceToBoundingBoxFace(Vector3.up, Vector3.forward, b, obj);
            }

            /*var colors = texture.GetPixels();
             *
             * for (int i = 0; i < colors.Length;i++){
             *      var col = colors[i];
             *      if (col.Equals(Color.white)){
             *              var v = getXYFromPosition(i);
             *              GameObject.CreatePrimitive(PrimitiveType.Cube).transform.position = v;
             *      }
             * }*/
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    var c = texture.GetPixel(i, j);
                    if (c.Equals(Color.white))
                    {
                        var v = new Vector2(i, j);
                        GameObject.CreatePrimitive(PrimitiveType.Cube).transform.position = v;
                    }
                }
            }
        }
Exemplo n.º 2
0
        void fill(Room room, PropUnitCollection propUnitCollection, GameObject parent)
        {
            var points    = propUnitCollection.getListOfPoints();
            var neighbors = new List <Vector3>();


            foreach (Vector3 v in points)
            {
                var cell  = room.cells[v];
                var walls = cell.findWallWithAttribute(FaceTypes.WALL);
                foreach (Shape s in walls)
                {
                    neighbors.Add(s.normal.normalized);
                }

                foreach (Vector3 v0 in VoxelIterators.VonNeumanNeighbors())
                {
                    var v2 = v + v0;
                    if (grid.ContainsKey(v2) && grid[v2].C == Color.white)
                    {
                        neighbors.Add(v0);
                    }
                }
            }

            Vector3 horizontal;

            if (neighbors.Count == 0)
            {
                horizontal = Vector3.right;
            }
            else
            {
                var grouping  = neighbors.GroupBy(a => a.GetHashCode());
                var groupList = grouping.OrderByDescending(b => b.Count());
                horizontal = groupList.First().First();
            }

            foreach (PropUnit propUnit in propUnitCollection.list)
            {
                var center   = propUnit.b.center;
                var vertical = Vector3.forward;
                var prop     = GameObject.Instantiate(propUnit.overlay.prop);
                Aligner.AlignBoundingBoxFaceToBoundingBoxFace(horizontal, vertical, propUnit.b, prop);
                prop.transform.parent = parent.transform;
            }
        }
Exemplo n.º 3
0
		public void placeMapPieces (IEnumerable<Room> rooms){

			GameObject physicalMap = new GameObject();
			physicalMap.name = "Completed Map";
			
			Dictionary<Bounds,int> boundsCount = new Dictionary<Bounds, int>();
			Dictionary<Bounds,BoundsData> maxCount = new Dictionary<Bounds,BoundsData>();
			Dictionary<Bounds,List<Vector3>> directions = new Dictionary<Bounds, List<Vector3>>();
			List<GameObject> markedForDeletion = new List<GameObject>();
			GameObject parent = new GameObject();
			
			var cellDict = new CellMap();
			foreach (Room r in rooms){
				propFill(physicalMap,r);
				foreach (Cell c in r.cells.Values) cellDict.addElement(c);
			
			}
			
				
			

			setComponentDirectory(componentDirectoryFile);
			

			var walls = cellDict.wallList;
			var edges = cellDict.edgeList;
			
			
			
			while (walls.Any()){
				var s = walls.Last();
				walls.Remove(s);

					Vector3 right;
					Vector3 center;
					Bounds bounds;
					
					right = s.groupNormal;
					center = s.groupCenter;
					bounds = s.groupBounds;
					

					var forward = Vector3.forward;
					var up = Vector3.Cross(forward,right);
					var dot = Vector3.Dot(Vector3.forward,right);
					if (Mathf.Approximately(Math.Abs(dot),1)){
						up = Vector3.up;
						forward = Vector3.right;
					}
					
					bounds.size += right * .1f;
					

					var tag = s.tag;
		
					var g = componentDirectory[tag].getComponent(true);
					g.transform.parent = physicalMap.transform;
					Aligner.AlignBoundingBoxFaceToBoundingBoxFace(forward,up,bounds,g);
				}
	
			
				foreach (Edge e in edges){
					var forward = e.slope;
					forward = new Vector3(Math.Abs(forward.x),Math.Abs(forward.y),Math.Abs(forward.z));
					var up = Vector3.up;
					
					if (Mathf.Approximately(Math.Abs(Vector3.Dot(up,forward)),1)){
						up = Vector3.forward;
						
					}
					var right = Vector3.Cross(forward,up);
					var tag = e.tag;
					
					var size = right * .1f + up * .1f + forward;
					var bounds = new Bounds(e.center(),size);

					var g = Instantiate(componentDirectory[tag].defaultComponent);
					g.transform.parent = physicalMap.transform;
					Aligner.AlignBoundingBoxFaceToBoundingBoxFace(forward,up,bounds,g);
				}
		
			
			physicalMap.transform.localEulerAngles += offsetRotation;
			physicalMap.transform.localScale = finalScale;
			physicalMap.transform.localPosition += offsetPosition;
			
		}