Mesh Compression 学习 -- OpenCtm 创建mesh文件

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值