Chapter 8 Primary 3D objects

The following commands allow users to build primary 3D geometries: Box, Cone, Cylinder, Sphere, ElevationGrid, Extrusion, and IndexedFaceSet. The menu items shown in figure 1 and toolbar buttons in figure 2 are associated with these commands.

3d menu items

Figure 1 The primary 3D node menu items

3d obj toolbar buttons

Figure 2 The primary 3D node toolbar buttons

Each of these commands has following tasks:

  1. generating a Shape node that contains a primary 3D geometry,
  2. setting the geometry in activated state,
  3. and inserting the Shape into the Scene Graph.

A single separated 3D node not contained in a Shape node may be ignored by the X3D Browser in most cases, this is why each of these commands creates a Shape node.

Sections 1~6 explain how to use these primary 3D creation commands and how to edit these nodes and their fields; one following section specifies how to edit common properties; the last section specifies boolean operations: Combine, Difference, Intersection, Exclusion, and Division.

These commands are accessible when editing X3D, Classic VRML, and VRML97 Models.

1. Box

This command creates a Box node centered at (0, 0, 0) in a local coordinate system and aligned with the coordinate axes; the box measures 2 units in each dimension, from -1 to +1. Thebox toolbar button and the Box menu item are associated with the command.

In Design View, an activated or selected box has 8 points  for editing the size field. When the cursor moves near to a point, a small spot appears, which allows users to drag-and-drop. See figure 3(a). Check Transformation section in Chapter Design View for further information.

box & hot point

Figure 3(a) A box and a small spot for drag-and-drop

In Tree View, to edit the size field values, follow the steps below.

  1. Expand the box tree item tree item if it is collapsed,
  2. Click the size tree item size leaf item to activate the in-place editorin-place editor, and input 3 floating point numbers.

Figure 3(b) shows a Box node Scene Graph. 

box tree items

Figure 3(b) Editing the size field values in Tree View

2. Cone

This command creates a Cone geometry centered in a local coordinate system and whose central axis is aligned with the y-axis; the cone has a radius of 1.0 at the bottom and a height of 2.0, with its apex at y = height/2 and its bottom at y = -height/2. The cone toolbar button and the Cone menu item are associated with this command.

In Design View, an activated or selected cone has 5 small spots, which allow users to change the size.

  1. To change the bottomRadius field, drag-and-drop one of the spots along the x, or z-axis.
  2. To change the height field, drag-and-drop one of the spots along the y-axis. 

See figure 4(a). When the mouse cursor moves near to a point, drag-and-drop function is activated.

Check Transformation section in Chapter Design View for further information.

cone & hot points

Figure 4(a) A cone and its 5 small black spots for drag-and-drop operations

In Tree View, to edit the size, expand the cone tree item tree branch if it is collapsed, then

Figure 4(b) shows a Cone tree list.

cone tree items

Figure 4(b) The Cone fields structure in Tree View

To set whether sides of the cone are created and displayed, set the side field value.

To set whether the bottom cap of the cone is created and displayed, set the bottom filed. 

Similar to the solid field, they can be edited in the Tree View. See the TRUE-FALSE box section for how to edit these fields.

3. Cylinder

The Cylinder command creates a capped cylinder centered at (0,0,0) in a local coordinate system and with a central axis oriented along the y-axis. The cylindertoolbar button and the Cylinder menu item are associated with this command.

In Design View, to edit the radius value, drag-and-drop the cylinder along x- or z-axis; to edit the height, drag-and-drop the cylinder along y-axis. Check Transformation section in Chapter Design View for further information.

To set whether sides of the geometry are created and displayed, set the side field value; to set whether the bottom or top cap of the geometry is created,  set the bottom or top value. Similar to the solid field, they can be edited in Tree View. See the TRUE-FALSE box section for how to edit these fields.

To edit cylinder size in Tree View, first expand the cone tree item node item if it is collapsed, then

Figure 4(c) shows a Cylinder tree list.

Cylinder

Figure 4(c) The Cylinder fields structure in Tree View

4. Sphere

The Sphere command creates an unit sphere centered at (0,0,0) in a local coordinate system. The sphere icon toolbar button and the Sphere menu item are associated with this command.

In Design View, to edit the radius value, drag-and-drop the geometry along any axis. Check Transformation section in Chapter Design View for further information.

