Example #1
0
    static RoomNode GetOverlapped(Bounds room, LinkedList <RoomNode> existing, Vector3 corridorDir)
    {
        RoomNode firstHit     = null;
        float    firstHitDist = Mathf.Infinity;

        foreach (RoomNode e in existing)
        {
            if (RoomNode.CheckOverlap(room, e.roomBounds))
            {
                if (firstHit == null)
                {
                    Vector3 hitWall  = e.roomBounds.center - Vector3.Scale(e.roomBounds.extents, corridorDir);
                    float   hitCoord = Util.VecSum(Vector3.Scale(hitWall, Util.VecAbs(corridorDir)));
                    firstHit     = e;
                    firstHitDist = hitCoord;
                }
                else
                {
                    Vector3 hitWall  = e.roomBounds.center - Vector3.Scale(e.roomBounds.extents, corridorDir);
                    float   hitCoord = Util.VecSum(Vector3.Scale(hitWall, Util.VecAbs(corridorDir)));
                    if (hitCoord < firstHitDist)
                    {
                        firstHitDist = hitCoord;
                        firstHit     = e;
                    }
                }
            }
        }

        return(firstHit);
    }
Example #2
0
    public static GameObject BuildRoom(RoomNode room, RoomStyle roomStyle)
    {
        GameObject boxObj = new GameObject(room.name);

        for (int i = 0; i < 6; i++)
        {
            Vector3 dir = Util.VecDenum(i);


            Bounds wallBounds = new Bounds(room.roomBounds.center + Vector3.Scale(room.roomBounds.extents, dir),
                                           Vector3.Scale(room.roomBounds.size, Util.LNot(dir)));

            int      holeCount   = 0;
            Bounds[] tempDoorSet = new Bounds[room.neighbors.Count];
            foreach (RoomNode neighbor in room.neighbors)
            {
                //if(wallBounds.Intersects(neighbor.roomBounds))
                if (RoomNode.CheckOverlap(wallBounds, neighbor.roomBounds, -1))
                {
                    Bounds b = RoomNode.OverlapBounds(room.roomBounds, neighbor.roomBounds);
                    b.extents += Util.VecAbs(dir);
                    tempDoorSet[holeCount] = b;
                    holeCount++;
                }
            }

            Bounds[] doorSet = new Bounds[holeCount];
            for (int k = 0; k < holeCount; k++)
            {
                doorSet[k] = tempDoorSet[k];
            }

            Mesh wallMesh = BuildWall(wallBounds, doorSet, dir * -1);
            if (wallMesh != null)
            {
                TangentSolver.Solve(wallMesh);
                GameObject wallObj = new GameObject("Wall", typeof(MeshRenderer), typeof(MeshFilter), typeof(MeshCollider));
                wallObj.GetComponent <MeshFilter>().mesh = wallMesh;
                wallObj.transform.parent        = boxObj.transform;
                wallObj.transform.localPosition = Vector3.Scale(room.roomBounds.extents, dir);
                wallObj.renderer.material       = roomStyle.materials[i];
                wallObj.GetComponent <MeshCollider>().sharedMesh = wallMesh;
            }
        }

        return(boxObj);
    }