如果您正在使用HOOPS Communicator,您可能想在生成流缓存模型之前利用HOOPS Exchange的高级功能和转换选项。
申请HOOPS试用 HOOPS中文网
如何使用
如您所知,LibConverter是HOOPS Communicator软件包中包含的一个简单的API,converter.exe实际上就是使用这个API。
项目mini_converter是使用该API的良好开端:
HOOPS_Communicator\authoring\converter\example\sample_projects\mini_converter
- 您要实现的工作流程是:
CAD文件——[HOOPS Exchange C API]——PRC ModelFile——[LibConverter]——SCS文件
实现这个工作流程最重要的API是在LibConvert中:
bool Communicator::Importer::Load (void * modelFile )
实施
您需要做的是:
- 初始化HOOPS Exchange C API
- 在PRC缓冲区A3DAsmModelFile*中使用HOOPS Exchange导入CAD文件
- 使用HOOPS Exchange对A3DAsmModelFile*做任何你想做的事情。
- 初始化LibConverter
- 导入PRC缓冲区A3DAsmModelFile*。
- 导出到SCS
要初始化和使用HOOPS Exchange,您可以查看HOOPS Exchange包中的ImportExport示例。
类A3DSDKHOOPSExchangeLoader使API的使用更容易,我们在编程指南1中,展示了如何使用它:
A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY)); A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters CHECK_RET(sHoopsExchangeLoader.Import(sImport));
调用导入函数后,PRC缓冲区将在sHoopsExchangeLoader.m_psModelFile中。
因此,您可以像这样使用以后的LibConverter:
SC_Import_Options importOptions; importer.Load(sHoopsExchangeLoader.m_psModelFile); SC_Export_Options exportOptions; // Export SSC exporter.WriteSC(nullptr, output.c_str(), exportOptions);
样本
使用A3DSDKHOOPSExchangeLoader这种结构隐藏了对API的实际调用,这使得它更简单。但如果你只是做直接调用,那它不适合你,因为它需要更多的包含。
下面是一个示例来演示上述实现:
- 替换:HOOPS_Communicator_2022_XX\authoring\converter\example\sample_projects\mini_converter\mini.cpp中的代码。
- 在额外的include目录中添加HOOPS_Exchange_Publish_2022_XX\include的路径。
- 替换代码中的路径(有需要修改的地方用TODO注释)
#include "libconverter.h" using namespace Communicator; ///TODO: Add the Additional include directory = "[...]/HOOPS_Exchange_Publish_2022_XX\include" #define INITIALIZE_A3D_API #include #include using namespace std; int main(int argc, char* argv[]) { ///TODO: the license variable is not used, you may pass "" as the first argument. ///USAGE: ./mini_converter "" "CAD/FILE/INPUT.CAD" "PATH/TO/SCS.SCS" string input, output; // Obtain the input and output filenames size_t n = 1; // Skip verb if (n < argc) input = argv[n++]; if (n < argc) output = argv[n++]; // Initiliaze HOOPS Exchange ///TODO: REPLACE THE PATH TO BIN\\WIN64_VC140 A3DStatus iRet; if (!A3DSDKLoadLibrary("HOOPS_Exchange_Publish_2022_SP1_U1\\bin\\win64_v140")) return A3D_ERROR; ///TODO: I'm using directly the HOOPS_LICENSE variable defined in hoops_license.h. The license you generate on our developer zone is unified, //that means it works with HOOPS COmmunicator, HOOPS Exchange, LibConverter, etc... A3DLicPutUnifiedLicense(HOOPS_LICENSE); A3DInt32 iMajorVersion = 0, iMinorVersion = 0; iRet = A3DDllGetVersion(&iMajorVersion, &iMinorVersion); if (iRet != A3D_SUCCESS) return iRet; iRet = A3DDllInitialize(A3D_DLL_MAJORVERSION, A3D_DLL_MINORVERSION); if (iRet != A3D_SUCCESS) return iRet; // Import A3DAsmModelFile* m_psModelFile; A3DRWParamsLoadData m_sLoadData; A3D_INITIALIZE_DATA(A3DRWParamsLoadData, m_sLoadData); m_sLoadData.m_sGeneral.m_bReadSolids = true; m_sLoadData.m_sGeneral.m_bReadSurfaces = true; m_sLoadData.m_sGeneral.m_bReadWireframes = true; m_sLoadData.m_sGeneral.m_bReadPmis = true; m_sLoadData.m_sGeneral.m_bReadAttributes = true; m_sLoadData.m_sGeneral.m_bReadHiddenObjects = true; m_sLoadData.m_sGeneral.m_bReadConstructionAndReferences = false; m_sLoadData.m_sGeneral.m_bReadActiveFilter = true; m_sLoadData.m_sGeneral.m_eReadingMode2D3D = kA3DRead_3D; m_sLoadData.m_sGeneral.m_eReadGeomTessMode = kA3DReadGeomAndTess; m_sLoadData.m_sGeneral.m_eDefaultUnit = kA3DUnitUnknown; m_sLoadData.m_sTessellation.m_eTessellationLevelOfDetail = kA3DTessLODMedium; m_sLoadData.m_sAssembly.m_bUseRootDirectory = true; m_sLoadData.m_sMultiEntries.m_bLoadDefault = true; m_sLoadData.m_sPmi.m_bAlwaysSubstituteFont = false; m_sLoadData.m_sPmi.m_pcSubstitutionFont = (char*)"Myriad CAD"; iRet = A3DAsmModelFileLoadFromFile(input.c_str(), &m_sLoadData, &m_psModelFile); if (iRet != A3D_SUCCESS) return iRet; // HERE YOU CAN PROCESS m_psModelFile WITH HOOPS EXCHANGE ADVANCED FUNCTION Converter converter; // License Registration converter.Init(HOOPS_LICENSE); Importer importer; // Import Initialization if (!importer.Init(&converter)) return EXIT_FAILURE; //Import the PRC buffer directly SC_Import_Options importOptions; // Import if (!importer.Load(m_psModelFile)) return EXIT_FAILURE; Exporter exporter; // Export Initialization if (!exporter.Init(&importer)) return EXIT_FAILURE; SC_Export_Options exportOptions; // Export Stream Cache Model //export SCS if (!exporter.WriteSC(nullptr, output.c_str(), exportOptions)) return EXIT_FAILURE; return EXIT_SUCCESS; }
使用该工作流,您可以完全访问m_sLoadData(导入选项)。它比converter.exe包含更多参数。您还可以在导出前对模型进行处理(例如,缝合修复BRep)。
申请HOOPS Exchange试用http://x7pfmmn259623uby.mikecrm.com/l9292M9
7月26日HOOPS Exchange的专场峰会正在报名中,大家可以点击参与学习哦~
点击填写>>>峰会报名表