Sunday, March 31, 2024

Procedural Cities: New City and Residential Objects

I've added quite a few smaller features to 3DWorld's procedural cities, in particular to residential neighborhoods. I'll list all of the different types of objects that have recently been added and show at least one representative screenshot of each one. The last two posts were more on the technical side, with few images. This post will contain many images.

City Objects 

First we have the objects added to cities with commercial buildings. Parks were looking too empty since they previously only contained trees, benches, and maybe a flag. Now parks can have one or two winding paved paths crossing through them. These can be treated as either pedestrian or bike paths. (There are no bikes on these paths yet, but there are now static bikes - see below.) The placement algorithm will avoid adding objects such as trees that are too close to paths. People walking through the park don't yet use these paths. Now that I'm thinking of it, maybe I can modify the grid-based pedestrian path finding algorithm of the previous post to assign lower cost to grid cells over park paths.

I also added fountains to some parks. There are currently three 3D models to randomly choose from, but more models can be added to the config file at a later time.

City park with two wavy crossing paved paths and a fountain in the lower left corner.

Fountains can be found inside city blocks as well. They're placed anywhere that has enough open space and is far enough away from buildings. Birds can land on the tops of fountains. Maybe I should add benches or other items around the fountains?

Close-up of one of the three new fountains added to cities. Some are in parks, and others are on the concrete areas between buildings. This fountain has a pigeon on it.

I've added traffic cone objects that can be placed on the ground within cities. They can be used with either commercial cities or residential neighborhoods. These aren't 3D models but are instead formed from simple truncated cones and rectangles for their bases. Traffic cones can be placed anywhere, but initially I only put them in semicircles around the curved roads at the corners of cities. In the future I might add construction areas or closed roads where traffic cones can be used.

Traffic cones are now added to some areas of the city, currently only at the ends of road bends.

Residential Objects

There have been quite a few new additions to residential areas. Most of these are new types of 3D models that have been added, though I've also experimented with trees and plants.

First we have bicycles. These use a single model that's always painted red. Bikes are placed leaning against the exterior walls of houses and sometimes along front yard fences. The only placement rules are that they can't intersect previously placed objects and can't block doors. The same rules apply to the other object types shown later. Bicycles are not yet interactive; maybe some day the player can ride them.

Bicycles can be found leaning against some houses and fences.

I've added small potted plants around the exterior of houses and fences. There are three 3D models to choose from, one type of flower and two types of leafy plants. I'm reusing the same models that I placed on tables inside buildings. Since they're small and low-polygon, they're cheap and can be placed almost anywhere, so I can add several per house.

Oh, I almost forgot to mention that I added downspouts connected to the gutters of houses. You can see two of these in the image below. The small concrete slabs at the base of exterior doors are new as well.

Small potted plants of three varieties have been added around houses and fences.

The next type of vegetation I've added are smaller pine trees placed near houses. I already have deciduous and palm trees added to residential yards and pine trees in parks, but these add a bit more greenery.

I originally wanted to add bushes, but I couldn't quite get them working. The first problem was that trees are instanced all around the world with only 100 unique tree models for performance reasons. If I created bushes specifically for houses, that would have either increased the memory usage of trees or reduced the number of unique trees placed in the rest of the scene. The second problem was that there's little control over the shape of the tree, and sometimes a stray branch clipped through the exterior wall of the house. Pine trees use much simpler models (32 branch quads vs. thousands of leaves) and have a well controlled shape, which avoids both problems.

Small pine trees have been placed around the exterior of houses in residential neighborhoods.

Now it's time to add more sources of outdoor fun and exercise for the city residents. Some back yards have swimming pools. Most of the yards without a pool now have either swing sets or trampolines. These objects have fewer placement restrictions and can be added in situations where pools can't. For example, they can be added to smaller yards that can't easily be fenced in. The only real requirement is that they be in the "back" yard, which really only means they can't be placed between the front of the house and the street.

Here's a swing set placed in a back yard by a balcony. Extra padding has been accounted for in the placement to make sure there's enough space to swing. They're not currently interactive or animated though. I would love to have the seats swing back and forth when pushed by the player, but none of the free 3D swing set models I found have this sort of animation. Birds can land and take off from swing sets. If you look closely, you can see a dark gray bird on the center of the top bar in the screenshot below.

This screenshot manages to capture many of the new additions: A swing set (with a bird that just landed on it), a bike in the far back right, a pine tree on the left, and potted plants against the house near the center.

