## Chapter 13. 3D objects

The possibilities for managing 3D objects from Visual LISP are closely related to the type of entity to be used. We have seen that these entities have been added at different times, and the functions available for working with them are largely related to that circumstance.

In all cases, the

*command/vl-cmdf*interface can be used when dealing with arguments and options that can be introduced via the keyboard or through graphic screen designations. Through*entmake*it is possible to create surface entities of the legacy*AcadPolyfaceMesh*and*AcadPolygonMesh*types. These are complex entities of the*POLYLINE*type identified by its DXF group code 70: bit 6 on (value = 64) for*AcadPolyfaceMesh*and bit 4 on (value = 16) for*AcadPolygonMesh*. These entities can also be created using the corresponding ActiveX methods through the*vla-Add3DMesh*and*vla-AddPolyfaceMesh*functions.
As a consequence of ACIS data encryption, ActiveX methods are the only programming alternative for 3DSolid objects without resorting to the

*command/vl-cmdf*interface.
The Release 2010 Subdivision surfaces (

*MESH*entities) can be created by*entmake*but the documentation of their DXF group codes DXF is imprecise, fact which we will try to clarify through some examples. The object model does not expose ActiveX methods for their creation, which is only possible using*entmake*or the*command/vl-cmdf*interface, The use of commands can save programming work, but*entmake*can create custom surfaces not available through commands. Once created, the*MESH*entity’s properties exposed in the ActiveX object allow the modification of its vertices coordinates to obtain a variety of three-dimensional shapes using Visual LISP programs. In this manner we can profit both from*entmake*as from the AutoCAD commands to create basic shapes that can later be modified by accessing its properties.*PolygonMesh*and*PolyfaceMesh*objects as well as*3DSolids*can also be converted into*MESH*entities. The old commands for creating surfaces, _*REVSURF*, _*TABSURF*, _*RULESURF*, or _*EDGESURF*now can generate Subdivision surfaces.
And once the desired shapes are created as meshes they can be converted into the new

*procedural*or*NURBS*surfaces, as appropriate to the model we are working on. This is a relatively unexplored field, and the results presented are the result of ongoing investigations that we hope will help our readers in their 3D modeling tasks.
AutoLISP / Visual LISP also offers us the opportunity to work in a way that we could call “hybrid” using in the same program its scripting capabilities for invoking commands, the possibility of accessing the drawing’s database through

*entmake/entmod*, and once created the object, by changing its ActiveX exposed properties.
This chapter introduces some of the essential concepts that must be mastered to deal with programming in a 3D environment. These include:

- The transformation between Coordinate Systems.
- Vector operations.
- Transformations in space, including translation, rotation, scaling, etc. and the transformation matrices through which they are specified.
- Modification of the 3D viewpoints so as to aid in the comprehension of the generated forms.
- How to set through programming the 3D objects visualization mode including colors, shadows and transparencies.

The issues have been addressed taking advantage of functions, methods and properties readily available in the programming language, so that a great mathematical background is not essential.

#### This Chapter includes the following sections:

13.1. Programming options from Visual LISP.

13.2. How does AutoCAD work in 3D?.

13.3. Transformation matrices.

13.4. Sample Program: Scailin transformations specifying the base point.

13.5. Transformation between Coordinate Systems.

13.6. Viewpoint and Visual Style.

13.7. Summary.

#### Chapter 13 Source code.

**Your questions or comments about this Chapter's contents are welcome!**## Chapter 14. NURBS curves: The SPLINE entity

The

*SPLINE*entity is an implementation of the*Non-Uniform Basis Spline*(NURBS) mathematical model that facilitates the creation and representation of curves and surfaces including both highly complex freeform objects and simple geometric ones. They are characterized by:- Their ability to represent virtually any shape, from points, straight lines, or polylines to conic sections (circles, ellipses, parabolas and hyperbolas) and completely arbitrary free forms.
- The great control that can be attained over the curve’s shape, being able to change its curvature and continuity by manipulating its set of control vertices and knots.
- Achieving the representation of highly complex shapes with an extremely reduced amount of data.