In Tree View, to edit the radius field value, follow the steps below.

  1. Expand the cone tree item tree branch if it is collapsed.
  2. Click the radius radius tree item to activate the in-place editorin-place editor, and input one (1) floating point number.

Figure 4(d) shows a Sphere node tree branch.

Sphere

Figure 4(d) The Sphere fields structure in Tree View

5. ElevationGrid

The ElevationGrid command creates a node specifies an uniform rectangular grid of varying height in the Y=0 plane of a local coordinate system. The elevation grid icon toolbar button and the ElevationGrid menu item are associated with this command.

The initial field values of xDimension and zDimension, which indicate the numbers of elements of the grid height array in the X and Z directions, are 0, 0.

To change xDimension value, expand the xDimensionfield item in Tree View, see an example shown in figure 5, click its leaf item to activate its in-place editor, and input one(1) integer number.

an elevationationGrid tree an elevationGrid geo

Figure 5 A grid after setting xDimension and xDimension fields

To specify per-vertex or per-quadrilateral colors for an ElevationGrid node, set the value of colorPerVertex in Tree View, see figure 6.

elevationGrid tree

Figure 6 Setting a colorPerVertex field value in Tree View

To set each vertex has a normal attribute or a quadrilateral does, edit the normalPerVertex field in Tree View, see figure 7.

normalPerVertex

Figure 7 Setting a normalPerVertex field value in Tree View

To set distance between neighbor lines in X or Z direction, click the xSpacing or zSpacing field tree item to bring up the in-place editor in Tree View, and input a positive floating point number.

In Design View, to edit the height, do the following steps.

  1. Select the Shape node or make sure it is in active state.
  2. Activate Select points command.
  3. Select a set of points by pressing down and holding left mouse button to drag-and-drop.
  4. Set Mouse Command type to Scale Y.
  5. Move the cursor over the scene window, drag-and-drop the point set to proper position.

Check Transformation section in Chapter Design View for further information.

In Tree View, to edit the height field values, click the tree item to bring up an MFField editor.

For how to set other rendering properties, like ccw, convex, solid, and creaseAngle fields, check part Set common geometry fields in this chapter.

6. Extrusion

The function of the Extrusion command is to create a geometric shape based on a two dimensional cross-section line extruding along a three dimensional spine in a local coordinate system. The cross-section can be scaled and rotated at each spine point to produce a wide variety of shapes. The extrusion icontoolbar button and the Extrusion menu item are associated with this command.

cross section, spine extrusion extrusion frame

Figure 8 Building an Extrusion node from a Polyline2D and a LineSet node

6.1. Create an Extrusion Geometry

In Design View, to create an Extrusion node, follow the steps below.

  1. Create a Polyline2D node that describes a cross-section curve. See the Polyline2D command for how to build and edit the geometry.
  2. Create a LineSet node, which records a piecewise linear curve. See the LineSet command for how to build and edit the geometry.
  3. Select the Polyline2D and the LineSet nodes. See the Selection commands in the Design View chapter and Selection commands in the Tree View chapter.
  4. Activate the Extrusion command. If the Ctrl key is up, the original two nodes are erased; if the key down, the two shapes are reserved. See figure 9 as an example.

an extrusion node

Figure 9 An Extrusion node and its original geometries

There is no sequence requirement whether the Polyline2D node or the LineSet should be created first, and there is not sequence requirement which one should be selected first when building an Extrusion node. Click here to see two lines and their extrusion code.

Optional operations can be added to the generated node.

  1. Adding a list of 2D scale parameters, which possibly make the extrusion node has different sized cross-section.
  2. Adding a list of 3D orientation parameters, which possibly twist the generated node.

To set whether the sides, the beginning cap and the end cap are created, edit the side, beginCap, and endCap fields in Tree View. The operation is similar to that of the solid field.

For how to set other rendering properties, like ccw, convex, solid, and creaseAngle fields, check the part Set common geometry fields in this chapter.

6.2. Scale

This modeler provides four (4) visual commands to scale Shape nodes: Scale X, Scale Y, Scale Z, and Scale, which are described in the Design View chapter.

There are 4 steps to scale an Extrusion geometry.

  1. Select the geometry. See the Selection commands in the Design View chapter and Selection commands in the Tree View chapter.
  2. Set selection mode to facet. See the Selection commands in the Design View chapter for how to set selection mode.
  3. Activate one of the 4 commands.
  4. Drag-and-drop the geometry to let the shape be deformed. 

In the drag-and-drop step, the deformation starts from the endCap —the scale field at the endCap changes the most and the it remains unchanged at the startCap. However,  if the Shift key is pressed down, the deformation format goes to another side.

The following are different methods to edit the scale field values to make an extrusion node scaled about the origin:

For example, a spine curve has 4 points, defined as:

	spine [ -5.188 -0.911 0, -4.319 2.653 0, -2.099 5.663 0, 0.515 7.881 0]

The scale field can be modified like this:

	scale [1 1, 1 1, 1 1, 1.5 1.5]

scaled extrusion

Figure 10(a) A scaled extrusion geometry whose last cross section plan (endCap) is enlarged 1.5 times.

scale

Figure 10(b) scale field values in the MFField editing dialog box

6.3. Twist and Bend

Twist and Bend operations may result from editing orientation field values. Four (4) visual commands support it: Rotation X, Rotation Y, Rotation Z, and Arbitrary Rotation, which are described in the Design View chapter. Which command results in Twist and which one does a Bend operation depend on geometry axis direction. However, please be noticed that the most powerful Bend operation is to edit the LineSet geometry.  Figure 11 shows an example that Rotation Y command is used to twist a bar.

scale 

Figure 11 Twist operation results from Rotation Y command

There are 4 steps to twist or bend an Extrusion geometry.

  1. Select the geometry. See the Selection commands in the Design View chapter and Selection commands in the Tree View chapter.
  2. Set selection mode to facet. See the Selection commands in the Design View chapter for how to set selection mode.
  3. Activate one of the 4 commands.
  4. Drag-and-drop the geometry to let the shape be deformed. 

In the drag-and-drop step, the deformation starts from the endCap —the orientation field at the end cap changes the most and it remains unchanged at the start cap. However, if the Shift key is pressed down, the deformation format goes to another side.

In Tree View and Code View, the orientation field values can also be edited.

Each orientation element has 4 floating point numbers (x, y, z, a). X, y, and z define a normalized rotation axis vector about which the rotation takes place. The forth number specifies the rotation angle in radians. In the following example, the endCap is rotated 0.4 radian about axis (0, 0, 1).

	orientation [ 0 0 1 0, 0 0 1 0, 0 0 0 0,0 0 1 0.4,]

7. IndexedFaceSet

The function of the IndexedFaceSet command is to create a geometric shape based on constructing facesets (polygons) from a set of coordinates in a local coordinate system. Figure 12 is an example of the node, which contains 6 triangles. The indexed facettoolbar button and the IndexedFaceSet menu item are associated with this command.

Normally, the IndexedFaceSet node is generated from other node(s), such as NURBS, sphere, et al. But in some cases, creating an IndexedFaceSet from points and facesets can still be hopeful.

an indexedFaceSet

Figure 12 An IndexedFaceSet node that contains 6 triangles

To add points to the node, click the left mouse button in Design View that can catch points and lines.

If the cursor hits no points, the cursor shape is an arrow. When users press down the left button, a new point is added to the node.

If the cursor hits a point or a line of the node, the cursor shape changes to a cross and Design View catches the coordinate value. When users press down the left button, a copy of the coordinate value is added to the node.

Press the Enter key to end a faceset editing and start a new one; press the Esc key to escape the process.

To edit the created points of the facesets in this node, see how to Edit points in the Rendering chapter.

To edit the normal field, see Normal section in the Rendering chapter.

The normalIndex field defines each vertex or faceset normal index. Click the field tree item brings up an MFField Editing dialog box.

To set each vertex has a normal attribute or a quadrilateral does, edit the normal field in Tree View. To bring up the TRUE-FALSE box, click the field tree item.

The process of editing colorPerVertex, color, and colorIndex fields is similar to that of the normalPerVertex, normal, and normalIndex respectively.

For how to set other rendering properties, like ccw, convex, solid, and creaseAngle fields, check the part Set common geometry fields in this chapter.

7.1. Pyramin 1: an example using IndexedFacseSet

The following four(4) steps show how to use IndexedFaceSet to build a small pyramid.

  1. activate Geometry 3D|IndexedFaceSet node creation command,
  2. select IndexedFaceSet node in Tree View and activate Rendering|Coordinate node creation command,
  3. click Coordinate|point filed tree item in Tree View to start the MFField dialog and input five(5) point coordinates,
  4. click IndexedFaceSet|coordIndex filed tree item in Tree View to start the MFField dialog and input four(4) groups of triangle index.

Here are the X3D codes that created by step 1, step 2, step 3, and step 4.

8. Set common geometry fields values

8.1. ccw

By default, the quadrilaterals of a geometry are created with a counterclockwise ordering. Setting the ccw field to FALSE reverses the normal direction. To change the setting, expand the solid tree item ccw field item, whose parent is the geometry nod tree item, such as box tree item, click the leaf item to bring up the TRUE-FALSE box.

8.2. convex

The default value of this field is TRUE. To change the value, expand the convex tree item convex field item, whose parent is a geometry nod tree item, such as box tree item, click its leaf item to bring up the TRUE-FALSE box.

8.3. creaseAngle

To set the field value, expand the field item, whose parent is a geometry nod tree item, such as box tree item, click its leaf item to bring up its in-place editor, and input a floating point number.

8.4. solid

To set whether a geometry is visible when viewed from inside, in the Tree View, expand the solid tree item solid field item, whose parent is a geometry nod tree item, such as box tree item and cone tree item, click its leaf item to bring up the TRUE-FALSE box.

8.5. Transformation

For transformation, see the Transform command in the Grouping chapter and the Transformation commands in the Design View chapter.

9. Boolean Operation

Boolean operation allows users to build different real-like 3D worlds through basic geometries, such as box, cone, sphere, cylinder, and extruded shapes. This modeler provides 5 types of operations: Combine, Difference, Intersection, Exclusion, and Division. To use these functions, first select two geometrical objects, than activate one of commands by pressing icons or menu items.

Boolean Operation Menu

Figure 13 Boolean Operation menu items

Boolean Operation toolbar buttons

Figure 14 Boolean operation toolbar buttons

9.1. Combine

The function of this command is to combine two solid geometrical objects and it generates a new node, which normally discards obscure partitions and reserves visible ones viewing from outside. The menu item Combine and the hot iconCombine are associated with this command.

9.2. Difference

The function of this command is to cut one solid geometrical object A with another ones B and it generates a new node, which normally removes any partitions of A inside B. The menu item Difference and the hot icon Difference are associated with this command.

9.3. Intersection

The function of this command is to build a solid geometrical object using public section(s) of two geometrical objects and it generates a new node, which discards any partitions of A and B outside the shared public sections. The menu item Intersection and the hot iconIntersection are associated with this command.

9.4. Exclusion

The function of this command is to build a solid geometrical object by removing public section(s) of two geometrical objects and keeps not shared partitions. The menu item Exclusion and the hot iconExclusion are associated with this command.

9.5. Division

The function of this command is to divide two solid geometrical objects A and B into three nodes, public section(s) of two geometrical objects, and not shared partitions of both A and B. The menu item Division and the hot iconDivision are associated with this command.

9.6. A Boolean Operation example

The below image, figure 15, shows a cup pad which is made up of several small piece of bamboo, see figure 16. To build the smallest unit, we used the following steps.

Cup pad is made up of some small units

Figure 15 My Cup Pad

Boolean Operation toolbar buttons

Figure 16 A small unit of My Cup Pad

Step 1: Create two cylinders and translate them along x-coordinate, see file MyPad.1.x3d.

Boolean Operation

Figure 17 Two (2) cylinders as basis geometry nodes are used for boolean operations

Step 2: Select the two cylinders and than activate Intersection command, and it generates a small block A, see file MyPad.2.x3d.

Boolean Operation

Figure 18 Intersection results

Step 3: Add a box to the scene, see file MyPad.3.x3d.

Boolean Operation

Figure 19 A box is added to scene for boolean operation

Step 4: Select the box and the small block A, and activate the command Intersection, it generates a small block B. Check file MyPad.4.x3d.

Boolean Operation

Figure 20 Boolean operation results

Step 5: Add a cylinder node to the scene and rotate it, see file MyPad.5.x3d.

Boolean Operation

Figure 20 Another cylinder is added to screen for boolean operations

Step 6: Select the cylinder and block B, and activate the Difference command, it generates a block C, as picture 16.