Go to Google Code Home
Google SketchUp SkpReader C++ API Documentation (Labs)

CreateMesh.cpp

This example shows how to create a mesh from a face. This example demonstrates the use of the ISkpFace::CreateMesh function, as well as working with the ISkpPolygonMesh object. This is typically done to triangulate a SketchUp face with one or more holes (inner loops) in it.

void CreateMesh(ISkpFace* pFace)
{
    HResult hr;
    CComPtr<ISkpPolygonMesh> pMesh;

    // This call will create the mesh including 
    // - all the points on the mesh
    // - The UV coordinates for the front face
    // - The UV coordinates for the back face
    // - The normal vectors at each mesh point.
    hr = pFace->CreateMesh(PolygonMeshPoints | PolygonMeshUVQFront | PolygonMeshUVQBack | PolygonMeshNormals, &pMesh);

    // Now as an example, we iterate through the resulting mesh,
    // printing out the mesh points.
    long numPoints = 0;
    hr = pMesh->get_Count(&numPoints);
    long index;
    for( index = 1; index <= numPoints; index++ )
    {
      // Get the point from the mesh
      CComPtr<ISkpPoint3d> pSkpPoint;
      hr = pMesh->get_Point(i, &pSkpPoint);

      // Get the coordinates from the point
      double x,y,z;
      pSkpPoint->Get(&x,&y,&z);

      // Print out the point coordinates
      printf("Point x, y, z: %g, %g, %g", x, y, z);
    }
}


©2010 Google - Google Home - About Google