J'ai été à la recherche d'un kit de développement logiciel qui peut accéder au dossier interne (modèle 3D dossier) de l'HoloLens et de le charger dans une application en cours d'exécution et nous avons essayé beaucoup de liens en vain. Quelqu'un peut-il nous aider à résoudre ce problème?
Votre question est très large, mais pour être honnête UWP est un sujet délicat. Je suis en train de taper ceci sur mon téléphone, mais j'espère que cela vous aide à obtenir commencé.
Tout d'abord: Le Hololens utilise UWP
.
Pour faire des e / s de fichier dans UWP
applications que vous devez utiliser une API c# qui ne fonctionne que asynchrone! Afin de se familiariser avec ce concept et les mots clés async
, await
et Task
avant de commencer!
Notons en outre que la plupart de l'Unité de l'API peut être utilisé sur l'Unité principale de fil! Par conséquent, vous aurez besoin d'une classe dédiée qui permet de recevoir asynchrone Action
s et de les acheminer dans la prochaine Unité thread principal Update
appel via un ConcurrentQueue
comme par exemple
using System;
using System.Collections.Concurrent;
using UnityEngine;
public class MainThreadDispatcher : MonoBehaviour
{
private static MainThreadDispatcher _instance;
public static MainThreadDispatcher Instance
{
get
{
if (_instance) return _instance;
_instance = FindObjectOfType<MainThreadDispatcher>();
if (_instance) return _instance;
_instance = new GameObject(nameof(MainThreadDispatcher)).AddComponent<MainThreadDispatcher>();
return _instance;
}
}
private readonly ConcurrentQueue<Action> _actions = new ConcurrentQueue<Action>();
private void Awake()
{
if (_instance && _instance != this)
{
Destroy(gameObject);
return;
}
_instance = this;
DontDestroyOnLoad(gameObject);
}
public void DoInMainThread(Action action)
{
_actions.Enqueue(action);
}
private void Update()
{
while (_actions.TryDequeue(out var action))
{
action?.Invoke();
}
}
}
Maintenant, cela dit, vous êtes probablement à la recherche d' Windows.Storage.KnownFolders.Objects3D
qui est un Windows.Storage.StorageFolder
.
Ici vous allez utiliser GetFileAsync
afin d'obtenir un Windows.Storage.StorageFile
.
Ensuite, vous utilisez Windows.Storage.FileIO.ReadBufferAsync
afin de lire le contenu de ce fichier dans un IBuffer
.
Et enfin, vous pouvez utiliser ToArray
afin d'obtenir le raw byte[]
en dehors de ça.
Après tout ce que vous avez à envoyer le résultat dans l'Unité thread principal afin d'être capable de l'utiliser (ou de continuer avec le processus d'importation dans une autre façon asynchrone).
Vous pouvez essayer et utiliser quelque chose comme
using System;
using System.IO;
using System.Threading.Tasks;
#if WINDOWS_UWP // We only have these namespaces if on an UWP device
using Windows.Storage;
using System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions;
#endif
public static class Example
{
// Instead of directly returning byte[] you will need to use a callback
public static void GetFileContent(string filePath, Action<byte[]> onSuccess)
{
Task.Run(async () => await FileLoadingTask(filePath, onSuccess));
}
private static async Task FileLoadingTask(string filePath, Action<byte[]> onSuccess)
{
#if WINDOWS_UWP
// Get the 3D Objects folder
var folder = Windows.Storage.KnownFolders.Objects3D;
// get a file within it
var file = await folder.GetFileAsync(filePath);
// read the content into a buffer
var buffer = await Windows.Storage.FileIO.ReadBufferAsync(file);
// get a raw byte[]
var bytes = buffer.ToArray();
#else
// as a fallback and for testing in the Editor use he normal FileIO
var folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "3D Objects");
var fullFilePath = Path.Combine(folderPath, filePath);
var bytes = await File.ReadAllBytesAsync(fullFilePath);
#endif
// finally dispatch the callback action into the Unity main thread
MainThreadDispatcher.Instance.DoInMainThread(() => onSuccess?.Invoke(bytes));
}
}
Ce qui vous a ensuite retournés byte[]
est à vous! Il y a beaucoup de chargeur de mise en œuvre et les bibliothèques en ligne pour les différents types de fichiers.
Pour en savoir plus: