액세스하는 방법 파일에서 뮤 3D object 폴더를 응용 프로그램 실행 시간

0

질문

내가 찾고 있었어요 SDK 에 액세스할 수 있는 내부 폴더(3D 모델 폴더)의 뮤 로드 프로그램이 실행되 우리가 많이 연결의 소용이 없었습니다. 사람이 도움이 될 수 있습니다 우리에게 이 문제를 해결하는가?

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

최고의 응답

0

당신의 질문은 매우 광범위하지만 정직하게 UWP 는 것은 까다로운 주제입니다. 내가 이것을 타자를 치고 내 전화만 하지만 난 그것은 당신이 시작됩니다.


하 칩 사용 UWP.

을 하기를 위한 파일에 IO UWP 응용 프로그램을 사용할 필요한 특별한 c#API 작동하는 비동기! 그래서 얻을 잘 알고 이 개념과 키워드 async, awaitTask 을 시작하기 전에!

더욱이트는 화합의 API 에서만 사용할 수 있는 통일 주요 실! 따라서 당신은 필요한 전용 클래스에는 사용을 받는 비동기 Actions 고 그들을 파견으로 다음 Unity main 스레드 Update 통화 ConcurrentQueue 예를 들어,같은

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

이제 이 말은 대부분의 아마를 찾고 Windows.Storage.KnownFolders.Objects3DWindows.Storage.StorageFolder.

여기에서 당신이 사용하는 GetFileAsync 를 얻기 위해서 Windows.Storage.StorageFile.

다음 사용 Windows.Storage.FileIO.ReadBufferAsync 을 읽기 위해서는 이 파일의 내용으로 IBuffer.

마지막으로 사용할 수 있는 ToArray 을 얻기 위해서 원 byte[] 니다.

이 모든 후에 당신은 파견 결과로 다시 화합 main 스레드에 할 수있게하기 위해 사용하기(또는 계속된 수입 프로세스에서 또 다른 비동기 방식).

당신이 시도할 수 있습과 같은 것을 사용

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

당신이 무엇을 다음으로 돌아 byte[] 은 당신에게 달려 있습니다! 많은 loader 구현 라이브러리를 위해 온라인으로 다른 파일 형식입니다.


추가 읽기:

2021-11-24 09:34:08

다른 언어로

이 페이지는 다른 언어로되어 있습니다

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