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::GetVertexCount(_Out_ DWORD * pnVertexCount) { try { if (!pnVertexCount) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CMesh * pMesh = getMesh(); __NMRASSERT(pMesh); *pnVertexCount = pMesh->getNodeCount(); return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
LIB3MFMETHODIMP CCOMModelMeshObject::GetVertices(_Out_ MODELMESHVERTEX * pVertices, _In_ DWORD nBufferSize, _Out_opt_ DWORD * pnVertexCount) { UINT j, nIndex; try { if (!pVertices) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CMesh * pMesh = getMesh(); __NMRASSERT(pMesh); // Check Buffer size UINT nNodeCount = pMesh->getNodeCount(); if (pnVertexCount) *pnVertexCount = nNodeCount; if (nBufferSize < nNodeCount) throw CNMRException(NMR_ERROR_INVALIDBUFFERSIZE); MODELMESHVERTEX * pVertex = pVertices; for (nIndex = 0; nIndex < nNodeCount; nIndex++) { // retrieve node and return position MESHNODE * pNode = pMesh->getNode(nIndex); for (j = 0; j < 3; j++) pVertex->m_fPosition[j] = pNode->m_position.m_fields[j]; pVertex++; } return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }