Como acessar arquivos no Hololens objeto 3D Pasta e obtê-lo para a aplicação em tempo de execução

0

Pergunta

Eu estive procurando por um SDK que pode acessar a pasta interna (modelo 3D pasta) do HoloLens e carregá-lo em um aplicativo em execução e já tentei um monte de links sem sucesso. Alguém pode ajudar-nos a resolver este problema?

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

Melhor resposta

0

Sua pergunta é muito ampla, mas para ser honesto UWP é um assunto complicado. Eu estou escrevendo isso no meu telefone, mas apesar de eu espero que ele ajuda você a começar.


Primeiro de tudo: O Hololens usa UWP.

Para fazer o arquivo de e / s no UWP aplicativos que você precisa para usar um especial c# API que funciona apenas assíncronas! De modo a familiarizar-se com este conceito e o de palavras-chave async, await e Task antes de começar!

Além disso, note que a maioria dos Unity API pode ser usada somente na Unidade principal linha! Portanto, você vai precisar de uma turma dedicada que permite receber assíncrona Actions e despachá-los para a próxima Unidade thread principal Update chamada através de um ConcurrentQueue como e.

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

Agora, este disse que são a maioria, provavelmente, olhando para Windows.Storage.KnownFolders.Objects3D o que é um Windows.Storage.StorageFolder.

Aqui você irá usar GetFileAsync a fim de obter um Windows.Storage.StorageFile.

Em seguida, você usar Windows.Storage.FileIO.ReadBufferAsync para ler o conteúdo desse arquivo em um IBuffer.

E, finalmente, você pode usar ToArray a fim de obter matérias byte[] de fora.

Depois de tudo isso, você tem de enviar o resultado de volta para a Unidade thread principal, a fim de ser capaz de usá-lo de lá (ou continuar com o processo de importação no de outra forma assíncrona).

Você pode tentar usar algo como

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

O que você, em seguida, fazer com retornado byte[] é até você! Há muitos carregador de implementações e bibliotecas on-line para os diferentes tipos de arquivo.


Leitura adicional:

2021-11-24 09:34:08

Em outros idiomas

Esta página está em outros idiomas

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