OpenCTM API Reference

1.0.3

Introduction

OpenCTM is an open file format for storing compressed triangle meshes. In order to easily read and write OpenCTM files (usually suffixed .ctm) an API (Application Program Interface) is provided that can easily be used from most modern programming languages.

The OpenCTM functionality itself is written in highly portable standard C (C99).

Usage

For information about how to use the OpenCTM API, see openctm.h.

For information about the C++ wrapper classes, see CTMimporter and CTMexporter.

Example usage

Loading a CTM file

Here is a simple example of loading a CTM file:

   CTMcontext context;
   CTMuint    vertCount, triCount, * indices;
   CTMfloat   * vertices;

   // Create a new context
   context = ctmNewContext(CTM_IMPORT);

   // Load the OpenCTM file
   ctmLoad(context, "mymesh.ctm");
   if(ctmGetError(context) == CTM_NONE)
   {
     // Access the mesh data
     vertCount = ctmGetInteger(context, CTM_VERTEX_COUNT);
     vertices = ctmGetFloatArray(context, CTM_VERTICES);
     triCount = ctmGetInteger(context, CTM_TRIANGLE_COUNT);
     indices = ctmGetIntegerArray(context, CTM_INDICES);

     // Deal with the mesh (e.g. transcode it to our internal representation)
     // ...
   }

   // Free the context
   ctmFreeContext(context);

Creating a CTM file

Here is a simple example of creating a CTM file:

   CTMcontext context;
   CTMuint    vertCount, triCount, * indices;
   CTMfloat   * vertices;

   // Create our mesh in memory
   vertCount = 100;
   triCount = 120;
   vertices = (CTMfloat *) malloc(3 * sizeof(CTMfloat) * vertCount);
   indices = (CTMuint *) malloc(3 * sizeof(CTMuint) * triCount);
   // ...

   // Create a new context
   context = ctmNewContext(CTM_EXPORT);

   // Define our mesh representation to OpenCTM (store references to it in
   // the context)
   ctmDefineMesh(context, vertices, vertCount, indices, triCount, NULL);

   // Save the OpenCTM file
   ctmSave(context, "mymesh.ctm");

   // Free the context
   ctmFreeContext(context);

   // Free our mesh
   free(indices);
   free(vertices);

Copyright © 2009-2010 Marcus Geelnard — openctm.sourceforge.net