OpenCtm是一个跨平台mesh数据压缩开源软件。
官网地址:http://openctm.sourceforge.net/?page=about
提供三种数据压缩方式 (RAW 、MG1、MG2)
OpenCtm 的配置非常简单。加入 openctm.lib openctm.dll openctm.h openctmpp.h 即可。
这里提供创建mesh 文件的代码
#include "openctm.h"
#include "openctmpp.h"
#include "stdio.h"
#pragma comment(lib, "openctm.lib")
int main()
{
CTMuint aVerCount;
CTMuint aTriCount;
CTMfloat *aVertices = new CTMfloat[900000];
CTMuint *aIndices = new CTMuint[300000];
CTMcontext context;
CTMenum ret;
aVerCount = 300000;
aTriCount = 100000;
CTMfloat *ptrVertices = aVertices;
CTMuint *ptrIndices = aIndices;
for (int j = 0; j < aVerCount; j++)
{
*ptrVertices = j*0.1f;
*(ptrVertices + 1) = j*0.2f;
*(ptrVertices + 2) = j*0.3f;
ptrVertices += 3;
}
for (int i = 0; i < aTriCount; i++)
{
*(ptrIndices + 0) = i;
*(ptrIndices + 1) = i + 1;
*(ptrIndices + 2) = i + 2;
ptrIndices += 3;
}
context = ctmNewContext(CTM_EXPORT);
ctmDefineMesh(context, aVertices, aVerCount, aIndices, aTriCount, NULL);
ctmCompressionMethod(context, CTM_METHOD_MG1);
ctmSave(context, "test.ctm");
ctmFreeContext(context);
//getchar();
return 0;
}
代码中CTM_METHOD_MG1 可替换为CTM_METHOD_MG2 或 CTM_METHOD_RAW