Thursday, March 20, 2025

Procedural Warehouses

My last blog post showed the progress I've made on procedural factories. In this post, I'll show how I've generalized factories to industrial buildings and added warehouses as an industrial building sub-type. I have plans to add other building types such as power plants in the future. These buildings share many elements with factories such as overall floorplan, sub-rooms, wall and ceiling beams, sprinkler pipes, HVAC units, ducts, and fans. They also use many of the same textures such as slotted and rusty metals. Reuse of interior elements allows me to create these variants more quickly with less added code complexity.

Warehouses have some significant differences though, most notably the replacement of machines and tanks with rows of shelves. These are similar to shelves found in existing houses, storage rooms, and basements. One main difference is that they're constructed of plywood and metal frames, rather than wood boards mounted to walls. This gives them a sturdier and more industrial look. A second difference is in the types of objects placed on and around these shelves. There are boxes, crates, and pallets everywhere, both on shelves and on the floor. Ladders have been moved against the exterior walls by the entrance door, and the catwalk has been replaced with a forklift 3D model.

Warehouse viewed from the front near the office and entrance, with people and a forklift nearby. The floor has bottles and stains on it.

The placement system supports stacking of pallets on top of each other, stacking of boxes and crates, and placing boxes and crates on pallets. Most of this was done by extending the existing item stacking and player interaction system to be more general. The player can take all of these objects, but only from the top of the stack. Boxes on top can be opened, and the contained items can be removed. The player and building AI people can walk or step over low objects such as individual pallets, which means the placement system doesn't need to worry about them blocking access to areas of the warehouse.

Warehouses have the same office and bathroom sub-rooms as factories. I placed extra rows of high shelves on the roofs of these rooms to make better use of the open space. These shelves aren't against a supporting structure such as other shelves or an exterior wall, so I added a narrow horizontal I-beam connecting them to the exterior side walls. The player can climb ladders to get behind these shelves.

Warehouse showing a stack of pallets on the floor, the front office with entrance door, and additional shelves stacked on top of the sub-rooms.

Warehouse boxes contain a different selection of items compared to boxes found in houses and office buildings. I reworked the shelf and boxes system to allow a different collection of contained objects depending on building and room type. Warehouse boxes contain some of the common items found in earlier boxes such as bottles of water/coke/beer/wine, toilet paper, and cans of spray paint. But they also have new items, including cases of coke and beer cans, boxes of food, and electronic items such as computers, laptops, and microwaves. I even added boxes containing tiny machines which use the same generation and drawing code as machines found in extended basements and factories.

Items are selected based on a combination of randomness and matching the size and shape of the item to the size and shape of the box. For example, tall and narrow boxes may have computer towers, short boxes can contain laptops, and large wide boxes contain microwaves. The goal of the player should be to find the boxes containing more valuable items such as laptops, while avoiding zombies, snakes, spiders, etc.

A stack of boxes and crates next to shelves placed along an exterior wall. Some boxes have been opened, showing items inside.

Warehouses have several entrances. There's a front entrance that opens into the main office, rather than between the office and bathroom as in factories. This means that I had to modify building door and window logic to allow doors to be placed into sub-rooms that already have custom windows that don't match the upper level windows of the main warehouse area. There's a back garage door that would serve as a loading dock, currently using the house garage door texture. I may continue to work on loading docks if I add warehouses to cities in the future or connect the secondary buildings with roads. For now, it only has a connecting driveway, similar to those added to houses. And there's also one or more optional side entrance doors inserted in gaps between rows of shelves.

Warehouse loading door near the back, using the garage door texture.

Warehouses can be quite large. I originally only assigned industrial buildings to smaller brick structures of three to four floors in height. Now I've modified the config file to create some short and wide concrete block buildings that can serve as factories and warehouses. These look more realistic for this type of building. They also make industrial buildings common and easier to find.

I modified overhead map mode to color code buildings based on category/function. This allows the user to select a building and teleport to that location, which definitely helps to accelerate testing of custom types. It's important to visit both large and small buildings to make sure the interior elements scale properly and look reasonable for the interior areas. I spent quite a while fixing problems like this, in particular cases where basement or parking garage stairs were blocked by or intersecting other objects placed at the ground floor.

Large warehouse viewed by standing on top of the upper shelf over the office room. This vantage point is needed to see the size of the space. The forklift is along the back wall on the left.

What's next? I currently have hospitals and schools on my list. I already started working on hospitals, but I decided to go back and add warehouses first because they were a more natural continuation of my work on factories. I've been working a bit on schools as well. It's still early though, so I have no idea how these will turn out.

