LIB3MFMETHODIMP CCOMModelMeshObject::GetTriangleCount(_Out_ DWORD * pnTriangleCount)
	{
		try {
			if (!pnTriangleCount)
				throw CNMRException(NMR_ERROR_INVALIDPOINTER);

			CMesh * pMesh = getMesh();
			__NMRASSERT(pMesh);

			*pnTriangleCount = pMesh->getFaceCount();
			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();
		}
	}