As mentioned in this page Exchange Integration — HOOPS Visualize HPS Documentation 2022.0.0 documentation
You can import multiple models into the same scene graph using HPS::Exchange::ModelFileImportOptionsKit::SetLocation
.
This sample shows how to import multiple models which have different units into the same scene graph and display the model in the correct size.
Instructions
- Import CAD model using HOOPS Exchange API
- Get the unit of
A3DAsmModelFile
usingA3DAsmModelFileGetUnit
- Create a scale matrix from the units to display the model in millimeter
- Import
A3DAsmModelFile
under the existing CADModel in the scene graph withSetLocation
void CHPSView::OnUserCode()
{
A3DAsmModelFile* psModelFile;
A3DRWParamsLoadData sLoadData;
A3D_INITIALIZE_DATA(A3DRWParamsLoadData, sLoadData);
sLoadData.m_sGeneral.m_bReadSolids = true;
sLoadData.m_sGeneral.m_bReadSurfaces = true;
sLoadData.m_sGeneral.m_bReadWireframes = true;
sLoadData.m_sGeneral.m_bReadPmis = true;
sLoadData.m_sGeneral.m_bReadAttributes = true;
sLoadData.m_sGeneral.m_bReadHiddenObjects = true;
sLoadData.m_sGeneral.m_bReadConstructionAndReferences = false;
sLoadData.m_sGeneral.m_bReadActiveFilter = true;
sLoadData.m_sGeneral.m_eReadingMode2D3D = kA3DRead_3D;
sLoadData.m_sGeneral.m_eReadGeomTessMode = kA3DReadGeomAndTess;
sLoadData.m_sGeneral.m_eDefaultUnit = kA3DUnitUnknown;
sLoadData.m_sTessellation.m_eTessellationLevelOfDetail = kA3DTessLODMedium;
sLoadData.m_sAssembly.m_bUseRootDirectory = true;
sLoadData.m_sMultiEntries.m_bLoadDefault = true;
sLoadData.m_sPmi.m_bAlwaysSubstituteFont = false;
sLoadData.m_sPmi.m_pcSubstitutionFont = (char*) “Myriad CAD”;
A3DStatus iRet = A3DAsmModelFileLoadFromFile("file path", &sLoadData, &psModelFile);
A3DDouble dunit = 1.0;
iRet = A3DAsmModelFileGetUnit(psModelFile, &dunit);
HPS::Exchange::CADModel cadmodel = GetDocument()->GetCADModel();
if( cadmodel.Empty()) // for the first loading model
cadmodel = HPS::Exchange::Factory::CreateCADModel();
HPS::ComponentPath comppath;
comppath.PushBack(cadmodel);
try
{
HPS::Exchange::ModelFileImportOptionsKit optionkit = HPS::Exchange::ModelFileImportOptionsKit::GetDefault();
HPS::MatrixKit matrix = HPS::MatrixKit::GetDefault();
matrix.Scale(dunit, dunit, dunit); // Scale the model to millimeter
optionkit.SetLocation(comppath, matric);
HPS::Exchange::ImportNotifier notifier = HPS::Exchange::File::Import(psModelFile, optionkit);
notifier.Wait();
if (GetDocument()->GetCADModel().Empty())
{
HPS::View view = notifier.GetCADModel().ActivateDefaultCapture();
GetCanvas().AttachViewAsLayout(view);
GetDocument()->SetCADModel(notifier.GetCADModel());
}
}
catch (const HPS::IOException& ioe)
{
// handle error
}
}
When using HOOPS Exchange API, you need to include a header file, and load and initialize the Exchange library. Initializing HOOPS Exchange — HOOPS Exchange 2023 documentation