How-to: Combine multiple models with different unit

To combine multiple models which are defined in different unit to a prc file, you can create a product occurrence with scale for A3DAsmProductOccurrenceData::m_pLocation, to display the model in the same unit.

// specify input file
A3DImport sImport1(acSrcFileName1); // model in millimeter
A3DImport sImport2(acSrcFileName2); // model in meter

// specify output file
A3DExport sExport(acDstFileName);

A3DStatus iRet;
A3DAsmModelFileData sModelFileData;

// import #1
iRet = sHoopsExchangeLoader.Import(sImport1);

A3D_INITIALIZE_DATA(A3DAsmModelFileData, sModelFileData);
iRet = A3DAsmModelFileGet(sHoopsExchangeLoader.m_psModelFile, &sModelFileData);

// create instances
A3DAsmProductOccurrence* pInstance1ProductOccurrence = NULL;

A3DAsmProductOccurrenceData sProductOccurrenceData;
A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sProductOccurrenceData);
sProductOccurrenceData.m_ppPOccurrences = sModelFileData.m_ppPOccurrences;
sProductOccurrenceData.m_uiPOccurrencesSize = sModelFileData.m_uiPOccurrencesSize;
A3DAsmProductOccurrenceCreate(&sProductOccurrenceData, &pInstance1ProductOccurrence);

// import #2
iRet = sHoopsExchangeLoader.Import(sImport2);
iRet = A3DAsmModelFileGet(sHoopsExchangeLoader.m_psModelFile, &sModelFileData);

sProductOccurrenceData.m_ppPOccurrences = sModelFileData.m_ppPOccurrences;
sProductOccurrenceData.m_uiPOccurrencesSize = sModelFileData.m_uiPOccurrencesSize;

A3DAsmProductOccurrence* pInstance2ProductOccurrence = NULL;

// Set scale for second model : meter to millimeter 
A3DMiscCartesianTransformationData sTransformationData;
A3D_INITIALIZE_DATA(A3DMiscCartesianTransformationData, sTransformationData);
sTransformationData.m_sOrigin.m_dX = 0.;
sTransformationData.m_sOrigin.m_dY = 0.;
sTransformationData.m_sOrigin.m_dZ = 0.;
sTransformationData.m_sXVector.m_dX = 1.;
sTransformationData.m_sXVector.m_dY = 0.;
sTransformationData.m_sXVector.m_dZ = 0.;
sTransformationData.m_sYVector.m_dX = 0.;
sTransformationData.m_sYVector.m_dY = 1.;
sTransformationData.m_sYVector.m_dZ = 0.;
sTransformationData.m_sScale.m_dX = 1000.;
sTransformationData.m_sScale.m_dY = 1000.;
sTransformationData.m_sScale.m_dZ = 1000.;
A3DMiscCartesianTransformationCreate(&sTransformationData, &sProductOccurrenceData.m_pLocation);

iRet = A3DAsmProductOccurrenceCreate(&sProductOccurrenceData, &pInstance2ProductOccurrence);

// create root product occurrence
A3DAsmProductOccurrence* pRootProductOccurrence = NULL;
A3DAsmProductOccurrenceData sRootProductOccurrenceData;
A3D_INITIALIZE_DATA(A3DAsmProductOccurrenceData, sRootProductOccurrenceData);
sRootProductOccurrenceData.m_uiPOccurrencesSize = 2;
sRootProductOccurrenceData.m_ppPOccurrences = (A3DAsmProductOccurrence**)
malloc(sRootProductOccurrenceData.m_uiPOccurrencesSize * A3DUns32(sizeof(A3DAsmProductOccurrence*)));

sRootProductOccurrenceData.m_ppPOccurrences[0] = pInstance1ProductOccurrence;
sRootProductOccurrenceData.m_ppPOccurrences[1] = pInstance2ProductOccurrence;

iRet = A3DAsmProductOccurrenceCreate(&sRootProductOccurrenceData, &pRootProductOccurrence);
free(sRootProductOccurrenceData.m_ppPOccurrences);

// creating a ModelFile
A3DAsmModelFile* pModelFile;
A3DAsmModelFileData sData;
A3D_INITIALIZE_DATA(A3DAsmModelFileData, sData);
sData.m_uiPOccurrencesSize = 1;
sData.m_ppPOccurrences =
		(A3DAsmProductOccurrence**)malloc(sData.m_uiPOccurrencesSize * A3DUns32(sizeof(A3DAsmProductOccurrence*)));
sData.m_ppPOccurrences[0] = pRootProductOccurrence;
sData.m_bUnitFromCAD = true;
sData.m_dUnit = 1.; // millimeters
iRet = A3DAsmModelFileCreate(&sData, &pModelFile);

sHoopsExchangeLoader.m_psModelFile = pModelFile;
iRet = sHoopsExchangeLoader.Export(sExport);
2 Likes