/// <summary> /// Update the submeshes corresponding to the single mesh with multiple face classifications into submeshes. /// </summary> /// <param name="meshFilter">The mesh filter for the base mesh with multiple face classifications.</param> void UpdateMesh(MeshFilter meshFilter) { XRMeshSubsystem meshSubsystem = m_MeshManager.subsystem as XRMeshSubsystem; if (meshSubsystem == null) { return; } var meshId = ExtractTrackableId(meshFilter.name); var faceClassifications = meshSubsystem.GetFaceClassifications(meshId, Allocator.Persistent); if (!faceClassifications.IsCreated) { return; } using (faceClassifications) { if (faceClassifications.Length <= 0) { return; } var meshFilters = m_MeshFrackingMap[meshId]; var baseMesh = meshFilter.sharedMesh; for (int i = 0; i < k_NumClassifications; ++i) { var classifiedMeshFilter = meshFilters[i]; if (classifiedMeshFilter != null) { var classifiedMesh = classifiedMeshFilter.mesh; ExtractClassifiedMesh(baseMesh, faceClassifications, (ARMeshClassification)i, classifiedMesh); meshFilters[i].mesh = classifiedMesh; } } } }
/// <summary> /// Break up a single mesh with multiple face classifications into submeshes, each with an unique and uniform mesh /// classification. /// </summary> /// <param name="meshFilter">The mesh filter for the base mesh with multiple face classifications.</param> void BreakupMesh(MeshFilter meshFilter) { XRMeshSubsystem meshSubsystem = m_MeshManager.subsystem as XRMeshSubsystem; if (meshSubsystem == null) { return; } var meshId = ExtractTrackableId(meshFilter.name); var faceClassifications = meshSubsystem.GetFaceClassifications(meshId, Allocator.Persistent); if (!faceClassifications.IsCreated) { return; } using (faceClassifications) { if (faceClassifications.Length <= 0) { return; } Debug.Log("Before faceClassificationsList"); var faceClassificationsList = faceClassifications.Select(classification => allowedClassifications[classification]).ToList(); Debug.Log("After faceClassificationsList"); var parent = meshFilter.transform.parent; MeshFilter[] meshFilters = new MeshFilter[k_NumClassifications]; meshFilters[0] = (m_FloorMeshPrefab == null) ? null : Instantiate(m_FloorMeshPrefab, parent); meshFilters[1] = (m_WallMeshPrefab == null) ? null : Instantiate(m_WallMeshPrefab, parent); meshFilters[2] = (m_TableMeshPrefab == null) ? null : Instantiate(m_TableMeshPrefab, parent); foreach (var entry in meshFilters) { entry.GetComponent <MeshRenderer>().enabled = MeshVisualizationEnabled; } m_MeshFrackingMap[meshId] = meshFilters; Debug.Log("Created meshFilters"); var baseMesh = meshFilter.sharedMesh; for (int i = 0; i < k_NumClassifications; ++i) { var classifiedMeshFilter = meshFilters[i]; if (classifiedMeshFilter == null) { continue; } var classifiedMesh = classifiedMeshFilter.mesh; ExtractClassifiedMesh(baseMesh, faceClassificationsList, allowedClassificationsList[i], classifiedMesh); Debug.Log($"Extracted meshFilters for {allowedClassificationsList[i]}"); meshFilters[i].mesh = classifiedMesh; meshFilters[i].GetComponent <MeshCollider>().sharedMesh = classifiedMesh; } } }