Thursday, August 15, 2024

Procedural Building Door Handles

I've been experimenting with different types of handles for the doors in 3DWorld's procedural buildings. This will be a very short post on that topic. I have several different door textures for use with buildings. Two of them are used for exterior office building doors, one is for interior office doors, and one is shared for both house exterior and interior doors. I'm mostly concerned about handles for the interior doors because these are more likely to be close and visible to the player. They're also the ones the player can directly interact with.

These doors were originally simple box shapes with a door texture drawn on each side and white quads added to cover the exposed edges of open doors. The door handle (and lock, in the case of office doors) was included as part of the texture. This was very efficient and looked acceptable, though some amount of lighting was baked into the door texture and didn't always match the lighting inside the building. The biggest problem was that these handles were only 2D decals and didn't have any depth.

I decided to experiment with different forms of door handle geometry. The requirement is that door handles must rotate with the door when opening and closing, and also must be relatively efficient to draw. (Some of the larger buildings have as many as 1000 doors!) My first attempt was to add some cube/box shapes for the plate, shaft, and handle. The plate and shaft extended through the door to both sides while handles are added separately to each side, resulting in four boxes per door. This was quite efficient and also matched the rectangular geometry uses with most of the other interior objects and details. However, it didn't look all that good. In particular, there were no curved surfaces to catch the specular reflection from ceiling lights.

I wasn't too happy with this result. It was time to find a proper 3D model that I could use with doors. The most efficient model for this purpose is one with a somewhat low poly geometry and a single material, to minimize the number of draw calls. Fortunately, there were a number of free 3D models available online that worked.

The most difficult step was calculating the proper transform (rotate + translate) needed to make the handle move with the door when opened or closed by the player or AI people. The next most difficult part was to make door handle drawing efficient. I was able to enable both view frustum culling and wall/floor/ceiling occlusion culling using the same code as the other 3D models placed in buildings. In addition, I only consider drawing handles of doors within one floor of the player, and skip handles on the opposite side of closed doors from the player. It may still be possible to see a missing door handle in rare cases such as when looking down multiple flights of stairs. Fortunately, the door texture still has a handle visible underneath, so it's not too obvious when the handle geometry is missing. Exterior door handles are not drawn, and neither are handles for doors in buildings other than the one the player is in.

I added a variety of door handle colors. Houses use brass and various shades of white to gray. Office buildings use black and darker shades of gray. Technically, the grays should really be silver/metal, but there's currently no reflection drawn on the surface of the material.

Here is what these door handles look like. I changed the code to randomly add {no (texture), boxes, model} handles to each door, and found a room in a house and office building that had all three types of door handles visible.

House door handles, from left to right: cube geometry, 3D model, texture. These are brass colored.


Office door handles, from left to right: texture, cube geometry, 3D model. These are black painted metal.

That's good enough for now. The model handle colors don't always match the door plate and lock colors, but it's still better than not having them. I made door handle type a config file option and left the default as 3D model, since it looks the best in my opinion. The added draw time appears to be insignificant, maybe ~1% longer. I may go back and work on this again later.

2 comments:

  1. Given how close and often the player interacts with doors, I expect this change will make a significant difference to user experience.
    Seems like you could generate knob handles pretty easily though.

    ReplyDelete
    Replies
    1. These handles definitely look nicer, but they don't quite fit with the lighting and the style of the rest of the interior. I may need to add more 3D models for bits and pieces of things. I do worry about performance though, but so far it seems to be okay.

      Delete