And finally we have trampolines. I was only able to find one usable free model with the vertical bars and net, which is similar in style to the trampoline in my own yard. This one has good geometry, though that net has a high vertex count and over 100K triangles. The one downside is that the materials are very dark and have no bright colors for contrast. I believe the normals are wrong on the dark blue ring, which is why it doesn't appear to be properly lit from the sun.

Trampoline placed in the yard next to a house.

Adding all of these new 3D models comes with a performance cost. Some of them have high vertex/triangle counts. Some of them have many individual materials, which leads to a large number of draw calls that hurt performance. I had to add more aggressive LOD and material distance culling to recover some of the framerate. For example, meshes with very small triangles such as the net in the trampoline above are only drawn when close to the player. I applied the same approach to indoor objects such as couches, chairs, and lamps. However, all of these objects together are a fraction of the triangle count that's drawn when people and cars are enabled, as those models are far more detailed.

What else should I add? If you have any suggestions, leave them as a comment.

2 comments:

  1. In the first image the conical trees look too wide. You could also improve them by having a more "gothic arch" profile, with a pointed top curving to blend in to slightly widening sides.

    For the procedural trees, I seem to recall you are using instancing from a procedural library of a dozen or so variations for each species. Are you using instancing for the other objects (traffic cones, books, other props)? Or are those other objects lightweight enough to generate individually on the fly?

    Bikes aren't placed blocking doors? Totally unbelievable.

    Ooh, I think I recognize those potted plants!
    https://sketchfab.com/3d-models/potted-plant-mediterranean-flowering-low-poly-b8950690664342a497154a8ad2787566
    https://sketchfab.com/3d-models/potted-plant-mediterranean-broad-leaf-low-poly-5c0e99de5d0f46c59bb2ead487ba7b53
    https://sketchfab.com/3d-models/potted-plant-mediterranean-med-leaf-low-poly-bc7f26baef2a45d18dbd9a5d6d2ec565

    Let me know if you want me to add animations to the swings, or fix that trampoline. I'll bet dithering transparency would work really well for the net actually, if your engine has that capability. I could fix the normals anyhow, if you want.

    Seems like you could add parametric animated water to the fountains using truncated cones and your water ripple texture techniques. Doing a mix-and-match of the fountain core and the surrounding basin would be an easy way of getting more variation without adding more models.

    As for more items to add, maybe deck/yard furniture with those big yard umbrellas (could be parametrically generated)? Fire pits? Zen gardens with miniature Bonsai trees? Garbage cans?

    Ooh! Could you make some of the houses with basements occasionally have a bat-cave style vehicle elevator that comes up in the middle of the driveway?

    ReplyDelete
    Replies
    1. I'm not sure what's going on with the pine trees. The ones in the park have an odd scale that looks different from other trees. I recently added a variable to control width that I could probably use. These trees are very old, one of the first type of trees I added. They're only 32 textured quads, so I can't easily make their profiles curved without adding more vertices. I probably need to create a different tree. I don't need to draw 100K of these, they can have more polygons.

      Deciduous trees use instancing because they can have up to 10K leaves with a single tree taking ~1MB of GPU data. There are 100 unique tree instances in this scene. Everything else that's not a 3D model is uniquely drawn. Traffic cones and books add triangles and quads to a buffer that's sent to the GPU for drawing. The actual objects are only around 64 bytes in memory on the CPU.

      Yes, those are your potted plants. They seem to work both indoors and outdoors. Thanks!

      I have several swings models. Maybe one is already animated? If the swing part is a separate material from the frame I can probably animate it the same way as ceiling fans and helicopters.

      I'm not sure what the problem with the trampoline is. It seems to draw correctly in Windows 3D Viewer. I have options that will invert normals. I just added this model while I was writing the blog post. Also, the net is actually a very detailed mesh. It would have been better with a texture (like the chain link fences), but I couldn't find any free models like that. Fortunately, the mesh is only really visible when nearby, so I can skip drawing it for distant trampolines.

      One of the fountains comes with water and the other two don't. I was thinking about adding some sort of ponds to parks. What was limiting me earlier was that the terrain was drawn flat, so I couldn't dig below it. I recently change the terrain rendering so that it can skip drawing areas under cities, so I can draw something custom that's part of the park/city model instead.

      Umbrellas sound good. Thanks. I already have garbage cans.

      Delete