I've been working on adding schools to 3DWorld's procedural cities on and off for a few months now. I started schools shortly after hospitals, and switched back and forth between working on the two building types. Hospitals got to a semi-finished state first, so I wrote a blog post on them last month. This post will be on the topic of procedural schools. I'm not quite done with schools at this point, but I'm starting to work on other unrelated topics. Maybe reader comments/feedback will give me some ideas on how to finish schools. I definitely got a lot of good feedback on hospitals last month.
As with the hospitals post, I'll describe each new type of room and show at least one screenshot for each of them. Technically, none of the room types is really new, but they're all at least somewhat customized for schools.
School buildings are of the taller and blocky "city" form rather than the strip mall-like one or two floor schools that seem to be more common in areas with more land. I tried my best to fit them into my standard office building templates with a central hallway and optional secondary hallways, with possible vertical stacked parts of progressively smaller footprints. This leads to most of the rooms having similar sizes, which isn't ideal, but I'll try to work with that. I ran into that same limitation with hospitals. Maybe sometime I'll find a better system to create buildings with larger and more complex footprints. I could use that for malls and factories as well.
Classrooms
I actually added classrooms to both schools and hospitals, though they're much more common in schools. In fact most of the rooms in schools are assigned as classrooms. I feel like the classroom discussion belongs in the schools post rather than the hospitals post, so I held off on writing about them until now.
Classrooms have a few requirements. First, there is a minimum room size required to fit at least 3x3 student desks. In order to guarantee most rooms are large enough to be classrooms, I modified the hallway and room generation logic in the office building floor planning step to create fewer larger rooms. One component of this was to increase the threshold or building size needed for adding secondary hallways. Classrooms must also have at least one exterior wall with a window, and no stairs, elevators, or exterior doors.
Most of the space in classrooms is filled with a 2D grid of smaller student desks with chairs, placed in multiple rows and columns as space allows. I copied and customized the code that I used to place rows of shelves in retail rooms. Any desks that are too close to a door or other object are omitted. The placement logic is relatively simple compared to some other room types because I don't need to worry about things like exterior doors, stairs, and elevators. A random assortment of books, papers, pens, and pencils is placed on top of these desks.
A teacher desk is placed against a wall, with preference for the long side of the room and interior walls with no windows. This desk has drawers and the top surface can have papers and an optional cup, which contains coffee 50% of the time. If the wall is windowless, a chalkboard/blackboard is added behind the teacher's desk and covers most of the wall. I'm going to refer to it as a blackboard because I've made them all black rather than dark green. Plus it seems to fit better with "whiteboard" used in offices. I then added an American flag to one side of the blackboard and an analog clock to the other. To finish the room off, I placed a few other objects such as plants, paper and trash on the floor, and room number signs outside the door.
![]() |
A school classroom with student desks and a teacher's desk and chalkboard in front. |
Here's a larger classroom with darker chair colors. The screenshot was taken from inside the doorway to the room, which is why there are no desks or chairs in the foreground.
![]() |
A second classroom with darker chairs. |
Oh! I also changed the titles of most of the books found in schools to match a selection of real school subjects. The list I came up with is: Math, Mathematics, Algebra, Geometry, Trigonometry, Calculus, Science, Biology, Chemistry, Physics, Economics, Computer Science, English, Literature, Language Arts, Social Studies, History, Geography, Government, Sociology, and Visual Arts. Some of these have "I" or "II" suffixes. Unfortunately, I haven't yet found a way to make the subjects match the images placed on the book covers. The textbook subjects found in each classroom are random as well, rather than matching the subject taught in the room.
![]() |
A student desk with a calculus book ... that has a picture of a museum dinosaur exhibit on it? What does that have to do with calculus? |
Blackboards come with chalk and erasers that the player can use to draw on them. I was thinking of adding some existing text and drawings on the boards, but I don't know where to get the images from. Drawing text with normal font doesn't look correct; I need something handwritten. Most of the images I saw in Google image search are artistic drawings rather than something you would find in schools. I was only able to find one image of some math that was high resolution, free, not watermarked, and the correct color and aspect ratio. It's clipped at the edges, but otherwise looks okay. This image is added to the blackboards of 25% of classrooms. If I find more useful images I'll add them later. Sadly, erasers held by the player don't work on these images.
![]() |
Blackboard with some math writing that's somewhat stretched and clipped. |
Hallway Lockers
Most larger building types have hallways, but only schools have lockers placed in these hallways. I added rows of lockers to each side of the primary hallway on each floor, wherever there was space. There are gaps in the rows where doors or other objects such as water fountains and fire extinguishers block their placement. Each school building part chooses a random locker color from a selection of light/bright colors. Some lockers have padlocks added to them.
School hallways also have a random chance of papers and trash on the floor. Otherwise, they're similar to office buildings with restrooms, water fountains, fire extinguishers, and trashcans on each floor.
![]() |
A shorter school hallway with blue lockers and stairs. There is some paper trash visible in the bottom center. |
Some of the larger schools have hundreds of lockers lining the hallway. This is probably too many given the number of desks in the classrooms, but it's fine for now. I'm sure some schools have too few lockers as well.
![]() |
A longer school hallway with red lockers, elevators, and intersecting hallways. There are a few papers on the floor in the back. |
The player can open the lockers without padlocks, and of course they contain items. All locker interiors have a larger bottom section and a smaller top section. Both shelves can have stacks of textbooks. Smaller objects such as cell phones, paper balls, bottles, and cans are placed on these books or on the empty shelf. Some lockers have papers attached to the inside of their doors. The larger bottom shelf also has a chance of a hanging colored tee shirt (which is a bit undersized, so I had to add it at an angle).
![]() |
A school building with light brown lockers. I've opened the ones that aren't locked with a padlock. |
Cafeterias
I added a cafeteria to some schools, though it's generally not large enough to fit many students. The minimum size is set so that there are at least three rows of tables. Each row has either a single long table or two shorter tables with an aisle in between. Most building floorplans contain similar sized rooms, which is a limitation. Maybe I should remove walls and merge two or more adjacent rooms into a single larger room? That way it could be used for cafeterias, auditoriums, gyms, etc. Of course I would probably need to increase the ceiling height of these rooms as well. None of this is particularly easy given the way the floor planning code is written and the fact that room assignment is run at a later time when it's too late to change walls or doors.
Cafeterias are similar to mall food courts and use the same table and chair geometry. The main difference is that cafeteria tables tend to be longer than mall tables. Various food, drink, and school items are placed on these tables. This includes cans, bottles, cups, pizza boxes, bananas, plates, silverware, vases, books, and laptops. There's also a clock on the wall. Now that I'm writing this, I think I'll add larger cylindrical trashcans to the corners of the cafeteria.
Cafeterias always have some type of tile floor texture that's easier to clean than carpeting. The rest of the school has randomly either carpeted or tile floor.
Teacher Lounges
Teacher lounges are basically the same as the lounges found in some office buildings. They have a central table with chairs, one or more couches, and optionally a refrigerator, a vending machine, and a wall mounted TV. Here we have the opposite problem to cafeterias: The rooms are too large. I should probably add more items to make use of the extra space. Or maybe place teacher lounges next to cafeterias and move the wall so that half the lounge size is added to the cafeteria? This won't work in general though because there are multiple teacher lounges and only one cafeteria.
![]() |
Teacher lounge with couch, tables, chairs, bookcase, vending machine, refrigerator, and wall TV. |
Libraries
The final room type I've added to schools is libraries. Well, that's not really true. Schools have restrooms, offices, utility rooms, and server rooms as well. What I really meant to say is the final school-specific room type is libraries. Except that some office buildings have libraries as well. Anyway, this is the final type I'm going to discuss in the current post.
Libraries have the expected stacks of books in the form of bookcases against the walls. They also have normal office furniture such as desks, tables, chairs, and filing cabinets. Sometimes they're small, such as the library in the screenshot below. I'm adding libraries last since they're optional, so they only get assigned to rooms that haven't been set to some other purpose. This means that they don't have much selection based on room size, and some smaller schools have no libraries.
![]() |
A small school library with bookcases, desks, a computer, and a filing cabinet. |
That's as far as I've gotten with schools. There are still some room types that I want to add later, especially if I can get more control over room size and height. It would be nice if I could find a way to add procedural writing on blackboards as well.
The code can be found in my GitHub repo here.
Those chairs look exactly as comfortable as I recall every classroom chair being.
ReplyDeleteI'd change "Math" to "Maths" as a nod to your European audience. You might add a "III" suffix option as well. Maybe do prefixes too? "Introductory" and "Advanced" seem appropriate.
Also, I realize this is against the spirit of the project, but I have never seen students leave their books out on the desk. Maybe the game takes place in a sudden catastrophe kind of scenario? A nit-pick of course. Don't mind me.
The pictures on the front having nothing to do with the topic is totally realistic though. That reminds me of a gamejam system my brother and I developed which has books with spines and contents entirely composed of emoji. I don't think your font rendering system supports it, but perhaps it would amuse you:
https://github.com/dudecon/speedjam29/blob/main/Book_gen.py
You can play the game here:
https://dudecon.itch.io/riddle-rooms
The lockers are a nice touch. I don't quite understand why, but all the lockers having different items really impresses me. Are there lockers in the industrial buildings as well? I've seen them in areas where full-body PPE are required.
Those stairwells smack in the middle of the hallways always weird me out though. Never once have I seen that in real life, except maybe in the subway, or a shopping mall, but never in an office building.
Seems like bolt cutters need to be a thing in 3D World now. What kind of exotic goodies are in those padlocked lockers? We need to know!
Teacher lounge needs a procgen comically long air-hockey table or foosball table with two-dozen rows of handles. Maybe a procgen table tennis would be easier to make though.
Encouraging progress! What other room types are you planning to add?
Those chairs are the same ones I used for mall food courts. I wanted to keep them simple because there are so many in a building, something in the hundreds. The school with the red lockers has 5 floors with 16 classrooms each on the bottom part and 10 floors of 8 classrooms each on the top part, for 160 total. If each room has an average of 12 chairs +1 for teacher, that's 2080 chairs total.
DeleteBook titles could have more variety, but it needs to be different based on the subject. Some of the more advanced subjects wouldn't have a III and introductory/advanced doesn't apply to everything.
The idea is that everyone disappeared from these buildings and left everything as it was. Maybe they all turned into zombies.
I'll take a look at your game when I have a chance. I didn't realize you did game jams! If I had a texture atlas of emojis in a 16x16 grid I could use it as a font and draw characters with it.
Lockers aren't too expensive to handle. The items aren't generated until the player opens them. And even then, all the lockers in the entire school probably contain fewer items than a retail store and 5-10x less than a mall. That school with the red lockers has some ~1500 lockers total. At 8 items each that's 12K. Malls can have 40K+ objects. I currently only have lockers in schools. I think I should add locker rooms to hospitals and maybe the industrial buildings.
The office building where I work has the stairs and elevators as an island in the middle where the two hallways intersect, sort of like in my buildings (except I only have one hallway). That's actually where I got the idea from. I did move some of the elevators to the side of the hallway. But it was a mess because it broke the symmetry of the floorplan and required adding a ton of special cases for rooms next to elevators that were cut into L-shapes. I'm not sure I want to attempt that for stairs, since stairs are more complex than a vertical cube.
I could hide keys for the lockers around somewhere. I do have colored padlocks with matching colored keys for doors in houses. Or maybe I can have one master key that unlocks all of the lockers.
I can't remember ever being inside a teacher lounge, so I'm not sure what to put there. Some of them should have your "Any Object" vending machine. I've seen them in hospitals, but I couldn't find one in a school teacher lounge. Maybe the problem is that the texture is wider than the other vending machines, which makes the machine wider, and it's more difficult to fit. (The teacher lounges I found in other schools were all smaller than the one in the screenshot.)
I still want to add some sort of kitchen for the cafeteria. And a gym and auditorium if I can find a way to create a larger room. By the way, I added commercial laundry rooms to hotels and hospitals.
Ooh, nice! Looking forward to the new rooms. Commercial laundry rooms should make a good improvement, and with a gym room you'd have everything for a hotel building.
Delete