Modeling the Walls of a House
In this project, we will model a medium house. We will model only the exterior of the house.
The building of a house starts with a foundation, followed by walls. In this section, we will start by creating the main walls of the house.
Practical Learning: Introducing the Model
- Start Blender
- Click the default cube to select it (it should be selected already)
- On the left toolbar, click the Move button
- In the Properties window, click the Object button (it should be selected already) to access the primary properties of the cube.
Change the following values:
Name: Wall-External-Front
Location: X: 0
Y: 0.025
Z: 1.205
Rotation: X: 90
Y: 0
Z: 0
Scale: X: 2.6
Y: 1.205
Z: 0.025
- To duplicate the wall, position the mouse in the 3D Viewport. Press Alt + D and press Enter
- In the Object section of the Properties window, change the Y location to 2.425
Name: Wall-External-Back
Location Y: 3.975
- To add a new object, on the top menu, click Add -> Mesh -> Cube
- In the Object section of the Properties window, change the following values:
Name: Wall-External-Left
Location: X: -2.58
Y: 2
Z: 1.205
Rotation: X: 90
Y: 0
Z: 90
Scale: X: 2
Y: 1.205
Z: 0.025
- To duplicate the wall, position the mouse in the 3D Viewport. Press Alt + D and press Enter
- In the Object section of the Properties window, remove the - sign in the value of the Y location
Name: Wall-External-Right
Location X: 2.58
Adding (External) Doors
Obviously, a house should have doors. In this section, we will add the necessary doors to our house.
Practical Learning: Adding Doors
- In a previous lesson, we modeled a simple door. Start another instance of Blender and open that file
- Draw a rectangle that touches the door frame and its inside face (the door leaf)
- Press Ctrl + C to copy the door to the clipboard
- Return to the instance of Blender where we are modeling the house
- Position the mouse in the 3D Viewport and press Ctrl + V to paste the door
- While the door is still selected, right-click anywhere in the 3D Viewport and click Move to Collection
- In the window that comes up, click New Collection
- Type Door-External as the new name and press Enter
- On the Move to New Collection dialog box, click Create
- On the top menu, click View -> Viewpoint -> Front
- Use the red arrow of the X axis to move the door to the left as follow:
- In a previous lesson, we modeled a door lock. In the other instance of Blender you had started, open the file of that door lock
- Click the door lock to select it
- Press Ctrl + C to copy it
- Return to the instance of Blender where we are modeling the house
- Position the mouse in the 3D Viewport and press Ctrl + V to paste the door
- While the door lock is still selected, right-click anywhere in the 3D Viewport and click Move to Collection
- In the window that comes up, click New Collection
- On the Move to Collection dialog box, click Door-External
- On the top menu, click View -> Viewpoint -> Front
- Use the red arrow of the X axis to move the door to the left as follow:
- In a previous lesson, we modeled a door handle. In the other instance of Blender you had started, open the file of that door lock
- Draw a rectangle that touches the parts of the door handle to select
- Press Ctrl + C to copy the selection
- Return to the instance of Blender where we are modeling the house
- Position the mouse in the 3D Viewport and press Ctrl + V to paste the door
- While the door handle is still selected, right-click anywhere in the 3D Viewport and click Move to Collection
- In the window that comes up, click New Collection
- On the Move to Collection dialog box, click Door-External
- On the top menu, click View -> Viewpoint -> Front
- Press S, move the mouse towards the door lock to resize it, and click. Keep resizing the door handle until its size is approximately the same as the door lock
- Use the red arrow of the X axis to move the door to the left as follow:
- In the Outliner in the 3D Viewport window. Then, on your keyboard, press S
- Move the mouse very slightly and click
- On the top bar, click the Face button
- Click the top face of the cube to select it
- Rotate the cube to access the bottom face and click it to select it
- On the remaining shapes, click one of the faces that is parallel to the green Y axis to select it
- Click the face that is opposing that one to select it
- Click the face that is opposing that one to select it
- To edit the cube, on the main menu of Blender, click Modeling
- To confirm the separated parts, on the top-main menu of Blender, click Layout
Setting the Materials for Walls
We are planning to create some variances of the same house. Those variances will have different colors or wall appearances. To make this happen, we will separater the walls of the house.
Practical Learning: Setting the Materials for Walls
- To access the materials of the faces, on the top-main menu of Blender, click Shading
- On the bottom bar, click Material to select it
- Type Long-Wall and press Enter
- On the bottom bar, click the New Material button
- On the bottom bar, click Long-Wall.001 to select it
- Type Short-Wall and press Enter
- Click one of the other walls to select them
- On the bottom bar, click the arrow of the Browse Material combo box and select Short-Wall
- On the top menu of Blender, click Layout
Dividing the House Stories
Since we are modeling a medium house, we will make into two stories (two levels).
Practical Learning: Dividing the House Stories
- Click one of the sections of the walls
- On the top-main menu of Blender, click Modeling
- On the left bar, click the Loop Cut button
- Click one of the walls to create a horizontal cut
- Rotate the shape to access the other wall
- Click that wall to create a horizontal cut
- On the top-main menu of Blender, click Layout
- Click one of the other walls you did not select
- On the top-main menu of Blender, click Modeling
- While the Loop Cut button is still selected, click one of the walls to create a horizontal cut
- Rotate the shape to access the other wall
- Click that wall to create a horizontal cut
- On the left bar, click the Select Box button
- On the top menu of Blender, click Layout
- To add a new object, on the top menu, click Add -> Mesh -> Cube
- In the Object section of the Properties window, change the following values:
Name: Door-Frame
Location: X: -0.925
Y: 2.265
Z: 0.5
Scale: X: 0.285
Y: 0.0315
Z: 0.5
- To hide the walls of the house, in the numeric pad of the keyboard, press /
- To edit the cube, on the top-main menu of Blender, click Modeling
- To hide the walls of the house, in the numeric pad of the keyboard, press /
- On the left bar, click the Loop Cut button
- In the bottom-left side of the large Blender window, click Loop Cut And Slide to expand it
- Change the Number of Cuts value to 2:
Number of Cuts: 2
- In the Resize window in the bottom-left section of the 3D Viewport window, change the following values:
Move: X: 2.55
Y: 1
Z: 1
- In the Loop Cut and Move window, change the factor to -0.915:
Factor: -0.915
- On the top bar, click the Face button
- On your keyboard, press X
- On the menu that appears, click Faces
- Click the bottom-central face of the shape to select it
- On your keyboard, press Delete
- On the menu that appears, click Faces
- Click the other large face in the middle of the shape to select it
- Right-click anywhere in the 3D Viewport workspace window -> Separate -> Selection
- To display the hidden objects, in the numeric pad of the keyboard, press /
- To confirm the separated parts, on the top-main menu of Blender, click Layout
- Click the wide face in the middle of the shape to select it
- In the Object section of the Properties window, click Door-Frame.001 to select the name
- Position the mouse on the 3D Viewport. On your keyboard, press H to hide the face
- Click any border of the window to select it
- To continue editing the door, on the main menu of Blender, click Modeling
- On the top bar, click the Edge button
- On the window, click one of the interior edges of the opening to select it
- On your keyboard, press and hold Shift
- Click each of the interior edges of both openings of the door but don't select the bottom edge of each side
- On the menu bar, click Edge -> Bridge Edge Loops
- On the top-main menu of Blender, click Layout
- In the Outliner, click the Hide In Viewport button of Door-Leaf to unhide it
- In the 3D Viewport, click that interior face (Door-Leaf) to select it
- To edit the face, on the main menu of Blender, click Modeling
- On the top menu bar, click the Face button
- Click the large face on the door
- Press E to extrude and press Enter
- In the Extrude Region and Move window, change the Z value to -0.035:
Move Z: -0.035
- On the main menu of Blender, click Layout
Modeling a Basic Door Lock
Houses use doors to keep some of their areas safe. As a matter of fact, houses use various types of doors. To apply these safety measures, doors use locks. Doors in turn use various types of locks. For example, external and internal doors may use different types of locks. Normally, locks used on external doors use keys. In this exercise, we will model a simple door lock.
Practical Learning: Modeling a Basic Door Lock
- To start a new object, on the top menu bar, click Add -> Mesh -> Cone
- In the bottom-left section of the 3D Viewport, click Add Cube to expand its window
- In the Add Cube window, change the following characteristics:
Radius: 0.015
Radius 2: 0.01
Depth: 0.01
Location X: -1.135
Y: 2.25
Z: 0.55
Rotation X: 90
- In the Object section of the Properties window, click Cone to select the name
- Type Door-Lock-Round as the name and press Enter
- To edit the cone, on the top-main menu of Blender, click Modeling
- To hide the other objects, in the numeric pad of the keyboard, press /
- Click and drag the Rotate button to see the large back face of the cone
- On the top menu, click the Face button
- Click the large vertical face to select it
- Press E to extrude and press Enter
- In the Extrude Region and Move window, change the Z value to 0.45:
Move Z: 0.035
- Position the mouse on an empty area of the 3D Viewport window. Press E to extrude and press Enter
- In the Extrude Region and Move window, change the Z value to 0.1:
Move Z: 0.1
- Position the mouse in the 3D Viewport. Press S to resize the face. Pull the mouse slightly and click
- In the Resize window, change the X and the Z values to 0.95 each:
Scale: X: 0.95
Z: 0.95
- Position the mouse in the 3D Viewport. Press E to extrude, then press S to resize, then press Enter
- In the Extrude Region and Move window, change the X and the Z values to 0.5:
Scale: X: 0.95
Z: 0.95
- Rotate the cone to see the front face (you can use the middle button of the mouse)
- Click the front vertical face to select it
-----------------------------------------------------------------------------------------------------------
- Press E to extrude and press Enter
- In the Extrude Region and Move window, change the Z value to 0.025:
Move Z: 0.025
- Position the mouse in the 3D Viewport. Press S to resize. Slightly move the mouse and click
- In the Resize window, change the X and the Z values to 0.95 each:
Scale: X: 0.95
Z: 0.95
- While the face is still selected, position the mouse in the 3D Viewport. Press E to extrude, then press S to resize, then press Enter
- In the Extrude Region and Move window, change the X and the Z values to 0.875:
Scale: X: 0.875
Z: 0.875
- While the face is still selected, position the mouse in the 3D Viewport. Press E to extrude, then press S to resize, then press Enter
- In the Extrude Region and Move window, change the X and the Z values to 0.95:
Scale X: 0.95
Z: 0.95
- While the face is still selected, position the mouse on the 3D Viewport window. Press E to extrude, then press S to resize, then press Enter
- In the Extrude Region and Move window, change the X and the Z values to 0.95 each:
Scale: X: 0.985
Z: 0.985
- While the face is still selected, position the mouse on an empty area of the 3D Viewport window. Press E to extrude, then press S to resize, then press Enter
- In the Extrude Region and Move window, change the X and the Z values to 0.95 each:
Scale: X: 0.985
Z: 0.985
- While the face is still selected, position the mouse on an empty area of the 3D Viewport window. Press E to extrude, then press S to resize, then press Enter
- In the Extrude Region and Move window, change the X and the Z values to 0.95 each:
Scale: X: 0.95
Z: 0.95
- On the top tool menu, click the Edge button
- Press and hold Alt
- On the shape in the 3D Viewport, click one of the edges of the 5th circle from the external circle
- Release Alt
- Press G slightly and click
- In the Move window, change the values as follows:
Move: X: 0
Y: 0.25
Z: 0
- Press and hold Alt
- Click one of the edges of the 4th circle from the external circle
- Release Alt
- Press Ctrl + B and press Enter
- In the Bevel window, change the following values:
Width: 0.0125
Segments: 2
- While the Edge option is still selected, press and hold Alt
- Click one of the edges outside the inner circle
- Release Alt
- Position the mouse in the 3D Viewport window. Press Ctrl + B and press Enter
- In the Bevel window, change the following values:
Width: 0.0125
Segments: 2
- On the top bar, click the Face button
- Click the large central face to select it
- Press E to extrude
- Then press S to resize, then press Enter
- In the Extrude Region and Move window, change the X and Y values as follows:
Scale X: 0.65
Z: 0.65
- Position the mouse in the 3D Viewport window. Press G to move the face
- Move the mouse slightly and click
- In the Move window, change the following values:
Move X: 0
Y: 0
Z: -0.105
- While the face is still selected, press E to extrude
- Then press S, then press Enter
- In the Extrude Region and Move window, change the following values:
Move X: 0.975
Z: 0.975
- While the face is still selected, press E to extrude
- Tthen press S, then press Enter
- In the Extrude Region and Move window, change the following values:
Move X: 0.975
Z: 0.975
- While the face is still selected, press E to extrude
- Then press S, then press Enter
- In the Extrude Region and Move window, change the following values:
Move X: 0.205
Z: 0.85
- On the top tool menu, click the Edge button
- Press and hold Alt
- Click one of the edges of the circle between the three circles that were just drawn
- Release Alt
- Press G slightly and click
- In the Move window, change the values as follows:
Move: X: 0
Y: 0.025
Z: 0
- On the top toolbar, click the Face button
- Click the large oval face on the lock to select it
- Press E to extrude and press Enter
- In the Extrude Region and Move window, change the following values:
Move X: 0
Y: 0
Z: -0.75
- Position the mouse close to the oval hole. Press Ctrl + R to create a cut and click once
- Move the cut as close as possible to the oval hole. Then click to confirm the cut
- Position the mouse on the interior of the oval hole. Press Ctrl + R to create a cut inside the oval hole and click once
- Move the cut as close as possible to the outside of the oval hole. Then click to confirm the cut
- On the main menu of Blender, click Layout
- To save the lock, on the main menu, click File -> Save
- Set the document name Door-Lock-Simple-1
- Click Save
- While the lock is still selected, in the Properties window, click the Modifiers button
- Still in the Properties window, click Add Modifier -> Generate -> Subdivision Surface
- In the Properties window, set the Levels Viewport to 2:
Levels Viewport: 2
- Right-click the lock and click Shade Smooth:
- To save, on the main menu, click File -> Save As...
- Set the document name Door-Lock-Simple-2
- Click Save As
Adding Windows
Obviously, a house should have walls and window. In this section, we will add them to the model.
Finalizing the Interior Door
Practical Learning: Finalizing the Interior Door
- Click the default cube to select it (it should be selected already)
- In the Properties window, click the Object button (it should be selected already) to access the primary properties of the cube
- To add a window, position the mouse on the top-right side of the window until the mouse cursor appears as +
- Click and drag in the left direction and click
- Click the button in the top-left section of the right panel and select Asset Browser
- From the Asset Library window, drag Door-Frame-Simple to the 3D Viewport. In the 3D Viewport, drop the object in an occupied area, not on a wall of the house
- On the left toolbar, click the Move button
- From the Asset Library window, drag Door-Leaf-Simple to the 3D Viewport. In the 3D Viewport, drop the object in an occupied area, not on a wall of the house
- In the Asset Library window, click Door-Leaf-Simple to add it to the selection
- Release Ctrl
- In the Asset Library window, drag the selected items and drop the group in the 3D Viewport
- Close Blender
- When asked whether you want to save, click Don't Save
- Open another instance of Blender
- In a previous lesso method overloading, we saw that a method can get overloaded if you create more than one version in the same class. We also saw that the versions of the method must differ by their syntax or signature. Remember that the signature of a method doesn't include its return type. Based on this, you cannot overload a method based on the fact that one version returns a tuple and another does not.
- To overload a method that involves tuples, you will rely on the parameters. You can create a method that has different versions. Two or more versions of a method can take one tuple parameter each; each tuple-parameter can have the same number of elements but the elements can be different. Consider the following example:
This would produce:
Method Overloading and Tuples
On the other hand, you can overload a method by passing a mixture of primitive types and tuples.
Tuples and Properties
Introduction
You can create a property whose type is a tuple. To start, in the body of the class, you can declare a field variable that is a tuple type. Here is an example:
public class Member
{
}
To get the property, create a property that has a return type as a tuple. Here is an example:
A Read-Only Tuple Property
A read-only property is a a property with only a get clause. For a tuple property, make the get clause return a private field that has the same return type as the property. Here is an example:
}
}
If you want to use the property outside its class, it must have a value, which it cannot get on its own because it is a read-only property. The most common way you can initialize this property is by using a constructor that uses a parameter of the same tuple type as the property. After initializing the property, you can get its value and use it. Here is an example:
mbr.Identification.fee}");
WriteLine("===============================");
This would produce:
A Fully-Implemented Tuple Property
As seen in our introduction to properties, if you want to control the details of processing a property, you can create a private field that is the same tuple type as the property. Then add either or both a get and a set clauses. Here is an example:
An Automatic Tuple Property
If you are not planning to validate, accept, or reject the values of the property, you can create the property as an automatic one. Here is an example:
public (bool, string, PayFrequency, double) Salary { get; set; }
}
When creating the property, it is a good idea, although not a requirement, to name the elements of the tuple. It may also be a good idea to add comments that explain the roles of the elements of the tuple. Here is an example:
}
As mentioned in the previous lesson, if you don't name the elements of a tuple, the compiler gives them some default names as Item1, Item2, etc.
When using the property, you may need to access the elements of its type. You will access them by their names. From inside the class, such as in the body of a clause of another property or in the body of a method of the same name, type the name of the desired property, type a period, and select the element of your choice. Here is an example:
When using the property outside the class, if you have declared a variable of the class that owns the property, type the name of the object, a period, the name of the property, a period, and the desired element. Here is an example:
Once you have accessed the property or any of its elements, you can use it like any property as we have done in previous lessons.
If you create an automatic tuple property, you cannot individually initialize the elements of the tuple property. Still, you can access the elements to present to the user. Here is an example:
This would produce:
Topics on Tuples
Methods and Tuples
We saw how to involve tuples with functions. Everything we saw about passing a tuple as argument and returning a tuple can be applied exactly the same way to the methods of a class. Normally, methods deal with tuples exactly as we described for functions, with just minor adjustments. It is important to remember (as stated in our introductory lesson on functions) that a function is a section of code that behaves as if it written outside of a class. Otherwise, everything we studied about involving tuples and functions also applies to methods. This means that you can pass a tuple to a method and you can return a tuple from a method.As you know already, a method is a function created inside a class. As you know already, if you create a method, it has direct access to other members of the same class. In a method, you have direct access to the names of the tuples. To access an element of a tuple, type the name of the member, a period, and the desired member. That way, you can initialize a tuple. Here is an example:
An Object in a Tuple
All the elements we used so far in tuples were of regular types. In reality, each element is a placeholder for practically any type you want. Based on this, an element of a tuple can be an object of a structure or class type. Of course, you must have a class. You can create and use your own class. Here is an example of a class named Trapezoid created in a Windows Forms application named Geometry:
When creating the tuple, specify the desired element using the name of the class. Here is an example:
Trapezoid isosceles = new Circle();
(Trapezoid shape
When initializing the tuple or when specifying its value, you must define the object used as element. You have various options:
- You can first create an object and pass it in its placeholder of the tuple. Here is an example:
To access a member of the class, such as its property or methof, type the name of the tuple, a period, the name you gave to the element or the item_x default name, a period, and the name of the class member. Here is an example
using static System.Console;
Trapezoid trap = new Trapezoid();
trap.TopBase = 244.86;
trap.BottomBase = 384.92;
trap.Height = 175.74;
string msg = "An isosceles trapezoid is a quadrilateral with two opposing sidesl.";
(, string description) shape = (trap, msg);
WriteLine("Area: {0}",
}
- You can define the object in its placeholder of the value of the tuple. Here is an example:
}
Here is an example of running the program:
Top Base: 228.97
Bottom Base: 406.66
Height: 214.83
-------------------------
Area: 68276.19645
=========================
Press any key to close this window . . .
- You can create a function or method that returns an object of the class, then call that function in the placeholder in the tuple. Here is an example:
Here is an example of running the program:
Top Base: 228.68
Bottom Base: 369.37
Height: 273.69
-------------------------
Area: 81840.15225
=========================
Press any key to close this window . . .
In the above example, we used a tuple that has one element that is a class type. In the same way, you can create a tuple with more than one element that are of class or structure type. The elements can be of the same class (or structure) or different classes (or structures).
In the above example, we used our own class. On the other hand, we know that the .NET Framework provides a large collection of classes and structures. You can use any of most of the many classes of the .NET Framework for an element of a tuple.
The Name Involving a Tuple
We already know that, to help you identify something in your code, the C# language provides an operator named nameof. You can use this property on anything that involves a tuple, including a variable of a tuple type, a property of a tuple type, a function or method that returns a tuple, or a function or property that takes a tuple as argument. Here are examples:
using static System.Console;
(int nbr, string status, double salary) employee = (937_842, "Full Time", 22.48);
(string fname, string lname) Identify()
{
return ("Frank", "Lanson");
}
House house = new House()
{
PropertyNumber = 938_448,
Rooms = (5, 3.5),
MarketValue = 545_760
};
void Present(int nbr, (string title, House prop) listing)
{
WriteLine(listing.title);
WriteLine("----------------------------------");
WriteLine("Listing #: {0}", nbr);
WriteLine("Property #: {0}", listing.prop.PropertyNumber);
WriteLine("Bedrooms: {0}", listing.prop.Rooms.beds);
WriteLine("Bathrooms: {0}", listing.prop.Rooms.baths);
WriteLine("Market Value: {0}", listing.prop.MarketValue);
}
WriteLine("Employee Record");
WriteLine("----------------------------------");
WriteLine("Employee #: {0}", employee.nbr);
WriteLine("Employee Name: {0} {1}", Identify().fname, Identify().lname);
WriteLine("Employment Status: {0}", employee.status);
WriteLine("Hourly Salary: {0}", employee.salary);
WriteLine("==================================");
Present(1001, ("Property Listing", house));
WriteLine("==================================");
WriteLine("Name of Tuple Variable: {0}", nameof(employee));
WriteLine("Name of Tuple Function: {0}", nameof(Identify));
WriteLine("Name of Object: {0}", nameof(house));
WriteLine("Name of Tuple Property: {0}", nameof(house.Rooms));
WriteLine("Name of Function: {0}", nameof(Present));
WriteLine("==================================");
internal class House
{
public int PropertyNumber { get; set; }
public (int beds, double baths) Rooms { get; set; }
public double MarketValue { get; set; }
}
Practical Learning: Ending the Lesson
- Close Microsoft Visual Studio