合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
离线简模插件方便开发者对模型网格数据进行简化处理,支持处理具有顶点和索引信息的模型。
您只要预制好顶点和索引的数据以及长度信息,设置好简模比例和容错率,调用简模算法库就可以方便地获取到简模后的模型索引信息。简模插件操作便捷高效,具体集成请参见开发步骤章节。
- cmake_minimum_required(VERSION 3.0)
- project(main)
- set(CMAKE_CXX_STANDARD 11)
- link_directories("${CMAKE_CURRENT_SOURCE_DIR}/lib")
- add_executable(main main.cpp)
- target_link_libraries( main
- PUBLIC)
- #include <iostream>
- #include <Windows.h>
- #include <vector>
-
- // MeshInfo Struct
- struct MeshInfo {
- unsigned int vertexCnt;
- unsigned int vertexStride;
- unsigned int indexCnt;
- unsigned int targetIndexCnt;
- };
-
- // SlimMesh API
- typedef unsigned int (*SlimMeshFUN)(unsigned int *, const unsigned int *, const float *, MeshInfo, float);
-
- int main()
- {
- // Make Meshinfo and Call SlimMesh API
- const unsigned int VERTEX_ELEMENT_CNT = 3;
- const unsigned int EXPECT_INDEX_CNT = 6;
- std::vector<float> oriVertices = { 0, 0, 0, 1, 0, 0, 2, 0, 0, 0.5f, 1, 0, 1.5f, 1, 0 };
- std::vector<unsigned int> oriIndices = { 0, 1, 3, 3, 1, 4, 1, 2, 4 };
- SlimMeshFUN SlimMesh;
- HINSTANCE hdll;
- // 选择SlimMesh.dll的文件路径。
- hdll = LoadLibrary("../SlimMesh.dll");
- if (hdll == NULL) {
- std::cout << "cannot locate the SlimMesh.dll file" << std::endl;
- return -1;
- }
- SlimMesh = (SlimMeshFUN)GetProcAddress(hdll, "SlimMesh");
- MeshInfo meshInfo;
- meshInfo.indexCnt = static_cast<unsigned int>(oriIndices.size());
- meshInfo.vertexCnt = static_cast<unsigned int>(oriVertices.size()) / VERTEX_ELEMENT_CNT;
- meshInfo.vertexStride = sizeof(float) * VERTEX_ELEMENT_CNT;
- meshInfo.targetIndexCnt = EXPECT_INDEX_CNT;
- float targetError = 1e-2f;
- std::vector<unsigned int> targetIndices(meshInfo.indexCnt);
- int result = SlimMesh(&targetIndices[0], &oriIndices[0], &oriVertices[0], meshInfo, targetError);
- std::cout << "SlimMesh result = " << result << std::endl;
- targetIndices.clear();
- oriVertices.clear();
- oriIndices.clear();
- FreeLibrary(hdll);
- return 0;
- }