-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #361 from Netherlands3D/bugfix/obj-in-project
Bugfix/obj in project
- Loading branch information
Showing
5 changed files
with
150 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
Assets/_Functionalities/ObjImporter/Scripts/OBJParseQueue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Netherlands3D.Twin.Layers | ||
{ | ||
public class OBJParseQueue : MonoBehaviour | ||
{ | ||
public static OBJParseQueue Instance; | ||
|
||
public static bool IsParsing = false; //todo: the obj parser currently mixes up meshes if multiple are parsed at once. As a quick fix, only parse one at a time. | ||
public static Queue<ObjSpawner> ParseQueue = new(); | ||
public static Coroutine QueueCoroutine; | ||
|
||
private void Awake() | ||
{ | ||
if (Instance != null && Instance != this) | ||
{ | ||
Destroy(gameObject); | ||
return; | ||
} | ||
|
||
Instance = this; | ||
} | ||
|
||
public static void Enqueue(ObjSpawner spawner) | ||
{ | ||
if (spawner == null) return; | ||
|
||
ParseQueue.Enqueue(spawner); | ||
|
||
// Start processing if not already active | ||
if (!IsParsing) | ||
{ | ||
Instance.StartCoroutine(Instance.ProcessQueue()); | ||
} | ||
} | ||
|
||
public static void Remove(ObjSpawner spawner) | ||
{ | ||
if (ParseQueue.Contains(spawner)) | ||
{ | ||
// Rebuild the queue without the removed spawner | ||
var tempQueue = new Queue<ObjSpawner>(); | ||
while (ParseQueue.Count > 0) | ||
{ | ||
var item = ParseQueue.Dequeue(); | ||
if (item != spawner) | ||
{ | ||
tempQueue.Enqueue(item); | ||
} | ||
} | ||
|
||
foreach (var item in tempQueue) | ||
{ | ||
ParseQueue.Enqueue(item); | ||
} | ||
} | ||
} | ||
|
||
private IEnumerator ProcessQueue() | ||
{ | ||
IsParsing = true; | ||
|
||
while (ParseQueue.Count > 0) | ||
{ | ||
ObjSpawner currentSpawner = ParseQueue.Dequeue(); | ||
|
||
// Skip null or destroyed OBJSpawners | ||
if (currentSpawner == null) | ||
{ | ||
continue; | ||
} | ||
|
||
currentSpawner.StartImport(); | ||
|
||
// Wait until the current spawner signals completion | ||
while (!currentSpawner.IsImportComplete) | ||
{ | ||
yield return null; | ||
} | ||
} | ||
|
||
IsParsing = false; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/_Functionalities/ObjImporter/Scripts/OBJParseQueue.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters