OpenCTM: Open File Format for Compressed 3D Meshes

OpenCTM



OpenCTM (I guess OpenCTM means Open Compressed Triangle Mesh) is a file format for storing 3D triangle meshes in a compact and versatile format. The format supports per-vertex position, normal, texture coordinates and custom attributes. Large geometries up to billions of triangles and vertices can be stored (OpenCTM uses 32-bit face indices). The OpenCTM SDk is open source and written in C.

You can download the OpenCTM SDK HERE.

OpenCTM

Here is how to load a ctm file:

#include 
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);

and here is how to create a ctm file from your geometry.

#include 
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);

I’ll try to add it in GeeXLab



Related posts:

  1. OpenCTM 1.0.2: Compressed 3D Meshes SDK Available
  2. PhysX Tool: Convert Physics Scenes into an OBJ file with PhysX2Obj
  3. Most Often Used Open Source Gaming Engines
  4. NVIDIA OpenGL Texture Format Spreadsheet Updated
  5. Hacking Radeon HD 4800 Series Profile XML File