文档管理中心
我的
指南图形引擎服务应用开发离线简模插件

离线简模插件

本文导读

离线简模插件方便开发者对模型网格数据进行简化处理,支持处理具有顶点和索引信息的模型。

您只要预制好顶点和索引的数据以及长度信息,设置好简模比例和容错率,调用简模算法库就可以方便地获取到简模后的模型索引信息。简模插件操作便捷高效,具体集成请参见开发步骤章节。

开发步骤

  1. 下载SDK包,解压获取SDK库,下载地址请参见SDK下载:离线简模插件。
  2. 通过CMake等构建工具集成简模SDK库文件。

    收起
    自动换行
    深色代码主题
    复制
    1. cmake_minimum_required(VERSION 3.0)
    2. project(main)
    3. set(CMAKE_CXX_STANDARD 11)
    4. link_directories("${CMAKE_CURRENT_SOURCE_DIR}/lib")
    5. add_executable(main main.cpp)
    6. target_link_libraries( main
    7. PUBLIC)
    说明
    • 当前离线简模插件仅支持64位系统。
    • SlimMesh.dll与main可执行文件需要置于同一目录运行。

  3. 构造模型顶点信息数据,调用简模算法接口,获取简模后的模型数据。

    收起
    自动换行
    深色代码主题
    复制
    1. #include <iostream>
    2. #include <Windows.h>
    3. #include <vector>
    4. // MeshInfo Struct
    5. struct MeshInfo {
    6. unsigned int vertexCnt;
    7. unsigned int vertexStride;
    8. unsigned int indexCnt;
    9. unsigned int targetIndexCnt;
    10. };
    11. // SlimMesh API
    12. typedef unsigned int (*SlimMeshFUN)(unsigned int *, const unsigned int *, const float *, MeshInfo, float);
    13. int main()
    14. {
    15. // Make Meshinfo and Call SlimMesh API
    16. const unsigned int VERTEX_ELEMENT_CNT = 3;
    17. const unsigned int EXPECT_INDEX_CNT = 6;
    18. std::vector<float> oriVertices = { 0, 0, 0, 1, 0, 0, 2, 0, 0, 0.5f, 1, 0, 1.5f, 1, 0 };
    19. std::vector<unsigned int> oriIndices = { 0, 1, 3, 3, 1, 4, 1, 2, 4 };
    20. SlimMeshFUN SlimMesh;
    21. HINSTANCE hdll;
    22. // 选择SlimMesh.dll的文件路径。
    23. hdll = LoadLibrary("../SlimMesh.dll");
    24. if (hdll == NULL) {
    25. std::cout << "cannot locate the SlimMesh.dll file" << std::endl;
    26. return -1;
    27. }
    28. SlimMesh = (SlimMeshFUN)GetProcAddress(hdll, "SlimMesh");
    29. MeshInfo meshInfo;
    30. meshInfo.indexCnt = static_cast<unsigned int>(oriIndices.size());
    31. meshInfo.vertexCnt = static_cast<unsigned int>(oriVertices.size()) / VERTEX_ELEMENT_CNT;
    32. meshInfo.vertexStride = sizeof(float) * VERTEX_ELEMENT_CNT;
    33. meshInfo.targetIndexCnt = EXPECT_INDEX_CNT;
    34. float targetError = 1e-2f;
    35. std::vector<unsigned int> targetIndices(meshInfo.indexCnt);
    36. int result = SlimMesh(&targetIndices[0], &oriIndices[0], &oriVertices[0], meshInfo, targetError);
    37. std::cout << "SlimMesh result = " << result << std::endl;
    38. targetIndices.clear();
    39. oriVertices.clear();
    40. oriIndices.clear();
    41. FreeLibrary(hdll);
    42. return 0;
    43. }