Come accedere ai file in Hololens oggetto 3D Cartella e si può scaricare l'applicazione in fase di esecuzione

0

Domanda

Sto cercando un SDK che possono accedere alla cartella interna (modello 3D cartella) del HoloLens e caricare in un applicazione in esecuzione e abbiamo provato un sacco di link senza alcun risultato. Qualcuno può aiutarmi a risolvere questo problema?

3d-model c# hololens internals
2021-11-24 06:35:33
1

Migliore risposta

0

La tua domanda è estremamente ampio, ma ad essere onesti UWP è un soggetto complesso. Sto scrivendo questo sul mio telefono, però, ma spero che ti aiuta a ottenere iniziato.


Prima di tutto: La Hololens usa UWP.

Per fare i / o file in UWP applicazioni è necessario utilizzare una speciale c# API che funziona solo asincrono! In modo da ottenere familiarità con questo concetto e le parole chiave async, await e Task prima di iniziare!

Ulteriore nota che la maggior parte delle Unità di API può essere utilizzata solo su l'Unità principale del thread! Quindi avrete bisogno di una classe dedicata che consente di ricevere asincrona Actions e inviare loro nella prossima Unità thread principale Update chiamata tramite un ConcurrentQueue come ad esempio

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();
        }
    }
}

Ora detto questo si sono probabilmente alla ricerca per Windows.Storage.KnownFolders.Objects3D che è un Windows.Storage.StorageFolder.

Qui potrete utilizzare GetFileAsync al fine di ottenere un Windows.Storage.StorageFile.

Quindi, utilizzare Windows.Storage.FileIO.ReadBufferAsync per leggere il contenuto di questo file in un IBuffer.

E, infine, è possibile utilizzare ToArray al fine di ottenere il raw byte[] al di fuori di esso.

Dopo tutto questo, si dovrà inviare il risultato di nuovo in l'Unità principale del thread in modo da essere in grado di usarlo (o continuare con il processo di importazione in un altro modo asincrono).

Si può provare e usare qualcosa come

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));
    }
}

Quello che poi non restituito byte[] sta a voi! Ci sono molti loader implementazioni e le librerie online per i diversi tipi di file.


Ulteriore lettura:

2021-11-24 09:34:08

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................