8 comments:

  1. Glad to see the warehouse suggestion was fruitful! That looks pretty much just like a real warehouse!

    From the bottles on the floor, it appears the workers/zombies have been drinking on the job/prowl.

    The shelves on the sub-buildings look very much like a mezzanine level, which many warehouse/industrial buildings have. However, since forklifts can't drive on sub-buildings, the shelves there should be only tall as a person can reach, and only contain smaller boxes (no pallets). You might want to enclose them in walls, and add a large door for forklift access, and a set of stairs (or a ladder for small mezzanine). A mezzanine is also a classic place to house an equipment room.

    I love the nested structure that is developing! Items in boxes in palleted stacks in racks in aisles in warehouses.

    ReplyDelete
    Replies
    1. Bottles are selected randomly from the set, though I can exclude certain types. The idea was more that this building was abandoned when the zombie apocalypse started and some kids/young adults were hiding there drinking or something.

      There is an upper floor that the player can get to with a ladder. It's on the back side of the shelves, but you can still take items. I don't have anything else up there. Maybe I should add more to it. I'll make the shelves shorter and remove the pallets. Actually the main shelves are probably too high for a forklift to reach, but I do like how they tower over the player.

      3DWorld is full of nested structures. Everything from terrain tile down is nested. This forms a tree structure that's more efficient to generate incrementally and query.

      Delete
  2. Since you have a 2D "overhead map", how hard would it be to render a mini-map as an overlay? Could you render the whole area as a 3D model miniature in the lobby of city hall, which would allow you to teleport as well? Maybe a sub-section could be in each big building lobby, showing the adjacent few blocks of buildings? Oh! And a miniature of the building interior so you can easily teleport inside buildings as well!

    On the topic of miniatures, I love that you have miniature machines in the warehouse boxes. Would it be possible to carry one of these to a factory and use it to "set" the procgen seed for that building so you can replace all the machines in the building?

    Ooh! Capsules! Instead of the miniature machine sitting in a box, what about enclosing it in a capsule? Then you could have a variety of encapsulated objects which you can use to replace the various procgenned things. Object capsules for debugging objects! Building type capsules for debugging building types! Whole city capsules for changing the city seed! Landscape capsules to change the landscape while maintaining the city layout! In addition to the help it would be for debugging, it would be a great way to show off the speed and flexibility of the procgen system you've developed.

    ReplyDelete
    Replies
    1. The overhead map is generated by ray casting every pixel vertically into the scene, and only runs at 10-20 FPS. That's fine for an interactive map. If the mini map was small it's probably okay. I can already render map mode to a texture for generating screenshots.

      I'm not sure about rendering to a mini 3D model. That's more work than rendering to a texture. In theory I could draw the buildings at a smaller scale, but it can only draw blocks at the terrain tile level or city level, so there's not a whole lot of control over the area to draw.

      Overhead map mode shows the interior of the building if the player is inside. I'm not sure how the user would select a location to teleport to from a 3D model.

      Machines found in boxes vs. basements vs. factories are generated a bit differently. Basement machines have pipes into the walls, floors, and ceiling. Factory machines have pipes to adjacent machines and to floors. Boxed machines only have pipes going down because there is no ceiling, wall, or adjacent machine. So using the seed would produce a different machine for box vs. factory since the generation is different. There may be a way to fix it. It could get messy to regenerate existing machines in a factory though because of the way they're connected to other objects and placed around. For example, if the new machine had a different aspect ratio, it may clip through other objects that were placed around the old machine.

      I'm not sure about the capsules idea. I'm sure it's possible, but it could take months of effort. Maybe some day. I should probably try to get custom machines working first.

      Delete
    2. Okay, the player can now take small machines from boxes and change the machines in factories based on the last one added to their inventory. It sort of works. The size of the factory machine doesn't change, but the shape and texture matches the boxed machine.

      I also added a key command to randomly regenerate building interiors and posted a YouTube video of that.

      Delete
  3. On further pondering of the capsule idea, and switching the building "Type", it seems like there are a few classes of structures in 3D world.
    You've already explicitly identified one of them, the Industrial building. Here is a proposed taxonomy I just came up with, along with some examples of existing and proposed buildings.

    Industrial (thing buildings) warehouse, factory, workshop, maintenance bay/hangar

    Institution (people buildings) Home, school, hospital, prison, apartment, office, theater/lecture hall, stadium

    Nexus (hybrid) shop, parking lot, airport, dock, ferry, railway station

    I also find it interesting to note that each category contains variants of each other category. The hospital and prison, for instance, are industrial variants of the institutional building.


    In addition, there's an intermediate level of organization between the scale of the individual building and the scale of the city. None of these are in your game yet (except perhaps for neighborhood?), so the examples are all suggestions:

    Complex (multiple buildings): College campus, Extraction farm, government complex, prison complex, industrial complex, shopping mega-mall, city square, neighborhood.

    If you will continue to patiently entertain my suggestions, allow me to elucidate on a few of the types of Complex, and the kinds of buildings each might contain.

    College campus (people complex) apartment, lecture hall, school, home, hospital, (basically all of the Institutional building types above, with a focus on education)

    Industrial complex (thing place) Refinery (so many pipes everywhere!), power generator turbine, boiler building (nuclear, gas, coal, fusion, magic, etc), waste heat cooling (cooling tower, evaporator, radiator, smokestack, heat pump, etc), refinery, large external chemical storage tank, along with any/all of the Industrial buildings above.

    Extraction farm (wilderness complex)
    which can be sub-classified as:
    Industrial (feeding things): hydro-power dam, mine, quarry, sawmill, solar farm, wind farm
    Agrarian (feeding people): farm, orchard, vineyard, ranch

    City square (meta complex) Monument (maybe all the capsule types are available here in gameplay mode?)

    And, in keeping with the nesting of category variants, the large-scale complexes are often represented in the smaller scale specialized buildings. You'll find gardens (miniature farm) at homes and on college campuses, but never at a refinery or aircraft hanger.

    I think the home is actually a micro-cosom of the city actually. The attic is a mini warehouse, the bedrooms are apartments, the kitchen and common spaces is a mini campus, the basement is a mini industrial complex, and the yard is a mini wilderness complex.

    Feel free to use whatever of this is helpful.

    ReplyDelete
    Replies
    1. Thanks for all of the ideas! I'm not sure how much of this I'll get to. I have industrial (factory, warehouse), residential (house, apartment, hotel), commercial (office), then hospitals and schools which aren't classified yet. I might add things like parking garages, stores, and above ground malls.

      Cities have connections between buildings, and some blocks have buildings with the same size/texture/style. There are residential and commercial areas. However, I don't currently have a system of assigning buildings to particular types based on surrounding buildings, or placing groups of specific types together. Maybe some day.

      I definitely need to add wind turbines up in the mountains now. And maybe solar farms in flat areas?

      Delete