modular structure (like planetbase) (way of approach)

I’m trying to ‘sort of’ clone this game called Planetbase, as a learning project, In this game you build a Colony on a foreign planet. Each building has a connection to another one, so that all theese buildings form one structure.

The position of theese connections are not totally fixed. I was wondering how I would realize this myself in unity. I started off simple and created a dome, copied out a part and created a mask. This mask would just need to be moved and I could move the entrance/exit. I also created a simple archway to obstruct that I’m just cutting out a part of the dome.

The Dome is 2 Objects and also the Mask is 2 Objects, with seperate models for inside and outside. The inside of the Mask obstructs the inside of the Dome and the outside of the Mask obstructs the outside of the Dome.

Now, to me it sorta looks like I got things right and I just need to follow down this road. But doing this all with mask objects feels like an enormous fiddly task. I’m allready having trouble to keep control of the renderlayers. I can’t view my Dome from every direction, if there is another one next to it, without getting display bugs.

Do any of you guys have some tips for me? How would you approach this?

Using a depth mask isn’t a good approach in this case. That usually works if you have one object that should be masked. For a modular system the result will be unpredictable.

I would recommend one of those approaches:

  • Actually cut out the doorway by performing some simple CSG operations on the geometry procedurally. You most likely only need a sphere as cut-geometry. Cutting / trimming a mesh isn’t as difficult as it sounds, just a bit of fiddling. Also keep an eye open for ready to use solutions. This one states that runtime support for CSG is coming soon.
  • Use a shader that does the masking in one go. You could add parameters to a shader that define 2 or more spheres which are used to discard fragments based on their placement. @vexe once wrote such a shader. I would suggest a similar approach.

Keep in mind that realtime masking (the second approach) can add quite some overhead if you have a lot of such shaders at the same time. The first solution just requires some processing when the connection is placed. This has the advantage that the geometry can still be batched by the rendering system and renders in a single draw call.

You could try modeling different types of domes, for example one with only an entrance, one with two doors, and another with three etc…

Now since they are models you won’t need to fiddle with masks and such, they will just be simple models. Then when you place a dome, you can just rotate the whole thing around until the exits are where you want them to be.