The following topics are covered in this section.
This small collect of objects will do nicely in assisting if our exaplanation of the wonders of CSG.First off, note that this is a different viewing angle from the initial sample scene. This is to make it more obvious what the difference did. Note that the scene is a cube with some interesting sections taken out of it. This is because the box object was the first one listed in the difference (see the source). Also notice how the different parts of the now scarred cube are different colors. When you do a difference operation, the surface is colored based on which object acutally "created" that surface. So the hole through the center of the box is green because it was made with the green cylinder. If you wanted the entire surface to be all one color, you could either change each individual texture to the same, or you could remove all the textures on the individual objects, and just put one inside the difference.
See union for more detailed information on declaring CSG objects.
The result is a cylinder with sort of "squared off" ends. That volume corresponds to the space which is contained inside both of those objects. You can see which object was defining each boundary by the color of the result. Anywhere that is green is on the boundary of the cylinder and anything that is red is on the boundary of the box. Admittedly, this particular thing isn't too useful, but intersection, along with its close relative, difference, is probably the most powerful CSG directive for creating new and interesting objects.
See union for more detailed information on declaring CSG objects.
See the difference (no pun intended)? If you did, then there's something wrong. The only difference between between these two scenes is in the source. They render to the same image. One (the first) uses a difference, while the other (the second) uses an intersection. The reason they look the same is the second and third object in the second scene were inverted (don't just trust me, see for yourself). Remember how difference and intersection work. Difference carves away insides, and intersection carves away outsides. But by flipping the insides and outsides in the intersection, it, too, is effectively carving away outsides. In fact, difference is implemented in POV-Ray as an intersection with the second through nth objects inverted.
Here's an image which should make inverse more understandable. In this intersection, the box is inverted, so only regions outside the box and inside the cylinder remain.
Note how in the first image, the outline of the cylinder is clearly visible inside the box. In the second, this object is gone. The combined objects are now acutally a single, continuous unit.
One very important thing to keep in mind when creating merge objects is that coincident surfaces (surfaces which touch exactly at more than just a point or a line) will cause very strange errors in your object. Sections of the object will be randomly invisible, and things will be generally very twisted. For example, doing the following is bad.
merge {
cylinder {
<0, 0, 0>, <0, 3, 0>, 3
}
cone {
<0, 3, 0>, 3,
<0, 6, 0>, 0
}
texture { SomeTexture }
}
Note how the top of the cylinder and the bottom of the cone are the same. This is bad. Note that this will not always render incorrectly. Sometimes it'll come out ok, and sometimes it won't. C programmers will understand when we say that "the results will be undefined."
merge {
cylinder {
<0, 0, 0>, <0, 3, 0>, 3
}
cone {
<0, 2.99, 0>, 3,
<0, 6, 0>, 0
}
texture { SomeTexture }
}
Now the two objects overlap a bit. This is just enough to fix the problem, and won't impact the appearance of the object appreciably.
See union for more detailed information on declaring CSG objects.
union {
object { obj 1 }
object { obj 2 }
/* you can have as many objects as you wish */
object { obj n }
/* here go any textures, rotations, translations, and scales. */
}
Of course, if you want a difference, intersection, or merge, you should change the "union" above to the appropriate identifier.
Any object, whether finite, infinite, or CSG, can be used in a union. There are restrictions on objects in the other types of CSG, though. Any object used in an intersection, merge, or difference must have a clearly defined inside. Objects like triangles don't have insides, and so can only be used in unions, not the others. You can use clipping to simulate these operations on flat objects, though.
Unions are wonderful for creating coherent objects. For example, you can create an object with a great many components and group them all together into a union. After that, you can transform them by transforming the union instead of having to transform all the individual objects. You can also easily texture the objects as one. One thing to remember when texturing CSG objects, though, is that a texture for a specific object in a CSG will override any texture specified for the CSG object itself.
Here is the sample scene with the objects joined together in a union.
The Online POV-Ray Tutorial © 1996 The Online POV-Ray Tutorial ThinkQuest Team