LIB3MFMETHODIMP CCOMModelMeshObject::SetTriangle(_In_ DWORD nIndex, _In_ MODELMESHTRIANGLE * pTriangle) { UINT j; try { if (!pTriangle) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CMesh * pMesh = getMesh(); __NMRASSERT(pMesh); // Check for input validity UINT nNodeCount = pMesh->getNodeCount(); for (j = 0; j < 3; j++) if (pTriangle->m_nIndices[j] >= nNodeCount) throw CNMRException_Windows(NMR_ERROR_INVALIDINDEX, LIB3MF_INVALIDARG); if ((pTriangle->m_nIndices[0] == pTriangle->m_nIndices[1]) || (pTriangle->m_nIndices[0] == pTriangle->m_nIndices[2]) || (pTriangle->m_nIndices[1] == pTriangle->m_nIndices[2])) throw CNMRException_Windows(NMR_ERROR_INVALIDINDEX, LIB3MF_INVALIDARG); // retrieve node and return position MESHFACE * pFace = pMesh->getFace(nIndex); for (j = 0; j < 3; j++) pFace->m_nodeindices[j] = pTriangle->m_nIndices[j]; return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
LIB3MFMETHODIMP CCOMModelMeshObject::GetTriangle(_In_ DWORD nIndex, _Out_ MODELMESHTRIANGLE * pTriangle) { UINT j; try { if (!pTriangle) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CMesh * pMesh = getMesh(); __NMRASSERT(pMesh); // retrieve node and return position MESHFACE * pFace = pMesh->getFace(nIndex); for (j = 0; j < 3; j++) pTriangle->m_nIndices[j] = pFace->m_nodeindices[j]; return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
LIB3MFMETHODIMP CCOMModelMeshObject::GetTriangleIndices(_Out_ MODELMESHTRIANGLE * pIndices, _In_ DWORD nBufferSize, _Out_opt_ DWORD * pnTriangleCount) { UINT j, nIndex; try { if (!pIndices) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CMesh * pMesh = getMesh(); __NMRASSERT(pMesh); // Check Buffer size UINT nFaceCount = pMesh->getFaceCount(); if (pnTriangleCount) *pnTriangleCount = nFaceCount; if (nBufferSize < nFaceCount) throw CNMRException(NMR_ERROR_INVALIDBUFFERSIZE); MODELMESHTRIANGLE * pTriangle = pIndices; for (nIndex = 0; nIndex < nFaceCount; nIndex++) { // retrieve node and return position MESHFACE * pFace = pMesh->getFace(nIndex); for (j = 0; j < 3; j++) pTriangle->m_nIndices[j] = pFace->m_nodeindices[j]; pTriangle++; } return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }