/// <summary> /// Adds mesh info to the map of meshes to generate. /// </summary> /// <param name="info">The mesh info to add.</param> void AddToQueueIfNecessary(MLMeshing.BlockInfo info) { if (meshesToGenerateIDs.Contains(info.ID) || (info.State == MLMeshing.MeshState.Unchanged && meshObjMap.ContainsKey(info.ID))) { return; } meshesToGenerateIDs.Add(info.ID); meshesToGenerate.Enqueue(info); }
/// <summary> /// Requests mesh for mesh infos waiting to be generated. /// </summary> private void ProcessMeshRequests() { #if PLATFORM_LUMIN List <MLMeshing.MeshRequest> meshRequests = new List <MLMeshing.MeshRequest>(); Dictionary <MagicLeapNativeBindings.MLCoordinateFrameUID, MLMeshing.MeshState> blocksPerRequest = new Dictionary <MagicLeapNativeBindings.MLCoordinateFrameUID, MLMeshing.MeshState>(); int currentBatchCount; while (meshesBeingGenerated.Count < MeshQueueSize && meshesToGenerate.Count > 0) { currentBatchCount = 0; while (currentBatchCount < MeshBatchSize && meshesToGenerate.Count > 0) { MLMeshing.BlockInfo info = meshesToGenerate.Dequeue(); if (meshesToGenerateIDs.Contains(info.ID)) { meshRequests.Add(new MLMeshing.MeshRequest() { ID = info.ID, Level = LevelOfDetail }); blocksPerRequest.Add(info.ID, info.State); meshesToGenerateIDs.Remove(info.ID); } ++currentBatchCount; } if (blocksPerRequest.Count == 0) { Debug.LogErrorFormat("Error: MLMeshingBehavior failed to create a new mesh request, disabling script. Reason: Couldn't fill out mesh batch."); enabled = false; return; } MLResult result = MLMeshing.RequestMesh(in meshRequests, out ulong requestHandle, OnMeshRequestResult); if (!result.IsOk) { Debug.LogErrorFormat("Error: MLMeshingBehavior failed to create a new mesh request, disabling script. Reason: {0}", result); enabled = false; return; } meshesBeingGenerated.Add(requestHandle, blocksPerRequest); blocksPerRequest.Clear(); meshRequests.Clear(); } #endif }