Skip to content

Instantly share code, notes, and snippets.

@andybak
Created September 17, 2020 10:26
Show Gist options
  • Save andybak/e052414ca97f9d5f835b6090330c968d to your computer and use it in GitHub Desktop.
Save andybak/e052414ca97f9d5f835b6090330c968d to your computer and use it in GitHub Desktop.
// Generate the ground grid and extrude random buildings
var grid = Grids.Grids.MakeGrid(GridType, GridShape, width, depth);
grid = grid.VertexRotate(new OpParams(Jitter, randomValues: true));
var floors = grid.FaceKeep(new OpParams(.1f, pickRandomly));
var houses = floors.Loft(new OpParams(0, x=>Random.Range(.5f, 1.5f)));
var (walls, roofs) = houses.Split(new OpParams(FaceSelections.Existing));
// Make window holes
walls = walls.Loft(new OpParams(0.75f, FaceSelections.AllNew));
walls = walls.FaceSlide(new OpParams(0.15f, FaceSelections.Existing));
walls = walls.FaceRemove(new OpParams(FaceSelections.Existing));
// Thicken the walls
walls = walls.Shell(0.025f);
// Add domes to the roofs
var domes = roofs.LoftAlongProfile(FaceSelections.All, DomeHeight, DomeSegments, easingType);
// Make nice patterns on the ground
var ground = grid.Dual();
ground = ground.Bevel(new OpParams(0.25f));
ground = ground.Medial(new OpParams(3f));
// Add some edging around buildings
var edging = floors.Transform(new Vector3(0, .03f, 0));
edging = edging.FaceScale(new OpParams(0.25f));
edging.SetFaceRoles(ConwayPoly.Roles.Existing);
// Assemble everything
var town = new ConwayPoly();
town.Append(edging);
town.Append(ground);
town.Append(walls);
town.Append(domes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment