0
\$\begingroup\$

I'm working on a game where I have to procedurally generate a large open room building. I'm using Unity, but I think this applies to any engine. The room is made up of different wall segments. What makes this difficult for me is the ends of the segments have to join with a similar end of another segment. There are 2 types of ends. Flat and angled. The purpose of the angled ends is to create an outside corner. Meaning for example a flat wall then turns into a hallway it would use angled ends to make the transition. Adjoining 2 angled pieces

The method I tried initially was to define each segment type and what the follow up modules could be. Meaning SegmentA can be followed by: SegmentB, SegmentC, and SegmentD. Then I would randomly select which of those to add and place it, then move on and repeat. It works ok, but I feel like there is a better way to do it. It's pretty unwieldy and is kind of prone to bugs. I also run into issues trying to close the loop and return to the original segment.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Have you looked into the technique of "bitmasking" for tile selection? It's a simple way of analyzing the neighbourhood around a tile, and converting that information into an index to select the right tile type to place in that slot. \$\endgroup\$
    – DMGregory
    Apr 8, 2021 at 22:14
  • \$\begingroup\$ Is your code procedurally generating the meshes themselves, or procedurally assembling premade meshes? Your screenshot is of Blender, so I'm guessing the latter, but it's good to double-check. \$\endgroup\$
    – Kevin
    Apr 8, 2021 at 22:47
  • \$\begingroup\$ The code is only assembly premade meshes. I'll take a look at bitmasking the tile selection. \$\endgroup\$
    – jdbl
    Apr 9, 2021 at 0:59

2 Answers 2

0
\$\begingroup\$

the ends of the segments have to join with a similar end of another segment

Corner pieces could be much simpler: 1 mesh for a wall, 1 mesh for a corner.

enter image description here


I also run into issues trying to close the loop and return to the original segment.

Loop generation is hard and scales with degrees of freedom in the model. The rule of thumb is to start with a loop if you want a loop.

For example, you may start with a square made from many segments, move the points around to your taste while avoiding collisions, then "materialize" resulting scheme into a scene.

enter image description here

\$\endgroup\$
0
\$\begingroup\$

DMGregory was correct with his answer. Using the bitmasking worked well for me. I used this a reference. tutsplus My method was to define each segment by the resulting bit number. I used an array of bits since I had to reorder them depending on the rotation.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .