A mesh is an efficient way to store a parametrically rectangular grid of vertices. The geometry for a mesh is specified as the number of rows, the number of columns, and a list of vertices, in row-order:
virtual Adesk::Boolean AcGiWorldGeometry::mesh( const Adesk::UInt32 rows, const Adesk::UInt32 columns, const AcGePoint3d* pVertexList, const AcGiEdgeData* pEdgeData = NULL, const AcGiFaceData* pFaceData = NULL, const AcGiVertexData* pVertexData = NULL) const = 0;
The mesh() function has three optional parameters for attaching property data to edges, faces, or vertices. For edges in the mesh, you can attach color, layer, linetype, GS marker, and visibility properties. For example, you could use AcGiEdgeData::setColors() to attach a different color to each edge of the mesh. In the color list, first list the colors for all the row edges, then the colors for all the column edges. The following figure shows the ordering of edge property data for a sample mesh:
The following sample code creates a mesh and assigns colors using edge data and face data. It constructs a four-by-four mesh with cyan rows and green columns.
Adesk::Boolean AsdkMeshSamp::subWorldDraw(AcGiWorldDraw* pW) { Adesk::UInt32 i, j, k; Adesk::UInt32 numRows = 4; Adesk::UInt32 numCols = 4; AcGePoint3d *pVerts = new AcGePoint3d[numRows * numCols]; for (k = 0, i = 0; i < numRows; i++) { for (j = 0; j < numCols; j++, k++) { pVerts[k].x = (double)j; pVerts[k].y = (double)i; pVerts[k].z = 0.; } } // Construct an array of colors to be applied to each // edge of the mesh. Here, let the rows be cyan and // the columns be green. // AcGiEdgeData edgeInfo; Adesk::UInt32 numRowEdges = numRows * (numCols - 1); Adesk::UInt32 numColEdges = (numRows - 1) * numCols; Adesk::UInt32 numEdges = numRowEdges + numColEdges; short *pEdgeColorArray = new short[numEdges]; for (i = 0; i < numEdges; i++) { pEdgeColorArray[i] = i < numRowEdges ? kCyan : kGreen; } edgeInfo.setColors(pEdgeColorArray); // Make the first face transparent and the rest // different colors. // Adesk::UInt32 numFaces = (numRows - 1) * (numCols - 1); Adesk::UInt8 *pFaceVisArray = new Adesk::UInt8[numFaces]; short *pFaceColorArray = new short[numFaces]; AcGiFaceData faceInfo; faceInfo.setVisibility(pFaceVisArray); for (i = 0; i < numFaces; i++) { pFaceVisArray [i] = i ? kAcGiVisible : kAcGiInvisible; pFaceColorArray[i] = (short)(i + 1); } faceInfo.setColors(pFaceColorArray); // If the fill type is kAcGiFillAlways, then a shell, // mesh, or polygon will be interpreted as faces; // otherwise, they will be interpreted as edges. // Output mesh as faces. // pW- >subEntityTraits().setFillType(kAcGiFillAlways); pW->geometry ().mesh(numRows, numCols, pVerts, NULL, &faceInfo); // Output mesh as edges over the faces. // pW- >subEntityTraits().setFillType(kAcGiFillNever); pW->geometry ().mesh(numRows, numCols, pVerts, &edgeInfo); delete [] pVerts; delete [] pEdgeColorArray; delete [] pFaceColorArray; delete [] pFaceVisArray; return Adesk::kTrue; }
For faces in a mesh, you can attach color, layer, GS marker, normal, and visibility traits. To assign properties to faces in a mesh, you list the values for the faces in row-order, as indicated by the following figure:
Vertex data for the mesh is listed in the same order as in the vertex list. Properties that can be set with AcGiVertexData are normals and orientation.