Creating a polygon shape

A polygon shape is a plane geometry built from a set of contours. The RED::IMeshShape::Polygon functions lets the user create such a mesh by providing the list of contour. Each contour that has a CCW orientation is triangulated inside. Each contour with a CW orientation defines an outer region, i.e holes in the polygon.

Contours list containing vertex coordinates.

RED::Vector< RED::Vector< double > > contours;  // [[v1_x, v1_y, v1_z, v2_x, v2_y, v2_z, ...][...]...]
RED::Vector< RED::Vector< double > > texcoords; // [[t1_u, t1_v, t2_u, t2_v, ...][...]...]
// ... Fill this arrays ...
// contours contains the list of vertices for each contour (grouped by 3 coordinates X, Y and Z).
// texcoords contains the list of texcoords for each contour (grouped by 2 coordinates U and V).

RED::Object* mesh = RED::Factory::CreateInstance( CID_REDMeshShape );
RED::IMeshShape* imesh = mesh->As< RED::IMeshShape >();

// newtexcoords will associate the texcoords to the vertices of the created mesh.
RED::Vector< double > newtexcoords;
RC_TEST( imesh->Polygon( newtexcoords, contours, texcoords, RED::PWR_ODD, iresmgr->GetState() ) );

The RED::IMeshShape::Polygon method only fills the RED::MCL_VERTEX position channel. However, it allows to transmit data associated to the contour points. These data are returned per created vertices. They must be double values and each vertex can have unlimited data. It can be two textures coordinates and/or three color components for instance.

int count;
RC_TEST( imesh->GetVerticesCount( count ) );

// Creates a mesh array to store texture coordinates and retrieves this array.
double* texArray;
RC_TEST( imesh->SetArray( RED::MCL_TEX0, NULL, count, 2, RED::MFT_DOUBLE, iresmgr->GetState() ) );
RC_TEST( imesh->GetArray( (void*&)texArray, RED::MCL_TEX0, iresmgr->GetState() ) );

// For each newly created vertex.
for( int i = 0; i < count; ++i )
  // Fill the mesh texture coordinates using the returned textcoords array.
  // 2 texture coordinates per vertex.
  texArray[ i * 2     ] = newtexcoords[ i * 2     ]; // tex U.
  texArray[ i * 2 + 1 ] = newtexcoords[ i * 2 + 1 ]; // tex V.