void Mesh::loadMeshdata(const std::string& a_Filepath) { Assimp::Importer importer; const auto scene = importer.ReadFile(a_Filepath, aiPostProcessSteps::aiProcess_CalcTangentSpace | aiPostProcessSteps::aiProcess_Triangulate | aiPostProcessSteps::aiProcess_JoinIdenticalVertices | aiPostProcessSteps::aiProcess_SortByPType); auto error = importer.GetErrorString(); auto mesh = scene->mMeshes[0]; m_Vertices.reserve(mesh->mNumVertices); for (auto i = 0u; i < mesh->mNumVertices; i++) { m_Vertices.emplace_back(toXMFloat3(mesh->mVertices[i]), mesh->HasVertexColors(i) ? toXMFloat4(mesh->mColors[0][i]) : XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f), mesh->HasTextureCoords(i) ? toXMFloat2(mesh->mTextureCoords[0][i]) : XMFLOAT2(0.0f, 0.0f)); } m_Indices.reserve(mesh->mNumFaces * 3); for (auto i = 0u; i < mesh->mNumFaces; ++i) { aiFace currentFace = mesh->mFaces[i]; for (auto j = 0u; j < currentFace.mNumIndices; ++j) { m_Indices.push_back(currentFace.mIndices[j]); } } }
int ON_Mesh::GetConnectedComponents( bool bUseVertexConnections, bool bTopologicalConnections, ON_SimpleArray<ON_Mesh*>* components ) const { int i, j, k, kct, facecount = m_F.Count(); ON_SimpleArray<int> SortedFaceArray(facecount); SortedFaceArray.SetCount(facecount); int compct = GetConnectedComponents(bUseVertexConnections, bTopologicalConnections, SortedFaceArray); if (0 == compct || 0 == components) return compct; bool bHasFaceNormals = HasFaceNormals(); bool bHasPrincipalCurvatures = HasPrincipalCurvatures(); bool bHasSurfaceParameters = HasSurfaceParameters(); bool bHasTextureCoordinates = HasTextureCoordinates(); bool bHasVertexColors = HasVertexColors(); bool bHasVertexNormals = HasVertexNormals(); ON_MeshFace newface; newface.vi[0] = -1; newface.vi[1] = -1; newface.vi[2] = -1; newface.vi[3] = -1; ON_SimpleArray<int> vertidxarray(m_V.Count()); vertidxarray.SetCount(m_V.Count()); const ON_3dPoint* pMesh_D = 0; if ( HasDoublePrecisionVertices() ) { if ( m_V.Count() > 0 && HasSynchronizedDoubleAndSinglePrecisionVertices() ) { pMesh_D = DoublePrecisionVertices().Array(); } } ON_3dPointArray bogus_D; for (i=1;compct>=i;i++) { kct = vertidxarray.Count(); for (k=0; kct>k; k++) vertidxarray[k] = -1; ON_Mesh* pNewMesh = new ON_Mesh(); if (0 == pNewMesh) continue; ON_3dPointArray& pNewMesh_D = ( 0 != pMesh_D ) ? pNewMesh->DoublePrecisionVertices() : bogus_D; for (j=0;j<facecount;j++) { if ( i == SortedFaceArray[j] ) { const ON_MeshFace& face = m_F[j]; kct = face.IsTriangle()?3:4; for (k=0; k<kct; k++) { if (-1 != vertidxarray[face.vi[k]]) { newface.vi[k] = vertidxarray[face.vi[k]]; continue; } int newvi; if ( 0 != pMesh_D ) { newvi = pNewMesh_D.Count(); pNewMesh_D.Append(pMesh_D[face.vi[k]]); } else { newvi = pNewMesh->m_V.Count(); pNewMesh->m_V.Append(m_V[face.vi[k]]); } newface.vi[k] = vertidxarray[face.vi[k]] = newvi; if (true == bHasPrincipalCurvatures) pNewMesh->m_K.Append(m_K[face.vi[k]]); if (true == bHasSurfaceParameters) pNewMesh->m_S.Append(m_S[face.vi[k]]); if (true == bHasTextureCoordinates) pNewMesh->m_T.Append(m_T[face.vi[k]]); if (true == bHasVertexColors) pNewMesh->m_C.Append(m_C[face.vi[k]]); if (true == bHasVertexNormals) pNewMesh->m_N.Append(m_N[face.vi[k]]); } if (3 == kct) newface.vi[3] = newface.vi[2]; pNewMesh->m_F.Append(newface); if (true == bHasFaceNormals) pNewMesh->m_FN.Append(m_FN[j]); } } if ( 0 != pMesh_D ) pNewMesh->UpdateSinglePrecisionVertices(); pNewMesh->Compact(); if (0 < pNewMesh->m_F.Count()) components->Append(pNewMesh); else { delete pNewMesh; pNewMesh = 0; } } return compct; }