Manual:Traditional modeling, the CSG way/zh-cn

CSG 代表构造实体几何，描述了使用实体 3D 几何的最基本方式，即使用诸如并集、差集、或交集之类的布尔运算，向实体对象添加和移除部分实体，达成创建复杂对象的目的.

本手册前面提到，一方面，FreeCAD 可以处理多种类型的几何体；另一方面，我们使用 FreeCAD 设计的 3D 对象，是真实世界的对象. 因此，这里首选的、最有用的类型，毫无疑问，是实体，是 BREP 几何体，主要由Part 工作台来处理. 多边形网格仅由点和三角形构成，与此不同，BREP 对象的面由数学曲线定义，无论缩放比例如何，都保证有绝对的精度.



两者之间的差异，类似于位图和矢量图像之间的差异. 与位图图像一样，多边形网格的曲面划分为一系列的点. 如果你贴近观察，或者将它打印得非常大，你会发现它不是曲面而是切面. 在矢量图像和 BREP 数据里，曲线上任何点的位置都不会存储在几何体中，而是在运行中即时精确计算.

在 FreeCAD 中，所有基于 BREP 的几何都由另一个开源软件 OpenCasCade 处理. FreeCAD 与 OpenCasCade 内核之间的主要接口是 Part 工作台. 大多数其他工作台在 Part 工作台的基础上构建其功能.

其他工作台通常提供了更高级的工具来构建和操作几何体，实际上都操纵的是 Part 对象，因此非常有必要了解这些对象的内部工作机制，并且能够使用 Part 工具. 一些更智能的工具无法正确解决的问题，Part 工具因为更简单，经常可以帮你解决.

为了说明 Part 工作台的工作原理，我们将仅使用 CSG 操作对模型建模（螺钉除外，因为我们将使用一个插件，里面有尺寸，在下一章中介绍）.



让我们创建一个新文档（ Ctrl + N 或菜单 File -> New Document）来保存我们设计的桌子. 该文档最初在 Combo View 面板的 Model 选项卡中称为“unnamed”，但如果将文档（ Ctrl+Shift+S 或 菜单 File -> Save As）保存为称作“table.fcstd” 的新 FreeCAD 文档，文档便重命名为“table”，更清楚地标识了该项目.

现在我们切换到 Part 工作台，开始创建我们的第一个桌腿.


 * 按下 [[Image:Part_Box.png|16px]] Cube 按钮
 * 选择 Cube，然后设置以下属性（在 Data 选项卡中）：
 * 长度：80mm（或 8cm，或 0.8m，FreeCAD 可以使用任何单位）
 * 宽度：80mm
 * 高度：75cm
 * 按 Ctrl+C 然后按 Ctrl+V（或菜单 Edit -> Copy 然后 Paste）复制 Cube（没有任何变化，因为第二个对象与第一个重合. ）
 * 选择已创建的名为 Cube001 的新对象（单击左侧 Model 选项卡中的 Cube001）
 * 编辑其 Placement 属性来更改其位置：
 * 位置 x：8mm
 * 位置 y：8mm

你应该得到了两个高高的立方体，一个与另一个相距 8毫米.



现在我们可以从另一个中减去一个：选择第一个，即保留的那个，然后，按下 CTRL 键，选择另一个，即将被减去（顺序很重要），然后按下 Cut 按钮.



注意创建的对象，称为“Cut”. “Cut”仍然包含我们用作运算子的两个立方体. 实际上，文档中仍然存在两个“Cube"，仅被隐藏并在树视图中的“Cut”对象的分组中，仍然可以通过展开“Cut”对象旁边的箭头来选择它们. 如果需要，可以右键单击来将它们显示出来，或更改它们的属性.

然后改变它们的位置，数据如下：
 * 我们复制基础立方体 6 次，创建另外三个脚. 由于它仍然复制在剪贴板里，可以简单地粘贴（Ctrl + V）6次.
 * Cube002：x：0，y：80cm
 * Cube003：x：8mm，y：79.2cm
 * Cube004：x：120cm，y：0
 * Cube005：x：119.2cm，y：8mm
 * Cube006：x：120cm，y：80cm
 * Cube007：x：119.2cm，y：79.2cm


 * 做另外三个切割，首先选择“host”立方体，然后选择要切除的立方体. 我们有了四个 Cut 对象.



You might have been thinking that, instead of duplicating the base cube six times, we could have duplicated the complete foot three times. This is totally true, as always in FreeCAD, there are many ways to achieve a same result. This is a precious thing to remember, because, as we will advance into more complex objects, some operations might not give the correct result and we often need to try other ways.


 * We will now make holes for the screws, using the same Cut method. Since we need 8 holes, two in each foot, we could make 8 objects to be subtracted. Instead, let's explore other ways and make 4 tubes, that will be reused by two of the feet. So let's create four tubes by using the [[Image:Part_Cylinder.png|16px]] Cylinder tool. You can again, make only one and duplicate it afterwards. Give all cylinders a radius of 6mm. This time, we will need to rotate them, which is also done via the Placement property under the Data tab (Note: change the Axis property before setting the Angle, or the rotation will not be applied):
 * Cylinder: height: 130cm, angle: 90°, axis: x:0,y:1,z:0, position: x:-10mm, y:40mm, z:72cm
 * Cylinder001: height: 130cm, angle: 90°, axis: x:0,y:1,z:0, position: x:-10mm, y:84cm, z:72cm
 * Cylinder002: height: 90cm, angle: 90°, axis: x:-1,y:0,z:0, position: x:40mm, y:-10mm, z:70cm
 * Cylinder003: height: 90cm, angle: 90°, axis: x:-1,y:0,z:0, position: x:124cm, y:-10mm, z:70cm



You will notice that the cylinders are a bit longer than needed. This is because, as in all solid-based 3D applications, boolean operations in FreeCAD are sometimes oversensitive to face-on-face situations and might fail. By doing this, we put ourselves on the safe side.


 * Now let's do the subtractions. Select the first foot, then, with CTRL pressed, select one of the tubes that crosses it, press the Cut button. The hole will be done, and the tube hidden. Find it in the tree view by expanding the pierced foot.
 * Select another foot pierced by this hidden tube, then repeat the operation, this time Ctrl+ selecting the tube in the tree view, as it is hidden in the 3D view (you can also make it visible again and select it in the 3D view). Repeat this for the other feet until each of them has its two holes:



As you can see, each foot has become a quite long series of operations. All this stays parametric, and you can go change any parameter of any of the older operations anytime. In FreeCAD, we often refer to this pile as "modeling history", since it in fact carries all the history of the operations you did.

Another particularity of FreeCAD is that the concept of 3D object and the concept of 3D operation tend to blend into one same thing. The Cut is at the same time an operation, and the 3D object resulting from this operation. In FreeCAD this is called a "feature", rather than object or operation.


 * Now let's do the tabletop, it will be a simple block of wood, let's do it with another Box with length: 126cm, width: 86cm, height: 8cm, position: x: 10mm, y: 10mm, z, 67cm. In the View tab, you can give it a nice brownish, wood-like color by changing its Shape Color property:



Notice that, although the legs are 8mm thick, we placed it 10mm away, leaving 2mm between them. This is not necessary, of course, it won't happen with the real table, but it is a common thing to do in that kind of "assembled" models, it helps people who look at the model to understand that these are independent parts, that will need to be attached together manually later.

Now that our five pieces are complete, it is a good time to give them more proper names than "Cut015". By right-clicking the objects in the tree view (or pressing F2), you can rename them to something more meaningful to yourself or to another person who would open your file later. It is often said that simply giving proper names to your objects is much more important than the way you model them.


 * We will now place some screws. There is nowadays an extremely useful addon developed by a member of the FreeCAD community, that you can find on the FreeCAD addons repository, called Fasteners, that makes the insertion of screws very easy. Installing additional workbenches is easy and described on the addons pages.
 * Once you have installed the Fasteners Workbench and restarted FreeCAD, it will appear in the workbenches list, and we can switch to it. Adding a screw to one of our holes is done by first selecting the circular edge of our hole:




 * Then we can press one of the screw buttons of the Fasteners Workbench, for example the EN 1665 Hexagon bolt with flanges, heavy series. The screw will be placed and aligned with our hole, and the diameter will automatically be selected to match the size of our hole. Sometimes the screw will be placed inverted, which we can correct by flipping its invert property. We can also set its offset to 2mm, to follow the same rule we used between the tabletop and the feet:




 * Repeat this for all the holes, and our table is complete!

The internal structure of Part objects

As we saw above, it is possible in FreeCAD to select not only whole objects, but parts of them, such as the circular border of our screw hole. This is a good time to have a quick look at how Part objects are constructed internally. Every workbench that produces Part geometry will be based on these:


 * Vertices: These are points (usually endpoints) on which all the rest is built. For example, a line has two vertices.
 * Edges: the edges are linear geometry like lines, arcs, ellipses or NURBS curves. They usually have two vertices, but some special cases have only one (a closed circle for example).
 * Wires: A wire is a sequence of edges connected by their endpoints. It can contain edges of any type, and it can be closed or not.
 * Faces: Faces can be planar or curved, and can be formed by one closed wire, which forms the border of the face, or more than one, in case the face has holes.
 * Shells: Shells are simply a group of faces connected by their edges. It can be open or closed.
 * Solids: When a shell is tightly closed, that is, it has no "leak", it becomes a solid. Solids carry the notion of inside and outside. Many workbenches rely on this to make sure the objects they produce can be built in the real world.
 * Compounds: Compounds are simply aggregates of other shapes, no matter their type, into a single shape.

In the 3D view, you can select individual vertices, edges or faces. Selecting one of these also selects the whole object.

A note about shared design

You might look at the table above, and think its design is not good. The tightening of the feet with the tabletop is probably too weak. You might want to add reinforcing pieces, or simply you have other ideas to make it better. This is where sharing becomes interesting. You can download the file made during this exercise from the link below, and modify it to make it better. Then, if you share that improved file, others might be able to make it even better, or use your well-designed table in their projects. Your design might then give other ideas to other people, and maybe you will have helped a tiny bit to make a better world...

Downloads


 * The file produced in this exercise: https://github.com/yorikvanhavre/FreeCAD-manual/blob/master/files/table.FCStd

Read more


 * The Part Workbench
 * The FreeCAD addons repository
 * The Fasteners Workbench