Cómo acceder a los archivos en el Hololens 3D Carpeta de objetos y llegar a la apllication en tiempo de ejecución

0

Pregunta

He estado buscando un SDK que pueden acceder al interior de la carpeta (modelo 3D de la carpeta) de la HoloLens y lo carga en la ejecución de la aplicación y hemos probado un montón de enlaces en vano. ¿Alguien puede ayudarnos a resolver este problema?

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

Mejor respuesta

0

Tu pregunta es muy amplia, pero para ser honesto UWP es un tema difícil. Estoy escribiendo esto en mi teléfono, pero aunque tengo la esperanza de que le ayuda a empezar.


Primero de todo: El Hololens utiliza UWP.

Para hacer e / s de archivos en UWP aplicaciones que usted necesita para hacer uso de un API de c# que sólo funciona asincrónica! Para familiarizarse con este concepto y de las palabras clave async, await y Task antes de comenzar!

Nota además de que la mayoría de la Unidad de la API sólo puede ser utilizado en la Unidad principal hilo! Por lo tanto, usted tendrá una clase dedicada que permite recibir asincrónica Actions y enviarlos a la siguiente Unidad hilo principal Update llamar a través de un ConcurrentQueue como por ejemplo,

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

Ahora, este dijo que es más probable que buscando Windows.Storage.KnownFolders.Objects3D que es un Windows.Storage.StorageFolder.

Aquí usted va a utilizar GetFileAsync con el fin de obtener un Windows.Storage.StorageFile.

A continuación, utilice Windows.Storage.FileIO.ReadBufferAsync para leer el contenido de este archivo en un IBuffer.

Y, finalmente, puede utilizar ToArray con el fin de conseguir la raw byte[] fuera de él.

Después de todo esto, tienes que enviar el resultado en la Unidad principal hilo con el fin de ser capaz de utilizar de allí (o continuar con el proceso de importación de otra manera asíncrona).

Usted puede intentar 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));
    }
}

Qué hacer entonces con el vuelto byte[] es hasta usted! Hay muchos cargador de implementaciones y bibliotecas en línea para los diferentes tipos de archivo.


Leer más:

2021-11-24 09:34:08

En otros idiomas

Esta página está en otros idiomas

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