Figure 14.1. Splines defined from Fit Points and from Control Vertices. |

A spline curve is defined by a set of point coordinates that indicate the general shape of the curve. These points are adjusted by piecewise polynomial functions according to two different procedures:

- Fit Points: Splines created with the Fit method. The curve passes through each point, in which case (Figure 14.1, Left) it is an interpolation.
- Control Vertices: Splines created from the CV method. The curve adopts the general form of the polygon but does not necessarily pass through any of the control points, in which case (Figure 14.1, Right) it is an approximation.

Splines can be created through entmake and using the

*AddSpline*ActiveX method. The*entmake*function provides greater control over the creation of Splines, although this requires a deeper understanding of the parameters involved. The procedure used to create the curve determines the accessibility to some of its properties.
This seeks to fill an important shortcoming in AutoCAD’s documentation, explaining fundamental concepts such as:

- The curve's Degree.
- The Control Vertices.
- The Knot Vector and its relationship to the curve type.
- The Weights assigned to vertices and their effects.

NURBS surfaces are a generalization of NURBS curves and respond to the same algorithms, however they are not yet accessible to Visual LISP programming. But mastering the programming of SPLINES it is possible to create NURBS surfaces through the

*command/vl-cmdf*interface .
NURBS geometry has characteristics that justify its use in CAD systems. Among them we can highlight:

- There are standard procedures for the exchange of NURBS geometry among different design applications that use it as a basic resource, e.g., Autodesk Alias, Maya and Rhino.
- NURBS geometry has a precise and well-known definition that is part of the curriculum in most universities.
- This geometry can accurately represent both simple geometries such as lines, arcs or circles and more complex ones such as the surfaces used in automotive, naval or aeronautic design.
- The amount of information required for a NURBS representation is much less than for other 3D objects such as Polylines, Polygon meshes and Subdivision surfaces.
- Its implementation in computer programs is efficient and extremely accurate.

#### This Chapter includes the following sections:

14.1. Creating SPLINE entities.

14.2. SPLINE Methods and Properties.

14.3. Creating ca Helix shaped SPLINE by Control Vertices.

14.4. Sample Program: Creatins a HELIX.

14.5. Summary.

#### Chapter 14 Source code.

**Your questions or comments about this Chapter's contents are welcome!**## Chapter 15. VLAX-CURVE... Measuring curves and something else

Like the other Visual LISP ActiveX extensions,

*vlax-curve...*functions are not available when starting AutoCAD. These functions identified with the*vlax-curve*prefix, can be applied to the solution of a number of issues when operating on curves. To enable them it will be necessary as always, to evaluate (vl-load-com). Any program using them should be initiated with a call to this function.
Although we will not exhaust the topic of

*vlax-curve...*and related functions, we believe that this chapter is a clear demonstration of their possibilities. As always, we will have added new useful functions to our programmer’s library that can be used within our programs. A good example is the program used to draw tangents to the curve, that with minimal changes becomes another apparently very different program, which serves to establish with a single selection a coordinate system perpendicular to the selected entity. In the following chapters we will see how these functions can help in creating and editing objects in a 3D environment.#### This Chapter includes the following sections:

15.1. Visual LISP's VLAX-CURVE Extensions.

15.2. Common arguments..

15.3. Determining a curve's length.

15.4. Distance between points along a curve.

15.5. Measuring Areas

15.6. Calculating the first and second derivatives.

15.7. Sample Program: Drawing tangents to a curve.

15.8. Sample Program: UCS perpendicular to a curve at a selected point.

15.9. Determining points on a curve.

15.10. Sample Program: Breaking a curve into equal segments.

15.11. Determining intersections.

15.12. Summary.

#### Chapter 15 Source code.

**Your questions or comments about this Chapter's contents are welcome!**
## No comments:

## Post a Comment